2 comedi/drivers/ni_mio_cs.c
3 Hardware driver for NI PCMCIA MIO E series cards
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-2000 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 DAQCard E series
23 Devices: [National Instruments] DAQCard-AI-16XE-50 (ni_mio_cs),
24 DAQCard-AI-16E-4, DAQCard-6062E, DAQCard-6024E, DAQCard-6036E
25 Updated: Thu Oct 23 19:43:17 CDT 2003
27 See the notes in the ni_atmio.o driver.
30 The real guts of the driver is in ni_mio_common.c, which is
31 included by all the E series drivers.
33 References for specifications:
35 341080a.pdf DAQCard E Series Register Level Programmer Manual
39 #include <linux/module.h>
40 #include "../comedidev.h"
42 #include <linux/delay.h>
47 #include <pcmcia/cistpl.h>
48 #include <pcmcia/ds.h>
59 static const struct ni_board_struct ni_boards[] = {
62 .name = "DAQCard-ai-16xe-50",
65 .ai_fifo_depth = 1024,
66 .gainlkup = ai_gain_8,
68 .num_p0_dio_channels = 8,
69 .caldac = { dac8800, dac8043 },
72 .name = "DAQCard-ai-16e-4",
75 .ai_fifo_depth = 1024,
76 .gainlkup = ai_gain_16,
78 .num_p0_dio_channels = 8,
79 .caldac = { mb88341 }, /* verified */
82 .name = "DAQCard-6062E",
85 .ai_fifo_depth = 8192,
86 .gainlkup = ai_gain_16,
90 .ao_fifo_depth = 2048,
91 .ao_range_table = &range_bipolar10,
93 .num_p0_dio_channels = 8,
94 .caldac = { ad8804_debug }, /* verified */
96 /* specs incorrect! */
98 .name = "DAQCard-6024E",
101 .ai_fifo_depth = 1024,
102 .gainlkup = ai_gain_4,
106 .ao_range_table = &range_bipolar10,
108 .num_p0_dio_channels = 8,
109 .caldac = { ad8804_debug },
111 /* specs incorrect! */
113 .name = "DAQCard-6036E",
116 .ai_fifo_depth = 1024,
118 .gainlkup = ai_gain_4,
122 .ao_range_table = &range_bipolar10,
124 .num_p0_dio_channels = 8,
125 .caldac = { ad8804_debug },
129 .device_id = 0x0000, /* unknown */
130 .name = "DAQCard-6715",
134 .num_p0_dio_channels = 8,
135 .caldac = { mb88341, mb88341 },
140 #define interrupt_pin(a) 0
142 #define IRQ_POLARITY 1
144 #include "ni_mio_common.c"
146 /* How we access windowed registers */
148 /* We automatically take advantage of STC registers that can be
149 * read/written directly in the I/O space of the board. The
150 * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
152 static void mio_cs_win_out(struct comedi_device *dev, uint16_t data, int addr)
154 struct ni_private *devpriv = dev->private;
157 spin_lock_irqsave(&devpriv->window_lock, flags);
159 ni_writew(dev, data, addr * 2);
161 ni_writew(dev, addr, Window_Address);
162 ni_writew(dev, data, Window_Data);
164 spin_unlock_irqrestore(&devpriv->window_lock, flags);
167 static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr)
169 struct ni_private *devpriv = dev->private;
173 spin_lock_irqsave(&devpriv->window_lock, flags);
175 ret = ni_readw(dev, addr * 2);
177 ni_writew(dev, addr, Window_Address);
178 ret = ni_readw(dev, Window_Data);
180 spin_unlock_irqrestore(&devpriv->window_lock, flags);
185 static const void *ni_getboardtype(struct comedi_device *dev,
186 struct pcmcia_device *link)
188 static const struct ni_board_struct *board;
191 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
192 board = &ni_boards[i];
193 if (board->device_id == link->card_id)
199 static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
203 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
204 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
206 for (base = 0x000; base < 0x400; base += 0x20) {
207 p_dev->resource[0]->start = base;
208 ret = pcmcia_request_io(p_dev);
215 static int mio_cs_auto_attach(struct comedi_device *dev,
216 unsigned long context)
218 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
219 static const struct ni_board_struct *board;
220 struct ni_private *devpriv;
223 board = ni_getboardtype(dev, link);
226 dev->board_ptr = board;
227 dev->board_name = board->name;
229 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
230 ret = comedi_pcmcia_enable(dev, mio_pcmcia_config_loop);
233 dev->iobase = link->resource[0]->start;
236 ret = pcmcia_request_irq(link, ni_E_interrupt);
239 dev->irq = link->irq;
241 ret = ni_alloc_private(dev);
245 devpriv = dev->private;
247 devpriv->stc_writew = mio_cs_win_out;
248 devpriv->stc_readw = mio_cs_win_in;
249 devpriv->stc_writel = win_out2;
250 devpriv->stc_readl = win_in2;
252 return ni_E_init(dev);
255 static void mio_cs_detach(struct comedi_device *dev)
257 mio_common_detach(dev);
258 comedi_pcmcia_disable(dev);
261 static struct comedi_driver driver_ni_mio_cs = {
262 .driver_name = "ni_mio_cs",
263 .module = THIS_MODULE,
264 .auto_attach = mio_cs_auto_attach,
265 .detach = mio_cs_detach,
268 static int cs_attach(struct pcmcia_device *link)
270 return comedi_pcmcia_auto_config(link, &driver_ni_mio_cs);
273 static const struct pcmcia_device_id ni_mio_cs_ids[] = {
274 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */
275 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */
276 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x02c4), /* DAQCard-6062E */
277 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x075e), /* DAQCard-6024E */
278 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */
281 MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids);
283 static struct pcmcia_driver ni_mio_cs_driver = {
285 .owner = THIS_MODULE,
286 .id_table = ni_mio_cs_ids,
288 .remove = comedi_pcmcia_auto_unconfig,
290 module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver);
292 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
293 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
294 MODULE_LICENSE("GPL");