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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 Description: driver for MicroAxial ADQ12-B data acquisition and control card
26 Devices: [MicroAxial] ADQ12-B (adq12b)
27 Author: jeremy theler <thelerg@ib.cnea.gov.ar>
28 Updated: Thu, 21 Feb 2008 02:56:27 -0300
31 Driver for the acquisition card ADQ12-B (without any add-on).
33 - Analog input is subdevice 0 (16 channels single-ended or 8 differential)
34 - Digital input is subdevice 1 (5 channels)
35 - Digital output is subdevice 1 (8 channels)
36 - The PACER is not supported in this version
38 If you do not specify any options, they will default to
40 # comedi_config /dev/comedi0 adq12b 0x300,0,0
42 option 1: I/O base address. The following table is provided as a help
43 of the hardware jumpers.
46 0x300 1 (factory default)
53 option 2: unipolar/bipolar ADC selection: 0 -> bipolar, 1 -> unipolar
55 selection comedi_config option JUB
56 bipolar 0 2-3 (factory default)
59 option 3: single-ended/differential AI selection: 0 -> SE, 1 -> differential
61 selection comedi_config option JCHA JCHB
62 single-ended 0 1-2 1-2 (factory default)
63 differential 1 2-3 2-3
65 written by jeremy theler <thelerg@ib.cnea.gov.ar>
68 commission nacional de energia atomica
69 universidad nacional de cuyo
73 + changed supported devices string (missused the [] and ())
81 #include "../comedidev.h"
83 /* address scheme (page 2.17 of the manual) */
84 #define ADQ12B_SIZE 16
86 #define ADQ12B_CTREG 0x00
87 #define ADQ12B_STINR 0x00
88 #define ADQ12B_OUTBR 0x04
89 #define ADQ12B_ADLOW 0x08
90 #define ADQ12B_ADHIG 0x09
91 #define ADQ12B_CONT0 0x0c
92 #define ADQ12B_CONT1 0x0d
93 #define ADQ12B_CONT2 0x0e
94 #define ADQ12B_COWORD 0x0f
96 /* mask of the bit at STINR to check end of conversion */
97 #define ADQ12B_EOC 0x20
101 /* available ranges through the PGA gains */
102 static const struct comedi_lrange range_adq12b_ai_bipolar
= { 4, {
110 static const struct comedi_lrange range_adq12b_ai_unipolar
= { 4, {
119 struct adq12b_board
{
128 struct adq12b_private
{
129 int unipolar
; /* option 2 of comedi_config (1 is iobase) */
130 int differential
; /* option 3 of comedi_config */
133 unsigned int digital_state
;
137 * "instructions" read/write data in "one-shot" or "software-triggered"
141 static int adq12b_ai_rinsn(struct comedi_device
*dev
,
142 struct comedi_subdevice
*s
, struct comedi_insn
*insn
,
145 struct adq12b_private
*devpriv
= dev
->private;
148 unsigned char hi
, lo
, status
;
150 /* change channel and range only if it is different from the previous */
151 range
= CR_RANGE(insn
->chanspec
);
152 channel
= CR_CHAN(insn
->chanspec
);
153 if (channel
!= devpriv
->last_channel
|| range
!= devpriv
->last_range
) {
154 outb((range
<< 4) | channel
, dev
->iobase
+ ADQ12B_CTREG
);
155 udelay(50); /* wait for the mux to settle */
158 /* trigger conversion */
159 status
= inb(dev
->iobase
+ ADQ12B_ADLOW
);
161 /* convert n samples */
162 for (n
= 0; n
< insn
->n
; n
++) {
164 /* wait for end of conversion */
168 status
= inb(dev
->iobase
+ ADQ12B_STINR
);
169 status
= status
& ADQ12B_EOC
;
170 } while (status
== 0 && ++i
< TIMEOUT
);
171 /* } while (++i < 10); */
174 hi
= inb(dev
->iobase
+ ADQ12B_ADHIG
);
175 lo
= inb(dev
->iobase
+ ADQ12B_ADLOW
);
177 /* printk("debug: chan=%d range=%d status=%d hi=%d lo=%d\n",
178 channel, range, status, hi, lo); */
179 data
[n
] = (hi
<< 8) | lo
;
183 /* return the number of samples read/written */
187 static int adq12b_di_insn_bits(struct comedi_device
*dev
,
188 struct comedi_subdevice
*s
,
189 struct comedi_insn
*insn
, unsigned int *data
)
192 /* only bits 0-4 have information about digital inputs */
193 data
[1] = (inb(dev
->iobase
+ ADQ12B_STINR
) & (0x1f));
198 static int adq12b_do_insn_bits(struct comedi_device
*dev
,
199 struct comedi_subdevice
*s
,
200 struct comedi_insn
*insn
, unsigned int *data
)
202 struct adq12b_private
*devpriv
= dev
->private;
205 for (channel
= 0; channel
< 8; channel
++)
206 if (((data
[0] >> channel
) & 0x01) != 0)
207 outb((((data
[1] >> channel
) & 0x01) << 3) | channel
,
208 dev
->iobase
+ ADQ12B_OUTBR
);
210 /* store information to retrieve when asked for reading */
212 devpriv
->digital_state
&= ~data
[0];
213 devpriv
->digital_state
|= (data
[0] & data
[1]);
216 data
[1] = devpriv
->digital_state
;
221 static int adq12b_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
223 const struct adq12b_board
*board
= comedi_board(dev
);
224 struct adq12b_private
*devpriv
;
225 struct comedi_subdevice
*s
;
226 unsigned long iobase
;
227 int unipolar
, differential
;
230 iobase
= it
->options
[0];
231 unipolar
= it
->options
[1];
232 differential
= it
->options
[2];
234 printk(KERN_INFO
"comedi%d: adq12b called with options base=0x%03lx, "
235 "%s and %s\n", dev
->minor
, iobase
,
236 (unipolar
== 1) ? "unipolar" : "bipolar",
237 (differential
== 1) ? "differential" : "single-ended");
239 /* if no address was specified, try the default 0x300 */
241 printk(KERN_WARNING
"comedi%d: adq12b warning: I/O base "
242 "address not specified. Trying the default 0x300.\n",
247 printk("comedi%d: adq12b: 0x%04lx ", dev
->minor
, iobase
);
248 if (!request_region(iobase
, ADQ12B_SIZE
, "adq12b")) {
249 printk("I/O port conflict\n");
252 dev
->iobase
= iobase
;
254 dev
->board_name
= board
->name
;
256 ret
= alloc_private(dev
, sizeof(*devpriv
));
259 devpriv
= dev
->private;
261 devpriv
->unipolar
= unipolar
;
262 devpriv
->differential
= differential
;
263 devpriv
->digital_state
= 0;
265 * initialize channel and range to -1 so we make sure we
266 * always write at least once to the CTREG in the instruction
268 devpriv
->last_channel
= -1;
269 devpriv
->last_range
= -1;
271 ret
= comedi_alloc_subdevices(dev
, 3);
275 s
= &dev
->subdevices
[0];
276 /* analog input subdevice */
277 s
->type
= COMEDI_SUBD_AI
;
279 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
| SDF_DIFF
;
280 s
->n_chan
= board
->ai_diff_chans
;
282 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
;
283 s
->n_chan
= board
->ai_se_chans
;
287 s
->range_table
= &range_adq12b_ai_unipolar
;
289 s
->range_table
= &range_adq12b_ai_bipolar
;
291 s
->maxdata
= (1 << board
->ai_bits
) - 1;
293 s
->len_chanlist
= 4; /* This is the maximum chanlist length that
294 the board can handle */
295 s
->insn_read
= adq12b_ai_rinsn
;
297 s
= &dev
->subdevices
[1];
298 /* digital input subdevice */
299 s
->type
= COMEDI_SUBD_DI
;
300 s
->subdev_flags
= SDF_READABLE
;
301 s
->n_chan
= board
->di_chans
;
303 s
->range_table
= &range_digital
;
304 s
->insn_bits
= adq12b_di_insn_bits
;
306 s
= &dev
->subdevices
[2];
307 /* digital output subdevice */
308 s
->type
= COMEDI_SUBD_DO
;
309 s
->subdev_flags
= SDF_WRITABLE
;
310 s
->n_chan
= board
->do_chans
;
312 s
->range_table
= &range_digital
;
313 s
->insn_bits
= adq12b_do_insn_bits
;
315 printk(KERN_INFO
"attached\n");
320 static void adq12b_detach(struct comedi_device
*dev
)
323 release_region(dev
->iobase
, ADQ12B_SIZE
);
326 static const struct adq12b_board adq12b_boards
[] = {
337 static struct comedi_driver adq12b_driver
= {
338 .driver_name
= "adq12b",
339 .module
= THIS_MODULE
,
340 .attach
= adq12b_attach
,
341 .detach
= adq12b_detach
,
342 .board_name
= &adq12b_boards
[0].name
,
343 .offset
= sizeof(struct adq12b_board
),
344 .num_names
= ARRAY_SIZE(adq12b_boards
),
346 module_comedi_driver(adq12b_driver
);
348 MODULE_AUTHOR("Comedi http://www.comedi.org");
349 MODULE_DESCRIPTION("Comedi low-level driver");
350 MODULE_LICENSE("GPL");