diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-01-30 17:24:38 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-31 04:40:41 -0500 |
commit | 1ae6b20b88737f1828649b6cbe349c83b9f97bf0 (patch) | |
tree | 18b9e8559af054658eeb5186768ca6640eb9e3c3 | |
parent | 52c9bf4cf51d992b1b88edeaa63e018d178cbc83 (diff) |
staging: comedi: tidy up the general purpose driver functions
Group all the general comedi driver register/config/attach
prototypes into one place in comedidev.h.
Reorder the functions in drivers.c a bit so they are in a more
logical usage order (bottom to top).
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/comedidev.h | 49 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers.c | 94 |
2 files changed, 73 insertions, 70 deletions
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index ea585ebd07df..0f29dd5287bb 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h | |||
@@ -258,26 +258,6 @@ static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; | |||
258 | 258 | ||
259 | struct comedi_device *comedi_dev_from_minor(unsigned minor); | 259 | struct comedi_device *comedi_dev_from_minor(unsigned minor); |
260 | 260 | ||
261 | int comedi_alloc_subdevices(struct comedi_device *, int); | ||
262 | |||
263 | void comedi_device_detach(struct comedi_device *dev); | ||
264 | int comedi_device_attach(struct comedi_device *dev, | ||
265 | struct comedi_devconfig *it); | ||
266 | int comedi_driver_register(struct comedi_driver *); | ||
267 | int comedi_driver_unregister(struct comedi_driver *); | ||
268 | |||
269 | /** | ||
270 | * module_comedi_driver() - Helper macro for registering a comedi driver | ||
271 | * @__comedi_driver: comedi_driver struct | ||
272 | * | ||
273 | * Helper macro for comedi drivers which do not do anything special in module | ||
274 | * init/exit. This eliminates a lot of boilerplate. Each module may only use | ||
275 | * this macro once, and calling it replaces module_init() and module_exit(). | ||
276 | */ | ||
277 | #define module_comedi_driver(__comedi_driver) \ | ||
278 | module_driver(__comedi_driver, comedi_driver_register, \ | ||
279 | comedi_driver_unregister) | ||
280 | |||
281 | void init_polling(void); | 261 | void init_polling(void); |
282 | void cleanup_polling(void); | 262 | void cleanup_polling(void); |
283 | void start_polling(struct comedi_device *); | 263 | void start_polling(struct comedi_device *); |
@@ -384,9 +364,32 @@ void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, | |||
384 | int comedi_alloc_subdevice_minor(struct comedi_device *dev, | 364 | int comedi_alloc_subdevice_minor(struct comedi_device *dev, |
385 | struct comedi_subdevice *s); | 365 | struct comedi_subdevice *s); |
386 | void comedi_free_subdevice_minor(struct comedi_subdevice *s); | 366 | void comedi_free_subdevice_minor(struct comedi_subdevice *s); |
387 | int comedi_auto_config(struct device *hardware_device, | 367 | |
388 | struct comedi_driver *driver, unsigned long context); | 368 | /* drivers.c - general comedi driver functions */ |
389 | void comedi_auto_unconfig(struct device *hardware_device); | 369 | |
370 | int comedi_alloc_subdevices(struct comedi_device *, int); | ||
371 | |||
372 | void comedi_device_detach(struct comedi_device *); | ||
373 | int comedi_device_attach(struct comedi_device *, struct comedi_devconfig *); | ||
374 | |||
375 | int comedi_auto_config(struct device *, struct comedi_driver *, | ||
376 | unsigned long context); | ||
377 | void comedi_auto_unconfig(struct device *); | ||
378 | |||
379 | int comedi_driver_register(struct comedi_driver *); | ||
380 | int comedi_driver_unregister(struct comedi_driver *); | ||
381 | |||
382 | /** | ||
383 | * module_comedi_driver() - Helper macro for registering a comedi driver | ||
384 | * @__comedi_driver: comedi_driver struct | ||
385 | * | ||
386 | * Helper macro for comedi drivers which do not do anything special in module | ||
387 | * init/exit. This eliminates a lot of boilerplate. Each module may only use | ||
388 | * this macro once, and calling it replaces module_init() and module_exit(). | ||
389 | */ | ||
390 | #define module_comedi_driver(__comedi_driver) \ | ||
391 | module_driver(__comedi_driver, comedi_driver_register, \ | ||
392 | comedi_driver_unregister) | ||
390 | 393 | ||
391 | #ifdef CONFIG_COMEDI_PCI_DRIVERS | 394 | #ifdef CONFIG_COMEDI_PCI_DRIVERS |
392 | 395 | ||
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 151e0845569e..fe91e758184f 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c | |||
@@ -386,53 +386,6 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) | |||
386 | return comedi_device_postconfig(dev); | 386 | return comedi_device_postconfig(dev); |
387 | } | 387 | } |
388 | 388 | ||
389 | int comedi_driver_register(struct comedi_driver *driver) | ||
390 | { | ||
391 | driver->next = comedi_drivers; | ||
392 | comedi_drivers = driver; | ||
393 | |||
394 | return 0; | ||
395 | } | ||
396 | EXPORT_SYMBOL(comedi_driver_register); | ||
397 | |||
398 | int comedi_driver_unregister(struct comedi_driver *driver) | ||
399 | { | ||
400 | struct comedi_driver *prev; | ||
401 | int i; | ||
402 | |||
403 | /* check for devices using this driver */ | ||
404 | for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { | ||
405 | struct comedi_device *dev = comedi_dev_from_minor(i); | ||
406 | |||
407 | if (!dev) | ||
408 | continue; | ||
409 | |||
410 | mutex_lock(&dev->mutex); | ||
411 | if (dev->attached && dev->driver == driver) { | ||
412 | if (dev->use_count) | ||
413 | dev_warn(dev->class_dev, | ||
414 | "BUG! detaching device with use_count=%d\n", | ||
415 | dev->use_count); | ||
416 | comedi_device_detach(dev); | ||
417 | } | ||
418 | mutex_unlock(&dev->mutex); | ||
419 | } | ||
420 | |||
421 | if (comedi_drivers == driver) { | ||
422 | comedi_drivers = driver->next; | ||
423 | return 0; | ||
424 | } | ||
425 | |||
426 | for (prev = comedi_drivers; prev->next; prev = prev->next) { | ||
427 | if (prev->next == driver) { | ||
428 | prev->next = driver->next; | ||
429 | return 0; | ||
430 | } | ||
431 | } | ||
432 | return -EINVAL; | ||
433 | } | ||
434 | EXPORT_SYMBOL(comedi_driver_unregister); | ||
435 | |||
436 | int comedi_auto_config(struct device *hardware_device, | 389 | int comedi_auto_config(struct device *hardware_device, |
437 | struct comedi_driver *driver, unsigned long context) | 390 | struct comedi_driver *driver, unsigned long context) |
438 | { | 391 | { |
@@ -492,3 +445,50 @@ void comedi_auto_unconfig(struct device *hardware_device) | |||
492 | comedi_free_board_minor(minor); | 445 | comedi_free_board_minor(minor); |
493 | } | 446 | } |
494 | EXPORT_SYMBOL_GPL(comedi_auto_unconfig); | 447 | EXPORT_SYMBOL_GPL(comedi_auto_unconfig); |
448 | |||
449 | int comedi_driver_register(struct comedi_driver *driver) | ||
450 | { | ||
451 | driver->next = comedi_drivers; | ||
452 | comedi_drivers = driver; | ||
453 | |||
454 | return 0; | ||
455 | } | ||
456 | EXPORT_SYMBOL(comedi_driver_register); | ||
457 | |||
458 | int comedi_driver_unregister(struct comedi_driver *driver) | ||
459 | { | ||
460 | struct comedi_driver *prev; | ||
461 | int i; | ||
462 | |||
463 | /* check for devices using this driver */ | ||
464 | for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { | ||
465 | struct comedi_device *dev = comedi_dev_from_minor(i); | ||
466 | |||
467 | if (!dev) | ||
468 | continue; | ||
469 | |||
470 | mutex_lock(&dev->mutex); | ||
471 | if (dev->attached && dev->driver == driver) { | ||
472 | if (dev->use_count) | ||
473 | dev_warn(dev->class_dev, | ||
474 | "BUG! detaching device with use_count=%d\n", | ||
475 | dev->use_count); | ||
476 | comedi_device_detach(dev); | ||
477 | } | ||
478 | mutex_unlock(&dev->mutex); | ||
479 | } | ||
480 | |||
481 | if (comedi_drivers == driver) { | ||
482 | comedi_drivers = driver->next; | ||
483 | return 0; | ||
484 | } | ||
485 | |||
486 | for (prev = comedi_drivers; prev->next; prev = prev->next) { | ||
487 | if (prev->next == driver) { | ||
488 | prev->next = driver->next; | ||
489 | return 0; | ||
490 | } | ||
491 | } | ||
492 | return -EINVAL; | ||
493 | } | ||
494 | EXPORT_SYMBOL(comedi_driver_unregister); | ||