]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/ni_mio_cs.c
staging: comedi: ni_stc.h: remove read/write callbacks from ni_private
[karo-tx-linux.git] / drivers / staging / comedi / drivers / ni_mio_cs.c
1 /*
2     comedi/drivers/ni_mio_cs.c
3     Hardware driver for NI PCMCIA MIO E series cards
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7
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.
12
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.
17 */
18 /*
19 Driver: ni_mio_cs
20 Description: National Instruments DAQCard E series
21 Author: ds
22 Status: works
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
26
27 See the notes in the ni_atmio.o driver.
28 */
29 /*
30         The real guts of the driver is in ni_mio_common.c, which is
31         included by all the E series drivers.
32
33         References for specifications:
34
35            341080a.pdf  DAQCard E Series Register Level Programmer Manual
36
37 */
38
39 #include <linux/module.h>
40 #include "../comedidev.h"
41
42 #include <linux/delay.h>
43
44 #include "ni_stc.h"
45 #include "8255.h"
46
47 #include <pcmcia/cistpl.h>
48 #include <pcmcia/ds.h>
49
50 #define ATMIO 1
51 #undef PCIMIO
52
53 /*
54  *  AT specific setup
55  */
56
57 #define NI_SIZE 0x20
58
59 static const struct ni_board_struct ni_boards[] = {
60         {
61                 .device_id      = 0x010d,
62                 .name           = "DAQCard-ai-16xe-50",
63                 .n_adchan       = 16,
64                 .adbits         = 16,
65                 .ai_fifo_depth  = 1024,
66                 .gainlkup       = ai_gain_8,
67                 .ai_speed       = 5000,
68                 .num_p0_dio_channels = 8,
69                 .caldac         = { dac8800, dac8043 },
70         }, {
71                 .device_id      = 0x010c,
72                 .name           = "DAQCard-ai-16e-4",
73                 .n_adchan       = 16,
74                 .adbits         = 12,
75                 .ai_fifo_depth  = 1024,
76                 .gainlkup       = ai_gain_16,
77                 .ai_speed       = 4000,
78                 .num_p0_dio_channels = 8,
79                 .caldac         = { mb88341 },          /* verified */
80         }, {
81                 .device_id      = 0x02c4,
82                 .name           = "DAQCard-6062E",
83                 .n_adchan       = 16,
84                 .adbits         = 12,
85                 .ai_fifo_depth  = 8192,
86                 .gainlkup       = ai_gain_16,
87                 .ai_speed       = 2000,
88                 .n_aochan       = 2,
89                 .aobits         = 12,
90                 .ao_fifo_depth  = 2048,
91                 .ao_range_table = &range_bipolar10,
92                 .ao_speed       = 1176,
93                 .num_p0_dio_channels = 8,
94                 .caldac         = { ad8804_debug },     /* verified */
95          }, {
96                 /* specs incorrect! */
97                 .device_id      = 0x075e,
98                 .name           = "DAQCard-6024E",
99                 .n_adchan       = 16,
100                 .adbits         = 12,
101                 .ai_fifo_depth  = 1024,
102                 .gainlkup       = ai_gain_4,
103                 .ai_speed       = 5000,
104                 .n_aochan       = 2,
105                 .aobits         = 12,
106                 .ao_range_table = &range_bipolar10,
107                 .ao_speed       = 1000000,
108                 .num_p0_dio_channels = 8,
109                 .caldac         = { ad8804_debug },
110         }, {
111                 /* specs incorrect! */
112                 .device_id      = 0x0245,
113                 .name           = "DAQCard-6036E",
114                 .n_adchan       = 16,
115                 .adbits         = 16,
116                 .ai_fifo_depth  = 1024,
117                 .alwaysdither   = 1,
118                 .gainlkup       = ai_gain_4,
119                 .ai_speed       = 5000,
120                 .n_aochan       = 2,
121                 .aobits         = 16,
122                 .ao_range_table = &range_bipolar10,
123                 .ao_speed       = 1000000,
124                 .num_p0_dio_channels = 8,
125                 .caldac         = { ad8804_debug },
126          },
127 #if 0
128         {
129                 .device_id      = 0x0000,       /* unknown */
130                 .name           = "DAQCard-6715",
131                 .n_aochan       = 8,
132                 .aobits         = 12,
133                 .ao_671x        = 8192,
134                 .num_p0_dio_channels = 8,
135                 .caldac         = { mb88341, mb88341 },
136         },
137 #endif
138 };
139
140 #define interrupt_pin(a)        0
141
142 #define IRQ_POLARITY 1
143
144 #include "ni_mio_common.c"
145
146 /* How we access windowed registers */
147
148 /* We automatically take advantage of STC registers that can be
149  * read/written directly in the I/O space of the board.  The
150  * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
151
152 static void mio_cs_win_out(struct comedi_device *dev, uint16_t data, int addr)
153 {
154         struct ni_private *devpriv = dev->private;
155         unsigned long flags;
156
157         spin_lock_irqsave(&devpriv->window_lock, flags);
158         if (addr < 8) {
159                 ni_writew(dev, data, addr * 2);
160         } else {
161                 ni_writew(dev, addr, Window_Address);
162                 ni_writew(dev, data, Window_Data);
163         }
164         spin_unlock_irqrestore(&devpriv->window_lock, flags);
165 }
166
167 static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr)
168 {
169         struct ni_private *devpriv = dev->private;
170         unsigned long flags;
171         uint16_t ret;
172
173         spin_lock_irqsave(&devpriv->window_lock, flags);
174         if (addr < 8) {
175                 ret = ni_readw(dev, addr * 2);
176         } else {
177                 ni_writew(dev, addr, Window_Address);
178                 ret = ni_readw(dev, Window_Data);
179         }
180         spin_unlock_irqrestore(&devpriv->window_lock, flags);
181
182         return ret;
183 }
184
185 static const void *ni_getboardtype(struct comedi_device *dev,
186                                    struct pcmcia_device *link)
187 {
188         static const struct ni_board_struct *board;
189         int i;
190
191         for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
192                 board = &ni_boards[i];
193                 if (board->device_id == link->card_id)
194                         return board;
195         }
196         return NULL;
197 }
198
199 static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
200 {
201         int base, ret;
202
203         p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
204         p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
205
206         for (base = 0x000; base < 0x400; base += 0x20) {
207                 p_dev->resource[0]->start = base;
208                 ret = pcmcia_request_io(p_dev);
209                 if (!ret)
210                         return 0;
211         }
212         return -ENODEV;
213 }
214
215 static int mio_cs_auto_attach(struct comedi_device *dev,
216                               unsigned long context)
217 {
218         struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
219         static const struct ni_board_struct *board;
220         struct ni_private *devpriv;
221         int ret;
222
223         board = ni_getboardtype(dev, link);
224         if (!board)
225                 return -ENODEV;
226         dev->board_ptr = board;
227         dev->board_name = board->name;
228
229         link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
230         ret = comedi_pcmcia_enable(dev, mio_pcmcia_config_loop);
231         if (ret)
232                 return ret;
233         dev->iobase = link->resource[0]->start;
234
235         link->priv = dev;
236         ret = pcmcia_request_irq(link, ni_E_interrupt);
237         if (ret)
238                 return ret;
239         dev->irq = link->irq;
240
241         ret = ni_alloc_private(dev);
242         if (ret)
243                 return ret;
244
245         devpriv = dev->private;
246
247         devpriv->stc_writew     = mio_cs_win_out;
248         devpriv->stc_readw      = mio_cs_win_in;
249         devpriv->stc_writel     = win_out2;
250         devpriv->stc_readl      = win_in2;
251
252         return ni_E_init(dev);
253 }
254
255 static void mio_cs_detach(struct comedi_device *dev)
256 {
257         mio_common_detach(dev);
258         comedi_pcmcia_disable(dev);
259 }
260
261 static struct comedi_driver driver_ni_mio_cs = {
262         .driver_name    = "ni_mio_cs",
263         .module         = THIS_MODULE,
264         .auto_attach    = mio_cs_auto_attach,
265         .detach         = mio_cs_detach,
266 };
267
268 static int cs_attach(struct pcmcia_device *link)
269 {
270         return comedi_pcmcia_auto_config(link, &driver_ni_mio_cs);
271 }
272
273 static const struct pcmcia_device_id ni_mio_cs_ids[] = {
274         PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d),        /* DAQCard-ai-16xe-50 */
275         PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c),        /* DAQCard-ai-16e-4 */
276         PCMCIA_DEVICE_MANF_CARD(0x010b, 0x02c4),        /* DAQCard-6062E */
277         PCMCIA_DEVICE_MANF_CARD(0x010b, 0x075e),        /* DAQCard-6024E */
278         PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245),        /* DAQCard-6036E */
279         PCMCIA_DEVICE_NULL
280 };
281 MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids);
282
283 static struct pcmcia_driver ni_mio_cs_driver = {
284         .name           = "ni_mio_cs",
285         .owner          = THIS_MODULE,
286         .id_table       = ni_mio_cs_ids,
287         .probe          = cs_attach,
288         .remove         = comedi_pcmcia_auto_unconfig,
289 };
290 module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver);
291
292 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
293 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
294 MODULE_LICENSE("GPL");