Linux USB subsystem — initialize

來源:互聯網
上載者:User

目的:對USB作深入學習,在此留下筆記。歡迎討論。

[Linux 3.2] [driver/usb/core/usb.c]

USB作為Linux系統的一個子系統,其初始化函數被subsys_initcall修飾。

其初始化代碼如下:

/* * Init */static int __init usb_init(void){int retval;if (nousb) {pr_info("%s: USB support disabled\n", usbcore_name);return 0;}retval = usb_debugfs_init();if (retval)goto out;retval = bus_register(&usb_bus_type);if (retval)goto bus_register_failed;retval = bus_register_notifier(&usb_bus_type, &usb_bus_nb);if (retval)goto bus_notifier_failed;retval = usb_major_init();if (retval)goto major_init_failed;retval = usb_register(&usbfs_driver);if (retval)goto driver_register_failed;retval = usb_devio_init();if (retval)goto usb_devio_init_failed;retval = usbfs_init();if (retval)goto fs_init_failed;retval = usb_hub_init();if (retval)goto hub_init_failed;retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);if (!retval)goto out;usb_hub_cleanup();hub_init_failed:usbfs_cleanup();fs_init_failed:usb_devio_cleanup();usb_devio_init_failed:usb_deregister(&usbfs_driver);driver_register_failed:usb_major_cleanup();major_init_failed:bus_unregister_notifier(&usb_bus_type, &usb_bus_nb);bus_notifier_failed:bus_unregister(&usb_bus_type);bus_register_failed:usb_debugfs_cleanup();out:return retval;}

如果在boot參數(對u-boot是在bootargs裡面加:nousb)裡面有nousb,輸出: usbcore: USB support disabled,然後退出。

如果在boot參數()裡面沒有nousb,則進行USB的初始化工作。

初始化的主要內容如下:

1. usb debug 檔案系統初始化: usb_debugfs_init()。

2. 註冊USB匯流排 :bus_register(&usb_bus_type)。

3. 給USB匯流排註冊一個通知鏈 : bus_register_notifier(&usb_bus_type, &usb_bus_nb)。

4. usb_major_init

5. 註冊usbfs驅動: usb_register(&usbfs_driver)

     usbfs_driver在<drivers/usb/core/devio.c>中定義

6. usb_devio_init

7. USB檔案系統註冊:usbfs_init()。

    註:如果沒有CONFIG_USB_DEVICEFS,此函數為inline空函數。如果定義CONFIG_USB_DEVICEFS,則在<drivers/usb/core/inode.c>實現。

8. 對USB HUB進行初始化:usb_hub_init()

    usb_hub_init()在<driver/usb/core/hub.c>中實現。

9. 註冊一個generic的USB驅動:usb_register_device_driver(&usb_generic_driver, THIS_MODULE);

下面文章會依次對每個部分進行詳細描述。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.