2 comedi/drivers/ni_at_ao.c
3 Driver for NI AT-AO-6/10 boards
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000,2002 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: National Instruments AT-AO-6/10
26 Devices: [National Instruments] AT-AO-6 (at-ao-6), AT-AO-10 (at-ao-10)
29 Updated: Sun Dec 26 12:26:28 EST 2004
31 Configuration options:
32 [0] - I/O port base address
35 [3] - analog output range, set by jumpers on hardware (0 for -10 to 10V
36 bipolar, 1 for 0V to 10V unipolar)
40 * Register-level programming information can be found in NI
41 * document 320379.pdf.
44 #include "../comedidev.h"
46 #include <linux/ioport.h>
49 /* registers with _2_ are accessed when GRP2WR is set in CFG1 */
51 #define ATAO_SIZE 0x20
53 #define ATAO_2_DMATCCLR 0x00 /* W 16 */
54 #define ATAO_DIN 0x00 /* R 16 */
55 #define ATAO_DOUT 0x00 /* W 16 */
57 #define ATAO_CFG2 0x02 /* W 16 */
75 #define ATAO_2_INT1CLR 0x02 /* W 16 */
77 #define ATAO_CFG3 0x04 /* W 16 */
78 #define DMAMODE 0x0040
81 #define DOUTEN2 0x0008
82 #define DOUTEN1 0x0004
86 #define ATAO_2_INT2CLR 0x04 /* W 16 */
88 #define ATAO_82C53_BASE 0x06 /* RW 8 */
90 #define ATAO_82C53_CNTR1 0x06 /* RW 8 */
91 #define ATAO_82C53_CNTR2 0x07 /* RW 8 */
92 #define ATAO_82C53_CNTR3 0x08 /* RW 8 */
93 #define ATAO_82C53_CNTRCMD 0x09 /* W 8 */
100 #define MODESEL0 0x02
102 /* read-back command */
118 #define ATAO_2_RTSISHFT 0x06 /* W 8 */
121 #define ATAO_2_RTSISTRB 0x07 /* W 8 */
123 #define ATAO_CFG1 0x0a /* W 16 */
124 #define EXTINT2EN 0x8000
125 #define EXTINT1EN 0x4000
126 #define CNTINT2EN 0x2000
127 #define CNTINT1EN 0x1000
128 #define TCINTEN 0x0800
129 #define CNT1SRC 0x0400
130 #define CNT2SRC 0x0200
131 #define FIFOEN 0x0100
132 #define GRP2WR 0x0080
133 #define EXTUPDEN 0x0040
136 #define CH_mask 0x000f
137 #define ATAO_STATUS 0x0a /* R 16 */
144 #define PROMOUT 0x0001
146 #define ATAO_FIFO_WRITE 0x0c /* W 16 */
147 #define ATAO_FIFO_CLEAR 0x0c /* R 16 */
148 #define ATAO_DACn(x) (0x0c + 2*(x)) /* W */
151 * Board descriptions for two imaginary boards. Describing the
152 * boards in this way is optional, and completely driver-dependent.
153 * Some drivers use arrays such as this, other do not.
160 static const struct atao_board atao_boards[] = {
171 #define thisboard ((struct atao_board *)dev->board_ptr)
173 struct atao_private {
179 /* Used for AO readback */
180 unsigned int ao_readback[10];
183 #define devpriv ((struct atao_private *)dev->private)
185 static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it);
186 static int atao_detach(struct comedi_device *dev);
187 static struct comedi_driver driver_atao = {
188 .driver_name = "ni_at_ao",
189 .module = THIS_MODULE,
190 .attach = atao_attach,
191 .detach = atao_detach,
192 .board_name = &atao_boards[0].name,
193 .offset = sizeof(struct atao_board),
194 .num_names = ARRAY_SIZE(atao_boards),
197 static int __init driver_atao_init_module(void)
199 return comedi_driver_register(&driver_atao);
202 static void __exit driver_atao_cleanup_module(void)
204 comedi_driver_unregister(&driver_atao);
207 module_init(driver_atao_init_module);
208 module_exit(driver_atao_cleanup_module);
210 static void atao_reset(struct comedi_device *dev);
212 static int atao_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
213 struct comedi_insn *insn, unsigned int *data);
214 static int atao_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
215 struct comedi_insn *insn, unsigned int *data);
216 static int atao_dio_insn_bits(struct comedi_device *dev,
217 struct comedi_subdevice *s,
218 struct comedi_insn *insn, unsigned int *data);
219 static int atao_dio_insn_config(struct comedi_device *dev,
220 struct comedi_subdevice *s,
221 struct comedi_insn *insn, unsigned int *data);
222 static int atao_calib_insn_read(struct comedi_device *dev,
223 struct comedi_subdevice *s,
224 struct comedi_insn *insn, unsigned int *data);
225 static int atao_calib_insn_write(struct comedi_device *dev,
226 struct comedi_subdevice *s,
227 struct comedi_insn *insn, unsigned int *data);
229 static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
231 struct comedi_subdevice *s;
232 unsigned long iobase;
235 iobase = it->options[0];
238 ao_unipolar = it->options[3];
240 printk(KERN_INFO "comedi%d: ni_at_ao: 0x%04lx", dev->minor, iobase);
242 if (!request_region(iobase, ATAO_SIZE, "ni_at_ao")) {
243 printk(" I/O port conflict\n");
246 dev->iobase = iobase;
248 /* dev->board_ptr = atao_probe(dev); */
250 dev->board_name = thisboard->name;
252 if (alloc_private(dev, sizeof(struct atao_private)) < 0)
255 if (alloc_subdevices(dev, 4) < 0)
258 s = dev->subdevices + 0;
259 /* analog output subdevice */
260 s->type = COMEDI_SUBD_AO;
261 s->subdev_flags = SDF_WRITABLE;
262 s->n_chan = thisboard->n_ao_chans;
263 s->maxdata = (1 << 12) - 1;
265 s->range_table = &range_unipolar10;
267 s->range_table = &range_bipolar10;
268 s->insn_write = &atao_ao_winsn;
269 s->insn_read = &atao_ao_rinsn;
271 s = dev->subdevices + 1;
272 /* digital i/o subdevice */
273 s->type = COMEDI_SUBD_DIO;
274 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
277 s->range_table = &range_digital;
278 s->insn_bits = atao_dio_insn_bits;
279 s->insn_config = atao_dio_insn_config;
281 s = dev->subdevices + 2;
282 /* caldac subdevice */
283 s->type = COMEDI_SUBD_CALIB;
284 s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
287 s->insn_read = atao_calib_insn_read;
288 s->insn_write = atao_calib_insn_write;
290 s = dev->subdevices + 3;
291 /* eeprom subdevice */
292 /* s->type=COMEDI_SUBD_EEPROM; */
293 s->type = COMEDI_SUBD_UNUSED;
297 printk(KERN_INFO "\n");
302 static int atao_detach(struct comedi_device *dev)
304 printk(KERN_INFO "comedi%d: atao: remove\n", dev->minor);
307 release_region(dev->iobase, ATAO_SIZE);
312 static void atao_reset(struct comedi_device *dev)
314 /* This is the reset sequence described in the manual */
317 outw(devpriv->cfg1, dev->iobase + ATAO_CFG1);
319 outb(RWSEL0 | MODESEL2, dev->iobase + ATAO_82C53_CNTRCMD);
320 outb(0x03, dev->iobase + ATAO_82C53_CNTR1);
321 outb(CNTRSEL0 | RWSEL0 | MODESEL2, dev->iobase + ATAO_82C53_CNTRCMD);
324 outw(devpriv->cfg2, dev->iobase + ATAO_CFG2);
327 outw(devpriv->cfg3, dev->iobase + ATAO_CFG3);
329 inw(dev->iobase + ATAO_FIFO_CLEAR);
331 devpriv->cfg1 |= GRP2WR;
332 outw(devpriv->cfg1, dev->iobase + ATAO_CFG1);
334 outw(0, dev->iobase + ATAO_2_INT1CLR);
335 outw(0, dev->iobase + ATAO_2_INT2CLR);
336 outw(0, dev->iobase + ATAO_2_DMATCCLR);
338 devpriv->cfg1 &= ~GRP2WR;
339 outw(devpriv->cfg1, dev->iobase + ATAO_CFG1);
342 static int atao_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
343 struct comedi_insn *insn, unsigned int *data)
346 int chan = CR_CHAN(insn->chanspec);
349 for (i = 0; i < insn->n; i++) {
350 bits = data[i] - 0x800;
352 devpriv->cfg1 |= GRP2WR;
353 outw(devpriv->cfg1, dev->iobase + ATAO_CFG1);
355 outw(bits, dev->iobase + ATAO_DACn(chan));
357 devpriv->cfg1 &= ~GRP2WR;
358 outw(devpriv->cfg1, dev->iobase + ATAO_CFG1);
360 devpriv->ao_readback[chan] = data[i];
366 static int atao_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
367 struct comedi_insn *insn, unsigned int *data)
370 int chan = CR_CHAN(insn->chanspec);
372 for (i = 0; i < insn->n; i++)
373 data[i] = devpriv->ao_readback[chan];
378 static int atao_dio_insn_bits(struct comedi_device *dev,
379 struct comedi_subdevice *s,
380 struct comedi_insn *insn, unsigned int *data)
386 s->state &= ~data[0];
387 s->state |= data[0] & data[1];
388 outw(s->state, dev->iobase + ATAO_DOUT);
391 data[1] = inw(dev->iobase + ATAO_DIN);
396 static int atao_dio_insn_config(struct comedi_device *dev,
397 struct comedi_subdevice *s,
398 struct comedi_insn *insn, unsigned int *data)
400 int chan = CR_CHAN(insn->chanspec);
401 unsigned int mask, bit;
403 /* The input or output configuration of each digital line is
404 * configured by a special insn_config instruction. chanspec
405 * contains the channel to be changed, and data[0] contains the
406 * value COMEDI_INPUT or COMEDI_OUTPUT. */
408 mask = (chan < 4) ? 0x0f : 0xf0;
409 bit = (chan < 4) ? DOUTEN1 : DOUTEN2;
412 case INSN_CONFIG_DIO_OUTPUT:
414 devpriv->cfg3 |= bit;
416 case INSN_CONFIG_DIO_INPUT:
418 devpriv->cfg3 &= ~bit;
420 case INSN_CONFIG_DIO_QUERY:
422 (s->io_bits & (1 << chan)) ? COMEDI_OUTPUT : COMEDI_INPUT;
430 outw(devpriv->cfg3, dev->iobase + ATAO_CFG3);
436 * Figure 2-1 in the manual shows 3 chips labeled DAC8800, which
437 * are 8-channel 8-bit DACs. These are most likely the calibration
438 * DACs. It is not explicitly stated in the manual how to access
439 * the caldacs, but we can guess.
441 static int atao_calib_insn_read(struct comedi_device *dev,
442 struct comedi_subdevice *s,
443 struct comedi_insn *insn, unsigned int *data)
446 for (i = 0; i < insn->n; i++)
447 data[i] = 0; /* XXX */
451 static int atao_calib_insn_write(struct comedi_device *dev,
452 struct comedi_subdevice *s,
453 struct comedi_insn *insn, unsigned int *data)
455 unsigned int bitstring, bit;
456 unsigned int chan = CR_CHAN(insn->chanspec);
458 bitstring = ((chan & 0x7) << 8) | (data[insn->n - 1] & 0xff);
460 for (bit = 1 << (11 - 1); bit; bit >>= 1) {
461 outw(devpriv->cfg2 | ((bit & bitstring) ? SDATA : 0),
462 dev->iobase + ATAO_CFG2);
463 outw(devpriv->cfg2 | SCLK | ((bit & bitstring) ? SDATA : 0),
464 dev->iobase + ATAO_CFG2);
466 /* strobe the appropriate caldac */
467 outw(devpriv->cfg2 | (((chan >> 3) + 1) << 14),
468 dev->iobase + ATAO_CFG2);
469 outw(devpriv->cfg2, dev->iobase + ATAO_CFG2);
474 MODULE_AUTHOR("Comedi http://www.comedi.org");
475 MODULE_DESCRIPTION("Comedi low-level driver");
476 MODULE_LICENSE("GPL");