diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2006-07-01 22:08:49 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-09-27 14:58:50 -0400 |
commit | 8bb54ab573ecd1b4fe2ed66416a8d99a86e65316 (patch) | |
tree | 36df75387a62923e3bd152f3c2ce16147be1828c /include/linux | |
parent | 36e56a34586783c7986ce09d39db80b27c95ce24 (diff) |
usbcore: add usb_device_driver definition
This patch (as732) adds a usb_device_driver structure, for representing
drivers that manage an entire USB device as opposed to just an
interface. Support routines like usb_register_device_driver,
usb_deregister_device_driver, usb_probe_device, and usb_unbind_device
are also added.
Unlike an earlier version of this patch, the new code is type-safe. To
accomplish this, the existing struct driver embedded in struct
usb_driver had to be wrapped in an intermediate wrapper. This enables
the core to tell at runtime whether a particular struct driver belongs
to a device driver or to an interface driver.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/usb.h | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/include/linux/usb.h b/include/linux/usb.h index d2bd0c8e0154..b4ccce6d0982 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h | |||
@@ -540,7 +540,17 @@ struct usb_dynids { | |||
540 | }; | 540 | }; |
541 | 541 | ||
542 | /** | 542 | /** |
543 | * struct usb_driver - identifies USB driver to usbcore | 543 | * struct usbdrv_wrap - wrapper for driver-model structure |
544 | * @driver: The driver-model core driver structure. | ||
545 | * @for_devices: Non-zero for device drivers, 0 for interface drivers. | ||
546 | */ | ||
547 | struct usbdrv_wrap { | ||
548 | struct device_driver driver; | ||
549 | int for_devices; | ||
550 | }; | ||
551 | |||
552 | /** | ||
553 | * struct usb_driver - identifies USB interface driver to usbcore | ||
544 | * @name: The driver name should be unique among USB drivers, | 554 | * @name: The driver name should be unique among USB drivers, |
545 | * and should normally be the same as the module name. | 555 | * and should normally be the same as the module name. |
546 | * @probe: Called to see if the driver is willing to manage a particular | 556 | * @probe: Called to see if the driver is willing to manage a particular |
@@ -567,12 +577,12 @@ struct usb_dynids { | |||
567 | * or your driver's probe function will never get called. | 577 | * or your driver's probe function will never get called. |
568 | * @dynids: used internally to hold the list of dynamically added device | 578 | * @dynids: used internally to hold the list of dynamically added device |
569 | * ids for this driver. | 579 | * ids for this driver. |
570 | * @driver: the driver model core driver structure. | 580 | * @drvwrap: Driver-model core structure wrapper. |
571 | * @no_dynamic_id: if set to 1, the USB core will not allow dynamic ids to be | 581 | * @no_dynamic_id: if set to 1, the USB core will not allow dynamic ids to be |
572 | * added to this driver by preventing the sysfs file from being created. | 582 | * added to this driver by preventing the sysfs file from being created. |
573 | * | 583 | * |
574 | * USB drivers must provide a name, probe() and disconnect() methods, | 584 | * USB interface drivers must provide a name, probe() and disconnect() |
575 | * and an id_table. Other driver fields are optional. | 585 | * methods, and an id_table. Other driver fields are optional. |
576 | * | 586 | * |
577 | * The id_table is used in hotplugging. It holds a set of descriptors, | 587 | * The id_table is used in hotplugging. It holds a set of descriptors, |
578 | * and specialized data may be associated with each entry. That table | 588 | * and specialized data may be associated with each entry. That table |
@@ -606,10 +616,40 @@ struct usb_driver { | |||
606 | const struct usb_device_id *id_table; | 616 | const struct usb_device_id *id_table; |
607 | 617 | ||
608 | struct usb_dynids dynids; | 618 | struct usb_dynids dynids; |
609 | struct device_driver driver; | 619 | struct usbdrv_wrap drvwrap; |
610 | unsigned int no_dynamic_id:1; | 620 | unsigned int no_dynamic_id:1; |
611 | }; | 621 | }; |
612 | #define to_usb_driver(d) container_of(d, struct usb_driver, driver) | 622 | #define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver) |
623 | |||
624 | /** | ||
625 | * struct usb_device_driver - identifies USB device driver to usbcore | ||
626 | * @name: The driver name should be unique among USB drivers, | ||
627 | * and should normally be the same as the module name. | ||
628 | * @probe: Called to see if the driver is willing to manage a particular | ||
629 | * device. If it is, probe returns zero and uses dev_set_drvdata() | ||
630 | * to associate driver-specific data with the device. If unwilling | ||
631 | * to manage the device, return a negative errno value. | ||
632 | * @disconnect: Called when the device is no longer accessible, usually | ||
633 | * because it has been (or is being) disconnected or the driver's | ||
634 | * module is being unloaded. | ||
635 | * @suspend: Called when the device is going to be suspended by the system. | ||
636 | * @resume: Called when the device is being resumed by the system. | ||
637 | * @drvwrap: Driver-model core structure wrapper. | ||
638 | * | ||
639 | * USB drivers must provide all the fields listed above except drvwrap. | ||
640 | */ | ||
641 | struct usb_device_driver { | ||
642 | const char *name; | ||
643 | |||
644 | int (*probe) (struct usb_device *udev); | ||
645 | void (*disconnect) (struct usb_device *udev); | ||
646 | |||
647 | int (*suspend) (struct usb_device *udev, pm_message_t message); | ||
648 | int (*resume) (struct usb_device *udev); | ||
649 | struct usbdrv_wrap drvwrap; | ||
650 | }; | ||
651 | #define to_usb_device_driver(d) container_of(d, struct usb_device_driver, \ | ||
652 | drvwrap.driver) | ||
613 | 653 | ||
614 | extern struct bus_type usb_bus_type; | 654 | extern struct bus_type usb_bus_type; |
615 | 655 | ||
@@ -633,13 +673,17 @@ struct usb_class_driver { | |||
633 | * use these in module_init()/module_exit() | 673 | * use these in module_init()/module_exit() |
634 | * and don't forget MODULE_DEVICE_TABLE(usb, ...) | 674 | * and don't forget MODULE_DEVICE_TABLE(usb, ...) |
635 | */ | 675 | */ |
636 | int usb_register_driver(struct usb_driver *, struct module *); | 676 | extern int usb_register_driver(struct usb_driver *, struct module *); |
637 | static inline int usb_register(struct usb_driver *driver) | 677 | static inline int usb_register(struct usb_driver *driver) |
638 | { | 678 | { |
639 | return usb_register_driver(driver, THIS_MODULE); | 679 | return usb_register_driver(driver, THIS_MODULE); |
640 | } | 680 | } |
641 | extern void usb_deregister(struct usb_driver *); | 681 | extern void usb_deregister(struct usb_driver *); |
642 | 682 | ||
683 | extern int usb_register_device_driver(struct usb_device_driver *, | ||
684 | struct module *); | ||
685 | extern void usb_deregister_device_driver(struct usb_device_driver *); | ||
686 | |||
643 | extern int usb_register_dev(struct usb_interface *intf, | 687 | extern int usb_register_dev(struct usb_interface *intf, |
644 | struct usb_class_driver *class_driver); | 688 | struct usb_class_driver *class_driver); |
645 | extern void usb_deregister_dev(struct usb_interface *intf, | 689 | extern void usb_deregister_dev(struct usb_interface *intf, |