Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

H Hartley Sweeten and committed by
Greg Kroah-Hartman
5afbfa63 c3b52d46

+25 -58
+25 -58
drivers/staging/comedi/drivers/ke_counter.c
··· 28 28 Updated: Mon, 14 Apr 2008 15:42:42 +0100 29 29 Status: tested 30 30 31 - Configuration Options: 32 - [0] - PCI bus of device (optional) 33 - [1] - PCI slot of device (optional) 34 - If bus/slot is not specified, the first supported 35 - PCI device found will be used. 31 + Configuration Options: not applicable, uses PCI auto config 36 32 37 33 This driver is a simple driver to read the counter values from 38 34 Kolter Electronic PCI Counter Card. ··· 107 111 return 1; 108 112 } 109 113 110 - static struct pci_dev *cnt_find_pci_dev(struct comedi_device *dev, 111 - struct comedi_devconfig *it) 114 + static const void *cnt_find_boardinfo(struct comedi_device *dev, 115 + struct pci_dev *pcidev) 112 116 { 113 117 const struct cnt_board_struct *board; 114 - struct pci_dev *pcidev = NULL; 115 - int bus = it->options[0]; 116 - int slot = it->options[1]; 117 118 int i; 118 119 119 - /* Probe the device to determine what device in the series it is. */ 120 - for_each_pci_dev(pcidev) { 121 - if (bus || slot) { 122 - if (pcidev->bus->number != bus || 123 - PCI_SLOT(pcidev->devfn) != slot) 124 - continue; 125 - } 126 - if (pcidev->vendor != PCI_VENDOR_ID_KOLTER) 127 - continue; 128 - 129 - for (i = 0; i < ARRAY_SIZE(cnt_boards); i++) { 130 - board = &cnt_boards[i]; 131 - if (board->device_id != pcidev->device) 132 - continue; 133 - 134 - dev->board_ptr = board; 135 - return pcidev; 136 - } 120 + for (i = 0; i < ARRAY_SIZE(cnt_boards); i++) { 121 + board = &cnt_boards[i]; 122 + if (board->device_id == pcidev->device) 123 + return board; 137 124 } 138 - dev_err(dev->class_dev, 139 - "No supported board found! (req. bus %d, slot %d)\n", 140 - bus, slot); 141 125 return NULL; 142 126 } 143 127 144 - static int cnt_attach(struct comedi_device *dev, struct comedi_devconfig *it) 128 + static int cnt_attach_pci(struct comedi_device *dev, 129 + struct pci_dev *pcidev) 145 130 { 146 131 const struct cnt_board_struct *board; 147 - struct pci_dev *pcidev; 148 132 struct comedi_subdevice *subdevice; 149 - unsigned long io_base; 150 - int error; 133 + int ret; 151 134 152 - pcidev = cnt_find_pci_dev(dev, it); 153 - if (!pcidev) 154 - return -EIO; 155 135 comedi_set_hw_dev(dev, &pcidev->dev); 156 - board = comedi_board(dev); 157 136 137 + board = cnt_find_boardinfo(dev, pcidev); 138 + if (!board) 139 + return -ENODEV; 140 + dev->board_ptr = board; 158 141 dev->board_name = board->name; 159 142 160 - /* enable PCI device and request regions */ 161 - error = comedi_pci_enable(pcidev, CNT_DRIVER_NAME); 162 - if (error < 0) { 163 - printk(KERN_WARNING "comedi%d: " 164 - "failed to enable PCI device and request regions!\n", 165 - dev->minor); 166 - return error; 167 - } 143 + ret = comedi_pci_enable(pcidev, dev->board_name); 144 + if (ret) 145 + return ret; 146 + dev->iobase = pci_resource_start(pcidev, 0); 168 147 169 - /* read register base address [PCI_BASE_ADDRESS #0] */ 170 - io_base = pci_resource_start(pcidev, 0); 171 - dev->iobase = io_base; 172 - 173 - error = comedi_alloc_subdevices(dev, 1); 174 - if (error) 175 - return error; 148 + ret = comedi_alloc_subdevices(dev, 1); 149 + if (ret) 150 + return ret; 176 151 177 152 subdevice = dev->subdevices + 0; 178 153 dev->read_subdev = subdevice; ··· 163 196 outb(0, dev->iobase + 0x20); 164 197 outb(0, dev->iobase + 0x40); 165 198 166 - printk(KERN_INFO "comedi%d: " CNT_DRIVER_NAME " attached.\n", 167 - dev->minor); 199 + dev_info(dev->class_dev, "%s: %s attached\n", 200 + dev->driver->driver_name, dev->board_name); 201 + 168 202 return 0; 169 203 } 170 204 ··· 176 208 if (pcidev) { 177 209 if (dev->iobase) 178 210 comedi_pci_disable(pcidev); 179 - pci_dev_put(pcidev); 180 211 } 181 212 } 182 213 183 214 static struct comedi_driver ke_counter_driver = { 184 215 .driver_name = "ke_counter", 185 216 .module = THIS_MODULE, 186 - .attach = cnt_attach, 217 + .attach_pci = cnt_attach_pci, 187 218 .detach = cnt_detach, 188 219 }; 189 220