3 * Driver for MicroAxial ADQ12-B data acquisition and control card
4 * written by jeremy theler <thelerg@ib.cnea.gov.ar>
6 * commission nacional de energia atomica
7 * universidad nacional de cuyo
10 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
26 * Description: Driver for MicroAxial ADQ12-B data acquisition and control card
27 * Devices: [MicroAxial] ADQ12-B (adq12b)
28 * Author: jeremy theler <thelerg@ib.cnea.gov.ar>
29 * Updated: Thu, 21 Feb 2008 02:56:27 -0300
32 * Configuration options:
33 * [0] - I/O base address (set with hardware jumpers)
35 * 0x300 1 (factory default)
41 * [1] - Analog Input unipolar/bipolar selection
42 * selection option JUB
43 * bipolar 0 2-3 (factory default)
45 * [2] - Analog Input single-ended/differential selection
46 * selection option JCHA JCHB
47 * single-ended 0 1-2 1-2 (factory default)
48 * differential 1 2-3 2-3
50 * Driver for the acquisition card ADQ12-B (without any add-on).
52 * - Analog input is subdevice 0 (16 channels single-ended or 8 differential)
53 * - Digital input is subdevice 1 (5 channels)
54 * - Digital output is subdevice 1 (8 channels)
55 * - The PACER is not supported in this version
58 #include <linux/module.h>
59 #include <linux/delay.h>
61 #include "../comedidev.h"
63 /* address scheme (page 2.17 of the manual) */
64 #define ADQ12B_CTREG 0x00
65 #define ADQ12B_CTREG_MSKP BIT(7) /* enable pacer interrupt */
66 #define ADQ12B_CTREG_GTP BIT(6) /* enable pacer */
67 #define ADQ12B_CTREG_RANGE(x) ((x) << 4)
68 #define ADQ12B_CTREG_CHAN(x) ((x) << 0)
69 #define ADQ12B_STINR 0x00
70 #define ADQ12B_STINR_OUT2 BIT(7) /* timer 2 output state */
71 #define ADQ12B_STINR_OUTP BIT(6) /* pacer output state */
72 #define ADQ12B_STINR_EOC BIT(5) /* A/D end-of-conversion */
73 #define ADQ12B_STINR_IN_MASK (0x1f << 0)
74 #define ADQ12B_OUTBR 0x04
75 #define ADQ12B_ADLOW 0x08
76 #define ADQ12B_ADHIG 0x09
77 #define ADQ12B_TIMER_BASE 0x0c
79 /* available ranges through the PGA gains */
80 static const struct comedi_lrange range_adq12b_ai_bipolar = {
89 static const struct comedi_lrange range_adq12b_ai_unipolar = {
98 struct adq12b_private {
99 unsigned int last_ctreg;
102 static int adq12b_ai_eoc(struct comedi_device *dev,
103 struct comedi_subdevice *s,
104 struct comedi_insn *insn,
105 unsigned long context)
107 unsigned char status;
109 status = inb(dev->iobase + ADQ12B_STINR);
110 if (status & ADQ12B_STINR_EOC)
115 static int adq12b_ai_insn_read(struct comedi_device *dev,
116 struct comedi_subdevice *s,
117 struct comedi_insn *insn,
120 struct adq12b_private *devpriv = dev->private;
121 unsigned int chan = CR_CHAN(insn->chanspec);
122 unsigned int range = CR_RANGE(insn->chanspec);
127 /* change channel and range only if it is different from the previous */
128 val = ADQ12B_CTREG_RANGE(range) | ADQ12B_CTREG_CHAN(chan);
129 if (val != devpriv->last_ctreg) {
130 outb(val, dev->iobase + ADQ12B_CTREG);
131 devpriv->last_ctreg = val;
132 usleep_range(50, 100); /* wait for the mux to settle */
135 val = inb(dev->iobase + ADQ12B_ADLOW); /* trigger A/D */
137 for (i = 0; i < insn->n; i++) {
138 ret = comedi_timeout(dev, s, insn, adq12b_ai_eoc, 0);
142 val = inb(dev->iobase + ADQ12B_ADHIG) << 8;
143 val |= inb(dev->iobase + ADQ12B_ADLOW); /* retriggers A/D */
151 static int adq12b_di_insn_bits(struct comedi_device *dev,
152 struct comedi_subdevice *s,
153 struct comedi_insn *insn, unsigned int *data)
155 /* only bits 0-4 have information about digital inputs */
156 data[1] = (inb(dev->iobase + ADQ12B_STINR) & ADQ12B_STINR_IN_MASK);
161 static int adq12b_do_insn_bits(struct comedi_device *dev,
162 struct comedi_subdevice *s,
163 struct comedi_insn *insn,
170 mask = comedi_dio_update_state(s, data);
172 for (chan = 0; chan < 8; chan++) {
173 if ((mask >> chan) & 0x01) {
174 val = (s->state >> chan) & 0x01;
175 outb((val << 3) | chan,
176 dev->iobase + ADQ12B_OUTBR);
186 static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
188 struct adq12b_private *devpriv;
189 struct comedi_subdevice *s;
192 ret = comedi_request_region(dev, it->options[0], 0x10);
196 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
200 devpriv->last_ctreg = -1; /* force ctreg update */
202 ret = comedi_alloc_subdevices(dev, 3);
206 /* Analog Input subdevice */
207 s = &dev->subdevices[0];
208 s->type = COMEDI_SUBD_AI;
209 if (it->options[2]) {
210 s->subdev_flags = SDF_READABLE | SDF_DIFF;
213 s->subdev_flags = SDF_READABLE | SDF_GROUND;
217 s->range_table = it->options[1] ? &range_adq12b_ai_unipolar
218 : &range_adq12b_ai_bipolar;
219 s->insn_read = adq12b_ai_insn_read;
221 /* Digital Input subdevice */
222 s = &dev->subdevices[1];
223 s->type = COMEDI_SUBD_DI;
224 s->subdev_flags = SDF_READABLE;
227 s->range_table = &range_digital;
228 s->insn_bits = adq12b_di_insn_bits;
230 /* Digital Output subdevice */
231 s = &dev->subdevices[2];
232 s->type = COMEDI_SUBD_DO;
233 s->subdev_flags = SDF_WRITABLE;
236 s->range_table = &range_digital;
237 s->insn_bits = adq12b_do_insn_bits;
242 static struct comedi_driver adq12b_driver = {
243 .driver_name = "adq12b",
244 .module = THIS_MODULE,
245 .attach = adq12b_attach,
246 .detach = comedi_legacy_detach,
248 module_comedi_driver(adq12b_driver);
250 MODULE_AUTHOR("Comedi http://www.comedi.org");
251 MODULE_DESCRIPTION("Comedi low-level driver");
252 MODULE_LICENSE("GPL");