aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-05-15 20:36:01 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-05-15 20:56:50 -0400
commit5aac8294de60cd2ffac3236c7052571ed6c2d56d (patch)
tree01b3d49c02366d059751618f634f08c8ca6d33e6
parentd22418b09d894af6a1458911dd61e245b4d1d820 (diff)
staging: comedi: refactor ni_atmio 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_atmio.c92
1 files changed, 37 insertions, 55 deletions
diff --git a/drivers/staging/comedi/drivers/ni_atmio.c b/drivers/staging/comedi/drivers/ni_atmio.c
index 647c228abfbf..02cf44b38590 100644
--- a/drivers/staging/comedi/drivers/ni_atmio.c
+++ b/drivers/staging/comedi/drivers/ni_atmio.c
@@ -343,49 +343,8 @@ static struct pnp_device_id device_ids[] = {
343 343
344MODULE_DEVICE_TABLE(pnp, device_ids); 344MODULE_DEVICE_TABLE(pnp, device_ids);
345 345
346static int ni_atmio_attach(struct comedi_device *dev,
347 struct comedi_devconfig *it);
348static int ni_atmio_detach(struct comedi_device *dev);
349static struct comedi_driver driver_atmio = {
350 .driver_name = "ni_atmio",
351 .module = THIS_MODULE,
352 .attach = ni_atmio_attach,
353 .detach = ni_atmio_detach,
354};
355
356static int __init driver_atmio_init_module(void)
357{
358 return comedi_driver_register(&driver_atmio);
359}
360
361static void __exit driver_atmio_cleanup_module(void)
362{
363 comedi_driver_unregister(&driver_atmio);
364}
365
366module_init(driver_atmio_init_module);
367module_exit(driver_atmio_cleanup_module);
368
369#include "ni_mio_common.c" 346#include "ni_mio_common.c"
370 347
371static int ni_getboardtype(struct comedi_device *dev);
372
373/* clean up allocated resources */
374static int ni_atmio_detach(struct comedi_device *dev)
375{
376 mio_common_detach(dev);
377
378 if (dev->iobase)
379 release_region(dev->iobase, NI_SIZE);
380 if (dev->irq)
381 free_irq(dev->irq, dev);
382
383 if (devpriv->isapnp_dev)
384 pnp_device_detach(devpriv->isapnp_dev);
385
386 return 0;
387}
388
389static int ni_isapnp_find_board(struct pnp_dev **dev) 348static int ni_isapnp_find_board(struct pnp_dev **dev)
390{ 349{
391 struct pnp_dev *isapnp_dev = NULL; 350 struct pnp_dev *isapnp_dev = NULL;
@@ -424,6 +383,26 @@ static int ni_isapnp_find_board(struct pnp_dev **dev)
424 return 0; 383 return 0;
425} 384}
426 385
386static int ni_getboardtype(struct comedi_device *dev)
387{
388 int device_id = ni_read_eeprom(dev, 511);
389 int i;
390
391 for (i = 0; i < n_ni_boards; i++) {
392 if (ni_boards[i].device_id == device_id)
393 return i;
394
395 }
396 if (device_id == 255)
397 printk(" can't find board\n");
398 else if (device_id == 0)
399 printk(" EEPROM read error (?) or device not found\n");
400 else
401 printk(" unknown device ID %d -- contact author\n", device_id);
402
403 return -1;
404}
405
427static int ni_atmio_attach(struct comedi_device *dev, 406static int ni_atmio_attach(struct comedi_device *dev,
428 struct comedi_devconfig *it) 407 struct comedi_devconfig *it)
429{ 408{
@@ -518,22 +497,25 @@ static int ni_atmio_attach(struct comedi_device *dev,
518 return 0; 497 return 0;
519} 498}
520 499
521static int ni_getboardtype(struct comedi_device *dev) 500static int ni_atmio_detach(struct comedi_device *dev)
522{ 501{
523 int device_id = ni_read_eeprom(dev, 511); 502 mio_common_detach(dev);
524 int i;
525 503
526 for (i = 0; i < n_ni_boards; i++) { 504 if (dev->iobase)
527 if (ni_boards[i].device_id == device_id) 505 release_region(dev->iobase, NI_SIZE);
528 return i; 506 if (dev->irq)
507 free_irq(dev->irq, dev);
529 508
530 } 509 if (devpriv->isapnp_dev)
531 if (device_id == 255) 510 pnp_device_detach(devpriv->isapnp_dev);
532 printk(" can't find board\n");
533 else if (device_id == 0)
534 printk(" EEPROM read error (?) or device not found\n");
535 else
536 printk(" unknown device ID %d -- contact author\n", device_id);
537 511
538 return -1; 512 return 0;
539} 513}
514
515static struct comedi_driver ni_atmio_driver = {
516 .driver_name = "ni_atmio",
517 .module = THIS_MODULE,
518 .attach = ni_atmio_attach,
519 .detach = ni_atmio_detach,
520};
521module_comedi_driver(ni_atmio_driver);