Linux USB subsystem-USB hub initialize

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.