zoukankan      html  css  js  c++  java
  • dwc3 linux usb3.0 driver架构

    转:dwc3 linux usb3.0 driver架构_ARM-Linux-CSDN博客_linux usb3.0

    dwc3 linux usb3.0 driver架构:

     

    1. DRD driver

    DRD驱动在usb/dwc3

    1.1 dts

    dwc3@44000000 {
    /* Compatible ID used by the Linux driver for this kind of device */
    compatible = "snps,dwc3";
    /* Register bank location: AddressMSB, AddressLSB, SizeMSB, SizeLSB */
    reg = <0x0 0x44000000 0x0 0x100000>;
    interrupts = <0 8 4>;
    dr_mode = "otg";
    extcon = <&extcon_dwc3>;
    };


    extcon_dwc3: extcon_dwc3 {
    compatible = "linux,extcon-usb-gpio";
    id-gpio = <&porta 1 0>;
    };
    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", },
    { /* sentinel */ }
    };

    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驱动中进行实现并注册。
    ————————————————
    版权声明:本文为CSDN博主「hello_courage」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u012247418/article/details/104588657/

  • 相关阅读:
    防火墙实践
    提高工作效率的小技巧
    网络系统参数配置
    linux 文件截取
    python (1) 还不是大全的小问题
    iptables 命令记录
    网络常用端口
    HTTP时间指标
    错误集锦
    access数据库调用
  • 原文地址:https://www.cnblogs.com/newjiang/p/15675746.html
Copyright © 2011-2022 走看看