This source file includes following definitions.
- mpc624_ai_get_sample
- mpc624_ai_eoc
- mpc624_ai_insn_read
- mpc624_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
42
43
44
45
46 #include <linux/module.h>
47 #include "../comedidev.h"
48
49 #include <linux/delay.h>
50
51
52 #define MPC624_MASTER_CONTROL 0
53 #define MPC624_GNMUXCH 1
54 #define MPC624_ADC 2
55 #define MPC624_EE 3
56 #define MPC624_LEDS 4
57 #define MPC624_DIO 5
58 #define MPC624_IRQ_MASK 6
59
60
61 #define MPC624_ADBUSY BIT(5)
62 #define MPC624_ADSDO BIT(4)
63 #define MPC624_ADFO BIT(3)
64 #define MPC624_ADCS BIT(2)
65 #define MPC624_ADSCK BIT(1)
66 #define MPC624_ADSDI BIT(0)
67
68
69 #define MPC624_EOC_BIT BIT(31)
70 #define MPC624_DMY_BIT BIT(30)
71 #define MPC624_SGN_BIT BIT(29)
72
73
74 #define MPC624_OSR(x) (((x) & 0x1f) << 27)
75 #define MPC624_SPEED_3_52_KHZ MPC624_OSR(0x11)
76 #define MPC624_SPEED_1_76_KHZ MPC624_OSR(0x12)
77 #define MPC624_SPEED_880_HZ MPC624_OSR(0x13)
78 #define MPC624_SPEED_440_HZ MPC624_OSR(0x14)
79 #define MPC624_SPEED_220_HZ MPC624_OSR(0x15)
80 #define MPC624_SPEED_110_HZ MPC624_OSR(0x16)
81 #define MPC624_SPEED_55_HZ MPC624_OSR(0x17)
82 #define MPC624_SPEED_27_5_HZ MPC624_OSR(0x18)
83 #define MPC624_SPEED_13_75_HZ MPC624_OSR(0x19)
84 #define MPC624_SPEED_6_875_HZ MPC624_OSR(0x1f)
85
86 struct mpc624_private {
87 unsigned int ai_speed;
88 };
89
90
91 static const struct comedi_lrange range_mpc624_bipolar1 = {
92 1,
93 {
94
95
96 BIP_RANGE(2.02)
97 }
98 };
99
100 static const struct comedi_lrange range_mpc624_bipolar10 = {
101 1,
102 {
103
104
105 BIP_RANGE(20.2)
106 }
107 };
108
109 static unsigned int mpc624_ai_get_sample(struct comedi_device *dev,
110 struct comedi_subdevice *s)
111 {
112 struct mpc624_private *devpriv = dev->private;
113 unsigned int data_out = devpriv->ai_speed;
114 unsigned int data_in = 0;
115 unsigned int bit;
116 int i;
117
118
119 udelay(1);
120 for (i = 0; i < 32; i++) {
121
122 outb(0, dev->iobase + MPC624_ADC);
123 udelay(1);
124
125
126 bit = (data_out & BIT(31)) ? MPC624_ADSDI : 0;
127 outb(bit, dev->iobase + MPC624_ADC);
128 udelay(1);
129
130
131 outb(MPC624_ADSCK | bit, dev->iobase + MPC624_ADC);
132 udelay(1);
133
134
135 data_in <<= 1;
136 data_in |= (inb(dev->iobase + MPC624_ADC) & MPC624_ADSDO) >> 4;
137 udelay(1);
138
139 data_out <<= 1;
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158 if (data_in & MPC624_EOC_BIT)
159 dev_dbg(dev->class_dev, "EOC bit is set!");
160 if (data_in & MPC624_DMY_BIT)
161 dev_dbg(dev->class_dev, "DMY bit is set!");
162
163 if (data_in & MPC624_SGN_BIT) {
164
165
166
167
168
169
170 data_in &= 0x3fffffff;
171 } else {
172
173
174
175
176
177
178 data_in |= MPC624_SGN_BIT;
179 data_in = ~data_in;
180 data_in += 1;
181
182 data_in &= ~(MPC624_EOC_BIT | MPC624_DMY_BIT);
183 data_in = 0x20000000 - data_in;
184 }
185 return data_in;
186 }
187
188 static int mpc624_ai_eoc(struct comedi_device *dev,
189 struct comedi_subdevice *s,
190 struct comedi_insn *insn,
191 unsigned long context)
192 {
193 unsigned char status;
194
195 status = inb(dev->iobase + MPC624_ADC);
196 if ((status & MPC624_ADBUSY) == 0)
197 return 0;
198 return -EBUSY;
199 }
200
201 static int mpc624_ai_insn_read(struct comedi_device *dev,
202 struct comedi_subdevice *s,
203 struct comedi_insn *insn,
204 unsigned int *data)
205 {
206 int ret;
207 int i;
208
209
210
211
212
213 outb(insn->chanspec, dev->iobase + MPC624_GNMUXCH);
214
215 for (i = 0; i < insn->n; i++) {
216
217 outb(MPC624_ADSCK, dev->iobase + MPC624_ADC);
218 udelay(1);
219 outb(MPC624_ADCS | MPC624_ADSCK, dev->iobase + MPC624_ADC);
220 udelay(1);
221 outb(0, dev->iobase + MPC624_ADC);
222 udelay(1);
223
224
225 ret = comedi_timeout(dev, s, insn, mpc624_ai_eoc, 0);
226 if (ret)
227 return ret;
228
229 data[i] = mpc624_ai_get_sample(dev, s);
230 }
231
232 return insn->n;
233 }
234
235 static int mpc624_attach(struct comedi_device *dev, struct comedi_devconfig *it)
236 {
237 struct mpc624_private *devpriv;
238 struct comedi_subdevice *s;
239 int ret;
240
241 ret = comedi_request_region(dev, it->options[0], 0x10);
242 if (ret)
243 return ret;
244
245 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
246 if (!devpriv)
247 return -ENOMEM;
248
249 switch (it->options[1]) {
250 case 0:
251 devpriv->ai_speed = MPC624_SPEED_3_52_KHZ;
252 break;
253 case 1:
254 devpriv->ai_speed = MPC624_SPEED_1_76_KHZ;
255 break;
256 case 2:
257 devpriv->ai_speed = MPC624_SPEED_880_HZ;
258 break;
259 case 3:
260 devpriv->ai_speed = MPC624_SPEED_440_HZ;
261 break;
262 case 4:
263 devpriv->ai_speed = MPC624_SPEED_220_HZ;
264 break;
265 case 5:
266 devpriv->ai_speed = MPC624_SPEED_110_HZ;
267 break;
268 case 6:
269 devpriv->ai_speed = MPC624_SPEED_55_HZ;
270 break;
271 case 7:
272 devpriv->ai_speed = MPC624_SPEED_27_5_HZ;
273 break;
274 case 8:
275 devpriv->ai_speed = MPC624_SPEED_13_75_HZ;
276 break;
277 case 9:
278 devpriv->ai_speed = MPC624_SPEED_6_875_HZ;
279 break;
280 default:
281 devpriv->ai_speed = MPC624_SPEED_3_52_KHZ;
282 }
283
284 ret = comedi_alloc_subdevices(dev, 1);
285 if (ret)
286 return ret;
287
288
289 s = &dev->subdevices[0];
290 s->type = COMEDI_SUBD_AI;
291 s->subdev_flags = SDF_READABLE | SDF_DIFF;
292 s->n_chan = 4;
293 s->maxdata = 0x3fffffff;
294 s->range_table = (it->options[1] == 0) ? &range_mpc624_bipolar1
295 : &range_mpc624_bipolar10;
296 s->insn_read = mpc624_ai_insn_read;
297
298 return 0;
299 }
300
301 static struct comedi_driver mpc624_driver = {
302 .driver_name = "mpc624",
303 .module = THIS_MODULE,
304 .attach = mpc624_attach,
305 .detach = comedi_legacy_detach,
306 };
307 module_comedi_driver(mpc624_driver);
308
309 MODULE_AUTHOR("Comedi http://www.comedi.org");
310 MODULE_DESCRIPTION("Comedi driver for Micro/sys MPC-624 PC/104 board");
311 MODULE_LICENSE("GPL");