usb: fix DWC3/gadget issues and enable USB on Toradex i.MX95 boards
Subsystems (4)
cover usb: fix DWC3/gadget issues and enable USB on Toradex i.MX95 boards
This series fixes a few USB issues that show up on the Toradex i.MX95 based modules and finally enables USB support for them.
The i.MX95 has two USB controllers: a host-only DWC3 controller and a ChipIdea OTG controller. Getting both of them to work together in U-Boot requires a couple of fixes:
- Combining DWC3 (host only) with CI_UDC as the gadget driver, while DM_USB_GADGET is disabled, currently fails to link because DWC3 core provides dm_usb_gadget_handle_interrupts() even when the DWC3 gadget driver is not built (patch 1).
- The DWC3 reference clock lookup added by commit c6583354b7c1 ("usb:
dwc3: Look up reference clock DT phandle in both controller DT nodes") resolves an index found in the child node's clock-names against the clk_bulk of the parent glue node. On the Verdin iMX95 the two lists have a different order, so the wrong clock is picked, which shows up as intermittent enumeration failures behind a USB hub (patch 2).
- ehci_gadget picks the first USB device it finds, which on the i.MX95 is the host-only DWC3 controller instead of the ChipIdea OTG controller, so "ums" never enters device mode. Skip host-only controllers when looking for the gadget controller (patch 3).
The remaining patches enable CI_UDC on the Verdin iMX95 and turn on the DWC3 host controller support for the Verdin iMX95 and the Toradex SMARC iMX95.
Testing
-------
USB was tested on a Verdin iMX95, a Toradex SMARC iMX95 and an Apalis iMX6 (as a regression test for the ehci_gadget change) with:
usb start
and with:
ums 0 mmc 0
All three boards were enumerating a USB stick and appeared as USB devices on a PC connected to the USB device port.
Stefan Eichenberger (6):
usb: dwc3: core: only provide legacy gadget IRQ handler when
USB_DWC3_GADGET
usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
usb: skip host-only devices when picking the ehci gadget controller
configs: verdin-imx95: enable CI_UDC usb gadget driver
toradex: verdin-imx95: enable DWC3 USB controller support
toradex: smarc-imx95: enable DWC3 USB controller support
.../dts/imx95-toradex-smarc-dev-u-boot.dtsi | 8 ------- .../arm/dts/imx95-verdin-wifi-dev-u-boot.dtsi | 8 ------- configs/toradex-smarc-imx95_defconfig | 4 ++++ configs/verdin-imx95_defconfig | 3 ++- drivers/usb/dwc3/core.c | 2 +- drivers/usb/dwc3/dwc3-generic.c | 24 +++++++++++++++++-- drivers/usb/host/usb-uclass.c | 23 ++++++++++++++++-- 7 files changed, 50 insertions(+), 22 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/6 usb: dwc3: core: only provide legacy gadget IRQ handler when USB_DWC3_GADGET
From: Stefan Eichenberger <[email protected]>
Building a board with USB_DWC3=y (DWC3 used purely as an XHCI host controller), USB_DWC3_GADGET unset, and DM_USB_GADGET disabled (e.g. to use CONFIG_CI_UDC for a separate ChipIdea gadget/OTG controller) fails to link:
drivers/usb/gadget/ci_udc.o: in function `dm_usb_gadget_handle_interrupts':drivers/usb/gadget/ci_udc.c:983: multiple definition of dm_usb_gadget_handle_interrupts'; drivers/usb/dwc3/core.o:drivers/usb/dwc3/core.c:1034: first defined here drivers/usb/dwc3/core.o: in function dm_usb_gadget_handle_interrupts':drivers/usb/dwc3/core.c:1044: undefined reference to `dwc3_gadget_uboot_handle_interrupt'
Add "&& CONFIG_IS_ENABLED(USB_DWC3_GADGET)" to the guard so this code is only compiled when the DWC3 gadget driver it depends on is actually present, matching the Makefile dependency. Boards that combine DWC3 (host) with a separate legacy gadget driver like CI_UDC, with DM_USB_GADGET disabled, now link correctly. Boards that already use DWC3 in gadget mode without DM_USB_GADGET are unaffected since USB_DWC3_GADGET is set for them.
--- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/core.c +1 -1
@@ -1016,7 +1016,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("DesignWare USB3 DRD Controller Driver" ); -#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) +#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) &&CONFIG_IS_ENABLED (USB_DWC3_GADGET )__weak int dwc3_uboot_interrupt_status (struct udevice *dev) {return 1 ;
Signature · 1 line
2.55.0
PATCH 2/6 usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
In reply to Stefan EichenbergerFrom: Stefan Eichenberger <[email protected]>
On Verdin iMX95, with a USB hub permanently attached to the DWC3 host port the hub itself enumerates fine but a USB stick plugged into it fails intermittently:
Verdin iMX95 # usb start
starting USB...
USB XHCI 1.10
Device not responding to set address.
USB device not accepting new address (error=80000000)
Bus usb@4c100000: 2 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Verdin iMX95 # usb reset
resetting USB...
USB XHCI 1.10
WARN endpoint is halted
WARN endpoint is halted
unable to get device descriptor (error=-22)
Commit c6583354b7c1 ("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes") added a fallback that searches the DWC3 child node's "clock-names" for "ref"/"ref_clk" when it isn't found on the parent glue node, but always resolves the found index against glue->clks, a clk_bulk populated only from the parent glue node's own clock-names list. This is wrong since the child node's clock-names list is not guaranteed to be in the same order as the parent's, and indeed on Verdin iMX95 the child node has a different order than the parent node.
Fix it by resolving the index against the child node's clk and ensure to enable the clock before using it.
--- drivers/usb/dwc3/dwc3-generic.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +22 -2
@@ -31,6 +31,7 @@ struct dwc3_generic_priv {struct dwc3 dwc3;struct phy_bulk phys;struct gpio_desc *ulpi_reset; +struct clk ref_clk; };struct dwc3_generic_host_priv {
@@ -76,9 +77,28 @@ static int dwc3_generic_probe(struct udevice *dev, index =ofnode_stringlist_search (node,"clock-names" ,"ref" );if (index <0 ) index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); - } -if (index >=0 ) +/* +* glue->clks was populated from the parent glue node's own +* clock-names list, which can differ in length/order from +* this child node's list (e.g. i.MX95: glue has "hsio", +* "suspend", the dwc3 child has "bus_early", "ref", +* "suspend"). Reusing this index against glue->clks would +* silently resolve to the wrong clock, so fetch it directly +* from this node instead. +*/ +if (index >=0 ) { +if (!clk_get_by_index (dev, index, &priv->ref_clk)) { +clk_enable (&priv->ref_clk); + dwc3->ref_clk = &priv->ref_clk; + }else { +debug ("%s: failed to get ref_clk from DT\n" , dev->name); + } + }else { +debug ("%s: no ref_clk found in DT\n" , dev->name); + } + }else { dwc3->ref_clk = &glue->clks.clks[index]; + }#endif /*
Signature · 1 line
2.55.0
PATCH 3/6 usb: skip host-only devices when picking the ehci gadget controller
In reply to Stefan EichenbergerFrom: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has two USB controllers, a DWC3 host-only controller and a ChipIdea OTG controller. The latter is the one that can be used for USB gadget functionality. However, U-Boot incorrectly selects the host-only controller when attempting to set up a USB gadget, leading to failures in gadget mode.
Iterate over usb devices and skipping any that are host-only when selecting the controller for gadget mode. This ensures that a device only or otg controller is used for USB gadget functionality.
Verified on Verdin iMX95 hardware: "ums 0 mmc 0" now correctly flips the ChipIdea OTG controller into device mode and enumerates on the host PC.
--- drivers/usb/host/usb-uclass.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/usb/host/usb-uclass.c +21 -2
@@ -18,6 +18,7 @@#include <dm/device-internal.h> #include <dm/lists.h> #include <dm/uclass-internal.h> +#include <linux/usb/otg.h> #include <time.h> static bool asynch_allowed;
@@ -484,10 +485,23 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp)struct udevice *dev;int ret; -/* Find the old device and remove it */ +/* +* Find the first UCLASS_USB device that isn't host-only. SoCs can +* have more than one UCLASS_USB controller (e.g. i.MX95, where a +* host-only DWC3 port and the ChipIdea OTG port both register under +* UCLASS_USB); taking whichever device happens to be first could +* pick the host-only controller instead of the OTG-capable one this +* is actually meant to flip into device mode. +*/ ret =uclass_find_first_device (UCLASS_USB , &dev);if (ret)return ret; +while (dev &&usb_get_dr_mode (dev_ofnode (dev)) ==USB_DR_MODE_HOST ) +uclass_find_next_device (&dev); +if (!dev) +return -ENODEV ; + +/* Remove the old device */ ret =device_remove (dev,DM_REMOVE_NORMAL );if (ret)return ret;
@@ -507,10 +521,15 @@ int usb_remove_ehci_gadget(struct ehci_ctrl **ctlrp)struct udevice *dev;int ret; -/* Find the old device and remove it */ +/* Find the same non-host-only device usb_setup_ehci_gadget() used */ ret =uclass_find_first_device (UCLASS_USB , &dev);if (ret)return ret; +while (dev &&usb_get_dr_mode (dev_ofnode (dev)) ==USB_DR_MODE_HOST ) +uclass_find_next_device (&dev); +if (!dev) +return -ENODEV ; + ret =device_remove (dev,DM_REMOVE_NORMAL );if (ret)return ret;
Signature · 1 line
2.55.0
PATCH 5/6 toradex: verdin-imx95: enable DWC3 USB controller support
In reply to Stefan EichenbergerFrom: Stefan Eichenberger <[email protected]>
Enable the DWC3 USB host controller on the Verdin iMX95. Enable the DWC3 driver support by enabling the wrapper driver CONFIG_USB_DWC3_GENERIC and ensure the device tree nodes are kept enabled for U-Boot.
--- arch/arm/dts/imx95-verdin-wifi-dev-u-boot.dtsi | 8 -------- configs/verdin-imx95_defconfig | 1 + 2 files changed, 1 insertion(+), 8 deletions(-)
arch/arm/dts/imx95-verdin-wifi-dev-u-boot.dtsi +0 -8
@@ -90,14 +90,6 @@ /delete-property/power-domains; }; -&usb3 { - status = "disabled"; -}; - -&usb3_dwc3 { - status = "disabled"; -}; - &usb_recov_ctrl { bootph-pre-ram; };
configs/verdin-imx95_defconfig +1 -0
@@ -172,6 +172,7 @@ CONFIG_USB_XHCI_DWC3=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_DWC3=y # CONFIG_USB_DWC3_GADGET is not set +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Toradex"
Signature · 1 line
2.55.0
PATCH 4/6 configs: verdin-imx95: enable CI_UDC usb gadget driver
In reply to Stefan EichenbergerFrom: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has a ChipIdea USB device controller. This conflicts with CONFIG_DM_USB_GADGET. For the Verdin iMX95 we want to have CONFIG_CI_UDC enabled and CONFIG_DM_USB_GADGET disabled to make sure the ChipIdea USB device controller is used.
--- configs/verdin-imx95_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configs/verdin-imx95_defconfig +1 -1
@@ -167,7 +167,6 @@ CONFIG_FSL_LPUART=y CONFIG_SPI=y CONFIG_DM_THERMAL=y CONFIG_USB=y -CONFIG_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y CONFIG_USB_EHCI_HCD=y
@@ -179,6 +178,7 @@ CONFIG_USB_GADGET_MANUFACTURER="Toradex" CONFIG_USB_GADGET_VENDOR_NUM=0x1b67 CONFIG_USB_GADGET_PRODUCT_NUM=0x4000 CONFIG_USB_GADGET_OS_DESCRIPTORS=y +CONFIG_CI_UDC=y CONFIG_SDP_LOADADDR=0x90400000 CONFIG_ULP_WATCHDOG=y CONFIG_WDT=y
Signature · 1 line
2.55.0
PATCH 6/6 toradex: smarc-imx95: enable DWC3 USB controller support
In reply to Stefan EichenbergerFrom: Stefan Eichenberger <[email protected]>
The iMX95 USB controller is DWC3-based, but the DWC3 core/glue driver was never enabled for this board, therefore enable CONFIG_USB_DWC3, CONFIG_USB_XHCI_DWC3 and CONFIG_USB_DWC3_GENERIC to enable support for USB in U-Boot for the Toradex SMARC iMX95.
Remove the dwc3 nodes from the U-Boot device tree to keep them enabled now that the driver is there.
--- arch/arm/dts/imx95-toradex-smarc-dev-u-boot.dtsi | 8 -------- configs/toradex-smarc-imx95_defconfig | 4 ++++ 2 files changed, 4 insertions(+), 8 deletions(-)
arch/arm/dts/imx95-toradex-smarc-dev-u-boot.dtsi +0 -8
@@ -88,14 +88,6 @@ /delete-property/power-domains; }; -&usb3 { - status = "disabled"; -}; - -&usb3_dwc3 { - status = "disabled"; -}; - &usdhc1 { bootph-pre-ram; };
configs/toradex-smarc-imx95_defconfig +4 -0
@@ -166,7 +166,11 @@ CONFIG_SPI=y CONFIG_DM_THERMAL=y CONFIG_USB=y CONFIG_USB_XHCI_HCD=y +CONFIG_USB_XHCI_DWC3=y CONFIG_USB_EHCI_HCD=y +CONFIG_USB_DWC3=y +# CONFIG_USB_DWC3_GADGET is not set +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_HOST_ETHER=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Toradex"
Signature · 1 line
2.55.0
Re: [PATCH v1 1/6] usb: dwc3: core: only provide legacy gadget IRQ handler when USB_DWC3_GADGET
In reply to Stefan EichenbergerQuoted 32 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
Building a board with USB_DWC3=y (DWC3 used purely as an XHCI host controller),
USB_DWC3_GADGETunset, andDM_USB_GADGETdisabled (e.g. to useCONFIG_CI_UDCfor a separate ChipIdea gadget/OTG controller) fails to link:
drivers/usb/gadget/ci_udc.o: in function `dm_usb_gadget_handle_interrupts':drivers/usb/gadget/ci_udc.c:983: multiple definition ofdm_usb_gadget_handle_interrupts'; drivers/usb/dwc3/core.o:drivers/usb/dwc3/core.c:1034: first defined here drivers/usb/dwc3/core.o: in functiondm_usb_gadget_handle_interrupts':drivers/usb/dwc3/core.c:1044: undefined reference to `dwc3_gadget_uboot_handle_interrupt'Add "&&
CONFIG_IS_ENABLED(USB_DWC3_GADGET)" to the guard so this code is only compiled when the DWC3 gadget driver it depends on is actually present, matching theMakefiledependency. Boards that combine DWC3 (host) with a separate legacy gadget driver likeCI_UDC, withDM_USB_GADGETdisabled, now link correctly. Boards that already use DWC3 in gadget mode withoutDM_USB_GADGETare unaffected sinceUSB_DWC3_GADGETis set for them.Fixes 4d1589808970 ("usb: udc: dwc3: Fold board dm_usb_gadget_handle_interrupts() into DWC3 gadget")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/dwc3/core.c +0
-0
drivers/usb/dwc3/core.c MODULE_AUTHOR("Felipe Balbi <[email protected]>"); · line 1020
Quoted 6 lines
drivers/usb/dwc3/core.c +1
-1@@ -1016,7 +1016,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("DesignWare USB3 DRD Controller Driver" ); -#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) +#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) &&CONFIG_IS_ENABLED (USB_DWC3_GADGET )__weak int dwc3_uboot_interrupt_status (struct udevice *dev)
Simply enable DM_USB_GADGET , then the drivers/usb/gadget/udc/udc-uclass.c dm_usb_gadget_handle_interrupts() is used which correctly invokes the per-controller IRQ handler. DWC3_GADGET should likely depend on DM_USB_GADGET.
Re: [PATCH v1 2/6] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
In reply to Stefan EichenbergerQuoted 58 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
On Verdin iMX95, with a USB hub permanently attached to the DWC3 host port the hub itself enumerates fine but a USB stick plugged into it fails intermittently:
Verdin iMX95 # usb start
starting USB...
USB XHCI 1.10
Device not responding to set address.USB device not accepting new address (error=80000000)
Bus usb@4c100000: 2 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Verdin iMX95 # usb reset
resetting USB...
USB XHCI 1.10
WARN endpoint is halted
WARN endpoint is halted
unable to get device descriptor (error=-22)Commit
c6583354b7c1("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes") added a fallback that searches the DWC3 child node's "clock-names" for "ref"/"ref_clk" when it isn't found on the parent glue node, but always resolves the found index againstglue->clks, aclk_bulkpopulated only from the parent glue node's own clock-names list. This is wrong since the child node's clock-names list is not guaranteed to be in the same order as the parent's, and indeed on Verdin iMX95 the child node has a different order than the parent node.Fix it by resolving the index against the child node's clk and ensure to enable the clock before using it.
Fixes c6583354b7c1 ("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/dwc3-generic.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-generic.c +2
-2@@ -31,6 +31,7 @@ struct dwc3_generic_priv {struct dwc3 dwc3;struct phy_bulk phys;struct gpio_desc *ulpi_reset; +struct clk ref_clk; };struct dwc3_generic_host_priv {@@ -76,9 +77,28 @@ static int dwc3_generic_probe(struct udevice *dev, index =ofnode_stringlist_search (node,"clock-names" ,"ref" );if (index <0 ) index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); - } -if (index >=0 ) +/*
drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 90
Quoted 10 lines
drivers/usb/dwc3/dwc3-generic.c +10
-0+* glue->clks was populated from the parent glue node's own +* clock-names list, which can differ in length/order from +* this child node's list (e.g. i.MX95: glue has "hsio", +* "suspend", the dwc3 child has "bus_early", "ref", +* "suspend"). Reusing this index against glue->clks would +* silently resolve to the wrong clock, so fetch it directly +* from this node instead. +*/ +if (index >=0 ) { +if (!clk_get_by_index (dev, index, &priv->ref_clk)) {
Would it be possible to call clk_get_by_name(dev, ...) and clk_get_by_name(dev->parent, ...) instead, until one of them succeeds ? That could make the code simpler.
drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 94
Quoted 4 lines
drivers/usb/dwc3/dwc3-generic.c +4
-0+clk_enable (&priv->ref_clk); + dwc3->ref_clk = &priv->ref_clk; + }else { +debug ("%s: failed to get ref_clk from DT\n" , dev->name);
dev_dbg()
drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 97
Quoted 3 lines
drivers/usb/dwc3/dwc3-generic.c +3
-0+ } + }else { +debug ("%s: no ref_clk found in DT\n" , dev->name);
dev_dbg()
Quoted 7 lines
drivers/usb/dwc3/dwc3-generic.c +3
-0+ } + }else { dwc3->ref_clk = &glue->clks.clks[index]; + }#endif /*
Re: [PATCH v1 3/6] usb: skip host-only devices when picking the ehci gadget controller
In reply to Stefan EichenbergerQuoted 5 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has two USB controllers, a DWC3 host-only controller and a ChipIdea OTG controller. The latter is the one that can be used for USB gadget functionality.
Both DWC3 and CI HDRC controllers are dual-role on MX95, are they not ?
[...]
Re: [PATCH v1 1/6] usb: dwc3: core: only provide legacy gadget IRQ handler when USB_DWC3_GADGET
In reply to Marek VasutQuoted 28 lines · Marek Vasut
Quoted 27 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
Building a board with USB_DWC3=y (DWC3 used purely as an XHCI host controller),
USB_DWC3_GADGETunset, andDM_USB_GADGETdisabled (e.g. to useCONFIG_CI_UDCfor a separate ChipIdea gadget/OTG controller) fails to link:
drivers/usb/gadget/ci_udc.o: in function `dm_usb_gadget_handle_interrupts':drivers/usb/gadget/ci_udc.c:983: multiple definition ofdm_usb_gadget_handle_interrupts'; drivers/usb/dwc3/core.o:drivers/usb/dwc3/core.c:1034: first defined here drivers/usb/dwc3/core.o: in functiondm_usb_gadget_handle_interrupts':drivers/usb/dwc3/core.c:1044: undefined reference to `dwc3_gadget_uboot_handle_interrupt'Add "&&
CONFIG_IS_ENABLED(USB_DWC3_GADGET)" to the guard so this code is only compiled when the DWC3 gadget driver it depends on is actually present, matching theMakefiledependency. Boards that combine DWC3 (host) with a separate legacy gadget driver likeCI_UDC, withDM_USB_GADGETdisabled, now link correctly. Boards that already use DWC3 in gadget mode withoutDM_USB_GADGETare unaffected sinceUSB_DWC3_GADGETis set for them.Fixes 4d1589808970 ("usb: udc: dwc3: Fold board dm_usb_gadget_handle_interrupts() into DWC3 gadget")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
drivers/usb/dwc3/core.c MODULE_AUTHOR("Felipe Balbi <[email protected]>"); · line 1019
Quoted 10 lines
drivers/usb/dwc3/core.c +1
-1@@ -1016,7 +1016,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("DesignWare USB3 DRD Controller Driver" ); -#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) +#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) &&CONFIG_IS_ENABLED (USB_DWC3_GADGET )__weak int dwc3_uboot_interrupt_status (struct udevice *dev)Simply enable
DM_USB_GADGET, then thedrivers/usb/gadget/udc/udc-uclass.cdm_usb_gadget_handle_interrupts()is used which correctly invokes the per-controller IRQ handler.DWC3_GADGETshould likely depend onDM_USB_GADGET.
Unfortunately, CI_UDC is not a DM driver yet and it depends on !DM_USB_GADGET that's why I can't enable DM_USB_GADGET in that specific case. I think NXP is working on changing that driver to DM (at least they did that in their BSP). So my hope was to have this as intermediate solution. Also in our case we use the DWC3 controller in host mode only, so we don't need DWC3_GADGET at all.
Regards,
Stefan
Re: [PATCH v1 3/6] usb: skip host-only devices when picking the ehci gadget controller
In reply to Marek VasutQuoted 8 lines · Marek Vasut
Quoted 5 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has two USB controllers, a DWC3 host-only controller and a ChipIdea OTG controller. The latter is the one that can be used for USB gadget functionality.
Both DWC3 and CI HDRC controllers are dual-role on MX95, are they not ?
That's correct we only use the DWC3 controller in host mode. I will update the commit message in the next version to make that clear.
Regards,
Stefan
Re: [PATCH v1 2/6] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
In reply to Marek VasutQuoted 64 lines · Marek Vasut
Quoted 63 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
On Verdin iMX95, with a USB hub permanently attached to the DWC3 host port the hub itself enumerates fine but a USB stick plugged into it fails intermittently:
Verdin iMX95 # usb start
starting USB...
USB XHCI 1.10
Device not responding to set address.USB device not accepting new address (error=80000000)
Bus usb@4c100000: 2 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Verdin iMX95 # usb reset
resetting USB...
USB XHCI 1.10
WARN endpoint is halted
WARN endpoint is halted
unable to get device descriptor (error=-22)Commit
c6583354b7c1("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes") added a fallback that searches the DWC3 child node's "clock-names" for "ref"/"ref_clk" when it isn't found on the parent glue node, but always resolves the found index againstglue->clks, aclk_bulkpopulated only from the parent glue node's own clock-names list. This is wrong since the child node's clock-names list is not guaranteed to be in the same order as the parent's, and indeed on Verdin iMX95 the child node has a different order than the parent node.Fix it by resolving the index against the child node's clk and ensure to enable the clock before using it.
Fixes c6583354b7c1 ("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/dwc3-generic.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-generic.c +8
-2@@ -31,6 +31,7 @@ struct dwc3_generic_priv {struct dwc3 dwc3;struct phy_bulk phys;struct gpio_desc *ulpi_reset; +struct clk ref_clk; };struct dwc3_generic_host_priv {@@ -76,9 +77,28 @@ static int dwc3_generic_probe(struct udevice *dev, index =ofnode_stringlist_search (node,"clock-names" ,"ref" );if (index <0 ) index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); - } -if (index >=0 ) +/* +* glue->clks was populated from the parent glue node's own +* clock-names list, which can differ in length/order from +* this child node's list (e.g. i.MX95: glue has "hsio", +* "suspend", the dwc3 child has "bus_early", "ref", +* "suspend"). Reusing this index against glue->clks would +* silently resolve to the wrong clock, so fetch it directly
Quoted 9 lines
drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 90
Quoted 4 lines
drivers/usb/dwc3/dwc3-generic.c +4
-0+* from this node instead. +*/ +if (index >=0 ) { +if (!clk_get_by_index (dev, index, &priv->ref_clk)) {Would it be possible to call
clk_get_by_name(dev, ...)andclk_get_by_name(dev->parent, ...)instead, until one of them succeeds ? That could make the code simpler.
You are right, I try to rework that in the next version. Thanks for the suggestion. I will also remove/replace the debug() calls.
Regards,
Stefan
Re: [PATCH v1 1/6] usb: dwc3: core: only provide legacy gadget IRQ handler when USB_DWC3_GADGET
In reply to Stefan EichenbergerQuoted 44 lines · Stefan Eichenberger
Quoted 28 lines · Marek Vasut
Quoted 27 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
Building a board with USB_DWC3=y (DWC3 used purely as an XHCI host controller),
USB_DWC3_GADGETunset, andDM_USB_GADGETdisabled (e.g. to useCONFIG_CI_UDCfor a separate ChipIdea gadget/OTG controller) fails to link:
drivers/usb/gadget/ci_udc.o: in function `dm_usb_gadget_handle_interrupts':drivers/usb/gadget/ci_udc.c:983: multiple definition ofdm_usb_gadget_handle_interrupts'; drivers/usb/dwc3/core.o:drivers/usb/dwc3/core.c:1034: first defined here drivers/usb/dwc3/core.o: in functiondm_usb_gadget_handle_interrupts':drivers/usb/dwc3/core.c:1044: undefined reference to `dwc3_gadget_uboot_handle_interrupt'Add "&&
CONFIG_IS_ENABLED(USB_DWC3_GADGET)" to the guard so this code is only compiled when the DWC3 gadget driver it depends on is actually present, matching theMakefiledependency. Boards that combine DWC3 (host) with a separate legacy gadget driver likeCI_UDC, withDM_USB_GADGETdisabled, now link correctly. Boards that already use DWC3 in gadget mode withoutDM_USB_GADGETare unaffected sinceUSB_DWC3_GADGETis set for them.Fixes 4d1589808970 ("usb: udc: dwc3: Fold board dm_usb_gadget_handle_interrupts() into DWC3 gadget")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
drivers/usb/dwc3/core.c MODULE_AUTHOR("Felipe Balbi <[email protected]>"); · line 1019
Quoted 10 lines
drivers/usb/dwc3/core.c +1
-1@@ -1016,7 +1016,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("DesignWare USB3 DRD Controller Driver" ); -#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) +#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) &&CONFIG_IS_ENABLED (USB_DWC3_GADGET )__weak int dwc3_uboot_interrupt_status (struct udevice *dev)Simply enable
DM_USB_GADGET, then thedrivers/usb/gadget/udc/udc-uclass.cdm_usb_gadget_handle_interrupts()is used which correctly invokes the per-controller IRQ handler.DWC3_GADGETshould likely depend onDM_USB_GADGET.
Quoted 6 lines
Unfortunately,
CI_UDCis not a DM driver yet and it depends on !DM_USB_GADGET that's why I can't enableDM_USB_GADGETin that specific case. I think NXP is working on changing that driver to DM (at least they did that in their BSP). So my hope was to have this as intermediate solution. Also in our case we use the DWC3 controller in host mode only, so we don't needDWC3_GADGETat all.
So the NXP downstream tree has a DM_USB_GADGET driver that needs to be upstreamed, to solve this? We're quite a ways past where enhancing the non-DM side things is the normal workflow.
Signature · 1 line
Tom
Re: [PATCH v1 1/6] usb: dwc3: core: only provide legacy gadget IRQ handler when USB_DWC3_GADGET
In reply to Stefan EichenbergerQuoted 44 lines · Stefan Eichenberger
Quoted 28 lines · Marek Vasut
Quoted 27 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
Building a board with USB_DWC3=y (DWC3 used purely as an XHCI host controller),
USB_DWC3_GADGETunset, andDM_USB_GADGETdisabled (e.g. to useCONFIG_CI_UDCfor a separate ChipIdea gadget/OTG controller) fails to link:
drivers/usb/gadget/ci_udc.o: in function `dm_usb_gadget_handle_interrupts':drivers/usb/gadget/ci_udc.c:983: multiple definition ofdm_usb_gadget_handle_interrupts'; drivers/usb/dwc3/core.o:drivers/usb/dwc3/core.c:1034: first defined here drivers/usb/dwc3/core.o: in functiondm_usb_gadget_handle_interrupts':drivers/usb/dwc3/core.c:1044: undefined reference to `dwc3_gadget_uboot_handle_interrupt'Add "&&
CONFIG_IS_ENABLED(USB_DWC3_GADGET)" to the guard so this code is only compiled when the DWC3 gadget driver it depends on is actually present, matching theMakefiledependency. Boards that combine DWC3 (host) with a separate legacy gadget driver likeCI_UDC, withDM_USB_GADGETdisabled, now link correctly. Boards that already use DWC3 in gadget mode withoutDM_USB_GADGETare unaffected sinceUSB_DWC3_GADGETis set for them.Fixes 4d1589808970 ("usb: udc: dwc3: Fold board dm_usb_gadget_handle_interrupts() into DWC3 gadget")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
drivers/usb/dwc3/core.c MODULE_AUTHOR("Felipe Balbi <[email protected]>"); · line 1019
Quoted 10 lines
drivers/usb/dwc3/core.c +1
-1@@ -1016,7 +1016,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("DesignWare USB3 DRD Controller Driver" ); -#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) +#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) &&CONFIG_IS_ENABLED (USB_DWC3_GADGET )__weak int dwc3_uboot_interrupt_status (struct udevice *dev)Simply enable
DM_USB_GADGET, then thedrivers/usb/gadget/udc/udc-uclass.cdm_usb_gadget_handle_interrupts()is used which correctly invokes the per-controller IRQ handler.DWC3_GADGETshould likely depend onDM_USB_GADGET.
Quoted 6 lines
Unfortunately,
CI_UDCis not a DM driver yet and it depends on !DM_USB_GADGET that's why I can't enableDM_USB_GADGETin that specific case. I think NXP is working on changing that driver to DM (at least they did that in their BSP). So my hope was to have this as intermediate solution. Also in our case we use the DWC3 controller in host mode only, so we don't needDWC3_GADGETat all.
Let's convert the CI to DM and be done with it, esp. if there is existing code which does it.
Re: [PATCH v1 2/6] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
In reply to Stefan EichenbergerQuoted 75 lines · Stefan Eichenberger
Quoted 64 lines · Marek Vasut
Quoted 63 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
On Verdin iMX95, with a USB hub permanently attached to the DWC3 host port the hub itself enumerates fine but a USB stick plugged into it fails intermittently:
Verdin iMX95 # usb start
starting USB...
USB XHCI 1.10
Device not responding to set address.USB device not accepting new address (error=80000000)
Bus usb@4c100000: 2 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Verdin iMX95 # usb reset
resetting USB...
USB XHCI 1.10
WARN endpoint is halted
WARN endpoint is halted
unable to get device descriptor (error=-22)Commit
c6583354b7c1("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes") added a fallback that searches the DWC3 child node's "clock-names" for "ref"/"ref_clk" when it isn't found on the parent glue node, but always resolves the found index againstglue->clks, aclk_bulkpopulated only from the parent glue node's own clock-names list. This is wrong since the child node's clock-names list is not guaranteed to be in the same order as the parent's, and indeed on Verdin iMX95 the child node has a different order than the parent node.Fix it by resolving the index against the child node's clk and ensure to enable the clock before using it.
Fixes c6583354b7c1 ("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/dwc3-generic.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-generic.c +8
-2@@ -31,6 +31,7 @@ struct dwc3_generic_priv {struct dwc3 dwc3;struct phy_bulk phys;struct gpio_desc *ulpi_reset; +struct clk ref_clk; };struct dwc3_generic_host_priv {@@ -76,9 +77,28 @@ static int dwc3_generic_probe(struct udevice *dev, index =ofnode_stringlist_search (node,"clock-names" ,"ref" );if (index <0 ) index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); - } -if (index >=0 ) +/* +* glue->clks was populated from the parent glue node's own +* clock-names list, which can differ in length/order from +* this child node's list (e.g. i.MX95: glue has "hsio", +* "suspend", the dwc3 child has "bus_early", "ref", +* "suspend"). Reusing this index against glue->clks would +* silently resolve to the wrong clock, so fetch it directly Quoted 9 lines
drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 90
Quoted 4 lines
drivers/usb/dwc3/dwc3-generic.c +4
-0+* from this node instead. +*/ +if (index >=0 ) { +if (!clk_get_by_index (dev, index, &priv->ref_clk)) {Would it be possible to call
clk_get_by_name(dev, ...)andclk_get_by_name(dev->parent, ...)instead, until one of them succeeds ? That could make the code simpler.
Quoted 2 lines
You are right, I try to rework that in the next version. Thanks for the suggestion. I will also remove/replace the
debug()calls.
Excellent, thank you !
Re: [PATCH v1 3/6] usb: skip host-only devices when picking the ehci gadget controller
In reply to Stefan EichenbergerQuoted 4 lines · Stefan Eichenberger
Quoted 3 lines · Marek Vasut
Quoted 2 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
The i.MX95 SoC has two USB controllers, a DWC3 host-only controller and a ChipIdea OTG controller. The latter is the one that can be used for USB gadget functionality.
Both DWC3 and CI HDRC controllers are dual-role on MX95, are they not ?
That's correct we only use the DWC3 controller in host mode. I will update the commit message in the next version to make that clear.
Thank you.
Re: [PATCH v1 1/6] usb: dwc3: core: only provide legacy gadget IRQ handler when USB_DWC3_GADGET
In reply to Tom RiniQuoted 52 lines · Tom Rini
Quoted 44 lines · Stefan Eichenberger
Quoted 28 lines · Marek Vasut
Quoted 27 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
Building a board with USB_DWC3=y (DWC3 used purely as an XHCI host controller),
USB_DWC3_GADGETunset, andDM_USB_GADGETdisabled (e.g. to useCONFIG_CI_UDCfor a separate ChipIdea gadget/OTG controller) fails to link:
drivers/usb/gadget/ci_udc.o: in function `dm_usb_gadget_handle_interrupts':drivers/usb/gadget/ci_udc.c:983: multiple definition ofdm_usb_gadget_handle_interrupts'; drivers/usb/dwc3/core.o:drivers/usb/dwc3/core.c:1034: first defined here drivers/usb/dwc3/core.o: in functiondm_usb_gadget_handle_interrupts':drivers/usb/dwc3/core.c:1044: undefined reference to `dwc3_gadget_uboot_handle_interrupt'Add "&&
CONFIG_IS_ENABLED(USB_DWC3_GADGET)" to the guard so this code is only compiled when the DWC3 gadget driver it depends on is actually present, matching theMakefiledependency. Boards that combine DWC3 (host) with a separate legacy gadget driver likeCI_UDC, withDM_USB_GADGETdisabled, now link correctly. Boards that already use DWC3 in gadget mode withoutDM_USB_GADGETare unaffected sinceUSB_DWC3_GADGETis set for them.Fixes 4d1589808970 ("usb: udc: dwc3: Fold board dm_usb_gadget_handle_interrupts() into DWC3 gadget")Signed-off-by Stefan Eichenberger <[email protected]>--- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
drivers/usb/dwc3/core.c MODULE_AUTHOR("Felipe Balbi <[email protected]>"); · line 1019
Quoted 10 lines
drivers/usb/dwc3/core.c +1
-1@@ -1016,7 +1016,7 @@ MODULE_AUTHOR("Felipe Balbi <[email protected]>");MODULE_LICENSE ("GPL v2" );MODULE_DESCRIPTION ("DesignWare USB3 DRD Controller Driver" ); -#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) +#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) &&CONFIG_IS_ENABLED (USB_DWC3_GADGET )__weak int dwc3_uboot_interrupt_status (struct udevice *dev)Simply enable
DM_USB_GADGET, then thedrivers/usb/gadget/udc/udc-uclass.cdm_usb_gadget_handle_interrupts()is used which correctly invokes the per-controller IRQ handler.DWC3_GADGETshould likely depend onDM_USB_GADGET.Quoted 6 lines
Unfortunately,
CI_UDCis not a DM driver yet and it depends on !DM_USB_GADGET that's why I can't enableDM_USB_GADGETin that specific case. I think NXP is working on changing that driver to DM (at least they did that in their BSP). So my hope was to have this as intermediate solution. Also in our case we use the DWC3 controller in host mode only, so we don't needDWC3_GADGETat all.
Quoted 3 lines
So the NXP downstream tree has a
DM_USB_GADGETdriver that needs to be upstreamed, to solve this? We're quite a ways past where enhancing the non-DM side things is the normal workflow.
Okay, so we can only make this work if we first convert the UI_UDC driver to a DM driver. Thanks for the input, I will see what we can do about that.
Regards,
Stefan