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

staging: comedi: cb_pcidas: 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 6bfbd988
...@@ -45,11 +45,7 @@ Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas), ...@@ -45,11 +45,7 @@ Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas),
The boards may be autocalibrated using the comedi_calibrate The boards may be autocalibrated using the comedi_calibrate
utility. utility.
Configuration options: Configuration options: not applicable, uses PCI auto config
[0] - PCI bus of device (optional)
[1] - PCI slot of device (optional)
If bus/slot is not specified, the first supported
PCI device found will be used.
For commands, the scanned channels must be consecutive For commands, the scanned channels must be consecutive
(i.e. 4-5-6-7, 2-3-4,...), and must all have the same (i.e. 4-5-6-7, 2-3-4,...), and must all have the same
...@@ -1501,69 +1497,45 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d) ...@@ -1501,69 +1497,45 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static struct pci_dev *cb_pcidas_find_pci_device(struct comedi_device *dev, static const void *cb_pcidas_find_boardinfo(struct comedi_device *dev,
struct comedi_devconfig *it) struct pci_dev *pcidev)
{ {
const struct cb_pcidas_board *thisboard; const struct cb_pcidas_board *thisboard;
struct pci_dev *pcidev = NULL;
int bus = it->options[0];
int slot = it->options[1];
int i; int i;
for_each_pci_dev(pcidev) {
/* is it not a computer boards card? */
if (pcidev->vendor != PCI_VENDOR_ID_CB)
continue;
/* loop through cards supported by this driver */
for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) { for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) {
thisboard = &cb_pcidas_boards[i]; thisboard = &cb_pcidas_boards[i];
if (thisboard->device_id != pcidev->device) if (thisboard->device_id == pcidev->device)
continue; return thisboard;
/* was a particular bus/slot requested? */
if (bus || slot) {
/* are we on the wrong bus/slot? */
if (pcidev->bus->number != bus ||
PCI_SLOT(pcidev->devfn) != slot) {
continue;
} }
}
dev_dbg(dev->class_dev,
"Found %s on bus %i, slot %i\n",
thisboard->name,
pcidev->bus->number, PCI_SLOT(pcidev->devfn));
dev->board_ptr = thisboard;
return pcidev;
}
}
dev_err(dev->class_dev, "No supported card found\n");
return NULL; return NULL;
} }
static int cb_pcidas_attach(struct comedi_device *dev, static int cb_pcidas_attach_pci(struct comedi_device *dev,
struct comedi_devconfig *it) struct pci_dev *pcidev)
{ {
const struct cb_pcidas_board *thisboard; const struct cb_pcidas_board *thisboard;
struct cb_pcidas_private *devpriv; struct cb_pcidas_private *devpriv;
struct pci_dev *pcidev;
struct comedi_subdevice *s; struct comedi_subdevice *s;
int i; int i;
int ret; int ret;
if (alloc_private(dev, sizeof(struct cb_pcidas_private)) < 0)
return -ENOMEM;
devpriv = dev->private;
pcidev = cb_pcidas_find_pci_device(dev, it);
if (!pcidev)
return -EIO;
comedi_set_hw_dev(dev, &pcidev->dev); comedi_set_hw_dev(dev, &pcidev->dev);
thisboard = comedi_board(dev);
if (comedi_pci_enable(pcidev, dev->driver->driver_name)) { thisboard = cb_pcidas_find_boardinfo(dev, pcidev);
dev_err(dev->class_dev, if (!thisboard)
"Failed to enable PCI device and request regions\n"); return -ENODEV;
return -EIO; dev->board_ptr = thisboard;
} dev->board_name = thisboard->name;
ret = alloc_private(dev, sizeof(*devpriv));
if (ret)
return ret;
devpriv = dev->private;
ret = comedi_pci_enable(pcidev, dev->board_name);
if (ret)
return ret;
devpriv->s5933_config = pci_resource_start(pcidev, 0); devpriv->s5933_config = pci_resource_start(pcidev, 0);
devpriv->control_status = pci_resource_start(pcidev, 1); devpriv->control_status = pci_resource_start(pcidev, 1);
...@@ -1584,8 +1556,6 @@ static int cb_pcidas_attach(struct comedi_device *dev, ...@@ -1584,8 +1556,6 @@ static int cb_pcidas_attach(struct comedi_device *dev,
} }
dev->irq = pcidev->irq; dev->irq = pcidev->irq;
dev->board_name = thisboard->name;
ret = comedi_alloc_subdevices(dev, 7); ret = comedi_alloc_subdevices(dev, 7);
if (ret) if (ret)
return ret; return ret;
...@@ -1698,7 +1668,10 @@ static int cb_pcidas_attach(struct comedi_device *dev, ...@@ -1698,7 +1668,10 @@ static int cb_pcidas_attach(struct comedi_device *dev,
outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS, outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS,
devpriv->s5933_config + AMCC_OP_REG_INTCSR); devpriv->s5933_config + AMCC_OP_REG_INTCSR);
return 1; dev_info(dev->class_dev, "%s: %s attached\n",
dev->driver->driver_name, dev->board_name);
return 0;
} }
static void cb_pcidas_detach(struct comedi_device *dev) static void cb_pcidas_detach(struct comedi_device *dev)
...@@ -1719,14 +1692,13 @@ static void cb_pcidas_detach(struct comedi_device *dev) ...@@ -1719,14 +1692,13 @@ static void cb_pcidas_detach(struct comedi_device *dev)
if (pcidev) { if (pcidev) {
if (devpriv->s5933_config) if (devpriv->s5933_config)
comedi_pci_disable(pcidev); comedi_pci_disable(pcidev);
pci_dev_put(pcidev);
} }
} }
static struct comedi_driver cb_pcidas_driver = { static struct comedi_driver cb_pcidas_driver = {
.driver_name = "cb_pcidas", .driver_name = "cb_pcidas",
.module = THIS_MODULE, .module = THIS_MODULE,
.attach = cb_pcidas_attach, .attach_pci = cb_pcidas_attach_pci,
.detach = cb_pcidas_detach, .detach = cb_pcidas_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