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 struct pcm3724_board {
66 const char *name; /* driver name */
67 int dio; /* num of DIO */
68 int numofports; /* num of 8255 subdevices */
69 unsigned int IRQbits; /* allowed interrupts */
70 unsigned int io_range; /* len of IO space */
73 /* used to track configured dios */
79 static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
81 unsigned long iobase = arg;
83 /* printk("8255cb %d %d %d %lx\n", dir,port,data,arg); */
85 /* printk("8255 cb outb(%x, %lx)\n", data, iobase+port); */
86 outb(data, iobase + port);
89 inbres = inb(iobase + port);
90 /* printk("8255 cb inb(%lx) = %x\n", iobase+port, inbres); */
95 static int compute_buffer(int config, int devno, struct comedi_subdevice *s)
97 /* 1 in io_bits indicates output */
98 if (s->io_bits & 0x0000ff) {
104 if (s->io_bits & 0x00ff00) {
110 if (s->io_bits & 0xff0000) {
119 static void do_3724_config(struct comedi_device *dev,
120 struct comedi_subdevice *s, int chanspec)
124 unsigned long port_8255_cfg;
129 /* 1 in io_bits indicates output, 1 in config indicates input */
130 if (!(s->io_bits & 0x0000ff))
133 if (!(s->io_bits & 0x00ff00))
136 if (!(s->io_bits & 0xff0000))
139 buffer_config = compute_buffer(0, 0, dev->subdevices);
140 buffer_config = compute_buffer(buffer_config, 1, (dev->subdevices) + 1);
142 if (s == dev->subdevices)
143 port_8255_cfg = dev->iobase + _8255_CR;
145 port_8255_cfg = dev->iobase + SIZE_8255 + _8255_CR;
147 outb(buffer_config, dev->iobase + 8); /* update buffer register */
148 /* printk("pcm3724 buffer_config (%lx) %d, %x\n",
149 dev->iobase + _8255_CR, chanspec, buffer_config); */
151 outb(config, port_8255_cfg);
154 static void enable_chan(struct comedi_device *dev, struct comedi_subdevice *s,
159 struct priv_pcm3724 *priv;
164 mask = 1 << CR_CHAN(chanspec);
165 if (s == dev->subdevices) /* subdev 0 */
170 if (priv->dio_1 & 0xff0000)
173 if (priv->dio_1 & 0xff00)
176 if (priv->dio_1 & 0xff)
179 if (priv->dio_2 & 0xff0000)
182 if (priv->dio_2 & 0xff00)
185 if (priv->dio_2 & 0xff)
188 /* printk("gate control %x\n", gatecfg); */
189 outb(gatecfg, dev->iobase + 9);
192 /* overriding the 8255 insn config */
193 static int subdev_3724_insn_config(struct comedi_device *dev,
194 struct comedi_subdevice *s,
195 struct comedi_insn *insn, unsigned int *data)
200 mask = 1 << CR_CHAN(insn->chanspec);
203 else if (mask & 0x00ff00)
205 else if (mask & 0x0f0000)
211 case INSN_CONFIG_DIO_INPUT:
214 case INSN_CONFIG_DIO_OUTPUT:
217 case INSN_CONFIG_DIO_QUERY:
218 data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT;
225 do_3724_config(dev, s, insn->chanspec);
226 enable_chan(dev, s, insn->chanspec);
230 static int pcm3724_attach(struct comedi_device *dev,
231 struct comedi_devconfig *it)
233 const struct pcm3724_board *board = comedi_board(dev);
234 unsigned long iobase;
235 unsigned int iorange;
236 int ret, i, n_subdevices;
238 iobase = it->options[0];
239 iorange = board->io_range;
241 ret = alloc_private(dev, sizeof(struct priv_pcm3724));
245 ((struct priv_pcm3724 *)(dev->private))->dio_1 = 0;
246 ((struct priv_pcm3724 *)(dev->private))->dio_2 = 0;
248 printk(KERN_INFO "comedi%d: pcm3724: board=%s, 0x%03lx ", dev->minor,
249 board->name, iobase);
250 if (!iobase || !request_region(iobase, iorange, "pcm3724")) {
251 printk("I/O port conflict\n");
255 dev->iobase = iobase;
256 dev->board_name = board->name;
257 printk(KERN_INFO "\n");
259 n_subdevices = board->numofports;
261 ret = comedi_alloc_subdevices(dev, n_subdevices);
265 for (i = 0; i < dev->n_subdevices; i++) {
266 subdev_8255_init(dev, dev->subdevices + i, subdev_8255_cb,
267 (unsigned long)(dev->iobase + SIZE_8255 * i));
268 ((dev->subdevices) + i)->insn_config = subdev_3724_insn_config;
273 static void pcm3724_detach(struct comedi_device *dev)
275 const struct pcm3724_board *board = comedi_board(dev);
278 if (dev->subdevices) {
279 for (i = 0; i < dev->n_subdevices; i++)
280 subdev_8255_cleanup(dev, dev->subdevices + i);
283 release_region(dev->iobase, board->io_range);
286 static const struct pcm3724_board boardtypes[] = {
287 { "pcm3724", 48, 2, 0x00fc, PCM3724_SIZE, },
290 static struct comedi_driver pcm3724_driver = {
291 .driver_name = "pcm3724",
292 .module = THIS_MODULE,
293 .attach = pcm3724_attach,
294 .detach = pcm3724_detach,
295 .board_name = &boardtypes[0].name,
296 .num_names = ARRAY_SIZE(boardtypes),
297 .offset = sizeof(struct pcm3724_board),
299 module_comedi_driver(pcm3724_driver);
301 MODULE_AUTHOR("Comedi http://www.comedi.org");
302 MODULE_DESCRIPTION("Comedi low-level driver");
303 MODULE_LICENSE("GPL");