diff options
author | H Hartley Sweeten <hartleys@visionengravers.com> | 2012-08-16 22:48:56 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-17 11:14:33 -0400 |
commit | b41bf58f3a088008d856b02faedfdf23167833a2 (patch) | |
tree | eb7f007fba61204f3a86a83f943fbbe0adfb1ed4 | |
parent | d1438d4158ed9650e8beffb4eac22e6ae62a0200 (diff) |
staging: comedi: cb_pcimdda: cleanup pci probe
Make cb_pcimdda_probe() return the pointer to the found pci_dev
and move the comedi_pci_enable() call into the 'attach' function.
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>
-rw-r--r-- | drivers/staging/comedi/drivers/cb_pcimdda.c | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c index edce2756c706..0c6d941946fa 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdda.c +++ b/drivers/staging/comedi/drivers/cb_pcimdda.c | |||
@@ -213,54 +213,30 @@ static int cb_pcimdda_ao_rinsn(struct comedi_device *dev, | |||
213 | return i; | 213 | return i; |
214 | } | 214 | } |
215 | 215 | ||
216 | static int cb_pcimdda_probe(struct comedi_device *dev, | 216 | static struct pci_dev *cb_pcimdda_probe(struct comedi_device *dev, |
217 | const struct comedi_devconfig *it) | 217 | struct comedi_devconfig *it) |
218 | { | 218 | { |
219 | const struct cb_pcimdda_board *thisboard; | ||
220 | struct cb_pcimdda_private *devpriv = dev->private; | ||
221 | struct pci_dev *pcidev = NULL; | 219 | struct pci_dev *pcidev = NULL; |
222 | int index; | 220 | int index; |
223 | unsigned long registers; | ||
224 | 221 | ||
225 | for_each_pci_dev(pcidev) { | 222 | for_each_pci_dev(pcidev) { |
226 | /* is it not a computer boards card? */ | ||
227 | if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) | 223 | if (pcidev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS) |
228 | continue; | 224 | continue; |
229 | /* loop through cards supported by this driver */ | ||
230 | for (index = 0; index < ARRAY_SIZE(cb_pcimdda_boards); index++) { | 225 | for (index = 0; index < ARRAY_SIZE(cb_pcimdda_boards); index++) { |
231 | if (cb_pcimdda_boards[index].device_id != pcidev->device) | 226 | if (cb_pcimdda_boards[index].device_id != pcidev->device) |
232 | continue; | 227 | continue; |
233 | /* was a particular bus/slot requested? */ | ||
234 | if (it->options[0] || it->options[1]) { | 228 | if (it->options[0] || it->options[1]) { |
235 | /* are we on the wrong bus/slot? */ | ||
236 | if (pcidev->bus->number != it->options[0] || | 229 | if (pcidev->bus->number != it->options[0] || |
237 | PCI_SLOT(pcidev->devfn) != it->options[1]) { | 230 | PCI_SLOT(pcidev->devfn) != it->options[1]) { |
238 | continue; | 231 | continue; |
239 | } | 232 | } |
240 | } | 233 | } |
241 | /* found ! */ | ||
242 | 234 | ||
243 | devpriv->pci_dev = pcidev; | ||
244 | dev->board_ptr = cb_pcimdda_boards + index; | 235 | dev->board_ptr = cb_pcimdda_boards + index; |
245 | thisboard = comedi_board(dev); | 236 | return pcidev; |
246 | if (comedi_pci_enable(pcidev, thisboard->name)) { | ||
247 | printk | ||
248 | ("cb_pcimdda: Failed to enable PCI device and request regions\n"); | ||
249 | return -EIO; | ||
250 | } | ||
251 | registers = | ||
252 | pci_resource_start(devpriv->pci_dev, | ||
253 | thisboard->regs_badrindex); | ||
254 | devpriv->registers = registers; | ||
255 | devpriv->dio_registers | ||
256 | = devpriv->registers + thisboard->dio_offset; | ||
257 | return 0; | ||
258 | } | 237 | } |
259 | } | 238 | } |
260 | 239 | return NULL; | |
261 | printk("cb_pcimdda: No supported ComputerBoards/MeasurementComputing " | ||
262 | "card found at the requested position\n"); | ||
263 | return -ENODEV; | ||
264 | } | 240 | } |
265 | 241 | ||
266 | static int cb_pcimdda_attach(struct comedi_device *dev, | 242 | static int cb_pcimdda_attach(struct comedi_device *dev, |
@@ -268,6 +244,7 @@ static int cb_pcimdda_attach(struct comedi_device *dev, | |||
268 | { | 244 | { |
269 | const struct cb_pcimdda_board *thisboard; | 245 | const struct cb_pcimdda_board *thisboard; |
270 | struct cb_pcimdda_private *devpriv; | 246 | struct cb_pcimdda_private *devpriv; |
247 | struct pci_dev *pcidev; | ||
271 | struct comedi_subdevice *s; | 248 | struct comedi_subdevice *s; |
272 | int err; | 249 | int err; |
273 | 250 | ||
@@ -276,25 +253,20 @@ static int cb_pcimdda_attach(struct comedi_device *dev, | |||
276 | return err; | 253 | return err; |
277 | devpriv = dev->private; | 254 | devpriv = dev->private; |
278 | 255 | ||
279 | /* | 256 | pcidev = cb_pcimdda_probe(dev, it); |
280 | * If you can probe the device to determine what device in a series | 257 | if (!pcidev) |
281 | * it is, this is the place to do it. Otherwise, dev->board_ptr | 258 | return -EIO; |
282 | * should already be initialized. | 259 | devpriv->pci_dev = pcidev; |
283 | */ | ||
284 | err = cb_pcimdda_probe(dev, it); | ||
285 | if (err) | ||
286 | return err; | ||
287 | thisboard = comedi_board(dev); | 260 | thisboard = comedi_board(dev); |
288 | |||
289 | /* Output some info */ | ||
290 | printk("comedi%d: %s: ", dev->minor, thisboard->name); | ||
291 | |||
292 | /* | ||
293 | * Initialize dev->board_name. Note that we can use the "thisboard" | ||
294 | * macro now, since we just initialized it in the last line. | ||
295 | */ | ||
296 | dev->board_name = thisboard->name; | 261 | dev->board_name = thisboard->name; |
297 | 262 | ||
263 | err = comedi_pci_enable(pcidev, dev->board_name); | ||
264 | if (err) | ||
265 | return err; | ||
266 | devpriv->registers = pci_resource_start(devpriv->pci_dev, | ||
267 | thisboard->regs_badrindex); | ||
268 | devpriv->dio_registers = devpriv->registers + thisboard->dio_offset; | ||
269 | |||
298 | err = comedi_alloc_subdevices(dev, 2); | 270 | err = comedi_alloc_subdevices(dev, 2); |
299 | if (err) | 271 | if (err) |
300 | return err; | 272 | return err; |
@@ -336,7 +308,7 @@ static int cb_pcimdda_attach(struct comedi_device *dev, | |||
336 | s->type = COMEDI_SUBD_UNUSED; | 308 | s->type = COMEDI_SUBD_UNUSED; |
337 | } | 309 | } |
338 | 310 | ||
339 | printk("attached\n"); | 311 | dev_info(dev->class_dev, "%s attached\n", dev->board_name); |
340 | 312 | ||
341 | return 1; | 313 | return 1; |
342 | } | 314 | } |