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

staging: comedi: ke_counter: 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 c3b52d46
...@@ -28,11 +28,7 @@ Author: Michael Hillmann ...@@ -28,11 +28,7 @@ Author: Michael Hillmann
Updated: Mon, 14 Apr 2008 15:42:42 +0100 Updated: Mon, 14 Apr 2008 15:42:42 +0100
Status: tested Status: tested
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.
This driver is a simple driver to read the counter values from This driver is a simple driver to read the counter values from
Kolter Electronic PCI Counter Card. Kolter Electronic PCI Counter Card.
...@@ -111,72 +107,43 @@ static int cnt_rinsn(struct comedi_device *dev, ...@@ -111,72 +107,43 @@ static int cnt_rinsn(struct comedi_device *dev,
return 1; return 1;
} }
static struct pci_dev *cnt_find_pci_dev(struct comedi_device *dev, static const void *cnt_find_boardinfo(struct comedi_device *dev,
struct comedi_devconfig *it) struct pci_dev *pcidev)
{ {
const struct cnt_board_struct *board; const struct cnt_board_struct *board;
struct pci_dev *pcidev = NULL;
int bus = it->options[0];
int slot = it->options[1];
int i; int i;
/* Probe the device to determine what device in the series it is. */
for_each_pci_dev(pcidev) {
if (bus || slot) {
if (pcidev->bus->number != bus ||
PCI_SLOT(pcidev->devfn) != slot)
continue;
}
if (pcidev->vendor != PCI_VENDOR_ID_KOLTER)
continue;
for (i = 0; i < ARRAY_SIZE(cnt_boards); i++) { for (i = 0; i < ARRAY_SIZE(cnt_boards); i++) {
board = &cnt_boards[i]; board = &cnt_boards[i];
if (board->device_id != pcidev->device) if (board->device_id == pcidev->device)
continue; return board;
dev->board_ptr = board;
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 cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it) static int cnt_attach_pci(struct comedi_device *dev,
struct pci_dev *pcidev)
{ {
const struct cnt_board_struct *board; const struct cnt_board_struct *board;
struct pci_dev *pcidev;
struct comedi_subdevice *subdevice; struct comedi_subdevice *subdevice;
unsigned long io_base; int ret;
int error;
pcidev = cnt_find_pci_dev(dev, it);
if (!pcidev)
return -EIO;
comedi_set_hw_dev(dev, &pcidev->dev); comedi_set_hw_dev(dev, &pcidev->dev);
board = comedi_board(dev);
board = cnt_find_boardinfo(dev, pcidev);
if (!board)
return -ENODEV;
dev->board_ptr = board;
dev->board_name = board->name; dev->board_name = board->name;
/* enable PCI device and request regions */ ret = comedi_pci_enable(pcidev, dev->board_name);
error = comedi_pci_enable(pcidev, CNT_DRIVER_NAME); if (ret)
if (error < 0) { return ret;
printk(KERN_WARNING "comedi%d: " dev->iobase = pci_resource_start(pcidev, 0);
"failed to enable PCI device and request regions!\n",
dev->minor);
return error;
}
/* read register base address [PCI_BASE_ADDRESS #0] */
io_base = pci_resource_start(pcidev, 0);
dev->iobase = io_base;
error = comedi_alloc_subdevices(dev, 1); ret = comedi_alloc_subdevices(dev, 1);
if (error) if (ret)
return error; return ret;
subdevice = dev->subdevices + 0; subdevice = dev->subdevices + 0;
dev->read_subdev = subdevice; dev->read_subdev = subdevice;
...@@ -196,8 +163,9 @@ static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -196,8 +163,9 @@ static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it)
outb(0, dev->iobase + 0x20); outb(0, dev->iobase + 0x20);
outb(0, dev->iobase + 0x40); outb(0, dev->iobase + 0x40);
printk(KERN_INFO "comedi%d: " CNT_DRIVER_NAME " attached.\n", dev_info(dev->class_dev, "%s: %s attached\n",
dev->minor); dev->driver->driver_name, dev->board_name);
return 0; return 0;
} }
...@@ -208,14 +176,13 @@ static void cnt_detach(struct comedi_device *dev) ...@@ -208,14 +176,13 @@ static void cnt_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 ke_counter_driver = { static struct comedi_driver ke_counter_driver = {
.driver_name = "ke_counter", .driver_name = "ke_counter",
.module = THIS_MODULE, .module = THIS_MODULE,
.attach = cnt_attach, .attach_pci = cnt_attach_pci,
.detach = cnt_detach, .detach = cnt_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