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
99 /* available ranges through the PGA gains */
100 static const struct comedi_lrange range_adq12b_ai_bipolar = { 4, {
108 static const struct comedi_lrange range_adq12b_ai_unipolar = { 4, {
117 struct adq12b_private {
118 int unipolar; /* option 2 of comedi_config (1 is iobase) */
119 int differential; /* option 3 of comedi_config */
122 unsigned int digital_state;
126 * "instructions" read/write data in "one-shot" or "software-triggered"
130 static int adq12b_ai_rinsn(struct comedi_device *dev,
131 struct comedi_subdevice *s, struct comedi_insn *insn,
134 struct adq12b_private *devpriv = dev->private;
137 unsigned char hi, lo, status;
139 /* change channel and range only if it is different from the previous */
140 range = CR_RANGE(insn->chanspec);
141 channel = CR_CHAN(insn->chanspec);
142 if (channel != devpriv->last_channel || range != devpriv->last_range) {
143 outb((range << 4) | channel, dev->iobase + ADQ12B_CTREG);
144 udelay(50); /* wait for the mux to settle */
147 /* trigger conversion */
148 status = inb(dev->iobase + ADQ12B_ADLOW);
150 /* convert n samples */
151 for (n = 0; n < insn->n; n++) {
153 /* wait for end of conversion */
157 status = inb(dev->iobase + ADQ12B_STINR);
158 status = status & ADQ12B_EOC;
159 } while (status == 0 && ++i < TIMEOUT);
160 /* } while (++i < 10); */
163 hi = inb(dev->iobase + ADQ12B_ADHIG);
164 lo = inb(dev->iobase + ADQ12B_ADLOW);
166 /* printk("debug: chan=%d range=%d status=%d hi=%d lo=%d\n",
167 channel, range, status, hi, lo); */
168 data[n] = (hi << 8) | lo;
172 /* return the number of samples read/written */
176 static int adq12b_di_insn_bits(struct comedi_device *dev,
177 struct comedi_subdevice *s,
178 struct comedi_insn *insn, unsigned int *data)
181 /* only bits 0-4 have information about digital inputs */
182 data[1] = (inb(dev->iobase + ADQ12B_STINR) & (0x1f));
187 static int adq12b_do_insn_bits(struct comedi_device *dev,
188 struct comedi_subdevice *s,
189 struct comedi_insn *insn, unsigned int *data)
191 struct adq12b_private *devpriv = dev->private;
194 for (channel = 0; channel < 8; channel++)
195 if (((data[0] >> channel) & 0x01) != 0)
196 outb((((data[1] >> channel) & 0x01) << 3) | channel,
197 dev->iobase + ADQ12B_OUTBR);
199 /* store information to retrieve when asked for reading */
201 devpriv->digital_state &= ~data[0];
202 devpriv->digital_state |= (data[0] & data[1]);
205 data[1] = devpriv->digital_state;
210 static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
212 struct adq12b_private *devpriv;
213 struct comedi_subdevice *s;
216 ret = comedi_request_region(dev, it->options[0], ADQ12B_SIZE);
220 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
224 devpriv->unipolar = it->options[1];
225 devpriv->differential = it->options[2];
226 devpriv->digital_state = 0;
228 * initialize channel and range to -1 so we make sure we
229 * always write at least once to the CTREG in the instruction
231 devpriv->last_channel = -1;
232 devpriv->last_range = -1;
234 ret = comedi_alloc_subdevices(dev, 3);
238 s = &dev->subdevices[0];
239 /* analog input subdevice */
240 s->type = COMEDI_SUBD_AI;
241 if (devpriv->differential) {
242 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
245 s->subdev_flags = SDF_READABLE | SDF_GROUND;
249 if (devpriv->unipolar)
250 s->range_table = &range_adq12b_ai_unipolar;
252 s->range_table = &range_adq12b_ai_bipolar;
256 s->len_chanlist = 4; /* This is the maximum chanlist length that
257 the board can handle */
258 s->insn_read = adq12b_ai_rinsn;
260 s = &dev->subdevices[1];
261 /* digital input subdevice */
262 s->type = COMEDI_SUBD_DI;
263 s->subdev_flags = SDF_READABLE;
266 s->range_table = &range_digital;
267 s->insn_bits = adq12b_di_insn_bits;
269 s = &dev->subdevices[2];
270 /* digital output subdevice */
271 s->type = COMEDI_SUBD_DO;
272 s->subdev_flags = SDF_WRITABLE;
275 s->range_table = &range_digital;
276 s->insn_bits = adq12b_do_insn_bits;
281 static struct comedi_driver adq12b_driver = {
282 .driver_name = "adq12b",
283 .module = THIS_MODULE,
284 .attach = adq12b_attach,
285 .detach = comedi_legacy_detach,
287 module_comedi_driver(adq12b_driver);
289 MODULE_AUTHOR("Comedi http://www.comedi.org");
290 MODULE_DESCRIPTION("Comedi low-level driver");
291 MODULE_LICENSE("GPL");