This source file includes following definitions.
- dyna_pci10xx_ai_eoc
- dyna_pci10xx_insn_read_ai
- dyna_pci10xx_insn_write_ao
- dyna_pci10xx_di_insn_bits
- dyna_pci10xx_do_insn_bits
- dyna_pci10xx_auto_attach
- dyna_pci10xx_detach
- dyna_pci10xx_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 #include <linux/module.h>
27 #include <linux/delay.h>
28 #include <linux/mutex.h>
29
30 #include "../comedi_pci.h"
31
32 #define READ_TIMEOUT 50
33
34 static const struct comedi_lrange range_pci1050_ai = {
35 3, {
36 BIP_RANGE(10),
37 BIP_RANGE(5),
38 UNI_RANGE(10)
39 }
40 };
41
42 static const char range_codes_pci1050_ai[] = { 0x00, 0x10, 0x30 };
43
44 struct dyna_pci10xx_private {
45 struct mutex mutex;
46 unsigned long BADR3;
47 };
48
49 static int dyna_pci10xx_ai_eoc(struct comedi_device *dev,
50 struct comedi_subdevice *s,
51 struct comedi_insn *insn,
52 unsigned long context)
53 {
54 unsigned int status;
55
56 status = inw_p(dev->iobase);
57 if (status & BIT(15))
58 return 0;
59 return -EBUSY;
60 }
61
62 static int dyna_pci10xx_insn_read_ai(struct comedi_device *dev,
63 struct comedi_subdevice *s,
64 struct comedi_insn *insn,
65 unsigned int *data)
66 {
67 struct dyna_pci10xx_private *devpriv = dev->private;
68 int n;
69 u16 d = 0;
70 int ret = 0;
71 unsigned int chan, range;
72
73
74 chan = CR_CHAN(insn->chanspec);
75 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
76
77 mutex_lock(&devpriv->mutex);
78
79 for (n = 0; n < insn->n; n++) {
80
81 smp_mb();
82 outw_p(0x0000 + range + chan, dev->iobase + 2);
83 usleep_range(10, 20);
84
85 ret = comedi_timeout(dev, s, insn, dyna_pci10xx_ai_eoc, 0);
86 if (ret)
87 break;
88
89
90 d = inw_p(dev->iobase);
91
92 d &= 0x0FFF;
93 data[n] = d;
94 }
95 mutex_unlock(&devpriv->mutex);
96
97
98 return ret ? ret : n;
99 }
100
101
102 static int dyna_pci10xx_insn_write_ao(struct comedi_device *dev,
103 struct comedi_subdevice *s,
104 struct comedi_insn *insn,
105 unsigned int *data)
106 {
107 struct dyna_pci10xx_private *devpriv = dev->private;
108 int n;
109
110 mutex_lock(&devpriv->mutex);
111 for (n = 0; n < insn->n; n++) {
112 smp_mb();
113
114 outw_p(data[n], dev->iobase);
115 usleep_range(10, 20);
116 }
117 mutex_unlock(&devpriv->mutex);
118 return n;
119 }
120
121
122 static int dyna_pci10xx_di_insn_bits(struct comedi_device *dev,
123 struct comedi_subdevice *s,
124 struct comedi_insn *insn,
125 unsigned int *data)
126 {
127 struct dyna_pci10xx_private *devpriv = dev->private;
128 u16 d = 0;
129
130 mutex_lock(&devpriv->mutex);
131 smp_mb();
132 d = inw_p(devpriv->BADR3);
133 usleep_range(10, 100);
134
135
136 data[1] = d;
137 data[0] = s->state;
138 mutex_unlock(&devpriv->mutex);
139 return insn->n;
140 }
141
142 static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
143 struct comedi_subdevice *s,
144 struct comedi_insn *insn,
145 unsigned int *data)
146 {
147 struct dyna_pci10xx_private *devpriv = dev->private;
148
149 mutex_lock(&devpriv->mutex);
150 if (comedi_dio_update_state(s, data)) {
151 smp_mb();
152 outw_p(s->state, devpriv->BADR3);
153 usleep_range(10, 100);
154 }
155
156 data[1] = s->state;
157 mutex_unlock(&devpriv->mutex);
158
159 return insn->n;
160 }
161
162 static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
163 unsigned long context_unused)
164 {
165 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
166 struct dyna_pci10xx_private *devpriv;
167 struct comedi_subdevice *s;
168 int ret;
169
170 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
171 if (!devpriv)
172 return -ENOMEM;
173
174 ret = comedi_pci_enable(dev);
175 if (ret)
176 return ret;
177 dev->iobase = pci_resource_start(pcidev, 2);
178 devpriv->BADR3 = pci_resource_start(pcidev, 3);
179
180 mutex_init(&devpriv->mutex);
181
182 ret = comedi_alloc_subdevices(dev, 4);
183 if (ret)
184 return ret;
185
186
187 s = &dev->subdevices[0];
188 s->type = COMEDI_SUBD_AI;
189 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
190 s->n_chan = 16;
191 s->maxdata = 0x0FFF;
192 s->range_table = &range_pci1050_ai;
193 s->insn_read = dyna_pci10xx_insn_read_ai;
194
195
196 s = &dev->subdevices[1];
197 s->type = COMEDI_SUBD_AO;
198 s->subdev_flags = SDF_WRITABLE;
199 s->n_chan = 1;
200 s->maxdata = 0x0FFF;
201 s->range_table = &range_unipolar10;
202 s->insn_write = dyna_pci10xx_insn_write_ao;
203
204
205 s = &dev->subdevices[2];
206 s->type = COMEDI_SUBD_DI;
207 s->subdev_flags = SDF_READABLE;
208 s->n_chan = 16;
209 s->maxdata = 1;
210 s->range_table = &range_digital;
211 s->insn_bits = dyna_pci10xx_di_insn_bits;
212
213
214 s = &dev->subdevices[3];
215 s->type = COMEDI_SUBD_DO;
216 s->subdev_flags = SDF_WRITABLE;
217 s->n_chan = 16;
218 s->maxdata = 1;
219 s->range_table = &range_digital;
220 s->state = 0;
221 s->insn_bits = dyna_pci10xx_do_insn_bits;
222
223 return 0;
224 }
225
226 static void dyna_pci10xx_detach(struct comedi_device *dev)
227 {
228 struct dyna_pci10xx_private *devpriv = dev->private;
229
230 comedi_pci_detach(dev);
231 if (devpriv)
232 mutex_destroy(&devpriv->mutex);
233 }
234
235 static struct comedi_driver dyna_pci10xx_driver = {
236 .driver_name = "dyna_pci10xx",
237 .module = THIS_MODULE,
238 .auto_attach = dyna_pci10xx_auto_attach,
239 .detach = dyna_pci10xx_detach,
240 };
241
242 static int dyna_pci10xx_pci_probe(struct pci_dev *dev,
243 const struct pci_device_id *id)
244 {
245 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver,
246 id->driver_data);
247 }
248
249 static const struct pci_device_id dyna_pci10xx_pci_table[] = {
250 { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) },
251 { 0 }
252 };
253 MODULE_DEVICE_TABLE(pci, dyna_pci10xx_pci_table);
254
255 static struct pci_driver dyna_pci10xx_pci_driver = {
256 .name = "dyna_pci10xx",
257 .id_table = dyna_pci10xx_pci_table,
258 .probe = dyna_pci10xx_pci_probe,
259 .remove = comedi_pci_auto_unconfig,
260 };
261 module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver);
262
263 MODULE_LICENSE("GPL");
264 MODULE_AUTHOR("Prashant Shah <pshah.mumbai@gmail.com>");
265 MODULE_DESCRIPTION("Comedi based drivers for Dynalog PCI DAQ cards");