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 "../comedidev.h"
33 #include <linux/ioport.h>
34 #include <linux/delay.h>
38 #define PCM3724_SIZE 16
59 #define CR_B_MODE 0x04
62 #define CR_A_MODE(a) ((a)<<5)
65 /* used to track configured dios */
71 static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
73 unsigned long iobase = arg;
75 /* printk("8255cb %d %d %d %lx\n", dir,port,data,arg); */
77 /* printk("8255 cb outb(%x, %lx)\n", data, iobase+port); */
78 outb(data, iobase + port);
81 inbres = inb(iobase + port);
82 /* printk("8255 cb inb(%lx) = %x\n", iobase+port, inbres); */
87 static int compute_buffer(int config, int devno, struct comedi_subdevice *s)
89 /* 1 in io_bits indicates output */
90 if (s->io_bits & 0x0000ff) {
96 if (s->io_bits & 0x00ff00) {
102 if (s->io_bits & 0xff0000) {
111 static void do_3724_config(struct comedi_device *dev,
112 struct comedi_subdevice *s, int chanspec)
114 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
115 struct comedi_subdevice *s_dio2 = &dev->subdevices[1];
118 unsigned long port_8255_cfg;
123 /* 1 in io_bits indicates output, 1 in config indicates input */
124 if (!(s->io_bits & 0x0000ff))
127 if (!(s->io_bits & 0x00ff00))
130 if (!(s->io_bits & 0xff0000))
133 buffer_config = compute_buffer(0, 0, s_dio1);
134 buffer_config = compute_buffer(buffer_config, 1, s_dio2);
137 port_8255_cfg = dev->iobase + _8255_CR;
139 port_8255_cfg = dev->iobase + SIZE_8255 + _8255_CR;
141 outb(buffer_config, dev->iobase + 8); /* update buffer register */
142 /* printk("pcm3724 buffer_config (%lx) %d, %x\n",
143 dev->iobase + _8255_CR, chanspec, buffer_config); */
145 outb(config, port_8255_cfg);
148 static void enable_chan(struct comedi_device *dev, struct comedi_subdevice *s,
151 struct priv_pcm3724 *priv = dev->private;
152 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
158 mask = 1 << CR_CHAN(chanspec);
164 if (priv->dio_1 & 0xff0000)
167 if (priv->dio_1 & 0xff00)
170 if (priv->dio_1 & 0xff)
173 if (priv->dio_2 & 0xff0000)
176 if (priv->dio_2 & 0xff00)
179 if (priv->dio_2 & 0xff)
182 /* printk("gate control %x\n", gatecfg); */
183 outb(gatecfg, dev->iobase + 9);
186 /* overriding the 8255 insn config */
187 static int subdev_3724_insn_config(struct comedi_device *dev,
188 struct comedi_subdevice *s,
189 struct comedi_insn *insn, unsigned int *data)
194 mask = 1 << CR_CHAN(insn->chanspec);
197 else if (mask & 0x00ff00)
199 else if (mask & 0x0f0000)
205 case INSN_CONFIG_DIO_INPUT:
208 case INSN_CONFIG_DIO_OUTPUT:
211 case INSN_CONFIG_DIO_QUERY:
212 data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT;
219 do_3724_config(dev, s, insn->chanspec);
220 enable_chan(dev, s, insn->chanspec);
224 static int pcm3724_attach(struct comedi_device *dev,
225 struct comedi_devconfig *it)
227 struct priv_pcm3724 *priv;
228 struct comedi_subdevice *s;
231 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
236 ret = comedi_request_region(dev, it->options[0], PCM3724_SIZE);
240 ret = comedi_alloc_subdevices(dev, 2);
244 for (i = 0; i < dev->n_subdevices; i++) {
245 s = &dev->subdevices[i];
246 subdev_8255_init(dev, s, subdev_8255_cb,
247 (unsigned long)(dev->iobase + SIZE_8255 * i));
248 s->insn_config = subdev_3724_insn_config;
253 static void pcm3724_detach(struct comedi_device *dev)
257 for (i = 0; i < dev->n_subdevices; i++)
258 comedi_spriv_free(dev, i);
259 comedi_legacy_detach(dev);
262 static struct comedi_driver pcm3724_driver = {
263 .driver_name = "pcm3724",
264 .module = THIS_MODULE,
265 .attach = pcm3724_attach,
266 .detach = pcm3724_detach,
268 module_comedi_driver(pcm3724_driver);
270 MODULE_AUTHOR("Comedi http://www.comedi.org");
271 MODULE_DESCRIPTION("Comedi low-level driver");
272 MODULE_LICENSE("GPL");