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

staging: comedi: adl_pci6208: refactor pci6208_find_device()

Make the "find pci device" functions consistent in the comedi
drivers. Hopefully well be able to move it into the core...

Refactor the "find pci device" function to return a pointer to
the found struct pci_dev instead of an error code. Also, change
some of the tests to reduce the indent level of the code. Pass
the struct comedi_devconfig pointer to the function instead of
the bus/slot numbers.
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 949a18d3
...@@ -178,60 +178,43 @@ static int pci6208_ao_rinsn(struct comedi_device *dev, ...@@ -178,60 +178,43 @@ static int pci6208_ao_rinsn(struct comedi_device *dev,
/* return 1; */ /* return 1; */
/* } */ /* } */
static int pci6208_find_device(struct comedi_device *dev, int bus, int slot) static struct pci_dev *pci6208_find_device(struct comedi_device *dev,
struct comedi_devconfig *it)
{ {
struct pci6208_private *devpriv = dev->private; const struct pci6208_board *thisboard;
struct pci_dev *pci_dev = NULL; struct pci_dev *pci_dev = NULL;
int bus = it->options[0];
int slot = it->options[1];
int i; int i;
for_each_pci_dev(pci_dev) { for_each_pci_dev(pci_dev) {
if (pci_dev->vendor == PCI_VENDOR_ID_ADLINK) { if (pci_dev->vendor != PCI_VENDOR_ID_ADLINK)
for (i = 0; i < ARRAY_SIZE(pci6208_boards); i++) { continue;
if (pci6208_boards[i].dev_id == for (i = 0; i < ARRAY_SIZE(pci6208_boards); i++) {
pci_dev->device) { thisboard = &pci6208_boards[i];
/* if (thisboard->dev_id != pci_dev->device)
* was a particular bus/slot requested? continue;
*/ /* was a particular bus/slot requested? */
if ((bus != 0) || (slot != 0)) { if (bus || slot) {
/* /* are we on the wrong bus/slot? */
* are we on the if (pci_dev->bus->number != bus ||
* wrong bus/slot? PCI_SLOT(pci_dev->devfn) != slot)
*/ continue;
if (pci_dev->bus->number
!= bus ||
PCI_SLOT(pci_dev->devfn)
!= slot) {
continue;
}
}
dev->board_ptr = pci6208_boards + i;
goto found;
}
} }
dev_dbg(dev->class_dev,
"Found %s on bus %d, slot, %d, irq=%d\n",
thisboard->name,
pci_dev->bus->number,
PCI_SLOT(pci_dev->devfn),
pci_dev->irq);
dev->board_ptr = thisboard;
return pci_dev;
} }
} }
dev_err(dev->class_dev,
printk(KERN_ERR "comedi%d: no supported board found! " "No supported board found! (req. bus %d, slot %d)\n",
"(req. bus/slot : %d/%d)\n", bus, slot);
dev->minor, bus, slot); return NULL;
return -EIO;
found:
printk("comedi%d: found %s (b:s:f=%d:%d:%d) , irq=%d\n",
dev->minor,
pci6208_boards[i].name,
pci_dev->bus->number,
PCI_SLOT(pci_dev->devfn),
PCI_FUNC(pci_dev->devfn), pci_dev->irq);
/* TODO: Warn about non-tested boards. */
/* switch(board->device_id) */
/* { */
/* }; */
devpriv->pci_dev = pci_dev;
return 0;
} }
static int static int
...@@ -289,9 +272,9 @@ static int pci6208_attach(struct comedi_device *dev, ...@@ -289,9 +272,9 @@ static int pci6208_attach(struct comedi_device *dev,
return retval; return retval;
devpriv = dev->private; devpriv = dev->private;
retval = pci6208_find_device(dev, it->options[0], it->options[1]); devpriv->pci_dev = pci6208_find_device(dev, it);
if (retval < 0) if (!devpriv->pci_dev)
return retval; return -EIO;
thisboard = comedi_board(dev); thisboard = comedi_board(dev);
retval = pci6208_pci_setup(devpriv->pci_dev, &io_base, dev->minor); retval = pci6208_pci_setup(devpriv->pci_dev, &io_base, dev->minor);
......
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