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 /drivers/usb/core/usb.c | |
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 'drivers/usb/core/usb.c')
-rw-r--r-- | drivers/usb/core/usb.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 0b8c67bcde6..6dfbc284369 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -123,7 +123,7 @@ static int __find_interface(struct device * dev, void * data) | |||
123 | struct usb_interface *intf; | 123 | struct usb_interface *intf; |
124 | 124 | ||
125 | /* can't look at usb devices, only interfaces */ | 125 | /* can't look at usb devices, only interfaces */ |
126 | if (dev->driver == &usb_generic_driver) | 126 | if (is_usb_device(dev)) |
127 | return 0; | 127 | return 0; |
128 | 128 | ||
129 | intf = to_usb_interface(dev); | 129 | intf = to_usb_interface(dev); |
@@ -149,7 +149,8 @@ struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) | |||
149 | 149 | ||
150 | argb.minor = minor; | 150 | argb.minor = minor; |
151 | argb.interface = NULL; | 151 | argb.interface = NULL; |
152 | driver_for_each_device(&drv->driver, NULL, &argb, __find_interface); | 152 | driver_for_each_device(&drv->drvwrap.driver, NULL, &argb, |
153 | __find_interface); | ||
153 | return argb.interface; | 154 | return argb.interface; |
154 | } | 155 | } |
155 | 156 | ||
@@ -204,11 +205,13 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1) | |||
204 | device_initialize(&dev->dev); | 205 | device_initialize(&dev->dev); |
205 | dev->dev.bus = &usb_bus_type; | 206 | dev->dev.bus = &usb_bus_type; |
206 | dev->dev.dma_mask = bus->controller->dma_mask; | 207 | dev->dev.dma_mask = bus->controller->dma_mask; |
207 | dev->dev.driver_data = &usb_generic_driver_data; | 208 | dev->dev.driver = &usb_generic_driver.drvwrap.driver; |
208 | dev->dev.driver = &usb_generic_driver; | ||
209 | dev->dev.release = usb_release_dev; | 209 | dev->dev.release = usb_release_dev; |
210 | dev->state = USB_STATE_ATTACHED; | 210 | dev->state = USB_STATE_ATTACHED; |
211 | 211 | ||
212 | /* This magic assignment distinguishes devices from interfaces */ | ||
213 | dev->dev.platform_data = &usb_generic_driver; | ||
214 | |||
212 | INIT_LIST_HEAD(&dev->ep0.urb_list); | 215 | INIT_LIST_HEAD(&dev->ep0.urb_list); |
213 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; | 216 | dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; |
214 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; | 217 | dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; |
@@ -838,7 +841,7 @@ static int __init usb_init(void) | |||
838 | retval = usb_hub_init(); | 841 | retval = usb_hub_init(); |
839 | if (retval) | 842 | if (retval) |
840 | goto hub_init_failed; | 843 | goto hub_init_failed; |
841 | retval = driver_register(&usb_generic_driver); | 844 | retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE); |
842 | if (!retval) | 845 | if (!retval) |
843 | goto out; | 846 | goto out; |
844 | 847 | ||
@@ -868,7 +871,7 @@ static void __exit usb_exit(void) | |||
868 | if (nousb) | 871 | if (nousb) |
869 | return; | 872 | return; |
870 | 873 | ||
871 | driver_unregister(&usb_generic_driver); | 874 | usb_deregister_device_driver(&usb_generic_driver); |
872 | usb_major_cleanup(); | 875 | usb_major_cleanup(); |
873 | usbfs_cleanup(); | 876 | usbfs_cleanup(); |
874 | usb_deregister(&usbfs_driver); | 877 | usb_deregister(&usbfs_driver); |