天天看點

usb3.0驅動linux,dwc3 linux usb3.0 driver架構

dwc3 linux usb3.0 driver架構:

usb3.0驅動linux,dwc3 linux usb3.0 driver架構

1. DRD driver

DRD驅動在usb/dwc3

1.1 dts

[email protected] {

compatible = "snps,dwc3";

reg = <0x0 0x44000000 0x0 0x100000>;

interrupts = <0 8 4>;

dr_mode = "otg";

extcon = ;

};

extcon_dwc3: extcon_dwc3 {

compatible = "linux,extcon-usb-gpio";

id-gpio = ;

};

dr_mode可以配置為otg、host或者peripheral。

1.2 drd driver

usb/dwc3/core.c:

static struct platform_driver dwc3_driver = {

.probe = dwc3_probe,

.remove = dwc3_remove,

.driver = {

.name = "dwc3",

.of_match_table = of_match_ptr(of_dwc3_match),

.acpi_match_table = ACPI_PTR(dwc3_acpi_match),

.pm = &dwc3_dev_pm_ops,

},

};

static const struct of_device_id of_dwc3_match[] = {

{

.compatible = "snps,dwc3"

},

{

.compatible = "synopsys,dwc3"

},

{ },

};

1)首先根據"snps,dwc3"進行dts和driver的比對,執行dwc3_probe()

2) 在dwc3中先調用 dwc3_get_dr_mode()取得usb mode(dr_mode),這可以是otg、host或者device

3)然後調用 dwc3_core_init()初始化usb PHY interface和usb PHY,usb PHY的初始化參照第4節。

4)最後調用 dwc3_core_init_mode()初始化usb mode:

如果dr_mode為device,則初始化gadget。

如果dr_mode為host,需要初始化xHCI驅動。在dwc3_host_init函數的最後調用platform_device_add(xhci)添加platform device(xhci-hcd),用于比對xHCI driver(xHCI driver為platform driver),參照第3節。

如果dr_mode為otg,需要根據extcon來標明一個角色(host或者device)進行初始化,是以還需要extcon驅動的支援,參照第2節。

2. extcon driver

extcon驅動在drivers/extcon中,利用gpio或其他信号腳提供一種通知機制,控制usb DRD 模式的切換(作為host或者device)。

2.1 driver

extcon/extcon-usb-gpio.c:

tatic const struct of_device_id usb_extcon_dt_match[] = {

{ .compatible = "linux,extcon-usb-gpio", },

{ }

};

static struct platform_driver usb_extcon_driver = {

.probe = usb_extcon_probe,

.remove = usb_extcon_remove,

.driver = {

.name = "extcon-usb-gpio",

.pm = &usb_extcon_pm_ops,

.of_match_table = usb_extcon_dt_match,

},

.id_table = usb_extcon_platform_ids,

};

1)首先根據"linux,extcon-usb-gpio"進行dts和driver的比對,執行usb_extcon_probe()

2)在 usb_extcon_probe()中,先調用devm_extcon_dev_register()注冊裝置

3)然後為gpio注冊一個中斷處理程式,在該中斷進行中處理gpio中斷,并将資訊通過通知鍊機制發送給DRD driver

4)DRD driver收到消息後,切換usb的角色,重新初始化usb驅動,作為device或者host

3. xHCI driver

xHCI驅動在usb/host中,主要初始化xHCI。xHCI作為usb host部分的驅動。

3.1

usb/host/xhci-plat.c:

static struct platform_driver usb_xhci_driver = {

.probe = xhci_plat_probe,

.remove = xhci_plat_remove,

.driver = {

.name = "xhci-hcd",

.pm = &xhci_plat_pm_ops,

.of_match_table = of_match_ptr(usb_xhci_of_match),

.acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),

},

};

static int __init xhci_plat_init(void)

{

xhci_init_driver(&xhci_plat_hc_driver, &xhci_plat_overrides);

return platform_driver_register(&usb_xhci_driver);

}

1)在xhci_plat_init中調用platform_driver_register(&usb_xhci_driver)注冊platform driver("xhci-hcd")

2)首先根據name="xhci-hcd"比對到platform device後,執行xhci_plat_probe

3)在xhci_plat_probe中,進行xHCI的初始化,最後添加到usb core中

4. usb PHY driver

dwc3的PHY初始化主要在 dwc3_core_init中完成,如果确實需要初始化PHY,還需要相關PHY驅動的配合(提供具體的操作函數)。

1)synopsys采用femtoPHY,femtoPHY通常情況下無需初始化(設定)其寄存器,隻有調試或使用特殊功能時才需要通路。也就是說,對于femtoPHY,我們可以不寫驅動來進行初始化。

2)雖然不需要初始化PHY,但我們依然需要配置usb controller的PHY interface(PIPE、ULPI、UTMI),這在 dwc3_phy_setup中實作。

3)對于某些類型的PHY,必須要進行初始化,這就需要配置dts設定usb-phy或者phy-names。PHY初始化主要由 dwc3_core_get_phy和 dwc3_core_soft_reset等函數調用。裡面用到的函數指針需要在相關PHY驅動中進行實作并注冊。