From: H Hartley Sweeten Date: Sat, 18 Aug 2012 01:19:36 +0000 (-0700) Subject: staging: comedi: adv_pci_dio: use attach_pci callback X-Git-Tag: firefly_0821_release~3680^2~1977^2~839 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e5200165a9f34d75150e9de7b40dfcf8359bb5c7;p=firefly-linux-kernel-4.4.55.git staging: comedi: adv_pci_dio: 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/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c index 97fc6b872919..36b7c8d3b7e7 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -913,8 +913,7 @@ static int pci_dio_reset(struct comedi_device *dev) /* ============================================================================== */ -static int pci1760_attach(struct comedi_device *dev, - struct comedi_devconfig *it) +static int pci1760_attach(struct comedi_device *dev) { struct comedi_subdevice *s; int subdev = 0; @@ -1042,60 +1041,45 @@ static int pci_dio_add_8254(struct comedi_device *dev, return 0; } -static struct pci_dev *pci_dio_find_pci_dev(struct comedi_device *dev, - struct comedi_devconfig *it) +static const void *pci_dio_find_boardinfo(struct comedi_device *dev, + struct pci_dev *pcidev) { - struct pci_dev *pcidev = NULL; - int bus = it->options[0]; - int slot = it->options[1]; + const struct dio_boardtype *this_board; int i; - for_each_pci_dev(pcidev) { - if (bus || slot) { - if (bus != pcidev->bus->number || - slot != PCI_SLOT(pcidev->devfn)) - continue; - } - for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) { - if (boardtypes[i].vendor_id != pcidev->vendor) - continue; - if (boardtypes[i].device_id != pcidev->device) - continue; - dev->board_ptr = boardtypes + i; - return pcidev; - } + for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) { + this_board = &boardtypes[i]; + if (this_board->vendor_id == pcidev->vendor && + this_board->device_id == pcidev->device) + return this_board; } - dev_err(dev->class_dev, - "No supported board found! (req. bus %d, slot %d)\n", - bus, slot); return NULL; } -static int pci_dio_attach(struct comedi_device *dev, - struct comedi_devconfig *it) +static int pci_dio_attach_pci(struct comedi_device *dev, + struct pci_dev *pcidev) { const struct dio_boardtype *this_board; struct pci_dio_private *devpriv; - struct pci_dev *pcidev; struct comedi_subdevice *s; int ret, subdev, n_subdevices, i, j; + comedi_set_hw_dev(dev, &pcidev->dev); + + this_board = pci_dio_find_boardinfo(dev, pcidev); + if (!this_board) + return -ENODEV; + dev->board_ptr = this_board; + dev->board_name = this_board->name; + ret = alloc_private(dev, sizeof(*devpriv)); if (ret < 0) return ret; devpriv = dev->private; - pcidev = pci_dio_find_pci_dev(dev, it); - if (!pcidev) - return -EIO; - comedi_set_hw_dev(dev, &pcidev->dev); - this_board = comedi_board(dev); - dev->board_name = this_board->name; - ret = comedi_pci_enable(pcidev, dev->board_name); if (ret) return ret; - dev->iobase = pci_resource_start(pcidev, this_board->main_pci_region); if (this_board->cardtype == TYPE_PCI1760) { @@ -1161,7 +1145,7 @@ static int pci_dio_attach(struct comedi_device *dev, } if (this_board->cardtype == TYPE_PCI1760) - pci1760_attach(dev, it); + pci1760_attach(dev); devpriv->valid = 1; @@ -1211,15 +1195,14 @@ static void pci_dio_detach(struct comedi_device *dev) if (pcidev) { if (dev->iobase) comedi_pci_disable(pcidev); - pci_dev_put(pcidev); } } static struct comedi_driver adv_pci_dio_driver = { .driver_name = "adv_pci_dio", .module = THIS_MODULE, - .attach = pci_dio_attach, - .detach = pci_dio_detach + .attach_pci = pci_dio_attach_pci, + .detach = pci_dio_detach, }; static int __devinit adv_pci_dio_pci_probe(struct pci_dev *dev,