2 comedi/drivers/pcm724.c
4 Drew Csillag <drew_csillag@yahoo.com>
6 hardware driver for Advantech card:
15 Description: Advantech PCM-3724
16 Author: Drew Csillag <drew_csillag@yahoo.com>
17 Devices: [Advantech] PCM-3724 (pcm724)
20 This is driver for digital I/O boards PCM-3724 with 48 DIO.
21 It needs 8255.o for operations and only immediate mode is supported.
22 See the source for configuration details.
24 Copy/pasted/hacked from pcm724.c
27 * check_driver overrides:
31 #include <linux/module.h>
32 #include "../comedidev.h"
36 #define PCM3724_SIZE 16
57 #define CR_B_MODE 0x04
60 #define CR_A_MODE(a) ((a)<<5)
63 /* used to track configured dios */
69 static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
71 unsigned long iobase = arg;
73 /* printk("8255cb %d %d %d %lx\n", dir,port,data,arg); */
75 /* printk("8255 cb outb(%x, %lx)\n", data, iobase+port); */
76 outb(data, iobase + port);
79 inbres = inb(iobase + port);
80 /* printk("8255 cb inb(%lx) = %x\n", iobase+port, inbres); */
85 static int compute_buffer(int config, int devno, struct comedi_subdevice *s)
87 /* 1 in io_bits indicates output */
88 if (s->io_bits & 0x0000ff) {
94 if (s->io_bits & 0x00ff00) {
100 if (s->io_bits & 0xff0000) {
109 static void do_3724_config(struct comedi_device *dev,
110 struct comedi_subdevice *s, int chanspec)
112 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
113 struct comedi_subdevice *s_dio2 = &dev->subdevices[1];
116 unsigned long port_8255_cfg;
121 /* 1 in io_bits indicates output, 1 in config indicates input */
122 if (!(s->io_bits & 0x0000ff))
125 if (!(s->io_bits & 0x00ff00))
128 if (!(s->io_bits & 0xff0000))
131 buffer_config = compute_buffer(0, 0, s_dio1);
132 buffer_config = compute_buffer(buffer_config, 1, s_dio2);
135 port_8255_cfg = dev->iobase + _8255_CR;
137 port_8255_cfg = dev->iobase + SIZE_8255 + _8255_CR;
139 outb(buffer_config, dev->iobase + 8); /* update buffer register */
140 /* printk("pcm3724 buffer_config (%lx) %d, %x\n",
141 dev->iobase + _8255_CR, chanspec, buffer_config); */
143 outb(config, port_8255_cfg);
146 static void enable_chan(struct comedi_device *dev, struct comedi_subdevice *s,
149 struct priv_pcm3724 *priv = dev->private;
150 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
156 mask = 1 << CR_CHAN(chanspec);
162 if (priv->dio_1 & 0xff0000)
165 if (priv->dio_1 & 0xff00)
168 if (priv->dio_1 & 0xff)
171 if (priv->dio_2 & 0xff0000)
174 if (priv->dio_2 & 0xff00)
177 if (priv->dio_2 & 0xff)
180 /* printk("gate control %x\n", gatecfg); */
181 outb(gatecfg, dev->iobase + 9);
184 /* overriding the 8255 insn config */
185 static int subdev_3724_insn_config(struct comedi_device *dev,
186 struct comedi_subdevice *s,
187 struct comedi_insn *insn,
190 unsigned int chan = CR_CHAN(insn->chanspec);
203 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
207 do_3724_config(dev, s, insn->chanspec);
208 enable_chan(dev, s, insn->chanspec);
213 static int pcm3724_attach(struct comedi_device *dev,
214 struct comedi_devconfig *it)
216 struct priv_pcm3724 *priv;
217 struct comedi_subdevice *s;
220 priv = comedi_alloc_devpriv(dev, sizeof(*priv));
224 ret = comedi_request_region(dev, it->options[0], PCM3724_SIZE);
228 ret = comedi_alloc_subdevices(dev, 2);
232 for (i = 0; i < dev->n_subdevices; i++) {
233 s = &dev->subdevices[i];
234 subdev_8255_init(dev, s, subdev_8255_cb,
235 (unsigned long)(dev->iobase + SIZE_8255 * i));
236 s->insn_config = subdev_3724_insn_config;
241 static struct comedi_driver pcm3724_driver = {
242 .driver_name = "pcm3724",
243 .module = THIS_MODULE,
244 .attach = pcm3724_attach,
245 .detach = comedi_legacy_detach,
247 module_comedi_driver(pcm3724_driver);
249 MODULE_AUTHOR("Comedi http://www.comedi.org");
250 MODULE_DESCRIPTION("Comedi low-level driver");
251 MODULE_LICENSE("GPL");