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.
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.
25 Description: National Instruments DAQCard E series
28 Devices: [National Instruments] DAQCard-AI-16XE-50 (ni_mio_cs),
29 DAQCard-AI-16E-4, DAQCard-6062E, DAQCard-6024E, DAQCard-6036E
30 Updated: Thu Oct 23 19:43:17 CDT 2003
32 See the notes in the ni_atmio.o driver.
35 The real guts of the driver is in ni_mio_common.c, which is
36 included by all the E series drivers.
38 References for specifications:
40 341080a.pdf DAQCard E Series Register Level Programmer Manual
44 #include "../comedidev.h"
46 #include <linux/delay.h>
51 #include <pcmcia/cistpl.h>
52 #include <pcmcia/ds.h>
65 #define MAX_N_CALDACS 32
67 static const struct ni_board_struct ni_boards[] = {
70 .name = "DAQCard-ai-16xe-50",
73 .ai_fifo_depth = 1024,
74 .gainlkup = ai_gain_8,
76 .num_p0_dio_channels = 8,
77 .caldac = { dac8800, dac8043 },
80 .name = "DAQCard-ai-16e-4",
83 .ai_fifo_depth = 1024,
84 .gainlkup = ai_gain_16,
86 .num_p0_dio_channels = 8,
87 .caldac = { mb88341 }, /* verified */
90 .name = "DAQCard-6062E",
93 .ai_fifo_depth = 8192,
94 .gainlkup = ai_gain_16,
98 .ao_fifo_depth = 2048,
99 .ao_range_table = &range_bipolar10,
101 .num_p0_dio_channels = 8,
102 .caldac = { ad8804_debug }, /* verified */
104 /* specs incorrect! */
106 .name = "DAQCard-6024E",
109 .ai_fifo_depth = 1024,
110 .gainlkup = ai_gain_4,
114 .ao_range_table = &range_bipolar10,
116 .num_p0_dio_channels = 8,
117 .caldac = { ad8804_debug },
119 /* specs incorrect! */
121 .name = "DAQCard-6036E",
124 .ai_fifo_depth = 1024,
126 .gainlkup = ai_gain_4,
130 .ao_range_table = &range_bipolar10,
132 .num_p0_dio_channels = 8,
133 .caldac = { ad8804_debug },
137 .device_id = 0x0000, /* unknown */
138 .name = "DAQCard-6715",
142 .num_p0_dio_channels = 8,
143 .caldac = { mb88341, mb88341 },
148 #define interrupt_pin(a) 0
150 #define IRQ_POLARITY 1
154 struct pcmcia_device *link;
158 /* How we access registers */
160 #define ni_writel(a, b) (outl((a), (b)+dev->iobase))
161 #define ni_readl(a) (inl((a)+dev->iobase))
162 #define ni_writew(a, b) (outw((a), (b)+dev->iobase))
163 #define ni_readw(a) (inw((a)+dev->iobase))
164 #define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
165 #define ni_readb(a) (inb((a)+dev->iobase))
167 /* How we access windowed registers */
169 /* We automatically take advantage of STC registers that can be
170 * read/written directly in the I/O space of the board. The
171 * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
173 static void mio_cs_win_out(struct comedi_device *dev, uint16_t data, int addr)
175 struct ni_private *devpriv = dev->private;
178 spin_lock_irqsave(&devpriv->window_lock, flags);
180 ni_writew(data, addr * 2);
182 ni_writew(addr, Window_Address);
183 ni_writew(data, Window_Data);
185 spin_unlock_irqrestore(&devpriv->window_lock, flags);
188 static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr)
190 struct ni_private *devpriv = dev->private;
194 spin_lock_irqsave(&devpriv->window_lock, flags);
196 ret = ni_readw(addr * 2);
198 ni_writew(addr, Window_Address);
199 ret = ni_readw(Window_Data);
201 spin_unlock_irqrestore(&devpriv->window_lock, flags);
206 #include "ni_mio_common.c"
208 static const void *ni_getboardtype(struct comedi_device *dev,
209 struct pcmcia_device *link)
211 static const struct ni_board_struct *board;
214 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
215 board = &ni_boards[i];
216 if (board->device_id == link->card_id)
222 static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
226 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
227 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
229 for (base = 0x000; base < 0x400; base += 0x20) {
230 p_dev->resource[0]->start = base;
231 ret = pcmcia_request_io(p_dev);
238 static int mio_cs_auto_attach(struct comedi_device *dev,
239 unsigned long context)
241 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
242 static const struct ni_board_struct *board;
243 struct ni_private *devpriv;
246 board = ni_getboardtype(dev, link);
249 dev->board_ptr = board;
250 dev->board_name = board->name;
252 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
253 ret = comedi_pcmcia_enable(dev, mio_pcmcia_config_loop);
256 dev->iobase = link->resource[0]->start;
259 ret = pcmcia_request_irq(link, ni_E_interrupt);
262 dev->irq = link->irq;
264 ret = ni_alloc_private(dev);
268 devpriv = dev->private;
269 devpriv->stc_writew = mio_cs_win_out;
270 devpriv->stc_readw = mio_cs_win_in;
271 devpriv->stc_writel = win_out2;
272 devpriv->stc_readl = win_in2;
274 return ni_E_init(dev);
277 static void mio_cs_detach(struct comedi_device *dev)
279 mio_common_detach(dev);
280 comedi_pcmcia_disable(dev);
283 static struct comedi_driver driver_ni_mio_cs = {
284 .driver_name = "ni_mio_cs",
285 .module = THIS_MODULE,
286 .auto_attach = mio_cs_auto_attach,
287 .detach = mio_cs_detach,
290 static int cs_attach(struct pcmcia_device *link)
292 return comedi_pcmcia_auto_config(link, &driver_ni_mio_cs);
295 static const struct pcmcia_device_id ni_mio_cs_ids[] = {
296 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */
297 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */
298 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x02c4), /* DAQCard-6062E */
299 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x075e), /* DAQCard-6024E */
300 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */
303 MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids);
305 static struct pcmcia_driver ni_mio_cs_driver = {
307 .owner = THIS_MODULE,
308 .id_table = ni_mio_cs_ids,
310 .remove = comedi_pcmcia_auto_unconfig,
312 module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver);
314 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
315 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
316 MODULE_LICENSE("GPL");