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"
56 #define CR_B_MODE 0x04
59 #define CR_A_MODE(a) ((a)<<5)
62 /* used to track configured dios */
68 static int compute_buffer(int config, int devno, struct comedi_subdevice *s)
70 /* 1 in io_bits indicates output */
71 if (s->io_bits & 0x0000ff) {
77 if (s->io_bits & 0x00ff00) {
83 if (s->io_bits & 0xff0000) {
92 static void do_3724_config(struct comedi_device *dev,
93 struct comedi_subdevice *s, int chanspec)
95 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
96 struct comedi_subdevice *s_dio2 = &dev->subdevices[1];
99 unsigned long port_8255_cfg;
104 /* 1 in io_bits indicates output, 1 in config indicates input */
105 if (!(s->io_bits & 0x0000ff))
108 if (!(s->io_bits & 0x00ff00))
111 if (!(s->io_bits & 0xff0000))
114 buffer_config = compute_buffer(0, 0, s_dio1);
115 buffer_config = compute_buffer(buffer_config, 1, s_dio2);
118 port_8255_cfg = dev->iobase + _8255_CR;
120 port_8255_cfg = dev->iobase + SIZE_8255 + _8255_CR;
122 outb(buffer_config, dev->iobase + 8); /* update buffer register */
124 outb(config, port_8255_cfg);
127 static void enable_chan(struct comedi_device *dev, struct comedi_subdevice *s,
130 struct priv_pcm3724 *priv = dev->private;
131 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
137 mask = 1 << CR_CHAN(chanspec);
143 if (priv->dio_1 & 0xff0000)
146 if (priv->dio_1 & 0xff00)
149 if (priv->dio_1 & 0xff)
152 if (priv->dio_2 & 0xff0000)
155 if (priv->dio_2 & 0xff00)
158 if (priv->dio_2 & 0xff)
161 outb(gatecfg, dev->iobase + 9);
164 /* overriding the 8255 insn config */
165 static int subdev_3724_insn_config(struct comedi_device *dev,
166 struct comedi_subdevice *s,
167 struct comedi_insn *insn,
170 unsigned int chan = CR_CHAN(insn->chanspec);
183 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
187 do_3724_config(dev, s, insn->chanspec);
188 enable_chan(dev, s, insn->chanspec);
193 static int pcm3724_attach(struct comedi_device *dev,
194 struct comedi_devconfig *it)
196 struct priv_pcm3724 *priv;
197 struct comedi_subdevice *s;
200 priv = comedi_alloc_devpriv(dev, sizeof(*priv));
204 ret = comedi_request_region(dev, it->options[0], 0x10);
208 ret = comedi_alloc_subdevices(dev, 2);
212 for (i = 0; i < dev->n_subdevices; i++) {
213 s = &dev->subdevices[i];
214 ret = subdev_8255_init(dev, s, NULL,
215 dev->iobase + SIZE_8255 * i);
218 s->insn_config = subdev_3724_insn_config;
223 static struct comedi_driver pcm3724_driver = {
224 .driver_name = "pcm3724",
225 .module = THIS_MODULE,
226 .attach = pcm3724_attach,
227 .detach = comedi_legacy_detach,
229 module_comedi_driver(pcm3724_driver);
231 MODULE_AUTHOR("Comedi http://www.comedi.org");
232 MODULE_DESCRIPTION("Comedi low-level driver");
233 MODULE_LICENSE("GPL");