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), PCM-3730 (pcm3730), PCL-725 (pcl725),
11 * PCL-733 (pcl733), PCL-734 (pcl734),
12 * [ADLink] ACL-7130 (acl7130), ACL-7225b (acl7225b),
13 * [ICP] ISO-730 (iso730), P8R8-DIO (p8r8dio), P16R16-DIO (p16r16dio),
14 * [Diamond Systems] OPMM-1616-XT (opmm-1616-xt), PEARL-MM-P (pearl-mm-p),
15 * IR104-PBF (ir104-pbf),
16 * Author: José Luis Sánchez (jsanchezv@teleline.es)
19 * Configuration options:
22 * Interrupts are not supported.
23 * The ACL-7130 card has an 8254 timer/counter not supported by this driver.
26 #include <linux/module.h>
27 #include "../comedidev.h"
32 * The register map varies slightly depending on the board type but
33 * all registers are 8-bit.
35 * The boardinfo 'io_range' is used to allow comedi to request the
36 * proper range required by the board.
38 * The comedi_subdevice 'private' data is used to pass the register
39 * offset to the (*insn_bits) functions to read/write the correct
42 * The basic register mapping looks like this:
44 * BASE+0 Isolated outputs 0-7 (write) / inputs 0-7 (read)
45 * BASE+1 Isolated outputs 8-15 (write) / inputs 8-15 (read)
46 * BASE+2 TTL outputs 0-7 (write) / inputs 0-7 (read)
47 * BASE+3 TTL outputs 8-15 (write) / inputs 8-15 (read)
49 * The pcm3730 board does not have register BASE+1.
51 * The pcl725 and p8r8dio only have registers BASE+0 and BASE+1:
53 * BASE+0 Isolated outputs 0-7 (write) (read back on p8r8dio)
54 * BASE+1 Isolated inputs 0-7 (read)
56 * The acl7225b and p16r16dio boards have this register mapping:
58 * BASE+0 Isolated outputs 0-7 (write) (read back)
59 * BASE+1 Isolated outputs 8-15 (write) (read back)
60 * BASE+2 Isolated inputs 0-7 (read)
61 * BASE+3 Isolated inputs 8-15 (read)
63 * The pcl733 and pcl733 boards have this register mapping:
65 * BASE+0 Isolated outputs 0-7 (write) or inputs 0-7 (read)
66 * BASE+1 Isolated outputs 8-15 (write) or inputs 8-15 (read)
67 * BASE+2 Isolated outputs 16-23 (write) or inputs 16-23 (read)
68 * BASE+3 Isolated outputs 24-31 (write) or inputs 24-31 (read)
70 * The opmm-1616-xt board has this register mapping:
72 * BASE+0 Isolated outputs 0-7 (write) (read back)
73 * BASE+1 Isolated outputs 8-15 (write) (read back)
74 * BASE+2 Isolated inputs 0-7 (read)
75 * BASE+3 Isolated inputs 8-15 (read)
77 * These registers are not currently supported:
79 * BASE+2 Relay select register (write)
80 * BASE+3 Board reset control register (write)
81 * BASE+4 Interrupt control register (write)
82 * BASE+4 Change detect 7-0 status register (read)
83 * BASE+5 LED control register (write)
84 * BASE+5 Change detect 15-8 status register (read)
86 * The pearl-mm-p board has this register mapping:
88 * BASE+0 Isolated outputs 0-7 (write)
89 * BASE+1 Isolated outputs 8-15 (write)
91 * The ir104-pbf board has this register mapping:
93 * BASE+0 Isolated outputs 0-7 (write) (read back)
94 * BASE+1 Isolated outputs 8-15 (write) (read back)
95 * BASE+2 Isolated outputs 16-19 (write) (read back)
96 * BASE+4 Isolated inputs 0-7 (read)
97 * BASE+5 Isolated inputs 8-15 (read)
98 * BASE+6 Isolated inputs 16-19 (read)
101 struct pcl730_board {
103 unsigned int io_range;
104 unsigned is_pcl725:1;
105 unsigned is_acl7225b:1;
107 unsigned has_readback:1;
108 unsigned has_ttl_io:1;
115 static const struct pcl730_board pcl730_boards[] = {
121 .n_iso_out_chan = 16,
128 .n_iso_out_chan = 16,
136 .n_iso_out_chan = 16,
164 .io_range = 0x08, /* only 4 are used */
168 .n_iso_out_chan = 16,
176 .n_iso_out_chan = 16,
187 .n_iso_out_chan = 32,
189 .name = "opmm-1616-xt",
194 .n_iso_out_chan = 16,
197 .name = "pearl-mm-p",
200 .n_iso_out_chan = 16,
206 .n_iso_out_chan = 20,
211 static int pcl730_do_insn_bits(struct comedi_device *dev,
212 struct comedi_subdevice *s,
213 struct comedi_insn *insn,
216 unsigned long reg = (unsigned long)s->private;
219 mask = comedi_dio_update_state(s, data);
222 outb(s->state & 0xff, dev->iobase + reg);
223 if ((mask & 0xff00) && (s->n_chan > 8))
224 outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
225 if ((mask & 0xff0000) && (s->n_chan > 16))
226 outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
227 if ((mask & 0xff000000) && (s->n_chan > 24))
228 outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
236 static unsigned int pcl730_get_bits(struct comedi_device *dev,
237 struct comedi_subdevice *s)
239 unsigned long reg = (unsigned long)s->private;
242 val = inb(dev->iobase + reg);
244 val |= (inb(dev->iobase + reg + 1) << 8);
246 val |= (inb(dev->iobase + reg + 2) << 16);
248 val |= (inb(dev->iobase + reg + 3) << 24);
253 static int pcl730_di_insn_bits(struct comedi_device *dev,
254 struct comedi_subdevice *s,
255 struct comedi_insn *insn,
258 data[1] = pcl730_get_bits(dev, s);
263 static int pcl730_attach(struct comedi_device *dev,
264 struct comedi_devconfig *it)
266 const struct pcl730_board *board = dev->board_ptr;
267 struct comedi_subdevice *s;
271 ret = comedi_request_region(dev, it->options[0], board->io_range);
275 ret = comedi_alloc_subdevices(dev, board->n_subdevs);
281 if (board->n_iso_out_chan) {
282 /* Isolated Digital Outputs */
283 s = &dev->subdevices[subdev++];
284 s->type = COMEDI_SUBD_DO;
285 s->subdev_flags = SDF_WRITABLE;
286 s->n_chan = board->n_iso_out_chan;
288 s->range_table = &range_digital;
289 s->insn_bits = pcl730_do_insn_bits;
290 s->private = (void *)0;
292 /* get the initial state if supported */
293 if (board->has_readback)
294 s->state = pcl730_get_bits(dev, s);
297 if (board->n_iso_in_chan) {
298 /* Isolated Digital Inputs */
299 s = &dev->subdevices[subdev++];
300 s->type = COMEDI_SUBD_DI;
301 s->subdev_flags = SDF_READABLE;
302 s->n_chan = board->n_iso_in_chan;
304 s->range_table = &range_digital;
305 s->insn_bits = pcl730_di_insn_bits;
306 s->private = board->is_ir104 ? (void *)4 :
307 board->is_acl7225b ? (void *)2 :
308 board->is_pcl725 ? (void *)1 : (void *)0;
311 if (board->has_ttl_io) {
312 /* TTL Digital Outputs */
313 s = &dev->subdevices[subdev++];
314 s->type = COMEDI_SUBD_DO;
315 s->subdev_flags = SDF_WRITABLE;
316 s->n_chan = board->n_ttl_chan;
318 s->range_table = &range_digital;
319 s->insn_bits = pcl730_do_insn_bits;
320 s->private = (void *)2;
322 /* TTL Digital Inputs */
323 s = &dev->subdevices[subdev++];
324 s->type = COMEDI_SUBD_DI;
325 s->subdev_flags = SDF_READABLE;
326 s->n_chan = board->n_ttl_chan;
328 s->range_table = &range_digital;
329 s->insn_bits = pcl730_di_insn_bits;
330 s->private = (void *)2;
336 static struct comedi_driver pcl730_driver = {
337 .driver_name = "pcl730",
338 .module = THIS_MODULE,
339 .attach = pcl730_attach,
340 .detach = comedi_legacy_detach,
341 .board_name = &pcl730_boards[0].name,
342 .num_names = ARRAY_SIZE(pcl730_boards),
343 .offset = sizeof(struct pcl730_board),
345 module_comedi_driver(pcl730_driver);
347 MODULE_AUTHOR("Comedi http://www.comedi.org");
348 MODULE_DESCRIPTION("Comedi low-level driver");
349 MODULE_LICENSE("GPL");