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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
36e56a3458
commit
8bb54ab573
@@ -123,7 +123,7 @@ static int __find_interface(struct device * dev, void * data)
|
||||
struct usb_interface *intf;
|
||||
|
||||
/* can't look at usb devices, only interfaces */
|
||||
if (dev->driver == &usb_generic_driver)
|
||||
if (is_usb_device(dev))
|
||||
return 0;
|
||||
|
||||
intf = to_usb_interface(dev);
|
||||
@@ -149,7 +149,8 @@ struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
|
||||
|
||||
argb.minor = minor;
|
||||
argb.interface = NULL;
|
||||
driver_for_each_device(&drv->driver, NULL, &argb, __find_interface);
|
||||
driver_for_each_device(&drv->drvwrap.driver, NULL, &argb,
|
||||
__find_interface);
|
||||
return argb.interface;
|
||||
}
|
||||
|
||||
@@ -204,11 +205,13 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
|
||||
device_initialize(&dev->dev);
|
||||
dev->dev.bus = &usb_bus_type;
|
||||
dev->dev.dma_mask = bus->controller->dma_mask;
|
||||
dev->dev.driver_data = &usb_generic_driver_data;
|
||||
dev->dev.driver = &usb_generic_driver;
|
||||
dev->dev.driver = &usb_generic_driver.drvwrap.driver;
|
||||
dev->dev.release = usb_release_dev;
|
||||
dev->state = USB_STATE_ATTACHED;
|
||||
|
||||
/* This magic assignment distinguishes devices from interfaces */
|
||||
dev->dev.platform_data = &usb_generic_driver;
|
||||
|
||||
INIT_LIST_HEAD(&dev->ep0.urb_list);
|
||||
dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
|
||||
dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT;
|
||||
@@ -838,7 +841,7 @@ static int __init usb_init(void)
|
||||
retval = usb_hub_init();
|
||||
if (retval)
|
||||
goto hub_init_failed;
|
||||
retval = driver_register(&usb_generic_driver);
|
||||
retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);
|
||||
if (!retval)
|
||||
goto out;
|
||||
|
||||
@@ -868,7 +871,7 @@ static void __exit usb_exit(void)
|
||||
if (nousb)
|
||||
return;
|
||||
|
||||
driver_unregister(&usb_generic_driver);
|
||||
usb_deregister_device_driver(&usb_generic_driver);
|
||||
usb_major_cleanup();
|
||||
usbfs_cleanup();
|
||||
usb_deregister(&usbfs_driver);
|
||||
|
Reference in New Issue
Block a user