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

staging: comedi: rtd520: convert driver to attach_pci

Convert this driver to use the comedi PCI auto config mechanism
by adding an attach_pci callback.

Since this driver requires no extra configuration options, and
the attach callback is now optional, remove it.

Use the found 'dev->board_name' for the resource name passed to
comedi_pci_enable() and request_irq().

Since this driver no longer walks the pci bus to find the pci_dev,
remove the pci_dev_put() in the detach.
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 edecbd06
...@@ -108,8 +108,6 @@ Configuration options: ...@@ -108,8 +108,6 @@ Configuration options:
#include "comedi_fc.h" #include "comedi_fc.h"
#define DRV_NAME "rtd520"
/*====================================================================== /*======================================================================
Driver specific stuff (tunable) Driver specific stuff (tunable)
======================================================================*/ ======================================================================*/
...@@ -1392,59 +1390,39 @@ static void rtd_pci_latency_quirk(struct comedi_device *dev, ...@@ -1392,59 +1390,39 @@ static void rtd_pci_latency_quirk(struct comedi_device *dev,
#endif #endif
} }
static struct pci_dev *rtd_find_pci(struct comedi_device *dev, static const void *rtd_find_boardinfo(struct comedi_device *dev,
struct comedi_devconfig *it) struct pci_dev *pcidev)
{ {
const struct rtdBoard *thisboard; const struct rtdBoard *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) {
if (pcidev->vendor != PCI_VENDOR_ID_RTD)
continue;
if (bus || slot) {
if (pcidev->bus->number != bus ||
PCI_SLOT(pcidev->devfn) != slot)
continue;
}
for (i = 0; i < ARRAY_SIZE(rtd520Boards); i++) { for (i = 0; i < ARRAY_SIZE(rtd520Boards); i++) {
thisboard = &rtd520Boards[i]; thisboard = &rtd520Boards[i];
if (pcidev->device == thisboard->device_id) { if (pcidev->device == thisboard->device_id)
dev->board_ptr = thisboard; return thisboard;
return pcidev;
}
}
} }
dev_warn(dev->class_dev,
"no supported board found! (req. bus/slot: %d/%d)\n",
bus, slot);
return NULL; return NULL;
} }
static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it) static int rtd_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev)
{ /* board name and options flags */ {
const struct rtdBoard *thisboard; const struct rtdBoard *thisboard;
struct rtdPrivate *devpriv; struct rtdPrivate *devpriv;
struct pci_dev *pcidev;
struct comedi_subdevice *s; struct comedi_subdevice *s;
int ret; int ret;
thisboard = rtd_find_boardinfo(dev, pcidev);
if (!thisboard)
return -ENODEV;
dev->board_ptr = thisboard;
dev->board_name = thisboard->name;
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv) if (!devpriv)
return -ENOMEM; return -ENOMEM;
dev->private = devpriv; dev->private = devpriv;
pcidev = rtd_find_pci(dev, it); ret = comedi_pci_enable(pcidev, dev->board_name);
if (!pcidev)
return -EIO;
comedi_set_hw_dev(dev, &pcidev->dev);
thisboard = comedi_board(dev);
dev->board_name = thisboard->name;
ret = comedi_pci_enable(pcidev, DRV_NAME);
if (ret) if (ret)
return ret; return ret;
dev->iobase = 1; /* the "detach" needs this */ dev->iobase = 1; /* the "detach" needs this */
...@@ -1515,8 +1493,8 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -1515,8 +1493,8 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it)
rtd_init_board(dev); rtd_init_board(dev);
/* check if our interrupt is available and get it */ /* check if our interrupt is available and get it */
ret = request_irq(pcidev->irq, rtd_interrupt, ret = request_irq(pcidev->irq, rtd_interrupt, IRQF_SHARED,
IRQF_SHARED, DRV_NAME, dev); dev->board_name, dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
dev->irq = pcidev->irq; dev->irq = pcidev->irq;
...@@ -1559,14 +1537,13 @@ static void rtd_detach(struct comedi_device *dev) ...@@ -1559,14 +1537,13 @@ static void rtd_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 rtd520_driver = { static struct comedi_driver rtd520_driver = {
.driver_name = "rtd520", .driver_name = "rtd520",
.module = THIS_MODULE, .module = THIS_MODULE,
.attach = rtd_attach, .attach_pci = rtd_attach_pci,
.detach = rtd_detach, .detach = rtd_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