[<prev] [next>] [day] [month] [year] [list]
Message-ID: <201207111531.51788.hartleys@visionengravers.com>
Date: Wed, 11 Jul 2012 15:31:51 -0700
From: H Hartley Sweeten <hartleys@...ionengravers.com>
To: Linux Kernel <linux-kernel@...r.kernel.org>
CC: <devel@...verdev.osuosl.org>, <abbotti@....co.uk>,
<gregkh@...uxfoundation.org>
Subject: [PATCH 23/30] staging: comedi: dyna_pci10xx: factor out the "find pci device" code
Factor the "find pci device" code out of the attach function.
Signed-off-by: H Hartley Sweeten <hsweeten@...ionengravers.com>
Cc: Ian Abbott <abbotti@....co.uk>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
drivers/staging/comedi/drivers/dyna_pci10xx.c | 86 ++++++++++++++-------------
1 file changed, 44 insertions(+), 42 deletions(-)
diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index d0e3679..e189f71 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -229,36 +229,15 @@ static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
return insn->n;
}
-/******************************************************************************/
-/*********************** INITIALIZATION FUNCTIONS *****************************/
-/******************************************************************************/
-
-static int dyna_pci10xx_attach(struct comedi_device *dev,
- struct comedi_devconfig *it)
+static struct pci_dev *dyna_pci10xx_find_pci_dev(struct comedi_device *dev,
+ struct comedi_devconfig *it)
{
- struct comedi_subdevice *s;
- struct pci_dev *pcidev;
- unsigned int opt_bus, opt_slot;
- int board_index, i;
- int ret;
-
- mutex_lock(&start_stop_sem);
-
- if (alloc_private(dev, sizeof(struct dyna_pci10xx_private)) < 0) {
- printk(KERN_ERR "comedi: dyna_pci10xx: "
- "failed to allocate memory!\n");
- mutex_unlock(&start_stop_sem);
- return -ENOMEM;
- }
-
- opt_bus = it->options[0];
- opt_slot = it->options[1];
- dev->board_name = thisboard->name;
- dev->irq = 0;
+ struct pci_dev *pcidev = NULL;
+ unsigned int opt_bus = it->options[0];
+ unsigned int opt_slot = it->options[1];
+ int board_index;
+ int i;
- /*
- * Probe the PCI bus and located the matching device
- */
for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
pcidev != NULL;
pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
@@ -268,6 +247,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
if ((pcidev->vendor == PCI_VENDOR_ID_DYNALOG) &&
(pcidev->device == boardtypes[i].device_id)) {
board_index = i;
+ dev->board_ptr = &boardtypes[board_index];
break;
}
}
@@ -285,8 +265,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
goto found;
}
printk(KERN_ERR "comedi: dyna_pci10xx: no supported device found!\n");
- mutex_unlock(&start_stop_sem);
- return -EIO;
+ return NULL;
found:
@@ -299,11 +278,38 @@ found:
printk(KERN_ERR "comedi: dyna_pci10xx: "
"invalid PCI device\n");
}
+ return NULL;
+ }
+
+ printk(KERN_INFO "comedi: dyna_pci10xx: device found!\n");
+ return pcidev;
+}
+
+static int dyna_pci10xx_attach(struct comedi_device *dev,
+ struct comedi_devconfig *it)
+{
+ struct comedi_subdevice *s;
+ int ret;
+
+ mutex_lock(&start_stop_sem);
+
+ if (alloc_private(dev, sizeof(struct dyna_pci10xx_private)) < 0) {
+ printk(KERN_ERR "comedi: dyna_pci10xx: "
+ "failed to allocate memory!\n");
+ mutex_unlock(&start_stop_sem);
+ return -ENOMEM;
+ }
+
+ devpriv->pci_dev = dyna_pci10xx_find_pci_dev(dev, it);
+ if (!devpriv->pci_dev) {
mutex_unlock(&start_stop_sem);
return -EIO;
}
- if (comedi_pci_enable(pcidev, DRV_NAME)) {
+ dev->board_name = thisboard->name;
+ dev->irq = 0;
+
+ if (comedi_pci_enable(devpriv->pci_dev, DRV_NAME)) {
printk(KERN_ERR "comedi: dyna_pci10xx: "
"failed to enable PCI device and request regions!");
mutex_unlock(&start_stop_sem);
@@ -311,18 +317,14 @@ found:
}
mutex_init(&devpriv->mutex);
- dev->board_ptr = &boardtypes[board_index];
- devpriv->pci_dev = pcidev;
-
- printk(KERN_INFO "comedi: dyna_pci10xx: device found!\n");
/* initialize device base address registers */
- devpriv->BADR0 = pci_resource_start(pcidev, 0);
- devpriv->BADR1 = pci_resource_start(pcidev, 1);
- devpriv->BADR2 = pci_resource_start(pcidev, 2);
- devpriv->BADR3 = pci_resource_start(pcidev, 3);
- devpriv->BADR4 = pci_resource_start(pcidev, 4);
- devpriv->BADR5 = pci_resource_start(pcidev, 5);
+ devpriv->BADR0 = pci_resource_start(devpriv->pci_dev, 0);
+ devpriv->BADR1 = pci_resource_start(devpriv->pci_dev, 1);
+ devpriv->BADR2 = pci_resource_start(devpriv->pci_dev, 2);
+ devpriv->BADR3 = pci_resource_start(devpriv->pci_dev, 3);
+ devpriv->BADR4 = pci_resource_start(devpriv->pci_dev, 4);
+ devpriv->BADR5 = pci_resource_start(devpriv->pci_dev, 5);
ret = comedi_alloc_subdevices(dev, 4);
if (ret) {
@@ -375,7 +377,7 @@ found:
mutex_unlock(&start_stop_sem);
printk(KERN_INFO "comedi: dyna_pci10xx: %s - device setup completed!\n",
- boardtypes[board_index].name);
+ thisboard->name);
return 1;
}
--
1.7.11
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists