Skip to content

Commit

Permalink
staging: comedi: refactor das1800 driver and use module_comedi_driver
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed May 16, 2012
1 parent dd4f521 commit 1e991a1
Showing 1 changed file with 18 additions and 37 deletions.
55 changes: 18 additions & 37 deletions drivers/staging/comedi/drivers/das1800.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ enum {
das1802hr, das1802hr_da, das1801hc, das1802hc, das1801ao, das1802ao
};

static int das1800_attach(struct comedi_device *dev,
struct comedi_devconfig *it);
static int das1800_detach(struct comedi_device *dev);
static int das1800_probe(struct comedi_device *dev);
static int das1800_cancel(struct comedi_device *dev,
struct comedi_subdevice *s);
Expand Down Expand Up @@ -518,33 +515,6 @@ static const struct comedi_lrange range_ao_2 = {
};
*/

static struct comedi_driver driver_das1800 = {
.driver_name = "das1800",
.module = THIS_MODULE,
.attach = das1800_attach,
.detach = das1800_detach,
.num_names = ARRAY_SIZE(das1800_boards),
.board_name = &das1800_boards[0].name,
.offset = sizeof(struct das1800_board),
};

/*
* A convenient macro that defines init_module() and cleanup_module(),
* as necessary.
*/
static int __init driver_das1800_init_module(void)
{
return comedi_driver_register(&driver_das1800);
}

static void __exit driver_das1800_cleanup_module(void)
{
comedi_driver_unregister(&driver_das1800);
}

module_init(driver_das1800_init_module);
module_exit(driver_das1800_cleanup_module);

static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0,
unsigned int dma1)
{
Expand Down Expand Up @@ -579,15 +549,15 @@ static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0,
return -EINVAL;
break;
}
if (request_dma(dma0, driver_das1800.driver_name)) {
if (request_dma(dma0, dev->driver->driver_name)) {
dev_err(dev->hw_dev, "failed to allocate dma channel %i\n",
dma0);
return -EINVAL;
}
devpriv->dma0 = dma0;
devpriv->dma_current = dma0;
if (dma1) {
if (request_dma(dma1, driver_das1800.driver_name)) {
if (request_dma(dma1, dev->driver->driver_name)) {
dev_err(dev->hw_dev, "failed to allocate dma channel %i\n",
dma1);
return -EINVAL;
Expand Down Expand Up @@ -633,7 +603,7 @@ static int das1800_attach(struct comedi_device *dev,
return -ENOMEM;

printk(KERN_DEBUG "comedi%d: %s: io 0x%lx", dev->minor,
driver_das1800.driver_name, iobase);
dev->driver->driver_name, iobase);
if (irq) {
printk(KERN_CONT ", irq %u", irq);
if (dma0) {
Expand All @@ -650,7 +620,7 @@ static int das1800_attach(struct comedi_device *dev,
}

/* check if io addresses are available */
if (!request_region(iobase, DAS1800_SIZE, driver_das1800.driver_name)) {
if (!request_region(iobase, DAS1800_SIZE, dev->driver->driver_name)) {
printk
(" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n",
iobase, iobase + DAS1800_SIZE - 1);
Expand All @@ -671,7 +641,7 @@ static int das1800_attach(struct comedi_device *dev,
if (thisboard->ao_ability == 2) {
iobase2 = iobase + IOBASE2;
if (!request_region(iobase2, DAS1800_SIZE,
driver_das1800.driver_name)) {
dev->driver->driver_name)) {
printk
(" I/O port conflict: failed to allocate ports 0x%lx to 0x%lx\n",
iobase2, iobase2 + DAS1800_SIZE - 1);
Expand All @@ -683,7 +653,7 @@ static int das1800_attach(struct comedi_device *dev,
/* grab our IRQ */
if (irq) {
if (request_irq(irq, das1800_interrupt, 0,
driver_das1800.driver_name, dev)) {
dev->driver->driver_name, dev)) {
dev_dbg(dev->hw_dev, "unable to allocate irq %u\n",
irq);
return -EINVAL;
Expand Down Expand Up @@ -816,7 +786,7 @@ static int das1800_detach(struct comedi_device *dev)
}

dev_dbg(dev->hw_dev, "comedi%d: %s: remove\n", dev->minor,
driver_das1800.driver_name);
dev->driver->driver_name);

return 0;
};
Expand Down Expand Up @@ -1811,6 +1781,17 @@ static unsigned int suggest_transfer_size(struct comedi_cmd *cmd)
return size;
}

static struct comedi_driver das1800_driver = {
.driver_name = "das1800",
.module = THIS_MODULE,
.attach = das1800_attach,
.detach = das1800_detach,
.num_names = ARRAY_SIZE(das1800_boards),
.board_name = &das1800_boards[0].name,
.offset = sizeof(struct das1800_board),
};
module_comedi_driver(das1800_driver);

MODULE_AUTHOR("Comedi http://www.comedi.org");
MODULE_DESCRIPTION("Comedi low-level driver");
MODULE_LICENSE("GPL");

0 comments on commit 1e991a1

Please sign in to comment.