2 comedi/drivers/ni_atmio.c
3 Hardware driver for NI AT-MIO E series cards
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-2001 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: National Instruments AT-MIO-E series
22 Devices: [National Instruments] AT-MIO-16E-1 (ni_atmio),
23 AT-MIO-16E-2, AT-MIO-16E-10, AT-MIO-16DE-10, AT-MIO-64E-3,
24 AT-MIO-16XE-50, AT-MIO-16XE-10, AT-AI-16XE-10
26 Updated: Thu May 1 20:03:02 CDT 2003
28 The driver has 2.6 kernel isapnp support, and
29 will automatically probe for a supported board if the
30 I/O base is left unspecified with comedi_config.
32 the isapnp id numbers are unknown. If your board is not
33 recognized, please send the output of 'cat /proc/isapnp'
34 (you may need to modprobe the isa-pnp module for
35 /proc/isapnp to exist) so the
36 id numbers for your board can be added to the driver.
38 Otherwise, you can use the isapnptools package to configure
39 your board. Use isapnp to
40 configure the I/O base and IRQ for the board, and then pass
42 parameters in comedi_config. A sample isapnp.conf file is included
43 in the etc/ directory of Comedilib.
45 Comedilib includes a utility to autocalibrate these boards. The
46 boards seem to boot into a state where the all calibration DACs
47 are at one extreme of their range, thus the default calibration
48 is terrible. Calibration at boot is strongly encouraged.
50 To use the extended digital I/O on some of the boards, enable the
51 8255 driver when configuring the Comedi source tree.
53 External triggering is supported for some events. The channel index
54 (scan_begin_arg, etc.) maps to PFI0 - PFI9.
56 Some of the more esoteric triggering possibilities of these boards
60 The real guts of the driver is in ni_mio_common.c, which is included
61 both here and in ni_pcimio.c
63 Interrupt support added by Truxton Fulton <trux@truxton.com>
65 References for specifications:
67 340747b.pdf Register Level Programmer Manual (obsolete)
68 340747c.pdf Register Level Programmer Manual (new)
69 DAQ-STC reference manual
71 Other possibly relevant info:
73 320517c.pdf User manual (obsolete)
74 320517f.pdf User manual (new)
76 320906c.pdf maximum signal ratings
78 321791a.pdf discontinuation of at-mio-16e-10 rev. c
79 321808a.pdf about at-mio-16e-10 rev P
80 321837a.pdf discontinuation of at-mio-16de-10 rev d
81 321838a.pdf about at-mio-16de-10 rev N
85 need to deal with external reference for DAC, and other DAC
86 properties in board properties
88 deal with at-mio-16de-10 revision D to N changes, etc.
92 #include <linux/module.h>
93 #include <linux/interrupt.h>
94 #include "../comedidev.h"
96 #include <linux/isapnp.h>
108 static const struct ni_board_struct ni_boards[] = {
110 .isapnp_id = 0x0000, /* XXX unknown */
111 .name = "at-mio-16e-1",
114 .ai_fifo_depth = 8192,
115 .gainlkup = ai_gain_16,
119 .ao_fifo_depth = 2048,
120 .ao_range_table = &range_ni_E_ao_ext,
123 .num_p0_dio_channels = 8,
128 .name = "at-mio-16e-2",
131 .ai_fifo_depth = 2048,
132 .gainlkup = ai_gain_16,
136 .ao_fifo_depth = 2048,
137 .ao_range_table = &range_ni_E_ao_ext,
140 .num_p0_dio_channels = 8,
145 .name = "at-mio-16e-10",
148 .ai_fifo_depth = 512,
149 .gainlkup = ai_gain_16,
153 .ao_range_table = &range_ni_E_ao_ext,
156 .num_p0_dio_channels = 8,
157 .caldac = {ad8804_debug},
161 .name = "at-mio-16de-10",
164 .ai_fifo_depth = 512,
165 .gainlkup = ai_gain_16,
169 .ao_range_table = &range_ni_E_ao_ext,
172 .num_p0_dio_channels = 8,
173 .caldac = {ad8804_debug},
178 .name = "at-mio-64e-3",
181 .ai_fifo_depth = 2048,
182 .gainlkup = ai_gain_16,
186 .ao_fifo_depth = 2048,
187 .ao_range_table = &range_ni_E_ao_ext,
190 .num_p0_dio_channels = 8,
191 .caldac = {ad8804_debug},
195 .name = "at-mio-16xe-50",
198 .ai_fifo_depth = 512,
200 .gainlkup = ai_gain_8,
204 .ao_range_table = &range_bipolar10,
206 .num_p0_dio_channels = 8,
207 .caldac = {dac8800, dac8043},
210 .isapnp_id = 0x0000, /* XXX unknown */
211 .name = "at-mio-16xe-10",
214 .ai_fifo_depth = 512,
216 .gainlkup = ai_gain_14,
220 .ao_fifo_depth = 2048,
221 .ao_range_table = &range_ni_E_ao_ext,
224 .num_p0_dio_channels = 8,
225 .caldac = {dac8800, dac8043, ad8522},
228 .isapnp_id = 0x0000, /* XXX unknown */
229 .name = "at-ai-16xe-10",
232 .ai_fifo_depth = 512,
233 .alwaysdither = 1, /* unknown */
234 .gainlkup = ai_gain_14,
236 .num_p0_dio_channels = 8,
237 .caldac = {dac8800, dac8043, ad8522},
241 static const int ni_irqpin[] = {
242 -1, -1, -1, 0, 1, 2, -1, 3, -1, -1, 4, 5, 6, -1, -1, 7
245 #include "ni_mio_common.c"
247 static struct pnp_device_id device_ids[] = {
248 {.id = "NIC1900", .driver_data = 0},
249 {.id = "NIC2400", .driver_data = 0},
250 {.id = "NIC2500", .driver_data = 0},
251 {.id = "NIC2600", .driver_data = 0},
252 {.id = "NIC2700", .driver_data = 0},
256 MODULE_DEVICE_TABLE(pnp, device_ids);
258 static int ni_isapnp_find_board(struct pnp_dev **dev)
260 struct pnp_dev *isapnp_dev = NULL;
263 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
264 isapnp_dev = pnp_find_dev(NULL,
265 ISAPNP_VENDOR('N', 'I', 'C'),
266 ISAPNP_FUNCTION(ni_boards[i].
269 if (isapnp_dev == NULL || isapnp_dev->card == NULL)
272 if (pnp_device_attach(isapnp_dev) < 0) {
274 ("ni_atmio: %s found but already active, skipping.\n",
278 if (pnp_activate_dev(isapnp_dev) < 0) {
279 pnp_device_detach(isapnp_dev);
282 if (!pnp_port_valid(isapnp_dev, 0)
283 || !pnp_irq_valid(isapnp_dev, 0)) {
284 pnp_device_detach(isapnp_dev);
285 printk("ni_atmio: pnp invalid port or irq, aborting\n");
290 if (i == ARRAY_SIZE(ni_boards))
296 static int ni_getboardtype(struct comedi_device *dev)
298 int device_id = ni_read_eeprom(dev, 511);
301 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
302 if (ni_boards[i].device_id == device_id)
306 if (device_id == 255)
307 printk(" can't find board\n");
308 else if (device_id == 0)
309 printk(" EEPROM read error (?) or device not found\n");
311 printk(" unknown device ID %d -- contact author\n", device_id);
316 static int ni_atmio_attach(struct comedi_device *dev,
317 struct comedi_devconfig *it)
319 const struct ni_board_struct *boardtype;
320 struct ni_private *devpriv;
321 struct pnp_dev *isapnp_dev;
323 unsigned long iobase;
327 ret = ni_alloc_private(dev);
330 devpriv = dev->private;
332 iobase = it->options[0];
333 irq = it->options[1];
336 ret = ni_isapnp_find_board(&isapnp_dev);
340 iobase = pnp_port_start(isapnp_dev, 0);
341 irq = pnp_irq(isapnp_dev, 0);
342 comedi_set_hw_dev(dev, &isapnp_dev->dev);
345 ret = comedi_request_region(dev, iobase, 0x20);
351 board = ni_getboardtype(dev);
355 dev->board_ptr = ni_boards + board;
356 boardtype = comedi_board(dev);
358 printk(" %s", boardtype->name);
359 dev->board_name = boardtype->name;
364 if (irq > 15 || ni_irqpin[irq] == -1) {
365 printk(" invalid irq %u\n", irq);
368 printk(" ( irq = %u )", irq);
369 ret = request_irq(irq, ni_E_interrupt, 0,
373 printk(" irq not available\n");
379 /* generic E series stuff in ni_mio_common.c */
381 ret = ni_E_init(dev, ni_irqpin[dev->irq], 0);
389 static void ni_atmio_detach(struct comedi_device *dev)
391 struct pnp_dev *isapnp_dev;
393 mio_common_detach(dev);
394 comedi_legacy_detach(dev);
396 isapnp_dev = dev->hw_dev ? to_pnp_dev(dev->hw_dev) : NULL;
398 pnp_device_detach(isapnp_dev);
401 static struct comedi_driver ni_atmio_driver = {
402 .driver_name = "ni_atmio",
403 .module = THIS_MODULE,
404 .attach = ni_atmio_attach,
405 .detach = ni_atmio_detach,
407 module_comedi_driver(ni_atmio_driver);