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 ())
76 #include <linux/module.h>
77 #include <linux/delay.h>
79 #include "../comedidev.h"
81 /* address scheme (page 2.17 of the manual) */
82 #define ADQ12B_SIZE 16
84 #define ADQ12B_CTREG 0x00
85 #define ADQ12B_STINR 0x00
86 #define ADQ12B_OUTBR 0x04
87 #define ADQ12B_ADLOW 0x08
88 #define ADQ12B_ADHIG 0x09
89 #define ADQ12B_CONT0 0x0c
90 #define ADQ12B_CONT1 0x0d
91 #define ADQ12B_CONT2 0x0e
92 #define ADQ12B_COWORD 0x0f
94 /* mask of the bit at STINR to check end of conversion */
95 #define ADQ12B_EOC 0x20
97 /* available ranges through the PGA gains */
98 static const struct comedi_lrange range_adq12b_ai_bipolar = {
107 static const struct comedi_lrange range_adq12b_ai_unipolar = {
116 struct adq12b_private {
117 int unipolar; /* option 2 of comedi_config (1 is iobase) */
118 int differential; /* option 3 of comedi_config */
123 static int adq12b_ai_eoc(struct comedi_device *dev,
124 struct comedi_subdevice *s,
125 struct comedi_insn *insn,
126 unsigned long context)
128 unsigned char status;
130 status = inb(dev->iobase + ADQ12B_STINR);
131 if (status & ADQ12B_EOC)
136 static int adq12b_ai_rinsn(struct comedi_device *dev,
137 struct comedi_subdevice *s, struct comedi_insn *insn,
140 struct adq12b_private *devpriv = dev->private;
143 unsigned char hi, lo, status;
146 /* change channel and range only if it is different from the previous */
147 range = CR_RANGE(insn->chanspec);
148 channel = CR_CHAN(insn->chanspec);
149 if (channel != devpriv->last_channel || range != devpriv->last_range) {
150 outb((range << 4) | channel, dev->iobase + ADQ12B_CTREG);
151 udelay(50); /* wait for the mux to settle */
154 /* trigger conversion */
155 status = inb(dev->iobase + ADQ12B_ADLOW);
157 /* convert n samples */
158 for (n = 0; n < insn->n; n++) {
160 /* wait for end of conversion */
161 ret = comedi_timeout(dev, s, insn, adq12b_ai_eoc, 0);
166 hi = inb(dev->iobase + ADQ12B_ADHIG);
167 lo = inb(dev->iobase + ADQ12B_ADLOW);
169 data[n] = (hi << 8) | lo;
173 /* return the number of samples read/written */
177 static int adq12b_di_insn_bits(struct comedi_device *dev,
178 struct comedi_subdevice *s,
179 struct comedi_insn *insn, unsigned int *data)
182 /* only bits 0-4 have information about digital inputs */
183 data[1] = (inb(dev->iobase + ADQ12B_STINR) & (0x1f));
188 static int adq12b_do_insn_bits(struct comedi_device *dev,
189 struct comedi_subdevice *s,
190 struct comedi_insn *insn,
197 mask = comedi_dio_update_state(s, data);
199 for (chan = 0; chan < 8; chan++) {
200 if ((mask >> chan) & 0x01) {
201 val = (s->state >> chan) & 0x01;
202 outb((val << 3) | chan,
203 dev->iobase + ADQ12B_OUTBR);
213 static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
215 struct adq12b_private *devpriv;
216 struct comedi_subdevice *s;
219 ret = comedi_request_region(dev, it->options[0], ADQ12B_SIZE);
223 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
227 devpriv->unipolar = it->options[1];
228 devpriv->differential = it->options[2];
230 * initialize channel and range to -1 so we make sure we
231 * always write at least once to the CTREG in the instruction
233 devpriv->last_channel = -1;
234 devpriv->last_range = -1;
236 ret = comedi_alloc_subdevices(dev, 3);
240 s = &dev->subdevices[0];
241 /* analog input subdevice */
242 s->type = COMEDI_SUBD_AI;
243 if (devpriv->differential) {
244 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
247 s->subdev_flags = SDF_READABLE | SDF_GROUND;
251 if (devpriv->unipolar)
252 s->range_table = &range_adq12b_ai_unipolar;
254 s->range_table = &range_adq12b_ai_bipolar;
258 s->len_chanlist = 4; /* This is the maximum chanlist length that
259 the board can handle */
260 s->insn_read = adq12b_ai_rinsn;
262 s = &dev->subdevices[1];
263 /* digital input subdevice */
264 s->type = COMEDI_SUBD_DI;
265 s->subdev_flags = SDF_READABLE;
268 s->range_table = &range_digital;
269 s->insn_bits = adq12b_di_insn_bits;
271 s = &dev->subdevices[2];
272 /* digital output subdevice */
273 s->type = COMEDI_SUBD_DO;
274 s->subdev_flags = SDF_WRITABLE;
277 s->range_table = &range_digital;
278 s->insn_bits = adq12b_do_insn_bits;
283 static struct comedi_driver adq12b_driver = {
284 .driver_name = "adq12b",
285 .module = THIS_MODULE,
286 .attach = adq12b_attach,
287 .detach = comedi_legacy_detach,
289 module_comedi_driver(adq12b_driver);
291 MODULE_AUTHOR("Comedi http://www.comedi.org");
292 MODULE_DESCRIPTION("Comedi low-level driver");
293 MODULE_LICENSE("GPL");