staging: comedi: contec_pci_dio: 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@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
16dd84f52c
commit
f0bd6d3575
@ -97,9 +97,32 @@ static int contec_di_insn_bits(struct comedi_device *dev,
|
|||||||
return insn->n;
|
return insn->n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
|
static struct pci_dev *contec_find_pci_dev(struct comedi_device *dev,
|
||||||
|
struct comedi_devconfig *it)
|
||||||
{
|
{
|
||||||
struct pci_dev *pcidev = NULL;
|
struct pci_dev *pcidev = NULL;
|
||||||
|
|
||||||
|
for_each_pci_dev(pcidev) {
|
||||||
|
if (pcidev->vendor == PCI_VENDOR_ID_CONTEC &&
|
||||||
|
pcidev->device == PCI_DEVICE_ID_PIO1616L) {
|
||||||
|
if (it->options[0] || it->options[1]) {
|
||||||
|
/* Check bus and slot. */
|
||||||
|
if (it->options[0] != pcidev->bus->number ||
|
||||||
|
it->options[1] != PCI_SLOT(pcidev->devfn)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dev->board_ptr = contec_boards + 0;
|
||||||
|
return pcidev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printk("card not present!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
|
||||||
|
{
|
||||||
|
struct pci_dev *pcidev;
|
||||||
struct comedi_subdevice *s;
|
struct comedi_subdevice *s;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -114,27 +137,18 @@ static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for_each_pci_dev(pcidev) {
|
pcidev = contec_find_pci_dev(dev, it);
|
||||||
if (pcidev->vendor == PCI_VENDOR_ID_CONTEC &&
|
if (!pcidev)
|
||||||
pcidev->device == PCI_DEVICE_ID_PIO1616L) {
|
return -EIO;
|
||||||
if (it->options[0] || it->options[1]) {
|
|
||||||
/* Check bus and slot. */
|
|
||||||
if (it->options[0] != pcidev->bus->number ||
|
|
||||||
it->options[1] != PCI_SLOT(pcidev->devfn)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
devpriv->pci_dev = pcidev;
|
devpriv->pci_dev = pcidev;
|
||||||
|
|
||||||
if (comedi_pci_enable(pcidev, "contec_pci_dio")) {
|
if (comedi_pci_enable(pcidev, "contec_pci_dio")) {
|
||||||
printk
|
printk("error enabling PCI device and request regions!\n");
|
||||||
("error enabling PCI device and request regions!\n");
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
dev->iobase = pci_resource_start(pcidev, 0);
|
dev->iobase = pci_resource_start(pcidev, 0);
|
||||||
printk(" base addr %lx ", dev->iobase);
|
printk(" base addr %lx ", dev->iobase);
|
||||||
|
|
||||||
dev->board_ptr = contec_boards + 0;
|
|
||||||
|
|
||||||
s = dev->subdevices + 0;
|
s = dev->subdevices + 0;
|
||||||
|
|
||||||
s->type = COMEDI_SUBD_DI;
|
s->type = COMEDI_SUBD_DI;
|
||||||
@ -155,12 +169,6 @@ static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
|
|||||||
printk("attached\n");
|
printk("attached\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printk("card not present!\n");
|
|
||||||
|
|
||||||
return -EIO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void contec_detach(struct comedi_device *dev)
|
static void contec_detach(struct comedi_device *dev)
|
||||||
|
Loading…
Reference in New Issue
Block a user