目的:對USB作深入學習,在此留下筆記。歡迎討論。
[Linux 3.2] [driver/usb/core/driver.c]
函數:usb_register_device_driver
- /**
- * usb_register_device_driver - register a USB device (not interface) driver
- * @new_udriver: USB operations for the device driver
- * @owner: module owner of this driver.
- *
- * Registers a USB device driver with the USB core. The list of
- * unattached devices will be rescanned whenever a new driver is
- * added, allowing the new driver to attach to any recognized devices.
- * Returns a negative error code on failure and 0 on success.
- */
- int usb_register_device_driver(struct usb_device_driver *new_udriver,
- struct module *owner)
- {
- int retval = 0;
-
- if (usb_disabled())
- return -ENODEV;
-
- new_udriver->drvwrap.for_devices = 1;
- new_udriver->drvwrap.driver.name = (char *) new_udriver->name;
- new_udriver->drvwrap.driver.bus = &usb_bus_type;
- new_udriver->drvwrap.driver.probe = usb_probe_device;
- new_udriver->drvwrap.driver.remove = usb_unbind_device;
- new_udriver->drvwrap.driver.owner = owner;
-
- retval = driver_register(&new_udriver->drvwrap.driver);
-
- if (!retval) {
- pr_info("%s: registered new device driver %s\n",
- usbcore_name, new_udriver->name);
- usbfs_update_special();
- } else {
- printk(KERN_ERR "%s: error %d registering device "
- " driver %s\n",
- usbcore_name, retval, new_udriver->name);
- }
-
- return retval;
- }
- EXPORT_SYMBOL_GPL(usb_register_device_driver);
此過程是注冊一個usb的通用程驅動。驅動注冊的過程與usbfs驅動注冊類似。其結果是:在/sys/bus/usb/drivers/下面創建usb目錄。在usb目錄下面創建如下屬性文件。
bind uevent unbind
至此,整個usb core的初始化過程完成。
後面將進入到USB host controller的初始化。