aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-05-15 20:17:14 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-05-15 20:56:51 -0400
commitfe14fa2b243f301841ef193de334376bab686643 (patch)
tree62d1d6309ce4dbb8677dd4093d34e76cf2999c96
parentb48ed6233b7ae137c698637baf1fc8628310fa05 (diff)
staging: comedi: refactor ni_at_a2150 driver and use module_comedi_driver
Move the module_init/module_exit routines and the associated struct comedi_drive to the end of the source. This is more typical of how other drivers are written and removes the need for the forward declarations. Convert the driver to use the module_comedi_driver() macro which makes the code smaller and a bit simpler. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Cc: Mori Hess <fmhess@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/drivers/ni_at_a2150.c351
1 files changed, 163 insertions, 188 deletions
diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c b/drivers/staging/comedi/drivers/ni_at_a2150.c
index 4fc469da45e2..3231d102839e 100644
--- a/drivers/staging/comedi/drivers/ni_at_a2150.c
+++ b/drivers/staging/comedi/drivers/ni_at_a2150.c
@@ -171,46 +171,13 @@ struct a2150_private {
171 171
172#define devpriv ((struct a2150_private *)dev->private) 172#define devpriv ((struct a2150_private *)dev->private)
173 173
174static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it);
175static int a2150_detach(struct comedi_device *dev);
176static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s); 174static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
177 175
178static struct comedi_driver driver_a2150 = {
179 .driver_name = "ni_at_a2150",
180 .module = THIS_MODULE,
181 .attach = a2150_attach,
182 .detach = a2150_detach,
183};
184
185static irqreturn_t a2150_interrupt(int irq, void *d);
186static int a2150_ai_cmdtest(struct comedi_device *dev,
187 struct comedi_subdevice *s, struct comedi_cmd *cmd);
188static int a2150_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
189static int a2150_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
190 struct comedi_insn *insn, unsigned int *data);
191static int a2150_get_timing(struct comedi_device *dev, unsigned int *period, 176static int a2150_get_timing(struct comedi_device *dev, unsigned int *period,
192 int flags); 177 int flags);
193static int a2150_probe(struct comedi_device *dev);
194static int a2150_set_chanlist(struct comedi_device *dev, 178static int a2150_set_chanlist(struct comedi_device *dev,
195 unsigned int start_channel, 179 unsigned int start_channel,
196 unsigned int num_channels); 180 unsigned int num_channels);
197/*
198 * A convenient macro that defines init_module() and cleanup_module(),
199 * as necessary.
200 */
201static int __init driver_a2150_init_module(void)
202{
203 return comedi_driver_register(&driver_a2150);
204}
205
206static void __exit driver_a2150_cleanup_module(void)
207{
208 comedi_driver_unregister(&driver_a2150);
209}
210
211module_init(driver_a2150_init_module);
212module_exit(driver_a2150_cleanup_module);
213
214#ifdef A2150_DEBUG 181#ifdef A2150_DEBUG
215 182
216static void ni_dump_regs(struct comedi_device *dev) 183static void ni_dump_regs(struct comedi_device *dev)
@@ -331,161 +298,6 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
331 return IRQ_HANDLED; 298 return IRQ_HANDLED;
332} 299}
333 300
334/* probes board type, returns offset */
335static int a2150_probe(struct comedi_device *dev)
336{
337 int status = inw(dev->iobase + STATUS_REG);
338 return ID_BITS(status);
339}
340
341static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
342{
343 struct comedi_subdevice *s;
344 unsigned long iobase = it->options[0];
345 unsigned int irq = it->options[1];
346 unsigned int dma = it->options[2];
347 static const int timeout = 2000;
348 int i;
349
350 printk("comedi%d: %s: io 0x%lx", dev->minor, driver_a2150.driver_name,
351 iobase);
352 if (irq) {
353 printk(", irq %u", irq);
354 } else {
355 printk(", no irq");
356 }
357 if (dma) {
358 printk(", dma %u", dma);
359 } else {
360 printk(", no dma");
361 }
362 printk("\n");
363
364 /* allocate and initialize dev->private */
365 if (alloc_private(dev, sizeof(struct a2150_private)) < 0)
366 return -ENOMEM;
367
368 if (iobase == 0) {
369 printk(" io base address required\n");
370 return -EINVAL;
371 }
372
373 /* check if io addresses are available */
374 if (!request_region(iobase, A2150_SIZE, driver_a2150.driver_name)) {
375 printk(" I/O port conflict\n");
376 return -EIO;
377 }
378 dev->iobase = iobase;
379
380 /* grab our IRQ */
381 if (irq) {
382 /* check that irq is supported */
383 if (irq < 3 || irq == 8 || irq == 13 || irq > 15) {
384 printk(" invalid irq line %u\n", irq);
385 return -EINVAL;
386 }
387 if (request_irq(irq, a2150_interrupt, 0,
388 driver_a2150.driver_name, dev)) {
389 printk("unable to allocate irq %u\n", irq);
390 return -EINVAL;
391 }
392 devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq);
393 dev->irq = irq;
394 }
395 /* initialize dma */
396 if (dma) {
397 if (dma == 4 || dma > 7) {
398 printk(" invalid dma channel %u\n", dma);
399 return -EINVAL;
400 }
401 if (request_dma(dma, driver_a2150.driver_name)) {
402 printk(" failed to allocate dma channel %u\n", dma);
403 return -EINVAL;
404 }
405 devpriv->dma = dma;
406 devpriv->dma_buffer =
407 kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
408 if (devpriv->dma_buffer == NULL)
409 return -ENOMEM;
410
411 disable_dma(dma);
412 set_dma_mode(dma, DMA_MODE_READ);
413
414 devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma);
415 }
416
417 dev->board_ptr = a2150_boards + a2150_probe(dev);
418 dev->board_name = thisboard->name;
419
420 if (alloc_subdevices(dev, 1) < 0)
421 return -ENOMEM;
422
423 /* analog input subdevice */
424 s = dev->subdevices + 0;
425 dev->read_subdev = s;
426 s->type = COMEDI_SUBD_AI;
427 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER | SDF_CMD_READ;
428 s->n_chan = 4;
429 s->len_chanlist = 4;
430 s->maxdata = 0xffff;
431 s->range_table = &range_a2150;
432 s->do_cmd = a2150_ai_cmd;
433 s->do_cmdtest = a2150_ai_cmdtest;
434 s->insn_read = a2150_ai_rinsn;
435 s->cancel = a2150_cancel;
436
437 /* need to do this for software counting of completed conversions, to
438 * prevent hardware count from stopping acquisition */
439 outw(HW_COUNT_DISABLE, dev->iobase + I8253_MODE_REG);
440
441 /* set card's irq and dma levels */
442 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
443
444 /* reset and sync adc clock circuitry */
445 outw_p(DPD_BIT | APD_BIT, dev->iobase + CONFIG_REG);
446 outw_p(DPD_BIT, dev->iobase + CONFIG_REG);
447 /* initialize configuration register */
448 devpriv->config_bits = 0;
449 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
450 /* wait until offset calibration is done, then enable analog inputs */
451 for (i = 0; i < timeout; i++) {
452 if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0)
453 break;
454 udelay(1000);
455 }
456 if (i == timeout) {
457 printk
458 (" timed out waiting for offset calibration to complete\n");
459 return -ETIME;
460 }
461 devpriv->config_bits |= ENABLE0_BIT | ENABLE1_BIT;
462 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
463
464 return 0;
465};
466
467static int a2150_detach(struct comedi_device *dev)
468{
469 printk("comedi%d: %s: remove\n", dev->minor, driver_a2150.driver_name);
470
471 /* only free stuff if it has been allocated by _attach */
472 if (dev->iobase) {
473 /* put board in power-down mode */
474 outw(APD_BIT | DPD_BIT, dev->iobase + CONFIG_REG);
475 release_region(dev->iobase, A2150_SIZE);
476 }
477
478 if (dev->irq)
479 free_irq(dev->irq, dev);
480 if (devpriv) {
481 if (devpriv->dma)
482 free_dma(devpriv->dma);
483 kfree(devpriv->dma_buffer);
484 }
485
486 return 0;
487};
488
489static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s) 301static int a2150_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
490{ 302{
491 /* disable dma on card */ 303 /* disable dma on card */
@@ -928,6 +740,169 @@ static int a2150_set_chanlist(struct comedi_device *dev,
928 return 0; 740 return 0;
929} 741}
930 742
743/* probes board type, returns offset */
744static int a2150_probe(struct comedi_device *dev)
745{
746 int status = inw(dev->iobase + STATUS_REG);
747 return ID_BITS(status);
748}
749
750static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
751{
752 struct comedi_subdevice *s;
753 unsigned long iobase = it->options[0];
754 unsigned int irq = it->options[1];
755 unsigned int dma = it->options[2];
756 static const int timeout = 2000;
757 int i;
758
759 printk("comedi%d: %s: io 0x%lx", dev->minor, dev->driver->driver_name,
760 iobase);
761 if (irq) {
762 printk(", irq %u", irq);
763 } else {
764 printk(", no irq");
765 }
766 if (dma) {
767 printk(", dma %u", dma);
768 } else {
769 printk(", no dma");
770 }
771 printk("\n");
772
773 /* allocate and initialize dev->private */
774 if (alloc_private(dev, sizeof(struct a2150_private)) < 0)
775 return -ENOMEM;
776
777 if (iobase == 0) {
778 printk(" io base address required\n");
779 return -EINVAL;
780 }
781
782 /* check if io addresses are available */
783 if (!request_region(iobase, A2150_SIZE, dev->driver->driver_name)) {
784 printk(" I/O port conflict\n");
785 return -EIO;
786 }
787 dev->iobase = iobase;
788
789 /* grab our IRQ */
790 if (irq) {
791 /* check that irq is supported */
792 if (irq < 3 || irq == 8 || irq == 13 || irq > 15) {
793 printk(" invalid irq line %u\n", irq);
794 return -EINVAL;
795 }
796 if (request_irq(irq, a2150_interrupt, 0,
797 dev->driver->driver_name, dev)) {
798 printk("unable to allocate irq %u\n", irq);
799 return -EINVAL;
800 }
801 devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq);
802 dev->irq = irq;
803 }
804 /* initialize dma */
805 if (dma) {
806 if (dma == 4 || dma > 7) {
807 printk(" invalid dma channel %u\n", dma);
808 return -EINVAL;
809 }
810 if (request_dma(dma, dev->driver->driver_name)) {
811 printk(" failed to allocate dma channel %u\n", dma);
812 return -EINVAL;
813 }
814 devpriv->dma = dma;
815 devpriv->dma_buffer =
816 kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
817 if (devpriv->dma_buffer == NULL)
818 return -ENOMEM;
819
820 disable_dma(dma);
821 set_dma_mode(dma, DMA_MODE_READ);
822
823 devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma);
824 }
825
826 dev->board_ptr = a2150_boards + a2150_probe(dev);
827 dev->board_name = thisboard->name;
828
829 if (alloc_subdevices(dev, 1) < 0)
830 return -ENOMEM;
831
832 /* analog input subdevice */
833 s = dev->subdevices + 0;
834 dev->read_subdev = s;
835 s->type = COMEDI_SUBD_AI;
836 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER | SDF_CMD_READ;
837 s->n_chan = 4;
838 s->len_chanlist = 4;
839 s->maxdata = 0xffff;
840 s->range_table = &range_a2150;
841 s->do_cmd = a2150_ai_cmd;
842 s->do_cmdtest = a2150_ai_cmdtest;
843 s->insn_read = a2150_ai_rinsn;
844 s->cancel = a2150_cancel;
845
846 /* need to do this for software counting of completed conversions, to
847 * prevent hardware count from stopping acquisition */
848 outw(HW_COUNT_DISABLE, dev->iobase + I8253_MODE_REG);
849
850 /* set card's irq and dma levels */
851 outw(devpriv->irq_dma_bits, dev->iobase + IRQ_DMA_CNTRL_REG);
852
853 /* reset and sync adc clock circuitry */
854 outw_p(DPD_BIT | APD_BIT, dev->iobase + CONFIG_REG);
855 outw_p(DPD_BIT, dev->iobase + CONFIG_REG);
856 /* initialize configuration register */
857 devpriv->config_bits = 0;
858 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
859 /* wait until offset calibration is done, then enable analog inputs */
860 for (i = 0; i < timeout; i++) {
861 if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0)
862 break;
863 udelay(1000);
864 }
865 if (i == timeout) {
866 printk
867 (" timed out waiting for offset calibration to complete\n");
868 return -ETIME;
869 }
870 devpriv->config_bits |= ENABLE0_BIT | ENABLE1_BIT;
871 outw(devpriv->config_bits, dev->iobase + CONFIG_REG);
872
873 return 0;
874};
875
876static int a2150_detach(struct comedi_device *dev)
877{
878 printk("comedi%d: %s: remove\n", dev->minor, dev->driver->driver_name);
879
880 /* only free stuff if it has been allocated by _attach */
881 if (dev->iobase) {
882 /* put board in power-down mode */
883 outw(APD_BIT | DPD_BIT, dev->iobase + CONFIG_REG);
884 release_region(dev->iobase, A2150_SIZE);
885 }
886
887 if (dev->irq)
888 free_irq(dev->irq, dev);
889 if (devpriv) {
890 if (devpriv->dma)
891 free_dma(devpriv->dma);
892 kfree(devpriv->dma_buffer);
893 }
894
895 return 0;
896};
897
898static struct comedi_driver ni_at_a2150_driver = {
899 .driver_name = "ni_at_a2150",
900 .module = THIS_MODULE,
901 .attach = a2150_attach,
902 .detach = a2150_detach,
903};
904module_comedi_driver(ni_at_a2150_driver);
905
931MODULE_AUTHOR("Comedi http://www.comedi.org"); 906MODULE_AUTHOR("Comedi http://www.comedi.org");
932MODULE_DESCRIPTION("Comedi low-level driver"); 907MODULE_DESCRIPTION("Comedi low-level driver");
933MODULE_LICENSE("GPL"); 908MODULE_LICENSE("GPL");