Commit 327be979 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: cb_pcidas: factor out the find pci device code

Factor the "find pci device" code out of the attach function.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 82d8c74d
...@@ -1608,64 +1608,70 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d) ...@@ -1608,64 +1608,70 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static int cb_pcidas_attach(struct comedi_device *dev, static struct pci_dev *cb_pcidas_find_pci_device(struct comedi_device *dev,
struct comedi_devconfig *it) struct comedi_devconfig *it)
{ {
const struct cb_pcidas_board *thisboard; const struct cb_pcidas_board *thisboard;
struct cb_pcidas_private *devpriv;
struct comedi_subdevice *s;
struct pci_dev *pcidev = NULL; struct pci_dev *pcidev = NULL;
int index; int bus = it->options[0];
int slot = it->options[1];
int i; int i;
int ret;
/*
* Allocate the private structure area.
*/
if (alloc_private(dev, sizeof(struct cb_pcidas_private)) < 0)
return -ENOMEM;
devpriv = dev->private;
/*
* Probe the device to determine what device in the series it is.
*/
for_each_pci_dev(pcidev) { for_each_pci_dev(pcidev) {
/* is it not a computer boards card? */ /* is it not a computer boards card? */
if (pcidev->vendor != PCI_VENDOR_ID_CB) if (pcidev->vendor != PCI_VENDOR_ID_CB)
continue; continue;
/* loop through cards supported by this driver */ /* loop through cards supported by this driver */
for (index = 0; index < ARRAY_SIZE(cb_pcidas_boards); index++) { for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) {
if (cb_pcidas_boards[index].device_id != pcidev->device) thisboard = &cb_pcidas_boards[i];
if (thisboard->device_id != pcidev->device)
continue; continue;
/* was a particular bus/slot requested? */ /* was a particular bus/slot requested? */
if (it->options[0] || it->options[1]) { if (bus || slot) {
/* are we on the wrong bus/slot? */ /* are we on the wrong bus/slot? */
if (pcidev->bus->number != it->options[0] || if (pcidev->bus->number != bus ||
PCI_SLOT(pcidev->devfn) != it->options[1]) { PCI_SLOT(pcidev->devfn) != slot) {
continue; continue;
} }
} }
devpriv->pci_dev = pcidev; dev->board_ptr = thisboard;
dev->board_ptr = cb_pcidas_boards + index; return pcidev;
goto found;
} }
} }
return NULL;
}
static int cb_pcidas_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
{
const struct cb_pcidas_board *thisboard;
struct cb_pcidas_private *devpriv;
struct comedi_subdevice *s;
int i;
int ret;
dev_err(dev->class_dev, /*
"No supported ComputerBoards/MeasurementComputing card found on requested position\n"); * Allocate the private structure area.
return -EIO; */
if (alloc_private(dev, sizeof(struct cb_pcidas_private)) < 0)
return -ENOMEM;
devpriv = dev->private;
devpriv->pci_dev = cb_pcidas_find_pci_device(dev, it);
if (!devpriv->pci_dev) {
dev_err(dev->class_dev, "No supported card found\n");
return -EIO;
}
found:
thisboard = comedi_board(dev); thisboard = comedi_board(dev);
dev_dbg(dev->class_dev, "Found %s on bus %i, slot %i\n", dev_dbg(dev->class_dev, "Found %s on bus %i, slot %i\n",
cb_pcidas_boards[index].name, pcidev->bus->number, thisboard->name, devpriv->pci_dev->bus->number,
PCI_SLOT(pcidev->devfn)); PCI_SLOT(devpriv->pci_dev->devfn));
/* /*
* Enable PCI device and reserve I/O ports. * Enable PCI device and reserve I/O ports.
*/ */
if (comedi_pci_enable(pcidev, "cb_pcidas")) { if (comedi_pci_enable(devpriv->pci_dev, "cb_pcidas")) {
dev_err(dev->class_dev, dev_err(dev->class_dev,
"Failed to enable PCI device and request regions\n"); "Failed to enable PCI device and request regions\n");
return -EIO; return -EIO;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment