staging: comedi: adl_pci9118: factor out the find PCI device code
Factor out the code that finds a matching PCI device from attach function. 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>
This commit is contained in:
parent
8d0300a1d9
commit
93b6e4790e
1 changed files with 44 additions and 55 deletions
|
@ -2110,6 +2110,44 @@ static int pci9118_reset(struct comedi_device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct pci_dev *pci9118_find_pci(struct comedi_device *dev,
|
||||||
|
struct comedi_devconfig *it)
|
||||||
|
{
|
||||||
|
struct pci_dev *pcidev = NULL;
|
||||||
|
int bus = it->options[0];
|
||||||
|
int slot = it->options[1];
|
||||||
|
|
||||||
|
for_each_pci_dev(pcidev) {
|
||||||
|
if (pcidev->vendor != PCI_VENDOR_ID_AMCC)
|
||||||
|
continue;
|
||||||
|
if (pcidev->device != this_board->device_id)
|
||||||
|
continue;
|
||||||
|
if (bus || slot) {
|
||||||
|
/* requested particular bus/slot */
|
||||||
|
if (pcidev->bus->number != bus ||
|
||||||
|
PCI_SLOT(pcidev->devfn) != slot)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Look for device that isn't in use.
|
||||||
|
* Enable PCI device and request regions.
|
||||||
|
*/
|
||||||
|
if (comedi_pci_enable(pcidev, "adl_pci9118"))
|
||||||
|
continue;
|
||||||
|
printk(KERN_ERR ", b:s:f=%d:%d:%d, io=0x%4lx, 0x%4lx",
|
||||||
|
pcidev->bus->number,
|
||||||
|
PCI_SLOT(pcidev->devfn),
|
||||||
|
PCI_FUNC(pcidev->devfn),
|
||||||
|
(unsigned long)pci_resource_start(pcidev, 2),
|
||||||
|
(unsigned long)pci_resource_start(pcidev, 0));
|
||||||
|
return pcidev;
|
||||||
|
}
|
||||||
|
printk(KERN_ERR
|
||||||
|
"comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
|
||||||
|
dev->minor, bus, slot);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int pci9118_attach(struct comedi_device *dev,
|
static int pci9118_attach(struct comedi_device *dev,
|
||||||
struct comedi_devconfig *it)
|
struct comedi_devconfig *it)
|
||||||
{
|
{
|
||||||
|
@ -2117,17 +2155,10 @@ static int pci9118_attach(struct comedi_device *dev,
|
||||||
int ret, pages, i;
|
int ret, pages, i;
|
||||||
unsigned short master;
|
unsigned short master;
|
||||||
unsigned int irq;
|
unsigned int irq;
|
||||||
unsigned long iobase_a, iobase_9;
|
|
||||||
struct pci_dev *pcidev;
|
|
||||||
int opt_bus, opt_slot;
|
|
||||||
const char *errstr;
|
|
||||||
unsigned char pci_bus, pci_slot, pci_func;
|
|
||||||
u16 u16w;
|
u16 u16w;
|
||||||
|
|
||||||
printk("comedi%d: adl_pci9118: board=%s", dev->minor, this_board->name);
|
printk("comedi%d: adl_pci9118: board=%s", dev->minor, this_board->name);
|
||||||
|
|
||||||
opt_bus = it->options[0];
|
|
||||||
opt_slot = it->options[1];
|
|
||||||
if (it->options[3] & 1)
|
if (it->options[3] & 1)
|
||||||
master = 0; /* user don't want use bus master */
|
master = 0; /* user don't want use bus master */
|
||||||
else
|
else
|
||||||
|
@ -2139,61 +2170,19 @@ static int pci9118_attach(struct comedi_device *dev,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for matching PCI device */
|
devpriv->pcidev = pci9118_find_pci(dev, it);
|
||||||
errstr = "not found!";
|
if (!devpriv->pcidev)
|
||||||
pcidev = NULL;
|
|
||||||
while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_AMCC,
|
|
||||||
this_board->device_id,
|
|
||||||
pcidev))) {
|
|
||||||
/* Found matching vendor/device. */
|
|
||||||
if (opt_bus || opt_slot) {
|
|
||||||
/* Check bus/slot. */
|
|
||||||
if (opt_bus != pcidev->bus->number
|
|
||||||
|| opt_slot != PCI_SLOT(pcidev->devfn))
|
|
||||||
continue; /* no match */
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Look for device that isn't in use.
|
|
||||||
* Enable PCI device and request regions.
|
|
||||||
*/
|
|
||||||
if (comedi_pci_enable(pcidev, "adl_pci9118")) {
|
|
||||||
errstr =
|
|
||||||
"failed to enable PCI device and request regions!";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pcidev) {
|
|
||||||
if (opt_bus || opt_slot) {
|
|
||||||
printk(KERN_ERR " - Card at b:s %d:%d %s\n",
|
|
||||||
opt_bus, opt_slot, errstr);
|
|
||||||
} else {
|
|
||||||
printk(KERN_ERR " - Card %s\n", errstr);
|
|
||||||
}
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
|
||||||
|
|
||||||
if (master)
|
if (master)
|
||||||
pci_set_master(pcidev);
|
pci_set_master(devpriv->pcidev);
|
||||||
|
|
||||||
|
irq = devpriv->pcidev->irq;
|
||||||
|
devpriv->iobase_a = pci_resource_start(devpriv->pcidev, 0);
|
||||||
|
dev->iobase = pci_resource_start(devpriv->pcidev, 2);
|
||||||
|
|
||||||
pci_bus = pcidev->bus->number;
|
|
||||||
pci_slot = PCI_SLOT(pcidev->devfn);
|
|
||||||
pci_func = PCI_FUNC(pcidev->devfn);
|
|
||||||
irq = pcidev->irq;
|
|
||||||
iobase_a = pci_resource_start(pcidev, 0);
|
|
||||||
iobase_9 = pci_resource_start(pcidev, 2);
|
|
||||||
|
|
||||||
printk(KERN_ERR ", b:s:f=%d:%d:%d, io=0x%4lx, 0x%4lx", pci_bus,
|
|
||||||
pci_slot, pci_func, iobase_9, iobase_a);
|
|
||||||
|
|
||||||
dev->iobase = iobase_9;
|
|
||||||
dev->board_name = this_board->name;
|
dev->board_name = this_board->name;
|
||||||
|
|
||||||
devpriv->pcidev = pcidev;
|
|
||||||
devpriv->iobase_a = iobase_a;
|
|
||||||
|
|
||||||
pci9118_reset(dev);
|
pci9118_reset(dev);
|
||||||
|
|
||||||
if (it->options[3] & 2)
|
if (it->options[3] & 2)
|
||||||
|
|
Loading…
Add table
Reference in a new issue