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/cs.h>
52 #include <pcmcia/cistpl.h>
53 #include <pcmcia/ds.h>
66 #define MAX_N_CALDACS 32
68 static const struct ni_board_struct ni_boards
[] = {
70 .name
= "DAQCard-ai-16xe-50",
73 .ai_fifo_depth
= 1024,
75 .gainlkup
= ai_gain_8
,
81 .num_p0_dio_channels
= 8,
83 .caldac
= {dac8800
, dac8043
},
86 .name
= "DAQCard-ai-16e-4",
89 .ai_fifo_depth
= 1024,
91 .gainlkup
= ai_gain_16
,
97 .num_p0_dio_channels
= 8,
99 .caldac
= {mb88341
}, /* verified */
101 {.device_id
= 0x02c4,
102 .name
= "DAQCard-6062E",
105 .ai_fifo_depth
= 8192,
107 .gainlkup
= ai_gain_16
,
111 .ao_fifo_depth
= 2048,
112 .ao_range_table
= &range_bipolar10
,
115 .num_p0_dio_channels
= 8,
117 .caldac
= {ad8804_debug
}, /* verified */
119 {.device_id
= 0x075e,
120 .name
= "DAQCard-6024E", /* specs incorrect! */
123 .ai_fifo_depth
= 1024,
125 .gainlkup
= ai_gain_4
,
130 .ao_range_table
= &range_bipolar10
,
133 .num_p0_dio_channels
= 8,
135 .caldac
= {ad8804_debug
},
137 {.device_id
= 0x0245,
138 .name
= "DAQCard-6036E", /* specs incorrect! */
141 .ai_fifo_depth
= 1024,
143 .gainlkup
= ai_gain_4
,
148 .ao_range_table
= &range_bipolar10
,
151 .num_p0_dio_channels
= 8,
153 .caldac
= {ad8804_debug
},
156 {.device_id
= 0x0000, /* unknown */
157 .name
= "DAQCard-6715",
162 .num_p0_dio_channels
= 8,
163 .caldac
= {mb88341
, mb88341
},
166 /* N.B. Update ni_mio_cs_ids[] when entries added above. */
169 #define interrupt_pin(a) 0
171 #define IRQ_POLARITY 1
173 #define NI_E_IRQ_FLAGS IRQF_SHARED
177 struct pcmcia_device
*link
;
181 #define devpriv ((struct ni_private *)dev->private)
183 /* How we access registers */
185 #define ni_writel(a, b) (outl((a), (b)+dev->iobase))
186 #define ni_readl(a) (inl((a)+dev->iobase))
187 #define ni_writew(a, b) (outw((a), (b)+dev->iobase))
188 #define ni_readw(a) (inw((a)+dev->iobase))
189 #define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
190 #define ni_readb(a) (inb((a)+dev->iobase))
192 /* How we access windowed registers */
194 /* We automatically take advantage of STC registers that can be
195 * read/written directly in the I/O space of the board. The
196 * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
198 static void mio_cs_win_out(struct comedi_device
*dev
, uint16_t data
, int addr
)
202 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
204 ni_writew(data
, addr
* 2);
206 ni_writew(addr
, Window_Address
);
207 ni_writew(data
, Window_Data
);
209 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
212 static uint16_t mio_cs_win_in(struct comedi_device
*dev
, int addr
)
217 spin_lock_irqsave(&devpriv
->window_lock
, flags
);
219 ret
= ni_readw(addr
* 2);
221 ni_writew(addr
, Window_Address
);
222 ret
= ni_readw(Window_Data
);
224 spin_unlock_irqrestore(&devpriv
->window_lock
, flags
);
229 static int mio_cs_attach(struct comedi_device
*dev
,
230 struct comedi_devconfig
*it
);
231 static int mio_cs_detach(struct comedi_device
*dev
);
232 static struct comedi_driver driver_ni_mio_cs
= {
233 .driver_name
= "ni_mio_cs",
234 .module
= THIS_MODULE
,
235 .attach
= mio_cs_attach
,
236 .detach
= mio_cs_detach
,
239 #include "ni_mio_common.c"
241 static int ni_getboardtype(struct comedi_device
*dev
,
242 struct pcmcia_device
*link
);
244 /* clean up allocated resources */
245 /* called when driver is removed */
246 static int mio_cs_detach(struct comedi_device
*dev
)
248 mio_common_detach(dev
);
250 /* PCMCIA layer frees the IO region */
253 free_irq(dev
->irq
, dev
);
258 static void mio_cs_config(struct pcmcia_device
*link
);
259 static void cs_release(struct pcmcia_device
*link
);
260 static void cs_detach(struct pcmcia_device
*);
262 static struct pcmcia_device
*cur_dev
= NULL
;
264 static int cs_attach(struct pcmcia_device
*link
)
266 link
->resource
[0]->flags
|= IO_DATA_PATH_WIDTH_16
;
267 link
->resource
[0]->end
= 16;
268 link
->conf
.Attributes
= CONF_ENABLE_IRQ
;
269 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
278 static void cs_release(struct pcmcia_device
*link
)
280 pcmcia_disable_device(link
);
283 static void cs_detach(struct pcmcia_device
*link
)
285 DPRINTK("cs_detach(link=%p)\n", link
);
290 static int mio_cs_suspend(struct pcmcia_device
*link
)
292 DPRINTK("pm suspend\n");
297 static int mio_cs_resume(struct pcmcia_device
*link
)
299 DPRINTK("pm resume\n");
304 static int mio_pcmcia_config_loop(struct pcmcia_device
*p_dev
,
305 cistpl_cftable_entry_t
*cfg
,
306 cistpl_cftable_entry_t
*dflt
,
312 p_dev
->resource
[0]->end
= cfg
->io
.win
[0].len
;
313 p_dev
->io_lines
= cfg
->io
.flags
& CISTPL_IO_LINES_MASK
;
315 for (base
= 0x000; base
< 0x400; base
+= 0x20) {
316 p_dev
->resource
[0]->start
= base
;
317 ret
= pcmcia_request_io(p_dev
);
325 static void mio_cs_config(struct pcmcia_device
*link
)
329 DPRINTK("mio_cs_config(link=%p)\n", link
);
331 ret
= pcmcia_loop_config(link
, mio_pcmcia_config_loop
, NULL
);
333 dev_warn(&link
->dev
, "no configuration found\n");
338 dev_info(&link
->dev
, "no IRQ available\n");
340 ret
= pcmcia_request_configuration(link
, &link
->conf
);
343 static int mio_cs_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
345 struct pcmcia_device
*link
;
349 DPRINTK("mio_cs_attach(dev=%p,it=%p)\n", dev
, it
);
351 link
= cur_dev
; /* XXX hack */
355 dev
->driver
= &driver_ni_mio_cs
;
356 dev
->iobase
= link
->resource
[0]->start
;
360 printk("comedi%d: %s: DAQCard: io 0x%04lx, irq %u, ",
361 dev
->minor
, dev
->driver
->driver_name
, dev
->iobase
, irq
);
367 printk(" board fingerprint:");
368 for (i
= 0; i
< 32; i
+= 2) {
369 printk(" %04x %02x", inw(dev
->iobase
+ i
),
370 inb(dev
->iobase
+ i
+ 1));
373 printk(" board fingerprint (windowed):");
374 for (i
= 0; i
< 10; i
++)
375 printk(" 0x%04x", win_in(i
));
380 dev
->board_ptr
= ni_boards
+ ni_getboardtype(dev
, link
);
382 printk(" %s", boardtype
.name
);
383 dev
->board_name
= boardtype
.name
;
385 ret
= request_irq(irq
, ni_E_interrupt
, NI_E_IRQ_FLAGS
,
388 printk(" irq not available\n");
393 /* allocate private area */
394 ret
= ni_alloc_private(dev
);
398 devpriv
->stc_writew
= &mio_cs_win_out
;
399 devpriv
->stc_readw
= &mio_cs_win_in
;
400 devpriv
->stc_writel
= &win_out2
;
401 devpriv
->stc_readl
= &win_in2
;
403 ret
= ni_E_init(dev
, it
);
411 static int ni_getboardtype(struct comedi_device
*dev
,
412 struct pcmcia_device
*link
)
416 for (i
= 0; i
< n_ni_boards
; i
++) {
417 if (ni_boards
[i
].device_id
== link
->card_id
)
421 printk("unknown board 0x%04x -- pretend it is a ", link
->card_id
);
428 static struct pcmcia_device_id ni_mio_cs_ids
[] = {
429 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */
430 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */
431 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x02c4), /* DAQCard-6062E */
432 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x075e), /* DAQCard-6024E */
433 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */
437 MODULE_DEVICE_TABLE(pcmcia
, ni_mio_cs_ids
);
438 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
439 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
440 MODULE_LICENSE("GPL");
442 struct pcmcia_driver ni_mio_cs_driver
= {
444 .remove
= &cs_detach
,
445 .suspend
= &mio_cs_suspend
,
446 .resume
= &mio_cs_resume
,
447 .id_table
= ni_mio_cs_ids
,
448 .owner
= THIS_MODULE
,
454 int init_module(void)
456 pcmcia_register_driver(&ni_mio_cs_driver
);
457 comedi_driver_register(&driver_ni_mio_cs
);
461 void cleanup_module(void)
463 pcmcia_unregister_driver(&ni_mio_cs_driver
);
465 while (cur_dev
!= NULL
)
466 cs_detach(cur_dev
->handle
);
468 comedi_driver_unregister(&driver_ni_mio_cs
);