libata: bugfix: Remove __le32 in ata_tf_to_fis()
[sfrench/cifs-2.6.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 "../comedidev.h"
40
41 #include <linux/delay.h>
42
43 #include "ni_stc.h"
44 #include "8255.h"
45
46 #include <pcmcia/cistpl.h>
47 #include <pcmcia/ds.h>
48
49 #undef DEBUG
50
51 #define ATMIO 1
52 #undef PCIMIO
53
54 /*
55  *  AT specific setup
56  */
57
58 #define NI_SIZE 0x20
59
60 #define MAX_N_CALDACS 32
61
62 static const struct ni_board_struct ni_boards[] = {
63         {
64                 .device_id      = 0x010d,
65                 .name           = "DAQCard-ai-16xe-50",
66                 .n_adchan       = 16,
67                 .adbits         = 16,
68                 .ai_fifo_depth  = 1024,
69                 .gainlkup       = ai_gain_8,
70                 .ai_speed       = 5000,
71                 .num_p0_dio_channels = 8,
72                 .caldac         = { dac8800, dac8043 },
73         }, {
74                 .device_id      = 0x010c,
75                 .name           = "DAQCard-ai-16e-4",
76                 .n_adchan       = 16,
77                 .adbits         = 12,
78                 .ai_fifo_depth  = 1024,
79                 .gainlkup       = ai_gain_16,
80                 .ai_speed       = 4000,
81                 .num_p0_dio_channels = 8,
82                 .caldac         = { mb88341 },          /* verified */
83         }, {
84                 .device_id      = 0x02c4,
85                 .name           = "DAQCard-6062E",
86                 .n_adchan       = 16,
87                 .adbits         = 12,
88                 .ai_fifo_depth  = 8192,
89                 .gainlkup       = ai_gain_16,
90                 .ai_speed       = 2000,
91                 .n_aochan       = 2,
92                 .aobits         = 12,
93                 .ao_fifo_depth  = 2048,
94                 .ao_range_table = &range_bipolar10,
95                 .ao_speed       = 1176,
96                 .num_p0_dio_channels = 8,
97                 .caldac         = { ad8804_debug },     /* verified */
98          }, {
99                 /* specs incorrect! */
100                 .device_id      = 0x075e,
101                 .name           = "DAQCard-6024E",
102                 .n_adchan       = 16,
103                 .adbits         = 12,
104                 .ai_fifo_depth  = 1024,
105                 .gainlkup       = ai_gain_4,
106                 .ai_speed       = 5000,
107                 .n_aochan       = 2,
108                 .aobits         = 12,
109                 .ao_range_table = &range_bipolar10,
110                 .ao_speed       = 1000000,
111                 .num_p0_dio_channels = 8,
112                 .caldac         = { ad8804_debug },
113         }, {
114                 /* specs incorrect! */
115                 .device_id      = 0x0245,
116                 .name           = "DAQCard-6036E",
117                 .n_adchan       = 16,
118                 .adbits         = 16,
119                 .ai_fifo_depth  = 1024,
120                 .alwaysdither   = 1,
121                 .gainlkup       = ai_gain_4,
122                 .ai_speed       = 5000,
123                 .n_aochan       = 2,
124                 .aobits         = 16,
125                 .ao_range_table = &range_bipolar10,
126                 .ao_speed       = 1000000,
127                 .num_p0_dio_channels = 8,
128                 .caldac         = { ad8804_debug },
129          },
130 #if 0
131         {
132                 .device_id      = 0x0000,       /* unknown */
133                 .name           = "DAQCard-6715",
134                 .n_aochan       = 8,
135                 .aobits         = 12,
136                 .ao_671x        = 8192,
137                 .num_p0_dio_channels = 8,
138                 .caldac         = { mb88341, mb88341 },
139         },
140 #endif
141 };
142
143 #define interrupt_pin(a)        0
144
145 #define IRQ_POLARITY 1
146
147 struct ni_private {
148
149         struct pcmcia_device *link;
150
151 NI_PRIVATE_COMMON};
152
153 /* How we access registers */
154
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))
161
162 /* How we access windowed registers */
163
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. */
167
168 static void mio_cs_win_out(struct comedi_device *dev, uint16_t data, int addr)
169 {
170         struct ni_private *devpriv = dev->private;
171         unsigned long flags;
172
173         spin_lock_irqsave(&devpriv->window_lock, flags);
174         if (addr < 8) {
175                 ni_writew(data, addr * 2);
176         } else {
177                 ni_writew(addr, Window_Address);
178                 ni_writew(data, Window_Data);
179         }
180         spin_unlock_irqrestore(&devpriv->window_lock, flags);
181 }
182
183 static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr)
184 {
185         struct ni_private *devpriv = dev->private;
186         unsigned long flags;
187         uint16_t ret;
188
189         spin_lock_irqsave(&devpriv->window_lock, flags);
190         if (addr < 8) {
191                 ret = ni_readw(addr * 2);
192         } else {
193                 ni_writew(addr, Window_Address);
194                 ret = ni_readw(Window_Data);
195         }
196         spin_unlock_irqrestore(&devpriv->window_lock, flags);
197
198         return ret;
199 }
200
201 #include "ni_mio_common.c"
202
203 static const void *ni_getboardtype(struct comedi_device *dev,
204                                    struct pcmcia_device *link)
205 {
206         static const struct ni_board_struct *board;
207         int i;
208
209         for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
210                 board = &ni_boards[i];
211                 if (board->device_id == link->card_id)
212                         return board;
213         }
214         return NULL;
215 }
216
217 static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
218 {
219         int base, ret;
220
221         p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
222         p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
223
224         for (base = 0x000; base < 0x400; base += 0x20) {
225                 p_dev->resource[0]->start = base;
226                 ret = pcmcia_request_io(p_dev);
227                 if (!ret)
228                         return 0;
229         }
230         return -ENODEV;
231 }
232
233 static int mio_cs_auto_attach(struct comedi_device *dev,
234                               unsigned long context)
235 {
236         struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
237         static const struct ni_board_struct *board;
238         struct ni_private *devpriv;
239         int ret;
240
241         board = ni_getboardtype(dev, link);
242         if (!board)
243                 return -ENODEV;
244         dev->board_ptr = board;
245         dev->board_name = board->name;
246
247         link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
248         ret = comedi_pcmcia_enable(dev, mio_pcmcia_config_loop);
249         if (ret)
250                 return ret;
251         dev->iobase = link->resource[0]->start;
252
253         link->priv = dev;
254         ret = pcmcia_request_irq(link, ni_E_interrupt);
255         if (ret)
256                 return ret;
257         dev->irq = link->irq;
258
259         ret = ni_alloc_private(dev);
260         if (ret)
261                 return ret;
262
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;
268
269         return ni_E_init(dev);
270 }
271
272 static void mio_cs_detach(struct comedi_device *dev)
273 {
274         mio_common_detach(dev);
275         comedi_pcmcia_disable(dev);
276 }
277
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,
283 };
284
285 static int cs_attach(struct pcmcia_device *link)
286 {
287         return comedi_pcmcia_auto_config(link, &driver_ni_mio_cs);
288 }
289
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 */
296         PCMCIA_DEVICE_NULL
297 };
298 MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids);
299
300 static struct pcmcia_driver ni_mio_cs_driver = {
301         .name           = "ni_mio_cs",
302         .owner          = THIS_MODULE,
303         .id_table       = ni_mio_cs_ids,
304         .probe          = cs_attach,
305         .remove         = comedi_pcmcia_auto_unconfig,
306 };
307 module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver);
308
309 MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
310 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
311 MODULE_LICENSE("GPL");