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

staging: comedi: cb_pcimdas: use attach_pci callback

Convert this PCI driver to use the comedi PCI auto config attach
mechanism by adding an 'attach_pci' callback function. Since the
driver does not require any external configuration options, and
the legacy 'attach' callback is now optional, remove it.
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 2682b2dc
...@@ -251,58 +251,42 @@ static int cb_pcimdas_ao_rinsn(struct comedi_device *dev, ...@@ -251,58 +251,42 @@ static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
return i; return i;
} }
static struct pci_dev *cb_pcimdas_find_pci_dev(struct comedi_device *dev, static const void *cb_pcimdas_find_boardinfo(struct comedi_device *dev,
struct comedi_devconfig *it) struct pci_dev *pcidev)
{ {
struct pci_dev *pcidev = NULL; const struct cb_pcimdas_board *thisboard;
int bus = it->options[0];
int slot = it->options[1];
int i; int i;
for_each_pci_dev(pcidev) {
if (bus || slot) {
if (bus != pcidev->bus->number ||
slot != PCI_SLOT(pcidev->devfn))
continue;
}
if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
continue;
for (i = 0; i < ARRAY_SIZE(cb_pcimdas_boards); i++) { for (i = 0; i < ARRAY_SIZE(cb_pcimdas_boards); i++) {
if (cb_pcimdas_boards[i].device_id != pcidev->device) thisboard = &cb_pcimdas_boards[i];
continue; if (thisboard->device_id == pcidev->device)
return thisboard;
dev->board_ptr = cb_pcimdas_boards + i;
return pcidev;
}
} }
dev_err(dev->class_dev,
"No supported board found! (req. bus %d, slot %d)\n",
bus, slot);
return NULL; return NULL;
} }
static int cb_pcimdas_attach(struct comedi_device *dev, static int cb_pcimdas_attach_pci(struct comedi_device *dev,
struct comedi_devconfig *it) struct pci_dev *pcidev)
{ {
const struct cb_pcimdas_board *thisboard; const struct cb_pcimdas_board *thisboard;
struct cb_pcimdas_private *devpriv; struct cb_pcimdas_private *devpriv;
struct pci_dev *pcidev;
struct comedi_subdevice *s; struct comedi_subdevice *s;
unsigned long iobase_8255; unsigned long iobase_8255;
int ret; int ret;
comedi_set_hw_dev(dev, &pcidev->dev);
thisboard = cb_pcimdas_find_boardinfo(dev, pcidev);
if (!thisboard)
return -ENODEV;
dev->board_ptr = thisboard;
dev->board_name = thisboard->name;
ret = alloc_private(dev, sizeof(*devpriv)); ret = alloc_private(dev, sizeof(*devpriv));
if (ret) if (ret)
return ret; return ret;
devpriv = dev->private; devpriv = dev->private;
pcidev = cb_pcimdas_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
comedi_set_hw_dev(dev, &pcidev->dev);
thisboard = comedi_board(dev);
/* Warn about non-tested features */ /* Warn about non-tested features */
switch (thisboard->device_id) { switch (thisboard->device_id) {
case 0x56: case 0x56:
...@@ -313,11 +297,9 @@ static int cb_pcimdas_attach(struct comedi_device *dev, ...@@ -313,11 +297,9 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
"PLEASE REPORT USAGE TO <mocelet@sucs.org>\n"); "PLEASE REPORT USAGE TO <mocelet@sucs.org>\n");
} }
if (comedi_pci_enable(pcidev, "cb_pcimdas")) { ret = comedi_pci_enable(pcidev, dev->board_name);
dev_err(dev->class_dev, if (ret)
"Failed to enable PCI device and request regions\n"); return ret;
return -EIO;
}
dev->iobase = pci_resource_start(pcidev, 2); dev->iobase = pci_resource_start(pcidev, 2);
devpriv->BADR3 = pci_resource_start(pcidev, 3); devpriv->BADR3 = pci_resource_start(pcidev, 3);
...@@ -332,9 +314,6 @@ static int cb_pcimdas_attach(struct comedi_device *dev, ...@@ -332,9 +314,6 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
/* } */ /* } */
/* dev->irq = pcidev->irq; */ /* dev->irq = pcidev->irq; */
/* Initialize dev->board_name */
dev->board_name = thisboard->name;
ret = comedi_alloc_subdevices(dev, 3); ret = comedi_alloc_subdevices(dev, 3);
if (ret) if (ret)
return ret; return ret;
...@@ -369,7 +348,9 @@ static int cb_pcimdas_attach(struct comedi_device *dev, ...@@ -369,7 +348,9 @@ static int cb_pcimdas_attach(struct comedi_device *dev,
else else
s->type = COMEDI_SUBD_UNUSED; s->type = COMEDI_SUBD_UNUSED;
return 1; dev_info(dev->class_dev, "%s attached\n", dev->board_name);
return 0;
} }
static void cb_pcimdas_detach(struct comedi_device *dev) static void cb_pcimdas_detach(struct comedi_device *dev)
...@@ -381,14 +362,13 @@ static void cb_pcimdas_detach(struct comedi_device *dev) ...@@ -381,14 +362,13 @@ static void cb_pcimdas_detach(struct comedi_device *dev)
if (pcidev) { if (pcidev) {
if (dev->iobase) if (dev->iobase)
comedi_pci_disable(pcidev); comedi_pci_disable(pcidev);
pci_dev_put(pcidev);
} }
} }
static struct comedi_driver cb_pcimdas_driver = { static struct comedi_driver cb_pcimdas_driver = {
.driver_name = "cb_pcimdas", .driver_name = "cb_pcimdas",
.module = THIS_MODULE, .module = THIS_MODULE,
.attach = cb_pcimdas_attach, .attach_pci = cb_pcimdas_attach_pci,
.detach = cb_pcimdas_detach, .detach = cb_pcimdas_detach,
}; };
......
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