aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-08-16 22:46:40 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-17 11:14:32 -0400
commit2682b2dc46d30cad83c880645b57fbce46ab35fa (patch)
tree9f98efdc563608a025e13195487b2e8a5d14f3f6
parent5f7cab0a9b0651e8cb125eb7ce2b1cb21f48b24f (diff)
staging: comedi: cb_pcimdas: remove forward declarations
Move a couple of the functions in order to remove the need for the forward declarations. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdas.c240
1 files changed, 112 insertions, 128 deletions
diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c
index 124478d22a48..5a5f102bb97e 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -132,15 +132,124 @@ struct cb_pcimdas_private {
132 unsigned int ao_readback[2]; 132 unsigned int ao_readback[2];
133}; 133};
134 134
135/*
136 * "instructions" read/write data in "one-shot" or "software-triggered"
137 * mode.
138 */
135static int cb_pcimdas_ai_rinsn(struct comedi_device *dev, 139static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
136 struct comedi_subdevice *s, 140 struct comedi_subdevice *s,
137 struct comedi_insn *insn, unsigned int *data); 141 struct comedi_insn *insn, unsigned int *data)
142{
143 const struct cb_pcimdas_board *thisboard = comedi_board(dev);
144 struct cb_pcimdas_private *devpriv = dev->private;
145 int n, i;
146 unsigned int d;
147 unsigned int busy;
148 int chan = CR_CHAN(insn->chanspec);
149 unsigned short chanlims;
150 int maxchans;
151
152 /* only support sw initiated reads from a single channel */
153
154 /* check channel number */
155 if ((inb(devpriv->BADR3 + 2) & 0x20) == 0) /* differential mode */
156 maxchans = thisboard->ai_diff_chans;
157 else
158 maxchans = thisboard->ai_se_chans;
159
160 if (chan > (maxchans - 1))
161 return -ETIMEDOUT; /* *** Wrong error code. Fixme. */
162
163 /* configure for sw initiated read */
164 d = inb(devpriv->BADR3 + 5);
165 if ((d & 0x03) > 0) { /* only reset if needed. */
166 d = d & 0xfd;
167 outb(d, devpriv->BADR3 + 5);
168 }
169 outb(0x01, devpriv->BADR3 + 6); /* set bursting off, conversions on */
170 outb(0x00, devpriv->BADR3 + 7); /* set range to 10V. UP/BP is controlled by a switch on the board */
171
172 /*
173 * write channel limits to multiplexer, set Low (bits 0-3) and
174 * High (bits 4-7) channels to chan.
175 */
176 chanlims = chan | (chan << 4);
177 outb(chanlims, devpriv->BADR3 + 0);
178
179 /* convert n samples */
180 for (n = 0; n < insn->n; n++) {
181 /* trigger conversion */
182 outw(0, dev->iobase + 0);
183
184#define TIMEOUT 1000 /* typically takes 5 loops on a lightly loaded Pentium 100MHz, */
185 /* this is likely to be 100 loops on a 2GHz machine, so set 1000 as the limit. */
186
187 /* wait for conversion to end */
188 for (i = 0; i < TIMEOUT; i++) {
189 busy = inb(devpriv->BADR3 + 2) & 0x80;
190 if (!busy)
191 break;
192 }
193 if (i == TIMEOUT) {
194 printk("timeout\n");
195 return -ETIMEDOUT;
196 }
197 /* read data */
198 d = inw(dev->iobase + 0);
199
200 /* mangle the data as necessary */
201 /* d ^= 1<<(thisboard->ai_bits-1); // 16 bit data from ADC, so no mangle needed. */
202
203 data[n] = d;
204 }
205
206 /* return the number of samples read/written */
207 return n;
208}
209
138static int cb_pcimdas_ao_winsn(struct comedi_device *dev, 210static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
139 struct comedi_subdevice *s, 211 struct comedi_subdevice *s,
140 struct comedi_insn *insn, unsigned int *data); 212 struct comedi_insn *insn, unsigned int *data)
213{
214 struct cb_pcimdas_private *devpriv = dev->private;
215 int i;
216 int chan = CR_CHAN(insn->chanspec);
217
218 /* Writing a list of values to an AO channel is probably not
219 * very useful, but that's how the interface is defined. */
220 for (i = 0; i < insn->n; i++) {
221 switch (chan) {
222 case 0:
223 outw(data[i] & 0x0FFF, dev->iobase + DAC0_OFFSET);
224 break;
225 case 1:
226 outw(data[i] & 0x0FFF, dev->iobase + DAC1_OFFSET);
227 break;
228 default:
229 return -1;
230 }
231 devpriv->ao_readback[chan] = data[i];
232 }
233
234 /* return the number of samples read/written */
235 return i;
236}
237
238/* AO subdevices should have a read insn as well as a write insn.
239 * Usually this means copying a value stored in devpriv. */
141static int cb_pcimdas_ao_rinsn(struct comedi_device *dev, 240static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
142 struct comedi_subdevice *s, 241 struct comedi_subdevice *s,
143 struct comedi_insn *insn, unsigned int *data); 242 struct comedi_insn *insn, unsigned int *data)
243{
244 struct cb_pcimdas_private *devpriv = dev->private;
245 int i;
246 int chan = CR_CHAN(insn->chanspec);
247
248 for (i = 0; i < insn->n; i++)
249 data[i] = devpriv->ao_readback[chan];
250
251 return i;
252}
144 253
145static struct pci_dev *cb_pcimdas_find_pci_dev(struct comedi_device *dev, 254static struct pci_dev *cb_pcimdas_find_pci_dev(struct comedi_device *dev,
146 struct comedi_devconfig *it) 255 struct comedi_devconfig *it)
@@ -173,12 +282,6 @@ static struct pci_dev *cb_pcimdas_find_pci_dev(struct comedi_device *dev,
173 return NULL; 282 return NULL;
174} 283}
175 284
176/*
177 * Attach is called by the Comedi core to configure the driver
178 * for a particular board. If you specified a board_name array
179 * in the driver structure, dev->board_ptr contains that
180 * address.
181 */
182static int cb_pcimdas_attach(struct comedi_device *dev, 285static int cb_pcimdas_attach(struct comedi_device *dev,
183 struct comedi_devconfig *it) 286 struct comedi_devconfig *it)
184{ 287{
@@ -282,125 +385,6 @@ static void cb_pcimdas_detach(struct comedi_device *dev)
282 } 385 }
283} 386}
284 387
285/*
286 * "instructions" read/write data in "one-shot" or "software-triggered"
287 * mode.
288 */
289static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
290 struct comedi_subdevice *s,
291 struct comedi_insn *insn, unsigned int *data)
292{
293 const struct cb_pcimdas_board *thisboard = comedi_board(dev);
294 struct cb_pcimdas_private *devpriv = dev->private;
295 int n, i;
296 unsigned int d;
297 unsigned int busy;
298 int chan = CR_CHAN(insn->chanspec);
299 unsigned short chanlims;
300 int maxchans;
301
302 /* only support sw initiated reads from a single channel */
303
304 /* check channel number */
305 if ((inb(devpriv->BADR3 + 2) & 0x20) == 0) /* differential mode */
306 maxchans = thisboard->ai_diff_chans;
307 else
308 maxchans = thisboard->ai_se_chans;
309
310 if (chan > (maxchans - 1))
311 return -ETIMEDOUT; /* *** Wrong error code. Fixme. */
312
313 /* configure for sw initiated read */
314 d = inb(devpriv->BADR3 + 5);
315 if ((d & 0x03) > 0) { /* only reset if needed. */
316 d = d & 0xfd;
317 outb(d, devpriv->BADR3 + 5);
318 }
319 outb(0x01, devpriv->BADR3 + 6); /* set bursting off, conversions on */
320 outb(0x00, devpriv->BADR3 + 7); /* set range to 10V. UP/BP is controlled by a switch on the board */
321
322 /*
323 * write channel limits to multiplexer, set Low (bits 0-3) and
324 * High (bits 4-7) channels to chan.
325 */
326 chanlims = chan | (chan << 4);
327 outb(chanlims, devpriv->BADR3 + 0);
328
329 /* convert n samples */
330 for (n = 0; n < insn->n; n++) {
331 /* trigger conversion */
332 outw(0, dev->iobase + 0);
333
334#define TIMEOUT 1000 /* typically takes 5 loops on a lightly loaded Pentium 100MHz, */
335 /* this is likely to be 100 loops on a 2GHz machine, so set 1000 as the limit. */
336
337 /* wait for conversion to end */
338 for (i = 0; i < TIMEOUT; i++) {
339 busy = inb(devpriv->BADR3 + 2) & 0x80;
340 if (!busy)
341 break;
342 }
343 if (i == TIMEOUT) {
344 printk("timeout\n");
345 return -ETIMEDOUT;
346 }
347 /* read data */
348 d = inw(dev->iobase + 0);
349
350 /* mangle the data as necessary */
351 /* d ^= 1<<(thisboard->ai_bits-1); // 16 bit data from ADC, so no mangle needed. */
352
353 data[n] = d;
354 }
355
356 /* return the number of samples read/written */
357 return n;
358}
359
360static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
361 struct comedi_subdevice *s,
362 struct comedi_insn *insn, unsigned int *data)
363{
364 struct cb_pcimdas_private *devpriv = dev->private;
365 int i;
366 int chan = CR_CHAN(insn->chanspec);
367
368 /* Writing a list of values to an AO channel is probably not
369 * very useful, but that's how the interface is defined. */
370 for (i = 0; i < insn->n; i++) {
371 switch (chan) {
372 case 0:
373 outw(data[i] & 0x0FFF, dev->iobase + DAC0_OFFSET);
374 break;
375 case 1:
376 outw(data[i] & 0x0FFF, dev->iobase + DAC1_OFFSET);
377 break;
378 default:
379 return -1;
380 }
381 devpriv->ao_readback[chan] = data[i];
382 }
383
384 /* return the number of samples read/written */
385 return i;
386}
387
388/* AO subdevices should have a read insn as well as a write insn.
389 * Usually this means copying a value stored in devpriv. */
390static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
391 struct comedi_subdevice *s,
392 struct comedi_insn *insn, unsigned int *data)
393{
394 struct cb_pcimdas_private *devpriv = dev->private;
395 int i;
396 int chan = CR_CHAN(insn->chanspec);
397
398 for (i = 0; i < insn->n; i++)
399 data[i] = devpriv->ao_readback[chan];
400
401 return i;
402}
403
404static struct comedi_driver cb_pcimdas_driver = { 388static struct comedi_driver cb_pcimdas_driver = {
405 .driver_name = "cb_pcimdas", 389 .driver_name = "cb_pcimdas",
406 .module = THIS_MODULE, 390 .module = THIS_MODULE,