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
[] = {
69 .name
= "DAQCard-ai-16xe-50",
72 .ai_fifo_depth
= 1024,
74 .gainlkup
= ai_gain_8
,
80 .num_p0_dio_channels
= 8,
82 .caldac
= {dac8800
, dac8043
},
85 .name
= "DAQCard-ai-16e-4",
88 .ai_fifo_depth
= 1024,
90 .gainlkup
= ai_gain_16
,
96 .num_p0_dio_channels
= 8,
98 .caldac
= {mb88341
}, /* verified */
100 {.device_id
= 0x02c4,
101 .name
= "DAQCard-6062E",
104 .ai_fifo_depth
= 8192,
106 .gainlkup
= ai_gain_16
,
110 .ao_fifo_depth
= 2048,
111 .ao_range_table
= &range_bipolar10
,
114 .num_p0_dio_channels
= 8,
116 .caldac
= {ad8804_debug
}, /* verified */
118 {.device_id
= 0x075e,
119 .name
= "DAQCard-6024E", /* specs incorrect! */
122 .ai_fifo_depth
= 1024,
124 .gainlkup
= ai_gain_4
,
129 .ao_range_table
= &range_bipolar10
,
132 .num_p0_dio_channels
= 8,
134 .caldac
= {ad8804_debug
},
136 {.device_id
= 0x0245,
137 .name
= "DAQCard-6036E", /* specs incorrect! */
140 .ai_fifo_depth
= 1024,
142 .gainlkup
= ai_gain_4
,
147 .ao_range_table
= &range_bipolar10
,
150 .num_p0_dio_channels
= 8,
152 .caldac
= {ad8804_debug
},
155 {.device_id
= 0x0000, /* unknown */
156 .name
= "DAQCard-6715",
161 .num_p0_dio_channels
= 8,
162 .caldac
= {mb88341
, mb88341
},
165 /* N.B. Update ni_mio_cs_ids[] when entries added above. */
168 #define interrupt_pin(a) 0
170 #define IRQ_POLARITY 1
172 #define NI_E_IRQ_FLAGS IRQF_SHARED
176 struct pcmcia_device
*link
;
180 #define devpriv ((struct ni_private *)dev->private)
182 /* How we access registers */
184 #define ni_writel(a, b) (outl((a), (b)+dev->iobase))
185 #define ni_readl(a) (inl((a)+dev->iobase))
186 #define ni_writew(a, b) (outw((a), (b)+dev->iobase))
187 #define ni_readw(a) (inw((a)+dev->iobase))
188 #define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
189 #define ni_readb(a) (inb((a)+dev->iobase))
191 /* How we access windowed registers */
193 /* We automatically take advantage of STC registers that can be
194 * read/written directly in the I/O space of the board. The
195 * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
197 static void mio_cs_win_out(struct comedi_device
*dev
, uint16_t data
, int addr
)
201 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
203 ni_writew(data
, addr
* 2);
205 ni_writew(addr
, Window_Address
);
206 ni_writew(data
, Window_Data
);
208 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
211 static uint16_t mio_cs_win_in(struct comedi_device
*dev
, int addr
)
216 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
218 ret
= ni_readw(addr
* 2);
220 ni_writew(addr
, Window_Address
);
221 ret
= ni_readw(Window_Data
);
223 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
228 static int mio_cs_attach(struct comedi_device
*dev
,
229 struct comedi_devconfig
*it
);
230 static int mio_cs_detach(struct comedi_device
*dev
);
231 static struct comedi_driver driver_ni_mio_cs
= {
232 .driver_name
= "ni_mio_cs",
233 .module
= THIS_MODULE
,
234 .attach
= mio_cs_attach
,
235 .detach
= mio_cs_detach
,
238 #include "ni_mio_common.c"
240 static int ni_getboardtype(struct comedi_device
*dev
,
241 struct pcmcia_device
*link
);
243 /* clean up allocated resources */
244 /* called when driver is removed */
245 static int mio_cs_detach(struct comedi_device
*dev
)
247 mio_common_detach(dev
);
249 /* PCMCIA layer frees the IO region */
252 free_irq(dev
->irq
, dev
);
257 static void mio_cs_config(struct pcmcia_device
*link
);
258 static void cs_release(struct pcmcia_device
*link
);
259 static void cs_detach(struct pcmcia_device
*);
261 static struct pcmcia_device
*cur_dev
= NULL
;
263 static int cs_attach(struct pcmcia_device
*link
)
272 static void cs_release(struct pcmcia_device
*link
)
274 pcmcia_disable_device(link
);
277 static void cs_detach(struct pcmcia_device
*link
)
279 DPRINTK("cs_detach(link=%p)\n", link
);
284 static int mio_cs_suspend(struct pcmcia_device
*link
)
286 DPRINTK("pm suspend\n");
291 static int mio_cs_resume(struct pcmcia_device
*link
)
293 DPRINTK("pm resume\n");
298 static int mio_pcmcia_config_loop(struct pcmcia_device
*p_dev
, void *priv_data
)
302 p_dev
->resource
[0]->flags
&= ~IO_DATA_PATH_WIDTH
;
303 p_dev
->resource
[0]->flags
|= IO_DATA_PATH_WIDTH_16
;
305 for (base
= 0x000; base
< 0x400; base
+= 0x20) {
306 p_dev
->resource
[0]->start
= base
;
307 ret
= pcmcia_request_io(p_dev
);
315 static void mio_cs_config(struct pcmcia_device
*link
)
319 DPRINTK("mio_cs_config(link=%p)\n", link
);
320 link
->config_flags
|= CONF_ENABLE_IRQ
| CONF_AUTO_SET_IO
;
322 ret
= pcmcia_loop_config(link
, mio_pcmcia_config_loop
, NULL
);
324 dev_warn(&link
->dev
, "no configuration found\n");
329 dev_info(&link
->dev
, "no IRQ available\n");
331 ret
= pcmcia_enable_device(link
);
334 static int mio_cs_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
336 struct pcmcia_device
*link
;
340 DPRINTK("mio_cs_attach(dev=%p,it=%p)\n", dev
, it
);
342 link
= cur_dev
; /* XXX hack */
346 dev
->driver
= &driver_ni_mio_cs
;
347 dev
->iobase
= link
->resource
[0]->start
;
351 printk("comedi%d: %s: DAQCard: io 0x%04lx, irq %u, ",
352 dev
->minor
, dev
->driver
->driver_name
, dev
->iobase
, irq
);
358 printk(" board fingerprint:");
359 for (i
= 0; i
< 32; i
+= 2) {
360 printk(" %04x %02x", inw(dev
->iobase
+ i
),
361 inb(dev
->iobase
+ i
+ 1));
364 printk(" board fingerprint (windowed):");
365 for (i
= 0; i
< 10; i
++)
366 printk(" 0x%04x", win_in(i
));
371 dev
->board_ptr
= ni_boards
+ ni_getboardtype(dev
, link
);
373 printk(" %s", boardtype
.name
);
374 dev
->board_name
= boardtype
.name
;
376 ret
= request_irq(irq
, ni_E_interrupt
, NI_E_IRQ_FLAGS
,
379 printk(" irq not available\n");
384 /* allocate private area */
385 ret
= ni_alloc_private(dev
);
389 devpriv
->stc_writew
= &mio_cs_win_out
;
390 devpriv
->stc_readw
= &mio_cs_win_in
;
391 devpriv
->stc_writel
= &win_out2
;
392 devpriv
->stc_readl
= &win_in2
;
394 ret
= ni_E_init(dev
, it
);
402 static int ni_getboardtype(struct comedi_device
*dev
,
403 struct pcmcia_device
*link
)
407 for (i
= 0; i
< n_ni_boards
; i
++) {
408 if (ni_boards
[i
].device_id
== link
->card_id
)
412 printk("unknown board 0x%04x -- pretend it is a ", link
->card_id
);
419 static struct pcmcia_device_id ni_mio_cs_ids
[] = {
420 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */
421 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */
422 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x02c4), /* DAQCard-6062E */
423 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x075e), /* DAQCard-6024E */
424 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */
428 MODULE_DEVICE_TABLE(pcmcia
, ni_mio_cs_ids
);
429 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
430 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
431 MODULE_LICENSE("GPL");
433 struct pcmcia_driver ni_mio_cs_driver
= {
435 .remove
= &cs_detach
,
436 .suspend
= &mio_cs_suspend
,
437 .resume
= &mio_cs_resume
,
438 .id_table
= ni_mio_cs_ids
,
439 .owner
= THIS_MODULE
,
445 int init_module(void)
447 pcmcia_register_driver(&ni_mio_cs_driver
);
448 comedi_driver_register(&driver_ni_mio_cs
);
452 void cleanup_module(void)
454 pcmcia_unregister_driver(&ni_mio_cs_driver
);
456 while (cur_dev
!= NULL
)
457 cs_detach(cur_dev
->handle
);
459 comedi_driver_unregister(&driver_ni_mio_cs
);