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 "../comedidev.h"
41 #include <linux/delay.h>
46 #include <pcmcia/cistpl.h>
47 #include <pcmcia/ds.h>
60 #define MAX_N_CALDACS 32
62 static const struct ni_board_struct ni_boards
[] = {
65 .name
= "DAQCard-ai-16xe-50",
68 .ai_fifo_depth
= 1024,
69 .gainlkup
= ai_gain_8
,
71 .num_p0_dio_channels
= 8,
72 .caldac
= { dac8800
, dac8043
},
75 .name
= "DAQCard-ai-16e-4",
78 .ai_fifo_depth
= 1024,
79 .gainlkup
= ai_gain_16
,
81 .num_p0_dio_channels
= 8,
82 .caldac
= { mb88341
}, /* verified */
85 .name
= "DAQCard-6062E",
88 .ai_fifo_depth
= 8192,
89 .gainlkup
= ai_gain_16
,
93 .ao_fifo_depth
= 2048,
94 .ao_range_table
= &range_bipolar10
,
96 .num_p0_dio_channels
= 8,
97 .caldac
= { ad8804_debug
}, /* verified */
99 /* specs incorrect! */
101 .name
= "DAQCard-6024E",
104 .ai_fifo_depth
= 1024,
105 .gainlkup
= ai_gain_4
,
109 .ao_range_table
= &range_bipolar10
,
111 .num_p0_dio_channels
= 8,
112 .caldac
= { ad8804_debug
},
114 /* specs incorrect! */
116 .name
= "DAQCard-6036E",
119 .ai_fifo_depth
= 1024,
121 .gainlkup
= ai_gain_4
,
125 .ao_range_table
= &range_bipolar10
,
127 .num_p0_dio_channels
= 8,
128 .caldac
= { ad8804_debug
},
132 .device_id
= 0x0000, /* unknown */
133 .name
= "DAQCard-6715",
137 .num_p0_dio_channels
= 8,
138 .caldac
= { mb88341
, mb88341
},
143 #define interrupt_pin(a) 0
145 #define IRQ_POLARITY 1
149 struct pcmcia_device
*link
;
153 /* How we access registers */
155 #define ni_writel(a, b) (outl((a), (b)+dev->iobase))
156 #define ni_readl(a) (inl((a)+dev->iobase))
157 #define ni_writew(a, b) (outw((a), (b)+dev->iobase))
158 #define ni_readw(a) (inw((a)+dev->iobase))
159 #define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
160 #define ni_readb(a) (inb((a)+dev->iobase))
162 /* How we access windowed registers */
164 /* We automatically take advantage of STC registers that can be
165 * read/written directly in the I/O space of the board. The
166 * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
168 static void mio_cs_win_out(struct comedi_device
*dev
, uint16_t data
, int addr
)
170 struct ni_private
*devpriv
= dev
->private;
173 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
175 ni_writew(data
, addr
* 2);
177 ni_writew(addr
, Window_Address
);
178 ni_writew(data
, Window_Data
);
180 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
183 static uint16_t mio_cs_win_in(struct comedi_device
*dev
, int addr
)
185 struct ni_private
*devpriv
= dev
->private;
189 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
191 ret
= ni_readw(addr
* 2);
193 ni_writew(addr
, Window_Address
);
194 ret
= ni_readw(Window_Data
);
196 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
201 #include "ni_mio_common.c"
203 static const void *ni_getboardtype(struct comedi_device
*dev
,
204 struct pcmcia_device
*link
)
206 static const struct ni_board_struct
*board
;
209 for (i
= 0; i
< ARRAY_SIZE(ni_boards
); i
++) {
210 board
= &ni_boards
[i
];
211 if (board
->device_id
== link
->card_id
)
217 static int mio_pcmcia_config_loop(struct pcmcia_device
*p_dev
, void *priv_data
)
221 p_dev
->resource
[0]->flags
&= ~IO_DATA_PATH_WIDTH
;
222 p_dev
->resource
[0]->flags
|= IO_DATA_PATH_WIDTH_16
;
224 for (base
= 0x000; base
< 0x400; base
+= 0x20) {
225 p_dev
->resource
[0]->start
= base
;
226 ret
= pcmcia_request_io(p_dev
);
233 static int mio_cs_auto_attach(struct comedi_device
*dev
,
234 unsigned long context
)
236 struct pcmcia_device
*link
= comedi_to_pcmcia_dev(dev
);
237 static const struct ni_board_struct
*board
;
238 struct ni_private
*devpriv
;
241 board
= ni_getboardtype(dev
, link
);
244 dev
->board_ptr
= board
;
245 dev
->board_name
= board
->name
;
247 link
->config_flags
|= CONF_AUTO_SET_IO
| CONF_ENABLE_IRQ
;
248 ret
= comedi_pcmcia_enable(dev
, mio_pcmcia_config_loop
);
251 dev
->iobase
= link
->resource
[0]->start
;
254 ret
= pcmcia_request_irq(link
, ni_E_interrupt
);
257 dev
->irq
= link
->irq
;
259 ret
= ni_alloc_private(dev
);
263 devpriv
= dev
->private;
264 devpriv
->stc_writew
= mio_cs_win_out
;
265 devpriv
->stc_readw
= mio_cs_win_in
;
266 devpriv
->stc_writel
= win_out2
;
267 devpriv
->stc_readl
= win_in2
;
269 return ni_E_init(dev
);
272 static void mio_cs_detach(struct comedi_device
*dev
)
274 mio_common_detach(dev
);
275 comedi_pcmcia_disable(dev
);
278 static struct comedi_driver driver_ni_mio_cs
= {
279 .driver_name
= "ni_mio_cs",
280 .module
= THIS_MODULE
,
281 .auto_attach
= mio_cs_auto_attach
,
282 .detach
= mio_cs_detach
,
285 static int cs_attach(struct pcmcia_device
*link
)
287 return comedi_pcmcia_auto_config(link
, &driver_ni_mio_cs
);
290 static const struct pcmcia_device_id ni_mio_cs_ids
[] = {
291 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */
292 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */
293 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x02c4), /* DAQCard-6062E */
294 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x075e), /* DAQCard-6024E */
295 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */
298 MODULE_DEVICE_TABLE(pcmcia
, ni_mio_cs_ids
);
300 static struct pcmcia_driver ni_mio_cs_driver
= {
302 .owner
= THIS_MODULE
,
303 .id_table
= ni_mio_cs_ids
,
305 .remove
= comedi_pcmcia_auto_unconfig
,
307 module_comedi_pcmcia_driver(driver_ni_mio_cs
, ni_mio_cs_driver
);
309 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
310 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
311 MODULE_LICENSE("GPL");