2 * comedi/drivers/pcl730.c
3 * Driver for Advantech PCL-730 and clones
9 * Description: Advantech PCL-730 (& compatibles)
10 * Devices: (Advantech) PCL-730 [pcl730]
11 * (ICP) ISO-730 [iso730]
12 * (Adlink) ACL-7130 [acl7130]
13 * (Advantech) PCM-3730 [pcm3730]
14 * (Advantech) PCL-725 [pcl725]
15 * (ICP) P8R8-DIO [p16r16dio]
16 * (Adlink) ACL-7225b [acl7225b]
17 * (ICP) P16R16-DIO [p16r16dio]
18 * (Advantech) PCL-733 [pcl733]
19 * (Advantech) PCL-734 [pcl734]
20 * (Diamond Systems) OPMM-1616-XT [opmm-1616-xt]
21 * (Diamond Systems) PEARL-MM-P [prearl-mm-p]
22 * Author: José Luis Sánchez (jsanchezv@teleline.es)
25 * Configuration options:
28 * Interrupts are not supported.
29 * The ACL-7130 card has an 8254 timer/counter not supported by this driver.
32 #include <linux/module.h>
33 #include "../comedidev.h"
38 * The register map varies slightly depending on the board type but
39 * all registers are 8-bit.
41 * The boardinfo 'io_range' is used to allow comedi to request the
42 * proper range required by the board.
44 * The comedi_subdevice 'private' data is used to pass the register
45 * offset to the (*insn_bits) functions to read/write the correct
48 * The basic register mapping looks like this:
50 * BASE+0 Isolated outputs 0-7 (write) / inputs 0-7 (read)
51 * BASE+1 Isolated outputs 8-15 (write) / inputs 8-15 (read)
52 * BASE+2 TTL outputs 0-7 (write) / inputs 0-7 (read)
53 * BASE+3 TTL outputs 8-15 (write) / inputs 8-15 (read)
55 * The pcm3730 board does not have register BASE+1.
57 * The pcl725 and p8r8dio only have registers BASE+0 and BASE+1:
59 * BASE+0 Isolated outputs 0-7 (write) (read back on p8r8dio)
60 * BASE+1 Isolated inputs 0-7 (read)
62 * The acl7225b and p16r16dio boards have this register mapping:
64 * BASE+0 Isolated outputs 0-7 (write) (read back)
65 * BASE+1 Isolated outputs 8-15 (write) (read back)
66 * BASE+2 Isolated inputs 0-7 (read)
67 * BASE+3 Isolated inputs 8-15 (read)
69 * The pcl733 and pcl733 boards have this register mapping:
71 * BASE+0 Isolated outputs 0-7 (write) or inputs 0-7 (read)
72 * BASE+1 Isolated outputs 8-15 (write) or inputs 8-15 (read)
73 * BASE+2 Isolated outputs 16-23 (write) or inputs 16-23 (read)
74 * BASE+3 Isolated outputs 24-31 (write) or inputs 24-31 (read)
76 * The opmm-1616-xt board has this register mapping:
78 * BASE+0 Isolated outputs 0-7 (write) (read back)
79 * BASE+1 Isolated outputs 8-15 (write) (read back)
80 * BASE+2 Isolated inputs 0-7 (read)
81 * BASE+3 Isolated inputs 8-15 (read)
83 * These registers are not currently supported:
85 * BASE+2 Relay select register (write)
86 * BASE+3 Board reset control register (write)
87 * BASE+4 Interrupt control register (write)
88 * BASE+4 Change detect 7-0 status register (read)
89 * BASE+5 LED control register (write)
90 * BASE+5 Change detect 15-8 status register (read)
92 * The pearl-mm-p board has this register mapping:
94 * BASE+0 Isolated outputs 0-7 (write)
95 * BASE+1 Isolated outputs 8-15 (write)
100 unsigned int io_range;
101 unsigned is_pcl725:1;
102 unsigned is_acl7225b:1;
103 unsigned has_readback:1;
104 unsigned has_ttl_io:1;
111 static const struct pcl730_board pcl730_boards[] = {
117 .n_iso_out_chan = 16,
124 .n_iso_out_chan = 16,
132 .n_iso_out_chan = 16,
160 .io_range = 0x08, /* only 4 are used */
164 .n_iso_out_chan = 16,
172 .n_iso_out_chan = 16,
183 .n_iso_out_chan = 32,
185 .name = "opmm-1616-xt",
190 .n_iso_out_chan = 16,
193 .name = "pearl-mm-p",
196 .n_iso_out_chan = 16,
200 static int pcl730_do_insn_bits(struct comedi_device *dev,
201 struct comedi_subdevice *s,
202 struct comedi_insn *insn,
205 unsigned long reg = (unsigned long)s->private;
208 mask = comedi_dio_update_state(s, data);
211 outb(s->state & 0xff, dev->iobase + reg);
212 if ((mask & 0xff00) && (s->n_chan > 8))
213 outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
214 if ((mask & 0xff0000) && (s->n_chan > 16))
215 outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
216 if ((mask & 0xff000000) && (s->n_chan > 24))
217 outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
225 static unsigned int pcl730_get_bits(struct comedi_device *dev,
226 struct comedi_subdevice *s)
228 unsigned long reg = (unsigned long)s->private;
231 val = inb(dev->iobase + reg);
233 val |= (inb(dev->iobase + reg + 1) << 8);
235 val |= (inb(dev->iobase + reg + 2) << 16);
237 val |= (inb(dev->iobase + reg + 3) << 24);
242 static int pcl730_di_insn_bits(struct comedi_device *dev,
243 struct comedi_subdevice *s,
244 struct comedi_insn *insn,
247 data[1] = pcl730_get_bits(dev, s);
252 static int pcl730_attach(struct comedi_device *dev,
253 struct comedi_devconfig *it)
255 const struct pcl730_board *board = comedi_board(dev);
256 struct comedi_subdevice *s;
260 ret = comedi_request_region(dev, it->options[0], board->io_range);
264 ret = comedi_alloc_subdevices(dev, board->n_subdevs);
270 if (board->n_iso_out_chan) {
271 /* Isolated Digital Outputs */
272 s = &dev->subdevices[subdev++];
273 s->type = COMEDI_SUBD_DO;
274 s->subdev_flags = SDF_WRITABLE;
275 s->n_chan = board->n_iso_out_chan;
277 s->range_table = &range_digital;
278 s->insn_bits = pcl730_do_insn_bits;
279 s->private = (void *)0;
281 /* get the initial state if supported */
282 if (board->has_readback)
283 s->state = pcl730_get_bits(dev, s);
286 if (board->n_iso_in_chan) {
287 /* Isolated Digital Inputs */
288 s = &dev->subdevices[subdev++];
289 s->type = COMEDI_SUBD_DI;
290 s->subdev_flags = SDF_READABLE;
291 s->n_chan = board->n_iso_in_chan;
293 s->range_table = &range_digital;
294 s->insn_bits = pcl730_di_insn_bits;
295 s->private = board->is_acl7225b ? (void *)2 :
296 board->is_pcl725 ? (void *)1 : (void *)0;
299 if (board->has_ttl_io) {
300 /* TTL Digital Outputs */
301 s = &dev->subdevices[subdev++];
302 s->type = COMEDI_SUBD_DO;
303 s->subdev_flags = SDF_WRITABLE;
304 s->n_chan = board->n_ttl_chan;
306 s->range_table = &range_digital;
307 s->insn_bits = pcl730_do_insn_bits;
308 s->private = (void *)2;
310 /* TTL Digital Inputs */
311 s = &dev->subdevices[subdev++];
312 s->type = COMEDI_SUBD_DI;
313 s->subdev_flags = SDF_READABLE;
314 s->n_chan = board->n_ttl_chan;
316 s->range_table = &range_digital;
317 s->insn_bits = pcl730_di_insn_bits;
318 s->private = (void *)2;
324 static struct comedi_driver pcl730_driver = {
325 .driver_name = "pcl730",
326 .module = THIS_MODULE,
327 .attach = pcl730_attach,
328 .detach = comedi_legacy_detach,
329 .board_name = &pcl730_boards[0].name,
330 .num_names = ARRAY_SIZE(pcl730_boards),
331 .offset = sizeof(struct pcl730_board),
333 module_comedi_driver(pcl730_driver);
335 MODULE_AUTHOR("Comedi http://www.comedi.org");
336 MODULE_DESCRIPTION("Comedi low-level driver");
337 MODULE_LICENSE("GPL");