From: H Hartley Sweeten Date: Fri, 17 Aug 2012 02:55:43 +0000 (-0700) Subject: staging: comedi: ke_counter: use attach_pci callback X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=5afbfa638d52ac844459bca55170f354b109b4dc;p=linux-beck.git 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: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c index d4e9292483a0..a24e93278a48 100644 --- a/drivers/staging/comedi/drivers/ke_counter.c +++ b/drivers/staging/comedi/drivers/ke_counter.c @@ -28,11 +28,7 @@ Author: Michael Hillmann Updated: Mon, 14 Apr 2008 15:42:42 +0100 Status: tested -Configuration Options: - [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. +Configuration Options: not applicable, uses PCI auto config This driver is a simple driver to read the counter values from Kolter Electronic PCI Counter Card. @@ -111,72 +107,43 @@ static int cnt_rinsn(struct comedi_device *dev, return 1; } -static struct pci_dev *cnt_find_pci_dev(struct comedi_device *dev, - struct comedi_devconfig *it) +static const void *cnt_find_boardinfo(struct comedi_device *dev, + struct pci_dev *pcidev) { const struct cnt_board_struct *board; - struct pci_dev *pcidev = NULL; - int bus = it->options[0]; - int slot = it->options[1]; 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++) { - board = &cnt_boards[i]; - if (board->device_id != pcidev->device) - continue; - - dev->board_ptr = board; - return pcidev; - } + for (i = 0; i < ARRAY_SIZE(cnt_boards); i++) { + board = &cnt_boards[i]; + if (board->device_id == pcidev->device) + return board; } - dev_err(dev->class_dev, - "No supported board found! (req. bus %d, slot %d)\n", - bus, slot); 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; - struct pci_dev *pcidev; struct comedi_subdevice *subdevice; - unsigned long io_base; - int error; + int ret; - pcidev = cnt_find_pci_dev(dev, it); - if (!pcidev) - return -EIO; 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; - /* enable PCI device and request regions */ - error = comedi_pci_enable(pcidev, CNT_DRIVER_NAME); - if (error < 0) { - printk(KERN_WARNING "comedi%d: " - "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; + ret = comedi_pci_enable(pcidev, dev->board_name); + if (ret) + return ret; + dev->iobase = pci_resource_start(pcidev, 0); - error = comedi_alloc_subdevices(dev, 1); - if (error) - return error; + ret = comedi_alloc_subdevices(dev, 1); + if (ret) + return ret; subdevice = dev->subdevices + 0; dev->read_subdev = subdevice; @@ -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 + 0x40); - printk(KERN_INFO "comedi%d: " CNT_DRIVER_NAME " attached.\n", - dev->minor); + dev_info(dev->class_dev, "%s: %s attached\n", + dev->driver->driver_name, dev->board_name); + return 0; } @@ -208,14 +176,13 @@ static void cnt_detach(struct comedi_device *dev) if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); - pci_dev_put(pcidev); } } static struct comedi_driver ke_counter_driver = { .driver_name = "ke_counter", .module = THIS_MODULE, - .attach = cnt_attach, + .attach_pci = cnt_attach_pci, .detach = cnt_detach, };