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"
50 /* used to track configured dios */
56 static int compute_buffer(int config, int devno, struct comedi_subdevice *s)
58 /* 1 in io_bits indicates output */
59 if (s->io_bits & 0x0000ff) {
65 if (s->io_bits & 0x00ff00) {
71 if (s->io_bits & 0xff0000) {
80 static void do_3724_config(struct comedi_device *dev,
81 struct comedi_subdevice *s, int chanspec)
83 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
84 struct comedi_subdevice *s_dio2 = &dev->subdevices[1];
87 unsigned long port_8255_cfg;
89 config = I8255_CTRL_CW;
92 /* 1 in io_bits indicates output, 1 in config indicates input */
93 if (!(s->io_bits & 0x0000ff))
94 config |= I8255_CTRL_A_IO;
96 if (!(s->io_bits & 0x00ff00))
97 config |= I8255_CTRL_B_IO;
99 if (!(s->io_bits & 0xff0000))
100 config |= I8255_CTRL_C_HI_IO | I8255_CTRL_C_LO_IO;
102 buffer_config = compute_buffer(0, 0, s_dio1);
103 buffer_config = compute_buffer(buffer_config, 1, s_dio2);
106 port_8255_cfg = dev->iobase + I8255_CTRL_REG;
108 port_8255_cfg = dev->iobase + I8255_SIZE + I8255_CTRL_REG;
110 outb(buffer_config, dev->iobase + 8); /* update buffer register */
112 outb(config, port_8255_cfg);
115 static void enable_chan(struct comedi_device *dev, struct comedi_subdevice *s,
118 struct priv_pcm3724 *priv = dev->private;
119 struct comedi_subdevice *s_dio1 = &dev->subdevices[0];
125 mask = 1 << CR_CHAN(chanspec);
131 if (priv->dio_1 & 0xff0000)
134 if (priv->dio_1 & 0xff00)
137 if (priv->dio_1 & 0xff)
140 if (priv->dio_2 & 0xff0000)
143 if (priv->dio_2 & 0xff00)
146 if (priv->dio_2 & 0xff)
149 outb(gatecfg, dev->iobase + 9);
152 /* overriding the 8255 insn config */
153 static int subdev_3724_insn_config(struct comedi_device *dev,
154 struct comedi_subdevice *s,
155 struct comedi_insn *insn,
158 unsigned int chan = CR_CHAN(insn->chanspec);
171 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
175 do_3724_config(dev, s, insn->chanspec);
176 enable_chan(dev, s, insn->chanspec);
181 static int pcm3724_attach(struct comedi_device *dev,
182 struct comedi_devconfig *it)
184 struct priv_pcm3724 *priv;
185 struct comedi_subdevice *s;
188 priv = comedi_alloc_devpriv(dev, sizeof(*priv));
192 ret = comedi_request_region(dev, it->options[0], 0x10);
196 ret = comedi_alloc_subdevices(dev, 2);
200 for (i = 0; i < dev->n_subdevices; i++) {
201 s = &dev->subdevices[i];
202 ret = subdev_8255_init(dev, s, NULL, i * I8255_SIZE);
205 s->insn_config = subdev_3724_insn_config;
210 static struct comedi_driver pcm3724_driver = {
211 .driver_name = "pcm3724",
212 .module = THIS_MODULE,
213 .attach = pcm3724_attach,
214 .detach = comedi_legacy_detach,
216 module_comedi_driver(pcm3724_driver);
218 MODULE_AUTHOR("Comedi http://www.comedi.org");
219 MODULE_DESCRIPTION("Comedi low-level driver");
220 MODULE_LICENSE("GPL");