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>
112 #define MAX_N_CALDACS 32
114 static const struct ni_board_struct ni_boards[] = {
116 .isapnp_id = 0x0000, /* XXX unknown */
117 .name = "at-mio-16e-1",
120 .ai_fifo_depth = 8192,
122 .gainlkup = ai_gain_16,
126 .ao_fifo_depth = 2048,
127 .ao_range_table = &range_ni_E_ao_ext,
131 .num_p0_dio_channels = 8,
136 .name = "at-mio-16e-2",
139 .ai_fifo_depth = 2048,
141 .gainlkup = ai_gain_16,
145 .ao_fifo_depth = 2048,
146 .ao_range_table = &range_ni_E_ao_ext,
150 .num_p0_dio_channels = 8,
155 .name = "at-mio-16e-10",
158 .ai_fifo_depth = 512,
160 .gainlkup = ai_gain_16,
165 .ao_range_table = &range_ni_E_ao_ext,
168 .num_p0_dio_channels = 8,
169 .caldac = {ad8804_debug},
174 .name = "at-mio-16de-10",
177 .ai_fifo_depth = 512,
179 .gainlkup = ai_gain_16,
184 .ao_range_table = &range_ni_E_ao_ext,
187 .num_p0_dio_channels = 8,
188 .caldac = {ad8804_debug},
193 .name = "at-mio-64e-3",
196 .ai_fifo_depth = 2048,
198 .gainlkup = ai_gain_16,
202 .ao_fifo_depth = 2048,
203 .ao_range_table = &range_ni_E_ao_ext,
207 .num_p0_dio_channels = 8,
208 .caldac = {ad8804_debug},
212 .name = "at-mio-16xe-50",
215 .ai_fifo_depth = 512,
217 .gainlkup = ai_gain_8,
222 .ao_range_table = &range_bipolar10,
225 .num_p0_dio_channels = 8,
226 .caldac = {dac8800, dac8043},
230 .isapnp_id = 0x0000, /* XXX unknown */
231 .name = "at-mio-16xe-10",
234 .ai_fifo_depth = 512,
236 .gainlkup = ai_gain_14,
240 .ao_fifo_depth = 2048,
241 .ao_range_table = &range_ni_E_ao_ext,
244 .num_p0_dio_channels = 8,
245 .caldac = {dac8800, dac8043, ad8522},
249 .isapnp_id = 0x0000, /* XXX unknown */
250 .name = "at-ai-16xe-10",
253 .ai_fifo_depth = 512,
254 .alwaysdither = 1, /* unknown */
255 .gainlkup = ai_gain_14,
261 .num_p0_dio_channels = 8,
262 .caldac = {dac8800, dac8043, ad8522},
267 static const int ni_irqpin[] = {
268 -1, -1, -1, 0, 1, 2, -1, 3, -1, -1, 4, 5, 6, -1, -1, 7
271 #define interrupt_pin(a) (ni_irqpin[(a)])
273 #define IRQ_POLARITY 0
275 #define NI_E_IRQ_FLAGS 0
278 struct pnp_dev *isapnp_dev;
283 /* How we access registers */
285 #define ni_writel(a, b) (outl((a), (b)+dev->iobase))
286 #define ni_readl(a) (inl((a)+dev->iobase))
287 #define ni_writew(a, b) (outw((a), (b)+dev->iobase))
288 #define ni_readw(a) (inw((a)+dev->iobase))
289 #define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
290 #define ni_readb(a) (inb((a)+dev->iobase))
292 /* How we access windowed registers */
294 /* We automatically take advantage of STC registers that can be
295 * read/written directly in the I/O space of the board. The
296 * AT-MIO devices map the low 8 STC registers to iobase+addr*2. */
298 static void ni_atmio_win_out(struct comedi_device *dev, uint16_t data, int addr)
300 struct ni_private *devpriv = dev->private;
303 spin_lock_irqsave(&devpriv->window_lock, flags);
305 ni_writew(data, addr * 2);
307 ni_writew(addr, Window_Address);
308 ni_writew(data, Window_Data);
310 spin_unlock_irqrestore(&devpriv->window_lock, flags);
313 static uint16_t ni_atmio_win_in(struct comedi_device *dev, int addr)
315 struct ni_private *devpriv = dev->private;
319 spin_lock_irqsave(&devpriv->window_lock, flags);
321 ret = ni_readw(addr * 2);
323 ni_writew(addr, Window_Address);
324 ret = ni_readw(Window_Data);
326 spin_unlock_irqrestore(&devpriv->window_lock, flags);
331 static struct pnp_device_id device_ids[] = {
332 {.id = "NIC1900", .driver_data = 0},
333 {.id = "NIC2400", .driver_data = 0},
334 {.id = "NIC2500", .driver_data = 0},
335 {.id = "NIC2600", .driver_data = 0},
336 {.id = "NIC2700", .driver_data = 0},
340 MODULE_DEVICE_TABLE(pnp, device_ids);
342 #include "ni_mio_common.c"
344 static int ni_isapnp_find_board(struct pnp_dev **dev)
346 struct pnp_dev *isapnp_dev = NULL;
349 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
350 isapnp_dev = pnp_find_dev(NULL,
351 ISAPNP_VENDOR('N', 'I', 'C'),
352 ISAPNP_FUNCTION(ni_boards[i].
355 if (isapnp_dev == NULL || isapnp_dev->card == NULL)
358 if (pnp_device_attach(isapnp_dev) < 0) {
360 ("ni_atmio: %s found but already active, skipping.\n",
364 if (pnp_activate_dev(isapnp_dev) < 0) {
365 pnp_device_detach(isapnp_dev);
368 if (!pnp_port_valid(isapnp_dev, 0)
369 || !pnp_irq_valid(isapnp_dev, 0)) {
370 pnp_device_detach(isapnp_dev);
371 printk("ni_atmio: pnp invalid port or irq, aborting\n");
376 if (i == ARRAY_SIZE(ni_boards))
382 static int ni_getboardtype(struct comedi_device *dev)
384 int device_id = ni_read_eeprom(dev, 511);
387 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
388 if (ni_boards[i].device_id == device_id)
392 if (device_id == 255)
393 printk(" can't find board\n");
394 else if (device_id == 0)
395 printk(" EEPROM read error (?) or device not found\n");
397 printk(" unknown device ID %d -- contact author\n", device_id);
402 static int ni_atmio_attach(struct comedi_device *dev,
403 struct comedi_devconfig *it)
405 const struct ni_board_struct *boardtype;
406 struct ni_private *devpriv;
407 struct pnp_dev *isapnp_dev;
409 unsigned long iobase;
413 ret = ni_alloc_private(dev);
416 devpriv = dev->private;
418 devpriv->stc_writew = &ni_atmio_win_out;
419 devpriv->stc_readw = &ni_atmio_win_in;
420 devpriv->stc_writel = &win_out2;
421 devpriv->stc_readl = &win_in2;
423 iobase = it->options[0];
424 irq = it->options[1];
427 ret = ni_isapnp_find_board(&isapnp_dev);
431 iobase = pnp_port_start(isapnp_dev, 0);
432 irq = pnp_irq(isapnp_dev, 0);
433 devpriv->isapnp_dev = isapnp_dev;
436 ret = comedi_request_region(dev, iobase, NI_SIZE);
441 /* board existence sanity check */
445 printk(" board fingerprint:");
446 for (i = 0; i < 16; i += 2) {
447 printk(" %04x %02x", inw(dev->iobase + i),
448 inb(dev->iobase + i + 1));
455 board = ni_getboardtype(dev);
459 dev->board_ptr = ni_boards + board;
460 boardtype = comedi_board(dev);
462 printk(" %s", boardtype->name);
463 dev->board_name = boardtype->name;
468 if (irq > 15 || ni_irqpin[irq] == -1) {
469 printk(" invalid irq %u\n", irq);
472 printk(" ( irq = %u )", irq);
473 ret = request_irq(irq, ni_E_interrupt, NI_E_IRQ_FLAGS,
477 printk(" irq not available\n");
483 /* generic E series stuff in ni_mio_common.c */
485 ret = ni_E_init(dev);
493 static void ni_atmio_detach(struct comedi_device *dev)
495 struct ni_private *devpriv = dev->private;
497 mio_common_detach(dev);
498 comedi_legacy_detach(dev);
499 if (devpriv->isapnp_dev)
500 pnp_device_detach(devpriv->isapnp_dev);
503 static struct comedi_driver ni_atmio_driver = {
504 .driver_name = "ni_atmio",
505 .module = THIS_MODULE,
506 .attach = ni_atmio_attach,
507 .detach = ni_atmio_detach,
509 module_comedi_driver(ni_atmio_driver);