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

staging: comedi: cb_pcimdda: cleanup pci probe

Make cb_pcimdda_probe() return the pointer to the found pci_dev
and move the comedi_pci_enable() call into 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 d1438d41
...@@ -213,54 +213,30 @@ static int cb_pcimdda_ao_rinsn(struct comedi_device *dev, ...@@ -213,54 +213,30 @@ static int cb_pcimdda_ao_rinsn(struct comedi_device *dev,
return i; return i;
} }
static int cb_pcimdda_probe(struct comedi_device *dev, static struct pci_dev *cb_pcimdda_probe(struct comedi_device *dev,
const struct comedi_devconfig *it) struct comedi_devconfig *it)
{ {
const struct cb_pcimdda_board *thisboard;
struct cb_pcimdda_private *devpriv = dev->private;
struct pci_dev *pcidev = NULL; struct pci_dev *pcidev = NULL;
int index; int index;
unsigned long registers;
for_each_pci_dev(pcidev) { for_each_pci_dev(pcidev) {
/* is it not a computer boards card? */
if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
continue; continue;
/* loop through cards supported by this driver */
for (index = 0; index < ARRAY_SIZE(cb_pcimdda_boards); index++) { for (index = 0; index < ARRAY_SIZE(cb_pcimdda_boards); index++) {
if (cb_pcimdda_boards[index].device_id != pcidev->device) if (cb_pcimdda_boards[index].device_id != pcidev->device)
continue; continue;
/* was a particular bus/slot requested? */
if (it->options[0] || it->options[1]) { if (it->options[0] || it->options[1]) {
/* are we on the wrong bus/slot? */
if (pcidev->bus->number != it->options[0] || if (pcidev->bus->number != it->options[0] ||
PCI_SLOT(pcidev->devfn) != it->options[1]) { PCI_SLOT(pcidev->devfn) != it->options[1]) {
continue; continue;
} }
} }
/* found ! */
devpriv->pci_dev = pcidev;
dev->board_ptr = cb_pcimdda_boards + index; dev->board_ptr = cb_pcimdda_boards + index;
thisboard = comedi_board(dev); return pcidev;
if (comedi_pci_enable(pcidev, thisboard->name)) {
printk
("cb_pcimdda: Failed to enable PCI device and request regions\n");
return -EIO;
}
registers =
pci_resource_start(devpriv->pci_dev,
thisboard->regs_badrindex);
devpriv->registers = registers;
devpriv->dio_registers
= devpriv->registers + thisboard->dio_offset;
return 0;
} }
} }
return NULL;
printk("cb_pcimdda: No supported ComputerBoards/MeasurementComputing "
"card found at the requested position\n");
return -ENODEV;
} }
static int cb_pcimdda_attach(struct comedi_device *dev, static int cb_pcimdda_attach(struct comedi_device *dev,
...@@ -268,6 +244,7 @@ static int cb_pcimdda_attach(struct comedi_device *dev, ...@@ -268,6 +244,7 @@ static int cb_pcimdda_attach(struct comedi_device *dev,
{ {
const struct cb_pcimdda_board *thisboard; const struct cb_pcimdda_board *thisboard;
struct cb_pcimdda_private *devpriv; struct cb_pcimdda_private *devpriv;
struct pci_dev *pcidev;
struct comedi_subdevice *s; struct comedi_subdevice *s;
int err; int err;
...@@ -276,25 +253,20 @@ static int cb_pcimdda_attach(struct comedi_device *dev, ...@@ -276,25 +253,20 @@ static int cb_pcimdda_attach(struct comedi_device *dev,
return err; return err;
devpriv = dev->private; devpriv = dev->private;
/* pcidev = cb_pcimdda_probe(dev, it);
* If you can probe the device to determine what device in a series if (!pcidev)
* it is, this is the place to do it. Otherwise, dev->board_ptr return -EIO;
* should already be initialized. devpriv->pci_dev = pcidev;
*/
err = cb_pcimdda_probe(dev, it);
if (err)
return err;
thisboard = comedi_board(dev); thisboard = comedi_board(dev);
/* Output some info */
printk("comedi%d: %s: ", dev->minor, thisboard->name);
/*
* Initialize dev->board_name. Note that we can use the "thisboard"
* macro now, since we just initialized it in the last line.
*/
dev->board_name = thisboard->name; dev->board_name = thisboard->name;
err = comedi_pci_enable(pcidev, dev->board_name);
if (err)
return err;
devpriv->registers = pci_resource_start(devpriv->pci_dev,
thisboard->regs_badrindex);
devpriv->dio_registers = devpriv->registers + thisboard->dio_offset;
err = comedi_alloc_subdevices(dev, 2); err = comedi_alloc_subdevices(dev, 2);
if (err) if (err)
return err; return err;
...@@ -336,7 +308,7 @@ static int cb_pcimdda_attach(struct comedi_device *dev, ...@@ -336,7 +308,7 @@ static int cb_pcimdda_attach(struct comedi_device *dev,
s->type = COMEDI_SUBD_UNUSED; s->type = COMEDI_SUBD_UNUSED;
} }
printk("attached\n"); dev_info(dev->class_dev, "%s attached\n", dev->board_name);
return 1; return 1;
} }
......
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