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.
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.
24 Description: National Instruments AT-MIO-E series
26 Devices: [National Instruments] AT-MIO-16E-1 (ni_atmio),
27 AT-MIO-16E-2, AT-MIO-16E-10, AT-MIO-16DE-10, AT-MIO-64E-3,
28 AT-MIO-16XE-50, AT-MIO-16XE-10, AT-AI-16XE-10
30 Updated: Thu May 1 20:03:02 CDT 2003
32 The driver has 2.6 kernel isapnp support, and
33 will automatically probe for a supported board if the
34 I/O base is left unspecified with comedi_config.
36 the isapnp id numbers are unknown. If your board is not
37 recognized, please send the output of 'cat /proc/isapnp'
38 (you may need to modprobe the isa-pnp module for
39 /proc/isapnp to exist) so the
40 id numbers for your board can be added to the driver.
42 Otherwise, you can use the isapnptools package to configure
43 your board. Use isapnp to
44 configure the I/O base and IRQ for the board, and then pass
46 parameters in comedi_config. A sample isapnp.conf file is included
47 in the etc/ directory of Comedilib.
49 Comedilib includes a utility to autocalibrate these boards. The
50 boards seem to boot into a state where the all calibration DACs
51 are at one extreme of their range, thus the default calibration
52 is terrible. Calibration at boot is strongly encouraged.
54 To use the extended digital I/O on some of the boards, enable the
55 8255 driver when configuring the Comedi source tree.
57 External triggering is supported for some events. The channel index
58 (scan_begin_arg, etc.) maps to PFI0 - PFI9.
60 Some of the more esoteric triggering possibilities of these boards
64 The real guts of the driver is in ni_mio_common.c, which is included
65 both here and in ni_pcimio.c
67 Interrupt support added by Truxton Fulton <trux@truxton.com>
69 References for specifications:
71 340747b.pdf Register Level Programmer Manual (obsolete)
72 340747c.pdf Register Level Programmer Manual (new)
73 DAQ-STC reference manual
75 Other possibly relevant info:
77 320517c.pdf User manual (obsolete)
78 320517f.pdf User manual (new)
80 320906c.pdf maximum signal ratings
82 321791a.pdf discontinuation of at-mio-16e-10 rev. c
83 321808a.pdf about at-mio-16e-10 rev P
84 321837a.pdf discontinuation of at-mio-16de-10 rev d
85 321838a.pdf about at-mio-16de-10 rev N
89 need to deal with external reference for DAC, and other DAC
90 properties in board properties
92 deal with at-mio-16de-10 revision D to N changes, etc.
96 #include "../comedidev.h"
98 #include <linux/delay.h>
99 #include <linux/isapnp.h>
115 #define MAX_N_CALDACS 32
117 static const struct ni_board_struct ni_boards[] = {
119 isapnp_id:0x0000,/* XXX unknown */
120 name: "at-mio-16e-1",
130 .ao_range_table = &range_ni_E_ao_ext,
134 .num_p0_dio_channels = 8,
139 name: "at-mio-16e-2",
149 .ao_range_table = &range_ni_E_ao_ext,
153 .num_p0_dio_channels = 8,
158 name: "at-mio-16e-10",
168 .ao_range_table = &range_ni_E_ao_ext,
171 .num_p0_dio_channels = 8,
172 caldac: {ad8804_debug},
177 name: "at-mio-16de-10",
187 .ao_range_table = &range_ni_E_ao_ext,
190 .num_p0_dio_channels = 8,
191 caldac: {ad8804_debug},
196 name: "at-mio-64e-3",
206 .ao_range_table = &range_ni_E_ao_ext,
210 .num_p0_dio_channels = 8,
211 caldac: {ad8804_debug},
215 name: "at-mio-16xe-50",
225 .ao_range_table = &range_bipolar10,
228 .num_p0_dio_channels = 8,
229 caldac: {dac8800, dac8043},
233 isapnp_id:0x0000,/* XXX unknown */
234 name: "at-mio-16xe-10",
244 .ao_range_table = &range_ni_E_ao_ext,
247 .num_p0_dio_channels = 8,
248 caldac: {dac8800, dac8043, ad8522},
252 isapnp_id:0x0000,/* XXX unknown */
253 name: "at-ai-16xe-10",
257 alwaysdither:1, /* unknown */
264 .num_p0_dio_channels = 8,
265 caldac: {dac8800, dac8043, ad8522},
270 static const int ni_irqpin[] =
271 { -1, -1, -1, 0, 1, 2, -1, 3, -1, -1, 4, 5, 6, -1, -1, 7 };
273 #define interrupt_pin(a) (ni_irqpin[(a)])
275 #define IRQ_POLARITY 0
277 #define NI_E_IRQ_FLAGS 0
280 struct pnp_dev *isapnp_dev;
283 #define devpriv ((struct ni_private *)dev->private)
285 /* How we access registers */
287 #define ni_writel(a, b) (outl((a), (b)+dev->iobase))
288 #define ni_readl(a) (inl((a)+dev->iobase))
289 #define ni_writew(a, b) (outw((a), (b)+dev->iobase))
290 #define ni_readw(a) (inw((a)+dev->iobase))
291 #define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
292 #define ni_readb(a) (inb((a)+dev->iobase))
294 /* How we access windowed registers */
296 /* We automatically take advantage of STC registers that can be
297 * read/written directly in the I/O space of the board. The
298 * AT-MIO devices map the low 8 STC registers to iobase+addr*2. */
300 static void ni_atmio_win_out(struct comedi_device *dev, uint16_t data, int addr)
304 comedi_spin_lock_irqsave(&devpriv->window_lock, flags);
306 ni_writew(data, addr * 2);
308 ni_writew(addr, Window_Address);
309 ni_writew(data, Window_Data);
311 comedi_spin_unlock_irqrestore(&devpriv->window_lock, flags);
314 static uint16_t ni_atmio_win_in(struct comedi_device *dev, int addr)
319 comedi_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 comedi_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 static int ni_atmio_attach(struct comedi_device *dev, struct comedi_devconfig *it);
343 static int ni_atmio_detach(struct comedi_device *dev);
344 static struct comedi_driver driver_atmio = {
345 driver_name:"ni_atmio",
347 attach:ni_atmio_attach,
348 detach:ni_atmio_detach,
351 COMEDI_INITCLEANUP(driver_atmio);
353 #include "ni_mio_common.c"
355 static int ni_getboardtype(struct comedi_device *dev);
357 /* clean up allocated resources */
358 static int ni_atmio_detach(struct comedi_device *dev)
360 mio_common_detach(dev);
363 release_region(dev->iobase, NI_SIZE);
365 comedi_free_irq(dev->irq, dev);
367 if (devpriv->isapnp_dev)
368 pnp_device_detach(devpriv->isapnp_dev);
373 static int ni_isapnp_find_board(struct pnp_dev **dev)
375 struct pnp_dev *isapnp_dev = NULL;
378 for (i = 0; i < n_ni_boards; i++) {
379 isapnp_dev = pnp_find_dev(NULL,
380 ISAPNP_VENDOR('N', 'I', 'C'),
381 ISAPNP_FUNCTION(ni_boards[i].isapnp_id), NULL);
383 if (isapnp_dev == NULL || isapnp_dev->card == NULL)
386 if (pnp_device_attach(isapnp_dev) < 0) {
387 printk("ni_atmio: %s found but already active, skipping.\n", ni_boards[i].name);
390 if (pnp_activate_dev(isapnp_dev) < 0) {
391 pnp_device_detach(isapnp_dev);
394 if (!pnp_port_valid(isapnp_dev, 0)
395 || !pnp_irq_valid(isapnp_dev, 0)) {
396 pnp_device_detach(isapnp_dev);
397 printk("ni_atmio: pnp invalid port or irq, aborting\n");
402 if (i == n_ni_boards)
408 static int ni_atmio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
410 struct pnp_dev *isapnp_dev;
412 unsigned long iobase;
416 /* allocate private area */
417 if ((ret = ni_alloc_private(dev)) < 0)
419 devpriv->stc_writew = &ni_atmio_win_out;
420 devpriv->stc_readw = &ni_atmio_win_in;
421 devpriv->stc_writel = &win_out2;
422 devpriv->stc_readl = &win_in2;
424 iobase = it->options[0];
425 irq = it->options[1];
428 ret = ni_isapnp_find_board(&isapnp_dev);
432 iobase = pnp_port_start(isapnp_dev, 0);
433 irq = pnp_irq(isapnp_dev, 0);
434 devpriv->isapnp_dev = isapnp_dev;
437 /* reserve our I/O region */
439 printk("comedi%d: ni_atmio: 0x%04lx", dev->minor, iobase);
440 if (!request_region(iobase, NI_SIZE, "ni_atmio")) {
441 printk(" I/O port conflict\n");
445 dev->iobase = iobase;
448 /* board existence sanity check */
452 printk(" board fingerprint:");
453 for (i = 0; i < 16; i += 2) {
454 printk(" %04x %02x", inw(dev->iobase + i),
455 inb(dev->iobase + i + 1));
462 board = ni_getboardtype(dev);
466 dev->board_ptr = ni_boards + board;
468 printk(" %s", boardtype.name);
469 dev->board_name = boardtype.name;
474 if (irq > 15 || ni_irqpin[irq] == -1) {
475 printk(" invalid irq %u\n", irq);
478 printk(" ( irq = %u )", irq);
479 if ((ret = comedi_request_irq(irq, ni_E_interrupt,
480 NI_E_IRQ_FLAGS, "ni_atmio", dev)) < 0) {
481 printk(" irq not available\n");
487 /* generic E series stuff in ni_mio_common.c */
489 if ((ret = ni_E_init(dev, it)) < 0) {
496 static int ni_getboardtype(struct comedi_device *dev)
498 int device_id = ni_read_eeprom(dev, 511);
501 for (i = 0; i < n_ni_boards; i++) {
502 if (ni_boards[i].device_id == device_id) {
506 if (device_id == 255) {
507 printk(" can't find board\n");
508 } else if (device_id == 0) {
509 printk(" EEPROM read error (?) or device not found\n");
511 printk(" unknown device ID %d -- contact author\n", device_id);