2 comedi/drivers/pcl726.c
4 hardware driver for Advantech cards:
5 card: PCL-726, PCL-727, PCL-728
6 driver: pcl726, pcl727, pcl728
8 card: ACL-6126, ACL-6128
9 driver: acl6126, acl6128
11 COMEDI - Linux Control and Measurement Device Interface
12 Copyright (C) 1998 David A. Schleef <ds@schleef.org>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
26 Description: Advantech PCL-726 & compatibles
29 Devices: [Advantech] PCL-726 (pcl726), PCL-727 (pcl727), PCL-728 (pcl728),
30 [ADLink] ACL-6126 (acl6126), ACL-6128 (acl6128)
32 Interrupts are not supported.
36 [2]...[7] - D/A output range for channel 1-6:
37 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V,
38 4: 4-20mA, 5: unknown (external reference)
42 [2]...[13] - D/A output range for channel 1-12:
43 0: 0-5V, 1: 0-10V, 2: +/-5V,
46 Options for PCL-728 and ACL-6128:
48 [2], [3] - D/A output range for channel 1 and 2:
49 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V,
54 [1] - IRQ (0=disable, 3, 5, 6, 7, 9, 10, 11, 12, 15) (currently ignored)
55 [2]...[7] - D/A output range for channel 1-6:
56 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V,
61 Thanks to Circuit Specialists for having programming info (!) on
62 their web page. (http://www.cir.com/)
65 #include <linux/module.h>
66 #include <linux/interrupt.h>
68 #include "../comedidev.h"
70 #define PCL726_SIZE 16
71 #define PCL727_SIZE 32
74 #define PCL726_AO_MSB_REG(x) (0x00 + ((x) * 2))
75 #define PCL726_AO_LSB_REG(x) (0x01 + ((x) * 2))
76 #define PCL726_DO_MSB_REG 0x0c
77 #define PCL726_DO_LSB_REG 0x0d
78 #define PCL726_DI_MSB_REG 0x0e
79 #define PCL726_DI_LSB_REG 0x0f
81 #define PCL727_DI_MSB_REG 0x00
82 #define PCL727_DI_LSB_REG 0x01
83 #define PCL727_DO_MSB_REG 0x18
84 #define PCL727_DO_LSB_REG 0x19
86 static const struct comedi_lrange *const rangelist_726[] = {
95 static const struct comedi_lrange *const rangelist_727[] = {
102 static const struct comedi_lrange *const rangelist_728[] = {
111 struct pcl726_board {
114 unsigned int io_range;
115 unsigned int irq_mask;
116 unsigned int have_dio:1;
117 unsigned int is_pcl727:1;
118 const struct comedi_lrange *const *ao_ranges;
122 static const struct pcl726_board boardtypes[] = {
126 .io_range = PCL726_SIZE,
128 .ao_ranges = &rangelist_726[0],
129 .ao_num_ranges = ARRAY_SIZE(rangelist_726),
133 .io_range = PCL727_SIZE,
136 .ao_ranges = &rangelist_727[0],
137 .ao_num_ranges = ARRAY_SIZE(rangelist_727),
141 .io_range = PCL728_SIZE,
142 .ao_num_ranges = ARRAY_SIZE(rangelist_728),
143 .ao_ranges = &rangelist_728[0],
147 .io_range = PCL726_SIZE,
150 .ao_num_ranges = ARRAY_SIZE(rangelist_726),
151 .ao_ranges = &rangelist_726[0],
155 .io_range = PCL728_SIZE,
156 .ao_num_ranges = ARRAY_SIZE(rangelist_728),
157 .ao_ranges = &rangelist_728[0],
161 struct pcl726_private {
162 const struct comedi_lrange *rangelist[12];
163 unsigned int ao_readback[12];
166 static irqreturn_t pcl818_interrupt(int irq, void *d)
171 static int pcl726_ao_insn_write(struct comedi_device *dev,
172 struct comedi_subdevice *s,
173 struct comedi_insn *insn,
176 struct pcl726_private *devpriv = dev->private;
177 unsigned int chan = CR_CHAN(insn->chanspec);
178 unsigned int range = CR_RANGE(insn->chanspec);
182 for (i = 0; i < insn->n; i++) {
184 devpriv->ao_readback[chan] = val;
186 /* bipolar data to the DAC is two's complement */
187 if (comedi_chan_range_is_bipolar(s, chan, range))
188 val = comedi_offset_munge(s, val);
190 /* order is important, MSB then LSB */
191 outb((val >> 8) & 0xff, dev->iobase + PCL726_AO_MSB_REG(chan));
192 outb(val & 0xff, dev->iobase + PCL726_AO_LSB_REG(chan));
198 static int pcl726_ao_insn_read(struct comedi_device *dev,
199 struct comedi_subdevice *s,
200 struct comedi_insn *insn,
203 struct pcl726_private *devpriv = dev->private;
204 unsigned int chan = CR_CHAN(insn->chanspec);
207 for (i = 0; i < insn->n; i++)
208 data[i] = devpriv->ao_readback[chan];
213 static int pcl726_di_insn_bits(struct comedi_device *dev,
214 struct comedi_subdevice *s,
215 struct comedi_insn *insn,
218 const struct pcl726_board *board = comedi_board(dev);
221 if (board->is_pcl727) {
222 val = inb(dev->iobase + PCL727_DI_LSB_REG);
223 val |= (inb(dev->iobase + PCL727_DI_MSB_REG) << 8);
225 val = inb(dev->iobase + PCL726_DI_LSB_REG);
226 val |= (inb(dev->iobase + PCL726_DI_MSB_REG) << 8);
234 static int pcl726_do_insn_bits(struct comedi_device *dev,
235 struct comedi_subdevice *s,
236 struct comedi_insn *insn,
239 const struct pcl726_board *board = comedi_board(dev);
240 unsigned long io = dev->iobase;
243 mask = comedi_dio_update_state(s, data);
245 if (board->is_pcl727) {
247 outb(s->state & 0xff, io + PCL727_DO_LSB_REG);
249 outb((s->state >> 8), io + PCL727_DO_MSB_REG);
252 outb(s->state & 0xff, io + PCL726_DO_LSB_REG);
254 outb((s->state >> 8), io + PCL726_DO_MSB_REG);
263 static int pcl726_attach(struct comedi_device *dev,
264 struct comedi_devconfig *it)
266 const struct pcl726_board *board = comedi_board(dev);
267 struct pcl726_private *devpriv;
268 struct comedi_subdevice *s;
272 ret = comedi_request_region(dev, it->options[0], board->io_range);
276 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
281 * Hook up the external trigger source interrupt only if the
282 * user config option is valid and the board supports interrupts.
284 if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
285 ret = request_irq(it->options[1], pcl818_interrupt, 0,
286 dev->board_name, dev);
288 /* External trigger source is from Pin-17 of CN3 */
289 dev->irq = it->options[1];
293 /* setup the per-channel analog output range_table_list */
294 for (i = 0; i < 12; i++) {
295 unsigned int opt = it->options[2 + i];
297 if (opt < board->ao_num_ranges && i < board->n_aochan)
298 devpriv->rangelist[i] = board->ao_ranges[opt];
300 devpriv->rangelist[i] = &range_unknown;
303 ret = comedi_alloc_subdevices(dev, board->have_dio ? 3 : 1);
307 /* Analog Output subdevice */
308 s = &dev->subdevices[0];
309 s->type = COMEDI_SUBD_AO;
310 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
311 s->n_chan = board->n_aochan;
313 s->range_table_list = devpriv->rangelist;
314 s->insn_write = pcl726_ao_insn_write;
315 s->insn_read = pcl726_ao_insn_read;
317 if (board->have_dio) {
318 /* Digital Input subdevice */
319 s = &dev->subdevices[1];
320 s->type = COMEDI_SUBD_DI;
321 s->subdev_flags = SDF_READABLE;
324 s->insn_bits = pcl726_di_insn_bits;
325 s->range_table = &range_digital;
327 /* Digital Output subdevice */
328 s = &dev->subdevices[2];
329 s->type = COMEDI_SUBD_DO;
330 s->subdev_flags = SDF_WRITABLE;
333 s->insn_bits = pcl726_do_insn_bits;
334 s->range_table = &range_digital;
340 static struct comedi_driver pcl726_driver = {
341 .driver_name = "pcl726",
342 .module = THIS_MODULE,
343 .attach = pcl726_attach,
344 .detach = comedi_legacy_detach,
345 .board_name = &boardtypes[0].name,
346 .num_names = ARRAY_SIZE(boardtypes),
347 .offset = sizeof(struct pcl726_board),
349 module_comedi_driver(pcl726_driver);
351 MODULE_AUTHOR("Comedi http://www.comedi.org");
352 MODULE_DESCRIPTION("Comedi low-level driver");
353 MODULE_LICENSE("GPL");