Skip to content

Commit

Permalink
staging: comedi: refactor adv_pci1_dio driver and use module_comedi_p…
Browse files Browse the repository at this point in the history
…ci_driver

Move the module_init/module_exit routines and the associated
struct comedi_drive and struct pci_driver 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_pci_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 618fc38 commit c95dbea
Showing 1 changed file with 36 additions and 72 deletions.
108 changes: 36 additions & 72 deletions drivers/staging/comedi/drivers/adv_pci_dio.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,6 @@ enum hw_io_access {

#define OMBCMD_RETRY 0x03 /* 3 times try request before error */

static int pci_dio_attach(struct comedi_device *dev,
struct comedi_devconfig *it);
static int pci_dio_detach(struct comedi_device *dev);

struct diosubd_data {
int chans; /* num of chans */
int addr; /* PCI address ofset */
Expand All @@ -263,26 +259,6 @@ struct dio_boardtype {
enum hw_io_access io_access;
};

static DEFINE_PCI_DEVICE_TABLE(pci_dio_pci_table) = {
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1734) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1735) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1736) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1739) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1750) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1751) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1752) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1753) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1754) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1756) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1760) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1762) },
{ 0 }
};

MODULE_DEVICE_TABLE(pci, pci_dio_pci_table);

static const struct dio_boardtype boardtypes[] = {
{"pci1730", PCI_VENDOR_ID_ADVANTECH, 0x1730, PCIDIO_MAINREG,
TYPE_PCI1730,
Expand Down Expand Up @@ -406,13 +382,6 @@ static const struct dio_boardtype boardtypes[] = {
IO_16b}
};

static struct comedi_driver driver_pci_dio = {
.driver_name = "adv_pci_dio",
.module = THIS_MODULE,
.attach = pci_dio_attach,
.detach = pci_dio_detach
};

struct pci_dio_private {
struct pci_dio_private *prev; /* previous private struct */
struct pci_dio_private *next; /* next private struct */
Expand Down Expand Up @@ -1114,9 +1083,6 @@ static int CheckAndAllocCard(struct comedi_device *dev,
return 1;
}

/*
==============================================================================
*/
static int pci_dio_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
{
Expand Down Expand Up @@ -1160,7 +1126,7 @@ static int pci_dio_attach(struct comedi_device *dev,
return -EIO;
}

if (comedi_pci_enable(pcidev, driver_pci_dio.driver_name)) {
if (comedi_pci_enable(pcidev, dev->driver->driver_name)) {
dev_err(dev->hw_dev, "Error: Can't enable PCI device and request regions!\n");
return -EIO;
}
Expand Down Expand Up @@ -1244,9 +1210,6 @@ static int pci_dio_attach(struct comedi_device *dev,
return 0;
}

/*
==============================================================================
*/
static int pci_dio_detach(struct comedi_device *dev)
{
int i, j;
Expand Down Expand Up @@ -1311,49 +1274,50 @@ static int pci_dio_detach(struct comedi_device *dev)
return 0;
}

/*
==============================================================================
*/
static int __devinit driver_pci_dio_pci_probe(struct pci_dev *dev,
const struct pci_device_id *ent)
static struct comedi_driver adv_pci_dio_driver = {
.driver_name = "adv_pci_dio",
.module = THIS_MODULE,
.attach = pci_dio_attach,
.detach = pci_dio_detach
};

static int __devinit adv_pci_dio_pci_probe(struct pci_dev *dev,
const struct pci_device_id *ent)
{
return comedi_pci_auto_config(dev, &driver_pci_dio);
return comedi_pci_auto_config(dev, &adv_pci_dio_driver);
}

static void __devexit driver_pci_dio_pci_remove(struct pci_dev *dev)
static void __devexit adv_pci_dio_pci_remove(struct pci_dev *dev)
{
comedi_pci_auto_unconfig(dev);
}

static struct pci_driver driver_pci_dio_pci_driver = {
.id_table = pci_dio_pci_table,
.probe = &driver_pci_dio_pci_probe,
.remove = __devexit_p(&driver_pci_dio_pci_remove)
static DEFINE_PCI_DEVICE_TABLE(adv_pci_dio_pci_table) = {
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1734) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1735) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1736) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1739) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1750) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1751) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1752) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1753) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1754) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1756) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1760) },
{ PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1762) },
{ 0 }
};
MODULE_DEVICE_TABLE(pci, adv_pci_dio_pci_table);

static int __init driver_pci_dio_init_module(void)
{
int retval;

retval = comedi_driver_register(&driver_pci_dio);
if (retval < 0)
return retval;

driver_pci_dio_pci_driver.name = (char *)driver_pci_dio.driver_name;
return pci_register_driver(&driver_pci_dio_pci_driver);
}

static void __exit driver_pci_dio_cleanup_module(void)
{
pci_unregister_driver(&driver_pci_dio_pci_driver);
comedi_driver_unregister(&driver_pci_dio);
}

module_init(driver_pci_dio_init_module);
module_exit(driver_pci_dio_cleanup_module);
/*
==============================================================================
*/
static struct pci_driver adv_pci_dio_pci_driver = {
.name = "adv_pci_dio",
.id_table = adv_pci_dio_pci_table,
.probe = adv_pci_dio_pci_probe,
.remove = __devexit_p(adv_pci_dio_pci_remove),
};
module_comedi_pci_driver(adv_pci_dio_driver, adv_pci_dio_pci_driver);

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

0 comments on commit c95dbea

Please sign in to comment.