GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / comedi / drivers / ni_mio_cs.c
blob691c866e860ee8dbb2f8184c7cdbfe07e343d2a7
1 /*
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.
24 Driver: ni_mio_cs
25 Description: National Instruments DAQCard E series
26 Author: ds
27 Status: works
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>
48 #include "ni_stc.h"
49 #include "8255.h"
51 #include <pcmcia/cs.h>
52 #include <pcmcia/cistpl.h>
53 #include <pcmcia/ds.h>
55 #undef DEBUG
57 #define ATMIO 1
58 #undef PCIMIO
61 * AT specific setup
64 #define NI_SIZE 0x20
66 #define MAX_N_CALDACS 32
68 static const struct ni_board_struct ni_boards[] = {
69 {.device_id = 0x010d,
70 .name = "DAQCard-ai-16xe-50",
71 .n_adchan = 16,
72 .adbits = 16,
73 .ai_fifo_depth = 1024,
74 .alwaysdither = 0,
75 .gainlkup = ai_gain_8,
76 .ai_speed = 5000,
77 .n_aochan = 0,
78 .aobits = 0,
79 .ao_fifo_depth = 0,
80 .ao_unipolar = 0,
81 .num_p0_dio_channels = 8,
82 .has_8255 = 0,
83 .caldac = {dac8800, dac8043},
85 {.device_id = 0x010c,
86 .name = "DAQCard-ai-16e-4",
87 .n_adchan = 16,
88 .adbits = 12,
89 .ai_fifo_depth = 1024,
90 .alwaysdither = 0,
91 .gainlkup = ai_gain_16,
92 .ai_speed = 4000,
93 .n_aochan = 0,
94 .aobits = 0,
95 .ao_fifo_depth = 0,
96 .ao_unipolar = 0,
97 .num_p0_dio_channels = 8,
98 .has_8255 = 0,
99 .caldac = {mb88341}, /* verified */
101 {.device_id = 0x02c4,
102 .name = "DAQCard-6062E",
103 .n_adchan = 16,
104 .adbits = 12,
105 .ai_fifo_depth = 8192,
106 .alwaysdither = 0,
107 .gainlkup = ai_gain_16,
108 .ai_speed = 2000,
109 .n_aochan = 2,
110 .aobits = 12,
111 .ao_fifo_depth = 2048,
112 .ao_range_table = &range_bipolar10,
113 .ao_unipolar = 0,
114 .ao_speed = 1176,
115 .num_p0_dio_channels = 8,
116 .has_8255 = 0,
117 .caldac = {ad8804_debug}, /* verified */
119 {.device_id = 0x075e,
120 .name = "DAQCard-6024E", /* specs incorrect! */
121 .n_adchan = 16,
122 .adbits = 12,
123 .ai_fifo_depth = 1024,
124 .alwaysdither = 0,
125 .gainlkup = ai_gain_4,
126 .ai_speed = 5000,
127 .n_aochan = 2,
128 .aobits = 12,
129 .ao_fifo_depth = 0,
130 .ao_range_table = &range_bipolar10,
131 .ao_unipolar = 0,
132 .ao_speed = 1000000,
133 .num_p0_dio_channels = 8,
134 .has_8255 = 0,
135 .caldac = {ad8804_debug},
137 {.device_id = 0x0245,
138 .name = "DAQCard-6036E", /* specs incorrect! */
139 .n_adchan = 16,
140 .adbits = 16,
141 .ai_fifo_depth = 1024,
142 .alwaysdither = 1,
143 .gainlkup = ai_gain_4,
144 .ai_speed = 5000,
145 .n_aochan = 2,
146 .aobits = 16,
147 .ao_fifo_depth = 0,
148 .ao_range_table = &range_bipolar10,
149 .ao_unipolar = 0,
150 .ao_speed = 1000000,
151 .num_p0_dio_channels = 8,
152 .has_8255 = 0,
153 .caldac = {ad8804_debug},
155 /* N.B. Update ni_mio_cs_ids[] when entries added above. */
158 #define interrupt_pin(a) 0
160 #define IRQ_POLARITY 1
162 #define NI_E_IRQ_FLAGS IRQF_SHARED
164 struct ni_private {
166 struct pcmcia_device *link;
168 NI_PRIVATE_COMMON};
170 #define devpriv ((struct ni_private *)dev->private)
172 /* How we access registers */
174 #define ni_writel(a, b) (outl((a), (b)+dev->iobase))
175 #define ni_readl(a) (inl((a)+dev->iobase))
176 #define ni_writew(a, b) (outw((a), (b)+dev->iobase))
177 #define ni_readw(a) (inw((a)+dev->iobase))
178 #define ni_writeb(a, b) (outb((a), (b)+dev->iobase))
179 #define ni_readb(a) (inb((a)+dev->iobase))
181 /* How we access windowed registers */
183 /* We automatically take advantage of STC registers that can be
184 * read/written directly in the I/O space of the board. The
185 * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
187 static void mio_cs_win_out(struct comedi_device *dev, uint16_t data, int addr)
189 unsigned long flags;
191 spin_lock_irqsave(&devpriv->window_lock, flags);
192 if (addr < 8) {
193 ni_writew(data, addr * 2);
194 } else {
195 ni_writew(addr, Window_Address);
196 ni_writew(data, Window_Data);
198 spin_unlock_irqrestore(&devpriv->window_lock, flags);
201 static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr)
203 unsigned long flags;
204 uint16_t ret;
206 spin_lock_irqsave(&devpriv->window_lock, flags);
207 if (addr < 8) {
208 ret = ni_readw(addr * 2);
209 } else {
210 ni_writew(addr, Window_Address);
211 ret = ni_readw(Window_Data);
213 spin_unlock_irqrestore(&devpriv->window_lock, flags);
215 return ret;
218 static int mio_cs_attach(struct comedi_device *dev,
219 struct comedi_devconfig *it);
220 static int mio_cs_detach(struct comedi_device *dev);
221 static struct comedi_driver driver_ni_mio_cs = {
222 .driver_name = "ni_mio_cs",
223 .module = THIS_MODULE,
224 .attach = mio_cs_attach,
225 .detach = mio_cs_detach,
228 #include "ni_mio_common.c"
230 static int ni_getboardtype(struct comedi_device *dev,
231 struct pcmcia_device *link);
233 /* clean up allocated resources */
234 /* called when driver is removed */
235 static int mio_cs_detach(struct comedi_device *dev)
237 mio_common_detach(dev);
239 /* PCMCIA layer frees the IO region */
241 if (dev->irq)
242 free_irq(dev->irq, dev);
244 return 0;
247 static void mio_cs_config(struct pcmcia_device *link);
248 static void cs_release(struct pcmcia_device *link);
249 static void cs_detach(struct pcmcia_device *);
251 static struct pcmcia_device *cur_dev = NULL;
253 static int cs_attach(struct pcmcia_device *link)
255 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
256 link->resource[0]->end = 16;
257 link->conf.Attributes = CONF_ENABLE_IRQ;
258 link->conf.IntType = INT_MEMORY_AND_IO;
260 cur_dev = link;
262 mio_cs_config(link);
264 return 0;
267 static void cs_release(struct pcmcia_device *link)
269 pcmcia_disable_device(link);
272 static void cs_detach(struct pcmcia_device *link)
274 DPRINTK("cs_detach(link=%p)\n", link);
276 cs_release(link);
279 static int mio_cs_suspend(struct pcmcia_device *link)
281 DPRINTK("pm suspend\n");
283 return 0;
286 static int mio_cs_resume(struct pcmcia_device *link)
288 DPRINTK("pm resume\n");
289 return 0;
293 static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev,
294 cistpl_cftable_entry_t *cfg,
295 cistpl_cftable_entry_t *dflt,
296 unsigned int vcc,
297 void *priv_data)
299 int base, ret;
301 p_dev->resource[0]->end = cfg->io.win[0].len;
302 p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK;
304 for (base = 0x000; base < 0x400; base += 0x20) {
305 p_dev->resource[0]->start = base;
306 ret = pcmcia_request_io(p_dev);
307 if (!ret)
308 return 0;
310 return -ENODEV;
314 static void mio_cs_config(struct pcmcia_device *link)
316 int ret;
318 DPRINTK("mio_cs_config(link=%p)\n", link);
320 ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL);
321 if (ret) {
322 dev_warn(&link->dev, "no configuration found\n");
323 return;
326 if (!link->irq)
327 dev_info(&link->dev, "no IRQ available\n");
329 ret = pcmcia_request_configuration(link, &link->conf);
332 static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it)
334 struct pcmcia_device *link;
335 unsigned int irq;
336 int ret;
338 DPRINTK("mio_cs_attach(dev=%p,it=%p)\n", dev, it);
340 link = cur_dev;
341 if (!link)
342 return -EIO;
344 dev->driver = &driver_ni_mio_cs;
345 dev->iobase = link->resource[0]->start;
347 irq = link->irq;
349 printk("comedi%d: %s: DAQCard: io 0x%04lx, irq %u, ",
350 dev->minor, dev->driver->driver_name, dev->iobase, irq);
353 dev->board_ptr = ni_boards + ni_getboardtype(dev, link);
355 printk(" %s", boardtype.name);
356 dev->board_name = boardtype.name;
358 ret = request_irq(irq, ni_E_interrupt, NI_E_IRQ_FLAGS,
359 "ni_mio_cs", dev);
360 if (ret < 0) {
361 printk(" irq not available\n");
362 return -EINVAL;
364 dev->irq = irq;
366 /* allocate private area */
367 ret = ni_alloc_private(dev);
368 if (ret < 0)
369 return ret;
371 devpriv->stc_writew = &mio_cs_win_out;
372 devpriv->stc_readw = &mio_cs_win_in;
373 devpriv->stc_writel = &win_out2;
374 devpriv->stc_readl = &win_in2;
376 ret = ni_E_init(dev, it);
378 if (ret < 0)
379 return ret;
381 return 0;
384 static int ni_getboardtype(struct comedi_device *dev,
385 struct pcmcia_device *link)
387 int i;
389 for (i = 0; i < n_ni_boards; i++) {
390 if (ni_boards[i].device_id == link->card_id)
391 return i;
394 printk("unknown board 0x%04x -- pretend it is a ", link->card_id);
396 return 0;
399 #ifdef MODULE
401 static struct pcmcia_device_id ni_mio_cs_ids[] = {
402 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */
403 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */
404 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x02c4), /* DAQCard-6062E */
405 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x075e), /* DAQCard-6024E */
406 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */
407 PCMCIA_DEVICE_NULL
410 MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids);
411 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
412 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
413 MODULE_LICENSE("GPL");
415 struct pcmcia_driver ni_mio_cs_driver = {
416 .probe = &cs_attach,
417 .remove = &cs_detach,
418 .suspend = &mio_cs_suspend,
419 .resume = &mio_cs_resume,
420 .id_table = ni_mio_cs_ids,
421 .owner = THIS_MODULE,
422 .drv = {
423 .name = "ni_mio_cs",
427 int init_module(void)
429 pcmcia_register_driver(&ni_mio_cs_driver);
430 comedi_driver_register(&driver_ni_mio_cs);
431 return 0;
434 void cleanup_module(void)
436 pcmcia_unregister_driver(&ni_mio_cs_driver);
437 comedi_driver_unregister(&driver_ni_mio_cs);
439 #endif