This source file includes following definitions.
- icp_multi_ai_eoc
- icp_multi_ai_insn_read
- icp_multi_ao_ready
- icp_multi_ao_insn_write
- icp_multi_di_insn_bits
- icp_multi_do_insn_bits
- icp_multi_reset
- icp_multi_auto_attach
- icp_multi_pci_probe
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 #include <linux/module.h>
38 #include <linux/delay.h>
39
40 #include "../comedi_pci.h"
41
42 #define ICP_MULTI_ADC_CSR 0x00
43 #define ICP_MULTI_ADC_CSR_ST BIT(0)
44 #define ICP_MULTI_ADC_CSR_BSY BIT(0)
45 #define ICP_MULTI_ADC_CSR_BI BIT(4)
46 #define ICP_MULTI_ADC_CSR_RA BIT(5)
47 #define ICP_MULTI_ADC_CSR_DI BIT(6)
48 #define ICP_MULTI_ADC_CSR_DI_CHAN(x) (((x) & 0x7) << 9)
49 #define ICP_MULTI_ADC_CSR_SE_CHAN(x) (((x) & 0xf) << 8)
50 #define ICP_MULTI_AI 2
51 #define ICP_MULTI_DAC_CSR 0x04
52 #define ICP_MULTI_DAC_CSR_ST BIT(0)
53 #define ICP_MULTI_DAC_CSR_BSY BIT(0)
54 #define ICP_MULTI_DAC_CSR_BI BIT(4)
55 #define ICP_MULTI_DAC_CSR_RA BIT(5)
56 #define ICP_MULTI_DAC_CSR_CHAN(x) (((x) & 0x3) << 8)
57 #define ICP_MULTI_AO 6
58 #define ICP_MULTI_DI 8
59 #define ICP_MULTI_DO 0x0A
60 #define ICP_MULTI_INT_EN 0x0c
61 #define ICP_MULTI_INT_STAT 0x0e
62 #define ICP_MULTI_INT_ADC_RDY BIT(0)
63 #define ICP_MULTI_INT_DAC_RDY BIT(1)
64 #define ICP_MULTI_INT_DOUT_ERR BIT(2)
65 #define ICP_MULTI_INT_DIN_STAT BIT(3)
66 #define ICP_MULTI_INT_CIE0 BIT(4)
67 #define ICP_MULTI_INT_CIE1 BIT(5)
68 #define ICP_MULTI_INT_CIE2 BIT(6)
69 #define ICP_MULTI_INT_CIE3 BIT(7)
70 #define ICP_MULTI_INT_MASK 0xff
71 #define ICP_MULTI_CNTR0 0x10
72 #define ICP_MULTI_CNTR1 0x12
73 #define ICP_MULTI_CNTR2 0x14
74 #define ICP_MULTI_CNTR3 0x16
75
76
77 static const struct comedi_lrange icp_multi_ranges = {
78 4, {
79 UNI_RANGE(5),
80 UNI_RANGE(10),
81 BIP_RANGE(5),
82 BIP_RANGE(10)
83 }
84 };
85
86 static const char range_codes_analog[] = { 0x00, 0x20, 0x10, 0x30 };
87
88 static int icp_multi_ai_eoc(struct comedi_device *dev,
89 struct comedi_subdevice *s,
90 struct comedi_insn *insn,
91 unsigned long context)
92 {
93 unsigned int status;
94
95 status = readw(dev->mmio + ICP_MULTI_ADC_CSR);
96 if ((status & ICP_MULTI_ADC_CSR_BSY) == 0)
97 return 0;
98 return -EBUSY;
99 }
100
101 static int icp_multi_ai_insn_read(struct comedi_device *dev,
102 struct comedi_subdevice *s,
103 struct comedi_insn *insn,
104 unsigned int *data)
105 {
106 unsigned int chan = CR_CHAN(insn->chanspec);
107 unsigned int range = CR_RANGE(insn->chanspec);
108 unsigned int aref = CR_AREF(insn->chanspec);
109 unsigned int adc_csr;
110 int ret = 0;
111 int n;
112
113
114 if (aref == AREF_DIFF) {
115 adc_csr = ICP_MULTI_ADC_CSR_DI_CHAN(chan) |
116 ICP_MULTI_ADC_CSR_DI;
117 } else {
118 adc_csr = ICP_MULTI_ADC_CSR_SE_CHAN(chan);
119 }
120 adc_csr |= range_codes_analog[range];
121 writew(adc_csr, dev->mmio + ICP_MULTI_ADC_CSR);
122
123 for (n = 0; n < insn->n; n++) {
124
125 writew(adc_csr | ICP_MULTI_ADC_CSR_ST,
126 dev->mmio + ICP_MULTI_ADC_CSR);
127
128 udelay(1);
129
130
131 ret = comedi_timeout(dev, s, insn, icp_multi_ai_eoc, 0);
132 if (ret)
133 break;
134
135 data[n] = (readw(dev->mmio + ICP_MULTI_AI) >> 4) & 0x0fff;
136 }
137
138 return ret ? ret : n;
139 }
140
141 static int icp_multi_ao_ready(struct comedi_device *dev,
142 struct comedi_subdevice *s,
143 struct comedi_insn *insn,
144 unsigned long context)
145 {
146 unsigned int status;
147
148 status = readw(dev->mmio + ICP_MULTI_DAC_CSR);
149 if ((status & ICP_MULTI_DAC_CSR_BSY) == 0)
150 return 0;
151 return -EBUSY;
152 }
153
154 static int icp_multi_ao_insn_write(struct comedi_device *dev,
155 struct comedi_subdevice *s,
156 struct comedi_insn *insn,
157 unsigned int *data)
158 {
159 unsigned int chan = CR_CHAN(insn->chanspec);
160 unsigned int range = CR_RANGE(insn->chanspec);
161 unsigned int dac_csr;
162 int i;
163
164
165 dac_csr = ICP_MULTI_DAC_CSR_CHAN(chan);
166 dac_csr |= range_codes_analog[range];
167 writew(dac_csr, dev->mmio + ICP_MULTI_DAC_CSR);
168
169 for (i = 0; i < insn->n; i++) {
170 unsigned int val = data[i];
171 int ret;
172
173
174 ret = comedi_timeout(dev, s, insn, icp_multi_ao_ready, 0);
175 if (ret)
176 return ret;
177
178 writew(val, dev->mmio + ICP_MULTI_AO);
179
180
181 writew(dac_csr | ICP_MULTI_DAC_CSR_ST,
182 dev->mmio + ICP_MULTI_DAC_CSR);
183
184 s->readback[chan] = val;
185 }
186
187 return insn->n;
188 }
189
190 static int icp_multi_di_insn_bits(struct comedi_device *dev,
191 struct comedi_subdevice *s,
192 struct comedi_insn *insn,
193 unsigned int *data)
194 {
195 data[1] = readw(dev->mmio + ICP_MULTI_DI);
196
197 return insn->n;
198 }
199
200 static int icp_multi_do_insn_bits(struct comedi_device *dev,
201 struct comedi_subdevice *s,
202 struct comedi_insn *insn,
203 unsigned int *data)
204 {
205 if (comedi_dio_update_state(s, data))
206 writew(s->state, dev->mmio + ICP_MULTI_DO);
207
208 data[1] = s->state;
209
210 return insn->n;
211 }
212
213 static int icp_multi_reset(struct comedi_device *dev)
214 {
215 int i;
216
217
218 writew(0, dev->mmio + ICP_MULTI_INT_EN);
219 writew(ICP_MULTI_INT_MASK, dev->mmio + ICP_MULTI_INT_STAT);
220
221
222 for (i = 0; i < 4; i++) {
223 unsigned int dac_csr = ICP_MULTI_DAC_CSR_CHAN(i);
224
225
226 writew(dac_csr, dev->mmio + ICP_MULTI_DAC_CSR);
227
228
229 writew(0, dev->mmio + ICP_MULTI_AO);
230
231
232 writew(dac_csr | ICP_MULTI_DAC_CSR_ST,
233 dev->mmio + ICP_MULTI_DAC_CSR);
234 udelay(1);
235 }
236
237
238 writew(0, dev->mmio + ICP_MULTI_DO);
239
240 return 0;
241 }
242
243 static int icp_multi_auto_attach(struct comedi_device *dev,
244 unsigned long context_unused)
245 {
246 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
247 struct comedi_subdevice *s;
248 int ret;
249
250 ret = comedi_pci_enable(dev);
251 if (ret)
252 return ret;
253
254 dev->mmio = pci_ioremap_bar(pcidev, 2);
255 if (!dev->mmio)
256 return -ENOMEM;
257
258 ret = comedi_alloc_subdevices(dev, 4);
259 if (ret)
260 return ret;
261
262 icp_multi_reset(dev);
263
264
265 s = &dev->subdevices[0];
266 s->type = COMEDI_SUBD_AI;
267 s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF;
268 s->n_chan = 16;
269 s->maxdata = 0x0fff;
270 s->range_table = &icp_multi_ranges;
271 s->insn_read = icp_multi_ai_insn_read;
272
273
274 s = &dev->subdevices[1];
275 s->type = COMEDI_SUBD_AO;
276 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
277 s->n_chan = 4;
278 s->maxdata = 0x0fff;
279 s->range_table = &icp_multi_ranges;
280 s->insn_write = icp_multi_ao_insn_write;
281
282 ret = comedi_alloc_subdev_readback(s);
283 if (ret)
284 return ret;
285
286
287 s = &dev->subdevices[2];
288 s->type = COMEDI_SUBD_DI;
289 s->subdev_flags = SDF_READABLE;
290 s->n_chan = 16;
291 s->maxdata = 1;
292 s->range_table = &range_digital;
293 s->insn_bits = icp_multi_di_insn_bits;
294
295
296 s = &dev->subdevices[3];
297 s->type = COMEDI_SUBD_DO;
298 s->subdev_flags = SDF_WRITABLE;
299 s->n_chan = 8;
300 s->maxdata = 1;
301 s->range_table = &range_digital;
302 s->insn_bits = icp_multi_do_insn_bits;
303
304 return 0;
305 }
306
307 static struct comedi_driver icp_multi_driver = {
308 .driver_name = "icp_multi",
309 .module = THIS_MODULE,
310 .auto_attach = icp_multi_auto_attach,
311 .detach = comedi_pci_detach,
312 };
313
314 static int icp_multi_pci_probe(struct pci_dev *dev,
315 const struct pci_device_id *id)
316 {
317 return comedi_pci_auto_config(dev, &icp_multi_driver, id->driver_data);
318 }
319
320 static const struct pci_device_id icp_multi_pci_table[] = {
321 { PCI_DEVICE(PCI_VENDOR_ID_ICP, 0x8000) },
322 { 0 }
323 };
324 MODULE_DEVICE_TABLE(pci, icp_multi_pci_table);
325
326 static struct pci_driver icp_multi_pci_driver = {
327 .name = "icp_multi",
328 .id_table = icp_multi_pci_table,
329 .probe = icp_multi_pci_probe,
330 .remove = comedi_pci_auto_unconfig,
331 };
332 module_comedi_pci_driver(icp_multi_driver, icp_multi_pci_driver);
333
334 MODULE_AUTHOR("Comedi http://www.comedi.org");
335 MODULE_DESCRIPTION("Comedi driver for Inova ICP_MULTI board");
336 MODULE_LICENSE("GPL");