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_AO_MSB_REG(x) (0x00 + ((x) * 2))
71 #define PCL726_AO_LSB_REG(x) (0x01 + ((x) * 2))
72 #define PCL726_DO_MSB_REG 0x0c
73 #define PCL726_DO_LSB_REG 0x0d
74 #define PCL726_DI_MSB_REG 0x0e
75 #define PCL726_DI_LSB_REG 0x0f
77 #define PCL727_DI_MSB_REG 0x00
78 #define PCL727_DI_LSB_REG 0x01
79 #define PCL727_DO_MSB_REG 0x18
80 #define PCL727_DO_LSB_REG 0x19
82 static const struct comedi_lrange *const rangelist_726[] = {
91 static const struct comedi_lrange *const rangelist_727[] = {
98 static const struct comedi_lrange *const rangelist_728[] = {
107 struct pcl726_board {
109 unsigned long io_len;
110 unsigned int irq_mask;
112 unsigned int have_dio:1;
113 unsigned int is_pcl727:1;
114 const struct comedi_lrange *const *ao_ranges;
118 static const struct pcl726_board boardtypes[] = {
124 .ao_ranges = &rangelist_726[0],
125 .ao_num_ranges = ARRAY_SIZE(rangelist_726),
132 .ao_ranges = &rangelist_727[0],
133 .ao_num_ranges = ARRAY_SIZE(rangelist_727),
138 .ao_num_ranges = ARRAY_SIZE(rangelist_728),
139 .ao_ranges = &rangelist_728[0],
146 .ao_num_ranges = ARRAY_SIZE(rangelist_726),
147 .ao_ranges = &rangelist_726[0],
152 .ao_num_ranges = ARRAY_SIZE(rangelist_728),
153 .ao_ranges = &rangelist_728[0],
157 struct pcl726_private {
158 const struct comedi_lrange *rangelist[12];
159 unsigned int ao_readback[12];
162 static irqreturn_t pcl818_interrupt(int irq, void *d)
167 static int pcl726_ao_insn_write(struct comedi_device *dev,
168 struct comedi_subdevice *s,
169 struct comedi_insn *insn,
172 struct pcl726_private *devpriv = dev->private;
173 unsigned int chan = CR_CHAN(insn->chanspec);
174 unsigned int range = CR_RANGE(insn->chanspec);
178 for (i = 0; i < insn->n; i++) {
180 devpriv->ao_readback[chan] = val;
182 /* bipolar data to the DAC is two's complement */
183 if (comedi_chan_range_is_bipolar(s, chan, range))
184 val = comedi_offset_munge(s, val);
186 /* order is important, MSB then LSB */
187 outb((val >> 8) & 0xff, dev->iobase + PCL726_AO_MSB_REG(chan));
188 outb(val & 0xff, dev->iobase + PCL726_AO_LSB_REG(chan));
194 static int pcl726_ao_insn_read(struct comedi_device *dev,
195 struct comedi_subdevice *s,
196 struct comedi_insn *insn,
199 struct pcl726_private *devpriv = dev->private;
200 unsigned int chan = CR_CHAN(insn->chanspec);
203 for (i = 0; i < insn->n; i++)
204 data[i] = devpriv->ao_readback[chan];
209 static int pcl726_di_insn_bits(struct comedi_device *dev,
210 struct comedi_subdevice *s,
211 struct comedi_insn *insn,
214 const struct pcl726_board *board = comedi_board(dev);
217 if (board->is_pcl727) {
218 val = inb(dev->iobase + PCL727_DI_LSB_REG);
219 val |= (inb(dev->iobase + PCL727_DI_MSB_REG) << 8);
221 val = inb(dev->iobase + PCL726_DI_LSB_REG);
222 val |= (inb(dev->iobase + PCL726_DI_MSB_REG) << 8);
230 static int pcl726_do_insn_bits(struct comedi_device *dev,
231 struct comedi_subdevice *s,
232 struct comedi_insn *insn,
235 const struct pcl726_board *board = comedi_board(dev);
236 unsigned long io = dev->iobase;
239 mask = comedi_dio_update_state(s, data);
241 if (board->is_pcl727) {
243 outb(s->state & 0xff, io + PCL727_DO_LSB_REG);
245 outb((s->state >> 8), io + PCL727_DO_MSB_REG);
248 outb(s->state & 0xff, io + PCL726_DO_LSB_REG);
250 outb((s->state >> 8), io + PCL726_DO_MSB_REG);
259 static int pcl726_attach(struct comedi_device *dev,
260 struct comedi_devconfig *it)
262 const struct pcl726_board *board = comedi_board(dev);
263 struct pcl726_private *devpriv;
264 struct comedi_subdevice *s;
268 ret = comedi_request_region(dev, it->options[0], board->io_len);
272 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
277 * Hook up the external trigger source interrupt only if the
278 * user config option is valid and the board supports interrupts.
280 if (it->options[1] && (board->irq_mask & (1 << it->options[1]))) {
281 ret = request_irq(it->options[1], pcl818_interrupt, 0,
282 dev->board_name, dev);
284 /* External trigger source is from Pin-17 of CN3 */
285 dev->irq = it->options[1];
289 /* setup the per-channel analog output range_table_list */
290 for (i = 0; i < 12; i++) {
291 unsigned int opt = it->options[2 + i];
293 if (opt < board->ao_num_ranges && i < board->n_aochan)
294 devpriv->rangelist[i] = board->ao_ranges[opt];
296 devpriv->rangelist[i] = &range_unknown;
299 ret = comedi_alloc_subdevices(dev, board->have_dio ? 3 : 1);
303 /* Analog Output subdevice */
304 s = &dev->subdevices[0];
305 s->type = COMEDI_SUBD_AO;
306 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
307 s->n_chan = board->n_aochan;
309 s->range_table_list = devpriv->rangelist;
310 s->insn_write = pcl726_ao_insn_write;
311 s->insn_read = pcl726_ao_insn_read;
313 if (board->have_dio) {
314 /* Digital Input subdevice */
315 s = &dev->subdevices[1];
316 s->type = COMEDI_SUBD_DI;
317 s->subdev_flags = SDF_READABLE;
320 s->insn_bits = pcl726_di_insn_bits;
321 s->range_table = &range_digital;
323 /* Digital Output subdevice */
324 s = &dev->subdevices[2];
325 s->type = COMEDI_SUBD_DO;
326 s->subdev_flags = SDF_WRITABLE;
329 s->insn_bits = pcl726_do_insn_bits;
330 s->range_table = &range_digital;
336 static struct comedi_driver pcl726_driver = {
337 .driver_name = "pcl726",
338 .module = THIS_MODULE,
339 .attach = pcl726_attach,
340 .detach = comedi_legacy_detach,
341 .board_name = &boardtypes[0].name,
342 .num_names = ARRAY_SIZE(boardtypes),
343 .offset = sizeof(struct pcl726_board),
345 module_comedi_driver(pcl726_driver);
347 MODULE_AUTHOR("Comedi http://www.comedi.org");
348 MODULE_DESCRIPTION("Comedi low-level driver");
349 MODULE_LICENSE("GPL");