This source file includes following definitions.
- daq700_dio_insn_bits
- daq700_dio_insn_config
- daq700_ai_eoc
- daq700_ai_rinsn
- daq700_ai_config
- daq700_auto_attach
- daq700_cs_attach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 #include <linux/module.h>
42 #include <linux/delay.h>
43 #include <linux/interrupt.h>
44
45 #include "../comedi_pcmcia.h"
46
47
48 #define DIO_W 0x04
49 #define DIO_R 0x05
50 #define CMD_R1 0x00
51 #define CMD_R2 0x07
52 #define CMD_R3 0x05
53 #define STA_R1 0x00
54 #define STA_R2 0x01
55 #define ADFIFO_R 0x02
56 #define ADCLEAR_R 0x01
57 #define CDA_R0 0x08
58 #define CDA_R1 0x09
59 #define CDA_R2 0x0A
60 #define CMO_R 0x0B
61 #define TIC_R 0x06
62
63 #define CMD_R3_DIFF 0x04
64
65 static const struct comedi_lrange range_daq700_ai = {
66 3,
67 {
68 BIP_RANGE(10),
69 BIP_RANGE(5),
70 BIP_RANGE(2.5)
71 }
72 };
73
74 static int daq700_dio_insn_bits(struct comedi_device *dev,
75 struct comedi_subdevice *s,
76 struct comedi_insn *insn,
77 unsigned int *data)
78 {
79 unsigned int mask;
80 unsigned int val;
81
82 mask = comedi_dio_update_state(s, data);
83 if (mask) {
84 if (mask & 0xff)
85 outb(s->state & 0xff, dev->iobase + DIO_W);
86 }
87
88 val = s->state & 0xff;
89 val |= inb(dev->iobase + DIO_R) << 8;
90
91 data[1] = val;
92
93 return insn->n;
94 }
95
96 static int daq700_dio_insn_config(struct comedi_device *dev,
97 struct comedi_subdevice *s,
98 struct comedi_insn *insn,
99 unsigned int *data)
100 {
101 int ret;
102
103 ret = comedi_dio_insn_config(dev, s, insn, data, 0);
104 if (ret)
105 return ret;
106
107
108 s->io_bits = 0x00ff;
109
110 return insn->n;
111 }
112
113 static int daq700_ai_eoc(struct comedi_device *dev,
114 struct comedi_subdevice *s,
115 struct comedi_insn *insn,
116 unsigned long context)
117 {
118 unsigned int status;
119
120 status = inb(dev->iobase + STA_R2);
121 if ((status & 0x03))
122 return -EOVERFLOW;
123 status = inb(dev->iobase + STA_R1);
124 if ((status & 0x02))
125 return -ENODATA;
126 if ((status & 0x11) == 0x01)
127 return 0;
128 return -EBUSY;
129 }
130
131 static int daq700_ai_rinsn(struct comedi_device *dev,
132 struct comedi_subdevice *s,
133 struct comedi_insn *insn, unsigned int *data)
134 {
135 int n;
136 int d;
137 int ret;
138 unsigned int chan = CR_CHAN(insn->chanspec);
139 unsigned int aref = CR_AREF(insn->chanspec);
140 unsigned int range = CR_RANGE(insn->chanspec);
141 unsigned int r3_bits = 0;
142
143
144 if (aref == AREF_DIFF)
145 r3_bits |= CMD_R3_DIFF;
146
147 if (range >= 1)
148 range++;
149 outb(r3_bits | (range & 0x03), dev->iobase + CMD_R3);
150
151
152
153 outb(chan | 0x80, dev->iobase + CMD_R1);
154
155 udelay(2);
156
157
158 for (n = 0; n < insn->n; n++) {
159
160 outb(0x00, dev->iobase + CMD_R2);
161 outb(0x30, dev->iobase + CMO_R);
162 outb(0x00, dev->iobase + ADCLEAR_R);
163
164 inw(dev->iobase + ADFIFO_R);
165
166 outb(0x32, dev->iobase + CMO_R);
167
168
169 ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
170 if (ret)
171 return ret;
172
173
174 d = inw(dev->iobase + ADFIFO_R);
175
176
177 d &= 0x0fff;
178 d ^= 0x0800;
179 data[n] = d;
180 }
181 return n;
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195 static void daq700_ai_config(struct comedi_device *dev,
196 struct comedi_subdevice *s)
197 {
198 unsigned long iobase = dev->iobase;
199
200 outb(0x80, iobase + CMD_R1);
201 outb(0x00, iobase + CMD_R2);
202 outb(0x00, iobase + CMD_R3);
203 outb(0x32, iobase + CMO_R);
204 outb(0x00, iobase + TIC_R);
205 outb(0x00, iobase + ADCLEAR_R);
206 inw(iobase + ADFIFO_R);
207 }
208
209 static int daq700_auto_attach(struct comedi_device *dev,
210 unsigned long context)
211 {
212 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
213 struct comedi_subdevice *s;
214 int ret;
215
216 link->config_flags |= CONF_AUTO_SET_IO;
217 ret = comedi_pcmcia_enable(dev, NULL);
218 if (ret)
219 return ret;
220 dev->iobase = link->resource[0]->start;
221
222 ret = comedi_alloc_subdevices(dev, 2);
223 if (ret)
224 return ret;
225
226
227 s = &dev->subdevices[0];
228 s->type = COMEDI_SUBD_DIO;
229 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
230 s->n_chan = 16;
231 s->range_table = &range_digital;
232 s->maxdata = 1;
233 s->insn_bits = daq700_dio_insn_bits;
234 s->insn_config = daq700_dio_insn_config;
235 s->io_bits = 0x00ff;
236
237
238 s = &dev->subdevices[1];
239 s->type = COMEDI_SUBD_AI;
240 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
241 s->n_chan = 16;
242 s->maxdata = BIT(12) - 1;
243 s->range_table = &range_daq700_ai;
244 s->insn_read = daq700_ai_rinsn;
245 daq700_ai_config(dev, s);
246
247 return 0;
248 }
249
250 static struct comedi_driver daq700_driver = {
251 .driver_name = "ni_daq_700",
252 .module = THIS_MODULE,
253 .auto_attach = daq700_auto_attach,
254 .detach = comedi_pcmcia_disable,
255 };
256
257 static int daq700_cs_attach(struct pcmcia_device *link)
258 {
259 return comedi_pcmcia_auto_config(link, &daq700_driver);
260 }
261
262 static const struct pcmcia_device_id daq700_cs_ids[] = {
263 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x4743),
264 PCMCIA_DEVICE_NULL
265 };
266 MODULE_DEVICE_TABLE(pcmcia, daq700_cs_ids);
267
268 static struct pcmcia_driver daq700_cs_driver = {
269 .name = "ni_daq_700",
270 .owner = THIS_MODULE,
271 .id_table = daq700_cs_ids,
272 .probe = daq700_cs_attach,
273 .remove = comedi_pcmcia_auto_unconfig,
274 };
275 module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver);
276
277 MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>");
278 MODULE_DESCRIPTION(
279 "Comedi driver for National Instruments PCMCIA DAQCard-700 DIO/AI");
280 MODULE_LICENSE("GPL");