Objective: To study USB in depth and take notes here. Welcome to the discussion.
[Linux 3.2] [Driver/USB/CORE/hub. C]
Function: usb_hub_init
int usb_hub_init(void){if (usb_register(&hub_driver) < 0) {printk(KERN_ERR "%s: can't register hub driver\n",usbcore_name);return -1;}khubd_task = kthread_run(hub_thread, NULL, "khubd");if (!IS_ERR(khubd_task))return 0;/* Fall through if kernel_thread failed */usb_deregister(&hub_driver);printk(KERN_ERR "%s: can't start khubd\n", usbcore_name);return -1;}
Usb_hub_init mainly implements two functions: one is to register the hub driver, and the other is to start a kernel thread named khubd (this thread can be seen through PS or called a process. The kernel does not distinguish between processes and threads ).
The registration of the hub driver is the same as that of the usbfs driver. After registration, you can see the USB directory under/sys/bus/USB/drivers. Under the USB directory, create the following property file:
Bind module new_id uevent unbind
The following describes how to create a khubd thread:
Kthread_run (hub_thread, null, "khubd") --> hub_thread --> set_freezable () --> hub_events () --> wait_event_freezable (khubd_wait ,! List_empty (& hub_event_list) | kthread_should_stop (); sleep now, waiting for khubd_wait to wake up the process.
Hub_events is mainly used to process port status change and hub status change.
Hub_events will be further analyzed during USB enumeration.