2 comedi/drivers/adq12b.c
3 driver for MicroAxial ADQ12-B data acquisition and control card
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 Description: driver for MicroAxial ADQ12-B data acquisition and control card
21 Devices: [MicroAxial] ADQ12-B (adq12b)
22 Author: jeremy theler <thelerg@ib.cnea.gov.ar>
23 Updated: Thu, 21 Feb 2008 02:56:27 -0300
26 Driver for the acquisition card ADQ12-B (without any add-on).
28 - Analog input is subdevice 0 (16 channels single-ended or 8 differential)
29 - Digital input is subdevice 1 (5 channels)
30 - Digital output is subdevice 1 (8 channels)
31 - The PACER is not supported in this version
33 If you do not specify any options, they will default to
35 # comedi_config /dev/comedi0 adq12b 0x300,0,0
37 option 1: I/O base address. The following table is provided as a help
38 of the hardware jumpers.
41 0x300 1 (factory default)
48 option 2: unipolar/bipolar ADC selection: 0 -> bipolar, 1 -> unipolar
50 selection comedi_config option JUB
51 bipolar 0 2-3 (factory default)
54 option 3: single-ended/differential AI selection: 0 -> SE, 1 -> differential
56 selection comedi_config option JCHA JCHB
57 single-ended 0 1-2 1-2 (factory default)
58 differential 1 2-3 2-3
60 written by jeremy theler <thelerg@ib.cnea.gov.ar>
63 commission nacional de energia atomica
64 universidad nacional de cuyo
68 + changed supported devices string (missused the [] and ())
74 #include <linux/module.h>
75 #include <linux/delay.h>
77 #include "../comedidev.h"
79 /* address scheme (page 2.17 of the manual) */
80 #define ADQ12B_CTREG 0x00
81 #define ADQ12B_CTREG_MSKP (1 << 7) /* enable pacer interrupt */
82 #define ADQ12B_CTREG_GTP (1 << 6) /* enable pacer */
83 #define ADQ12B_CTREG_RANGE(x) ((x) << 4)
84 #define ADQ12B_CTREG_CHAN(x) ((x) << 0)
85 #define ADQ12B_STINR 0x00
86 #define ADQ12B_STINR_OUT2 (1 << 7) /* timer 2 output state */
87 #define ADQ12B_STINR_OUTP (1 << 6) /* pacer output state */
88 #define ADQ12B_STINR_EOC (1 << 5) /* A/D end-of-conversion */
89 #define ADQ12B_STINR_IN_MASK (0x1f << 0)
90 #define ADQ12B_OUTBR 0x04
91 #define ADQ12B_ADLOW 0x08
92 #define ADQ12B_ADHIG 0x09
93 #define ADQ12B_TIMER_BASE 0x0c
95 /* available ranges through the PGA gains */
96 static const struct comedi_lrange range_adq12b_ai_bipolar = {
105 static const struct comedi_lrange range_adq12b_ai_unipolar = {
114 struct adq12b_private {
115 unsigned int last_ctreg;
118 static int adq12b_ai_eoc(struct comedi_device *dev,
119 struct comedi_subdevice *s,
120 struct comedi_insn *insn,
121 unsigned long context)
123 unsigned char status;
125 status = inb(dev->iobase + ADQ12B_STINR);
126 if (status & ADQ12B_STINR_EOC)
131 static int adq12b_ai_insn_read(struct comedi_device *dev,
132 struct comedi_subdevice *s,
133 struct comedi_insn *insn,
136 struct adq12b_private *devpriv = dev->private;
137 unsigned int chan = CR_CHAN(insn->chanspec);
138 unsigned int range = CR_RANGE(insn->chanspec);
143 /* change channel and range only if it is different from the previous */
144 val = ADQ12B_CTREG_RANGE(range) | ADQ12B_CTREG_CHAN(chan);
145 if (val != devpriv->last_ctreg) {
146 outb(val, dev->iobase + ADQ12B_CTREG);
147 devpriv->last_ctreg = val;
148 udelay(50); /* wait for the mux to settle */
151 val = inb(dev->iobase + ADQ12B_ADLOW); /* trigger A/D */
153 for (i = 0; i < insn->n; i++) {
154 ret = comedi_timeout(dev, s, insn, adq12b_ai_eoc, 0);
158 val = inb(dev->iobase + ADQ12B_ADHIG) << 8;
159 val |= inb(dev->iobase + ADQ12B_ADLOW); /* retriggers A/D */
167 static int adq12b_di_insn_bits(struct comedi_device *dev,
168 struct comedi_subdevice *s,
169 struct comedi_insn *insn, unsigned int *data)
171 /* only bits 0-4 have information about digital inputs */
172 data[1] = (inb(dev->iobase + ADQ12B_STINR) & ADQ12B_STINR_IN_MASK);
177 static int adq12b_do_insn_bits(struct comedi_device *dev,
178 struct comedi_subdevice *s,
179 struct comedi_insn *insn,
186 mask = comedi_dio_update_state(s, data);
188 for (chan = 0; chan < 8; chan++) {
189 if ((mask >> chan) & 0x01) {
190 val = (s->state >> chan) & 0x01;
191 outb((val << 3) | chan,
192 dev->iobase + ADQ12B_OUTBR);
202 static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
204 struct adq12b_private *devpriv;
205 struct comedi_subdevice *s;
208 ret = comedi_request_region(dev, it->options[0], 0x10);
212 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
216 devpriv->last_ctreg = -1; /* force ctreg update */
218 ret = comedi_alloc_subdevices(dev, 3);
222 /* Analog Input subdevice */
223 s = &dev->subdevices[0];
224 s->type = COMEDI_SUBD_AI;
225 if (it->options[2]) {
226 s->subdev_flags = SDF_READABLE | SDF_DIFF;
229 s->subdev_flags = SDF_READABLE | SDF_GROUND;
233 s->range_table = it->options[1] ? &range_adq12b_ai_unipolar
234 : &range_adq12b_ai_bipolar;
235 s->insn_read = adq12b_ai_insn_read;
237 /* Digital Input subdevice */
238 s = &dev->subdevices[1];
239 s->type = COMEDI_SUBD_DI;
240 s->subdev_flags = SDF_READABLE;
243 s->range_table = &range_digital;
244 s->insn_bits = adq12b_di_insn_bits;
246 /* Digital Output subdevice */
247 s = &dev->subdevices[2];
248 s->type = COMEDI_SUBD_DO;
249 s->subdev_flags = SDF_WRITABLE;
252 s->range_table = &range_digital;
253 s->insn_bits = adq12b_do_insn_bits;
258 static struct comedi_driver adq12b_driver = {
259 .driver_name = "adq12b",
260 .module = THIS_MODULE,
261 .attach = adq12b_attach,
262 .detach = comedi_legacy_detach,
264 module_comedi_driver(adq12b_driver);
266 MODULE_AUTHOR("Comedi http://www.comedi.org");
267 MODULE_DESCRIPTION("Comedi low-level driver");
268 MODULE_LICENSE("GPL");