1 // SPDX-License-Identifier: GPL-2.0+
3 * Comedi 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>
11 * Description: National Instruments AT-MIO-E series
13 * Devices: [National Instruments] AT-MIO-16E-1 (ni_atmio),
14 * AT-MIO-16E-2, AT-MIO-16E-10, AT-MIO-16DE-10, AT-MIO-64E-3,
15 * AT-MIO-16XE-50, AT-MIO-16XE-10, AT-AI-16XE-10
17 * Updated: Thu May 1 20:03:02 CDT 2003
19 * The driver has 2.6 kernel isapnp support, and will automatically probe for
20 * a supported board if the I/O base is left unspecified with comedi_config.
21 * However, many of the isapnp id numbers are unknown. If your board is not
22 * recognized, please send the output of 'cat /proc/isapnp' (you may need to
23 * modprobe the isa-pnp module for /proc/isapnp to exist) so the id numbers
24 * for your board can be added to the driver.
26 * Otherwise, you can use the isapnptools package to configure your board.
27 * Use isapnp to configure the I/O base and IRQ for the board, and then pass
28 * the same values as parameters in comedi_config. A sample isapnp.conf file
29 * is included in the etc/ directory of Comedilib.
31 * Comedilib includes a utility to autocalibrate these boards. The boards
32 * seem to boot into a state where the all calibration DACs are at one
33 * extreme of their range, thus the default calibration is terrible.
34 * Calibration at boot is strongly encouraged.
36 * To use the extended digital I/O on some of the boards, enable the
37 * 8255 driver when configuring the Comedi source tree.
39 * External triggering is supported for some events. The channel index
40 * (scan_begin_arg, etc.) maps to PFI0 - PFI9.
42 * Some of the more esoteric triggering possibilities of these boards are
47 * The real guts of the driver is in ni_mio_common.c, which is included
48 * both here and in ni_pcimio.c
50 * Interrupt support added by Truxton Fulton <trux@truxton.com>
52 * References for specifications:
53 * 340747b.pdf Register Level Programmer Manual (obsolete)
54 * 340747c.pdf Register Level Programmer Manual (new)
55 * DAQ-STC reference manual
57 * Other possibly relevant info:
58 * 320517c.pdf User manual (obsolete)
59 * 320517f.pdf User manual (new)
61 * 320906c.pdf maximum signal ratings
62 * 321066a.pdf about 16x
63 * 321791a.pdf discontinuation of at-mio-16e-10 rev. c
64 * 321808a.pdf about at-mio-16e-10 rev P
65 * 321837a.pdf discontinuation of at-mio-16de-10 rev d
66 * 321838a.pdf about at-mio-16de-10 rev N
69 * - need to deal with external reference for DAC, and other DAC
70 * properties in board properties
71 * - deal with at-mio-16de-10 revision D to N changes, etc.
74 #include <linux/module.h>
75 #include <linux/interrupt.h>
76 #include <linux/comedi/comedidev.h>
77 #include <linux/isapnp.h>
78 #include <linux/comedi/comedi_8255.h>
82 /* AT specific setup */
83 static const struct ni_board_struct ni_boards[] = {
85 .name = "at-mio-16e-1",
87 .isapnp_id = 0x0000, /* XXX unknown */
90 .ai_fifo_depth = 8192,
91 .gainlkup = ai_gain_16,
95 .ao_fifo_depth = 2048,
96 .ao_range_table = &range_ni_E_ao_ext,
98 .caldac = { mb88341 },
100 .name = "at-mio-16e-2",
104 .ai_maxdata = 0x0fff,
105 .ai_fifo_depth = 2048,
106 .gainlkup = ai_gain_16,
109 .ao_maxdata = 0x0fff,
110 .ao_fifo_depth = 2048,
111 .ao_range_table = &range_ni_E_ao_ext,
113 .caldac = { mb88341 },
115 .name = "at-mio-16e-10",
119 .ai_maxdata = 0x0fff,
120 .ai_fifo_depth = 512,
121 .gainlkup = ai_gain_16,
124 .ao_maxdata = 0x0fff,
125 .ao_range_table = &range_ni_E_ao_ext,
127 .caldac = { ad8804_debug },
129 .name = "at-mio-16de-10",
133 .ai_maxdata = 0x0fff,
134 .ai_fifo_depth = 512,
135 .gainlkup = ai_gain_16,
138 .ao_maxdata = 0x0fff,
139 .ao_range_table = &range_ni_E_ao_ext,
141 .caldac = { ad8804_debug },
144 .name = "at-mio-64e-3",
148 .ai_maxdata = 0x0fff,
149 .ai_fifo_depth = 2048,
150 .gainlkup = ai_gain_16,
153 .ao_maxdata = 0x0fff,
154 .ao_fifo_depth = 2048,
155 .ao_range_table = &range_ni_E_ao_ext,
157 .caldac = { ad8804_debug },
159 .name = "at-mio-16xe-50",
163 .ai_maxdata = 0xffff,
164 .ai_fifo_depth = 512,
166 .gainlkup = ai_gain_8,
169 .ao_maxdata = 0x0fff,
170 .ao_range_table = &range_bipolar10,
172 .caldac = { dac8800, dac8043 },
174 .name = "at-mio-16xe-10",
176 .isapnp_id = 0x0000, /* XXX unknown */
178 .ai_maxdata = 0xffff,
179 .ai_fifo_depth = 512,
181 .gainlkup = ai_gain_14,
184 .ao_maxdata = 0xffff,
185 .ao_fifo_depth = 2048,
186 .ao_range_table = &range_ni_E_ao_ext,
188 .caldac = { dac8800, dac8043, ad8522 },
190 .name = "at-ai-16xe-10",
192 .isapnp_id = 0x0000, /* XXX unknown */
194 .ai_maxdata = 0xffff,
195 .ai_fifo_depth = 512,
196 .alwaysdither = 1, /* unknown */
197 .gainlkup = ai_gain_14,
199 .caldac = { dac8800, dac8043, ad8522 },
203 static const int ni_irqpin[] = {
204 -1, -1, -1, 0, 1, 2, -1, 3, -1, -1, 4, 5, 6, -1, -1, 7
207 #include "ni_mio_common.c"
209 static const struct pnp_device_id device_ids[] = {
210 {.id = "NIC1900", .driver_data = 0},
211 {.id = "NIC2400", .driver_data = 0},
212 {.id = "NIC2500", .driver_data = 0},
213 {.id = "NIC2600", .driver_data = 0},
214 {.id = "NIC2700", .driver_data = 0},
218 MODULE_DEVICE_TABLE(pnp, device_ids);
220 static int ni_isapnp_find_board(struct pnp_dev **dev)
222 struct pnp_dev *isapnp_dev = NULL;
225 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
228 ISAPNP_VENDOR('N', 'I', 'C'),
229 ISAPNP_FUNCTION(ni_boards[i].isapnp_id),
232 if (!isapnp_dev || !isapnp_dev->card)
235 if (pnp_device_attach(isapnp_dev) < 0)
238 if (pnp_activate_dev(isapnp_dev) < 0) {
239 pnp_device_detach(isapnp_dev);
243 if (!pnp_port_valid(isapnp_dev, 0) ||
244 !pnp_irq_valid(isapnp_dev, 0)) {
245 pnp_device_detach(isapnp_dev);
250 if (i == ARRAY_SIZE(ni_boards))
256 static const struct ni_board_struct *ni_atmio_probe(struct comedi_device *dev)
258 int device_id = ni_read_eeprom(dev, 511);
261 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
262 const struct ni_board_struct *board = &ni_boards[i];
264 if (board->device_id == device_id)
267 if (device_id == 255)
268 dev_err(dev->class_dev, "can't find board\n");
269 else if (device_id == 0)
270 dev_err(dev->class_dev,
271 "EEPROM read error (?) or device not found\n");
273 dev_err(dev->class_dev,
274 "unknown device ID %d -- contact author\n", device_id);
279 static int ni_atmio_attach(struct comedi_device *dev,
280 struct comedi_devconfig *it)
282 const struct ni_board_struct *board;
283 struct pnp_dev *isapnp_dev;
285 unsigned long iobase;
288 ret = ni_alloc_private(dev);
292 iobase = it->options[0];
293 irq = it->options[1];
296 ret = ni_isapnp_find_board(&isapnp_dev);
300 iobase = pnp_port_start(isapnp_dev, 0);
301 irq = pnp_irq(isapnp_dev, 0);
302 comedi_set_hw_dev(dev, &isapnp_dev->dev);
305 ret = comedi_request_region(dev, iobase, 0x20);
309 board = ni_atmio_probe(dev);
312 dev->board_ptr = board;
313 dev->board_name = board->name;
318 if (irq > 15 || ni_irqpin[irq] == -1)
320 ret = request_irq(irq, ni_E_interrupt, 0,
321 dev->board_name, dev);
327 /* generic E series stuff in ni_mio_common.c */
329 ret = ni_E_init(dev, ni_irqpin[dev->irq], 0);
336 static void ni_atmio_detach(struct comedi_device *dev)
338 struct pnp_dev *isapnp_dev;
340 mio_common_detach(dev);
341 comedi_legacy_detach(dev);
343 isapnp_dev = dev->hw_dev ? to_pnp_dev(dev->hw_dev) : NULL;
345 pnp_device_detach(isapnp_dev);
348 static struct comedi_driver ni_atmio_driver = {
349 .driver_name = "ni_atmio",
350 .module = THIS_MODULE,
351 .attach = ni_atmio_attach,
352 .detach = ni_atmio_detach,
354 module_comedi_driver(ni_atmio_driver);
356 MODULE_AUTHOR("Comedi https://www.comedi.org");
357 MODULE_DESCRIPTION("Comedi low-level driver");
358 MODULE_LICENSE("GPL");