usb: fix DWC3/gadget issues and enable USB on Toradex i.MX95 boards
Subsystems (5)
v2 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:
- Add support for the driver model to the ci_udc driver (patch 1). If DM_USB_GADGET is not enabled, keep the legacy driver support enabled so that boards relying on the legacy driver still work. The ci_udc driver does not bind independently, but instead relies on the ehci-mx6 driver to bind it (patch 2). I'm not sure if this approach is correct, but otherwise we would have two drivers binding to the same compatible string, which does not work.
- 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 3).
- 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 4).
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 (7):
usb: ci_udc: add driver model support
usb: ehci-mx6: bind the ChipIdea gadget driver
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/dwc3-generic.c | 47 ++++-- drivers/usb/gadget/Kconfig | 8 +- drivers/usb/gadget/ci_udc.c | 152 +++++++++++++++++- drivers/usb/host/ehci-mx6.c | 38 +++++ drivers/usb/host/usb-uclass.c | 23 ++- 9 files changed, 254 insertions(+), 37 deletions(-)
Signature · 1 line
2.55.0
PATCH v2 1/7 usb: ci_udc: add driver model support
From: Stefan Eichenberger <[email protected]>
Register the ChipIdea gadget as a UCLASS_USB_GADGET_GENERIC driver so it can be used on boards with DM_USB_GADGET enabled, which CI_UDC no longer excludes. The driver enables the clocks and the PHY of its device tree node and registers the gadget with usb_add_gadget_udc().
It has no of_match of its own. The controller node is shared with the EHCI host driver, which owns it and binds this driver by name, so CI_UDC depends on that driver once DM_USB_GADGET is enabled.
Boards without DM_USB_GADGET keep the existing behaviour.
--- drivers/usb/gadget/Kconfig | 8 +- drivers/usb/gadget/ci_udc.c | 152 +++++++++++++++++++++++++++++++++++- 2 files changed, 158 insertions(+), 2 deletions(-)
drivers/usb/gadget/Kconfig +7 -1
@@ -153,12 +153,18 @@ config USB_GADGET_OS_DESCRIPTORS config CI_UDC bool "ChipIdea device controller" - depends on !DM_USB_GADGET + depends on !DM_USB_GADGET || USB_EHCI_MX6 || USB_EHCI_MX7 select USB_GADGET_DUALSPEED help Say Y here to enable device controller functionality of the ChipIdea driver. + With DM_USB_GADGET enabled this driver has no device tree match of + its own. The EHCI host driver owns the controller node and binds + this driver by name for the ports whose dr_mode is "peripheral" or + "otg", which is why it is required. Without DM_USB_GADGET the + controller is picked up through the EHCI host driver as before. + config USB_GADGET_VBUS_DRAW int "Maximum VBUS Power usage (2-500 mA)" range 2 500
drivers/usb/gadget/ci_udc.c +151 -1
202 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v2 2/7 usb: ehci-mx6: bind the ChipIdea gadget driver
In reply to Stefan EichenbergerFrom: Stefan Eichenberger <[email protected]>
ci_udc has no device tree match of its own, so bind it here for the ports it can serve. This driver already owns the controller node.
A peripheral-only port is of no use as a host, so hand the node over completely and decline to bind. An OTG port serves both roles, so bind ci_udc in addition and stay bound. Neither device is probed at bind time, so "usb start" probes this one and puts the controller into host mode, while "ums" and "fastboot" probe the gadget one and put it into device mode.
Boards that do not enable both CI_UDC and DM_USB_GADGET are unaffected.
--- drivers/usb/host/ehci-mx6.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
drivers/usb/host/ehci-mx6.c +38 -0
@@ -20,6 +20,8 @@#include <asm/mach-imx/sys_proto.h> #include <dm.h> #include <asm/mach-types.h> +#include <dm/device_compat.h> +#include <dm/lists.h> #include <power/regulator.h> #include <linux/usb/otg.h> #include <linux/usb/phy.h>
@@ -553,6 +555,41 @@ static int ehci_usb_phy_mode(struct udevice *dev)return 0 ; } +static int ehci_usb_bind (struct udevice *dev) +{ +ofnode node =dev_ofnode (dev); +enum usb_dr_mode dr_mode; +int ret; + +/* +* The ChipIdea gadget driver has no device tree match of its own: it +* shares this node, so this driver owns it and decides which roles +* are wanted here. +*/ +if (!IS_ENABLED (CONFIG_CI_UDC ) || !CONFIG_IS_ENABLED (DM_USB_GADGET )) +return 0 ; + + dr_mode =usb_get_dr_mode (node); +if (dr_mode !=USB_DR_MODE_PERIPHERAL && dr_mode !=USB_DR_MODE_OTG ) +return 0 ; + + ret =device_bind_driver_to_node (dev->parent,"ci_udc" , +ofnode_get_name (node), node,NULL ); +if (ret) { +dev_err (dev,"failed to bind ChipIdea gadget: %d\n" , ret); +return ret; + } + +/* +* An OTG port serves both roles, so stay bound as well. Neither +* device is probed here: "usb start" probes this one and puts the +* controller into host mode, "ums" and "fastboot" probe the gadget +* one and put it into device mode. A peripheral-only port is of no +* use as a host, so hand the node over completely. +*/ +return dr_mode ==USB_DR_MODE_OTG ?0 : -ENODEV ; +} +static int ehci_usb_of_to_plat (struct udevice *dev) {struct usb_plat *plat =dev_get_plat (dev);
@@ -774,6 +811,7 @@ U_BOOT_DRIVER(usb_mx6) = { .name = "ehci_mx6", .id = UCLASS_USB, .of_match = mx6_usb_ids, + .bind = ehci_usb_bind, .of_to_plat = ehci_usb_of_to_plat, .probe = ehci_usb_probe, .remove = ehci_usb_remove,
Signature · 1 line
2.55.0
PATCH v2 3/7 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 looking the reference clock up by name with clk_get_by_name(), walking the dwc3 device first and then its parent glue device, so the clock is always resolved through the device that owns the node its name was found in. Also enable the clock before use, the child node's clocks are not part of the glue node's clk_bulk and are therefore not enabled by dwc3_glue_clk_init(), and disable it again in dwc3_generic_remove() to keep the enable balanced.
--- drivers/usb/dwc3/dwc3-generic.c | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-)
drivers/usb/dwc3/dwc3-generic.c +31 -16
@@ -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 {
@@ -47,8 +48,8 @@ static int dwc3_generic_probe(struct udevice *dev,struct dwc3_generic_plat *plat =dev_get_plat (dev);struct dwc3 *dwc3 = &priv->dwc3;struct dwc3_glue_data *glue =dev_get_plat (dev->parent); -int __maybe_unused index; -ofnode __maybe_unused node; +struct udevice *const __maybe_unused clk_devs[] = { dev, dev->parent }; +int __maybe_unused i; dwc3->dev = dev; dwc3->maximum_speed = plat->maximum_speed;
@@ -63,22 +64,31 @@ static int dwc3_generic_probe(struct udevice *dev,* - in top level generic node, with no subnode (i.MX8MQ) * - in generic subnode, with other clock in top level node (i.MX8MP) * - in both top level node and generic subnode (Rockchip) -* Cover all the possibilities here by looking into both nodes, start -* with the top level node as that seems to be used in majority of DTs -* to reference the clock. +* Cover all the possibilities here by looking into both nodes, the +* generic node first and the top level glue node second. The clock +* must be looked up on the device that owns the node it is described +* in, the clock-names lists of the two nodes are unrelated (e.g. on +* i.MX95 the glue node has "hsio", "suspend" while the generic +* subnode has "bus_early", "ref", "suspend"). */ - node =dev_ofnode (dev->parent); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); -if (index <0 ) { - node =dev_ofnode (dev); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); +for (i =0 ; i <ARRAY_SIZE (clk_devs); i++) { +struct clk clk; + + rc =clk_get_by_name (clk_devs[i],"ref" , &clk); +if (rc) + rc =clk_get_by_name (clk_devs[i],"ref_clk" , &clk); +if (rc) +continue ; + + priv->ref_clk = clk; + + rc =clk_enable (&priv->ref_clk); +if (rc && rc != -ENOSYS ) +dev_warn (dev,"failed to enable ref clock: %d\n" , rc); + + dwc3->ref_clk = &priv->ref_clk; +break ; } -if (index >=0 ) - dwc3->ref_clk = &glue->clks.clks[index];#endif /*
@@ -145,6 +155,11 @@ static int dwc3_generic_remove(struct udevice *dev,dwc3_remove (dwc3);dwc3_shutdown_phy (dev, &priv->phys); + +/* Balance the clk_enable() from dwc3_generic_probe() */ +if (dwc3->ref_clk) +clk_disable (dwc3->ref_clk); +unmap_physmem (dwc3->regs,MAP_NOCACHE );return 0 ;
Signature · 1 line
2.55.0
Re: [PATCH v2 3/7] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
Quoted 81 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 looking the reference clock up by name with
clk_get_by_name(), walking the dwc3 device first and then its parent glue device, so the clock is always resolved through the device that owns the node its name was found in. Also enable the clock before use, the child node's clocks are not part of the glue node'sclk_bulkand are therefore not enabled bydwc3_glue_clk_init(), and disable it again indwc3_generic_remove()to keep the enable balanced.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 | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-)drivers/usb/dwc3/dwc3-generic.c +9
-5@@ -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 {@@ -47,8 +48,8 @@ static int dwc3_generic_probe(struct udevice *dev,struct dwc3_generic_plat *plat =dev_get_plat (dev);struct dwc3 *dwc3 = &priv->dwc3;struct dwc3_glue_data *glue =dev_get_plat (dev->parent); -int __maybe_unused index; -ofnode __maybe_unused node; +struct udevice *const __maybe_unused clk_devs[] = { dev, dev->parent }; +int __maybe_unused i; dwc3->dev = dev; dwc3->maximum_speed = plat->maximum_speed;@@ -63,22 +64,31 @@ static int dwc3_generic_probe(struct udevice *dev,* - in top level generic node, with no subnode (i.MX8MQ) * - in generic subnode, with other clock in top level node (i.MX8MP) * - in both top level node and generic subnode (Rockchip) -* Cover all the possibilities here by looking into both nodes, start -* with the top level node as that seems to be used in majority of DTs -* to reference the clock. +* Cover all the possibilities here by looking into both nodes, the +* generic node first and the top level glue node second. The clock +* must be looked up on the device that owns the node it is described +* in, the clock-names lists of the two nodes are unrelated (e.g. on +* i.MX95 the glue node has "hsio", "suspend" while the generic +* subnode has "bus_early", "ref", "suspend"). */
drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 74
Quoted 10 lines
drivers/usb/dwc3/dwc3-generic.c +1
-9- node =dev_ofnode (dev->parent); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); -if (index <0 ) { - node =dev_ofnode (dev); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); +for (i =0 ; i <ARRAY_SIZE (clk_devs); i++) {
Do we need a loop for two device pointers, where we are basically sure that there won't ever be any more device pointers in the list ? (I think no, so please use four clk_get_by_name() calls and be done with it)
Also, please send this patch separately, so it can be picked as a bugfix for 2026.10 .
Thank you.
Quoted 7 lines
drivers/usb/dwc3/dwc3-generic.c +7
-0+struct clk clk; + + rc =clk_get_by_name (clk_devs[i],"ref" , &clk); +if (rc) + rc =clk_get_by_name (clk_devs[i],"ref_clk" , &clk); +if (rc) +continue ;
[...]
Re: [PATCH v2 3/7] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
Quoted 95 lines · Marek Vasut
Quoted 79 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 looking the reference clock up by name with
clk_get_by_name(), walking the dwc3 device first and then its parent glue device, so the clock is always resolved through the device that owns the node its name was found in. Also enable the clock before use, the child node's clocks are not part of the glue node'sclk_bulkand are therefore not enabled bydwc3_glue_clk_init(), and disable it again indwc3_generic_remove()to keep the enable balanced.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 | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-)drivers/usb/dwc3/dwc3-generic.c +9
-5@@ -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 {@@ -47,8 +48,8 @@ static int dwc3_generic_probe(struct udevice *dev,struct dwc3_generic_plat *plat =dev_get_plat (dev);struct dwc3 *dwc3 = &priv->dwc3;struct dwc3_glue_data *glue =dev_get_plat (dev->parent); -int __maybe_unused index; -ofnode __maybe_unused node; +struct udevice *const __maybe_unused clk_devs[] = { dev, dev->parent }; +int __maybe_unused i; dwc3->dev = dev; dwc3->maximum_speed = plat->maximum_speed;@@ -63,22 +64,31 @@ static int dwc3_generic_probe(struct udevice *dev,* - in top level generic node, with no subnode (i.MX8MQ) * - in generic subnode, with other clock in top level node (i.MX8MP) * - in both top level node and generic subnode (Rockchip) -* Cover all the possibilities here by looking into both nodes, start -* with the top level node as that seems to be used in majority of DTs -* to reference the clock. +* Cover all the possibilities here by looking into both nodes, the +* generic node first and the top level glue node second. The clock +* must be looked up on the device that owns the node it is described +* in, the clock-names lists of the two nodes are unrelated (e.g. on +* i.MX95 the glue node has "hsio", "suspend" while the generic +* subnode has "bus_early", "ref", "suspend"). */ drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 74
Quoted 10 lines
drivers/usb/dwc3/dwc3-generic.c +1
-9- node =dev_ofnode (dev->parent); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); -if (index <0 ) { - node =dev_ofnode (dev); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); +for (i =0 ; i <ARRAY_SIZE (clk_devs); i++) {Do we need a loop for two device pointers, where we are basically sure that there won't ever be any more device pointers in the list ? (I think no, so please use four
clk_get_by_name()calls and be done with it)
Quoted 4 lines
Also, please send this patch separately, so it can be picked as a bugfix for 2026.10 .
Thank you.
My fault, I somehow missunderstood the last comment and thought I should create a loop. I will change that and send it as a separate patch.
Thanks for the review.
Stefan
Re: [PATCH v2 3/7] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
Quoted 96 lines · Stefan Eichenberger
Quoted 95 lines · Marek Vasut
Quoted 79 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 looking the reference clock up by name with
clk_get_by_name(), walking the dwc3 device first and then its parent glue device, so the clock is always resolved through the device that owns the node its name was found in. Also enable the clock before use, the child node's clocks are not part of the glue node'sclk_bulkand are therefore not enabled bydwc3_glue_clk_init(), and disable it again indwc3_generic_remove()to keep the enable balanced.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 | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-)drivers/usb/dwc3/dwc3-generic.c +9
-5@@ -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 {@@ -47,8 +48,8 @@ static int dwc3_generic_probe(struct udevice *dev,struct dwc3_generic_plat *plat =dev_get_plat (dev);struct dwc3 *dwc3 = &priv->dwc3;struct dwc3_glue_data *glue =dev_get_plat (dev->parent); -int __maybe_unused index; -ofnode __maybe_unused node; +struct udevice *const __maybe_unused clk_devs[] = { dev, dev->parent }; +int __maybe_unused i; dwc3->dev = dev; dwc3->maximum_speed = plat->maximum_speed;@@ -63,22 +64,31 @@ static int dwc3_generic_probe(struct udevice *dev,* - in top level generic node, with no subnode (i.MX8MQ) * - in generic subnode, with other clock in top level node (i.MX8MP) * - in both top level node and generic subnode (Rockchip) -* Cover all the possibilities here by looking into both nodes, start -* with the top level node as that seems to be used in majority of DTs -* to reference the clock. +* Cover all the possibilities here by looking into both nodes, the +* generic node first and the top level glue node second. The clock +* must be looked up on the device that owns the node it is described +* in, the clock-names lists of the two nodes are unrelated (e.g. on +* i.MX95 the glue node has "hsio", "suspend" while the generic +* subnode has "bus_early", "ref", "suspend"). */ drivers/usb/dwc3/dwc3-generic.c static int dwc3_generic_probe(struct udevice *dev, · line 74
Quoted 10 lines
drivers/usb/dwc3/dwc3-generic.c +1
-9- node =dev_ofnode (dev->parent); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); -if (index <0 ) { - node =dev_ofnode (dev); - index =ofnode_stringlist_search (node,"clock-names" ,"ref" ); -if (index <0 ) - index =ofnode_stringlist_search (node,"clock-names" ,"ref_clk" ); +for (i =0 ; i <ARRAY_SIZE (clk_devs); i++) {Do we need a loop for two device pointers, where we are basically sure that there won't ever be any more device pointers in the list ? (I think no, so please use four
clk_get_by_name()calls and be done with it)
Quoted 7 lines
Quoted 4 lines
Also, please send this patch separately, so it can be picked as a bugfix for 2026.10 .
Thank you.
My fault, I somehow missunderstood the last comment and thought I should create a loop. I will change that and send it as a separate patch.
I could have been overloaded too and didn't explain it clearly.
In any case, thank you.
PATCH v2 4/7 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 controller and a ChipIdea controller. However, U-Boot might select a controller that is marked as host only in the device tree when attempting to set up a USB gadget, leading to failures in gadget mode.
Iterate over usb devices and skipping any that are marked host-only when selecting the controller for gadget mode. This ensures that a controller that is marked as device or otg 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
Re: [PATCH v2 4/7] usb: skip host-only devices when picking the ehci gadget controller
Quoted 7 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has two USB controllers, a DWC3 controller and a ChipIdea controller. However, U-Boot might select a controller that is marked as host only in the device tree when attempting to set up a USB gadget, leading to failures in gadget mode.
Quoted 7 lines
Iterate over usb devices and skipping any that are marked host-only when selecting the controller for gadget mode. This ensures that a controller that is marked as device or otg 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.
What was the previous incorrect behavior ?
Does your board DT have /aliases { usb0 = &... } entry pointing to the chipidea controller already ? The controller indexing should match the aliases ordering.
[...]
Re: [PATCH v2 4/7] usb: skip host-only devices when picking the ehci gadget controller
Quoted 12 lines · Marek Vasut
Quoted 11 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has two USB controllers, a DWC3 controller and a ChipIdea controller. However, U-Boot might select a controller that is marked as host only in the device tree when attempting to set up a USB gadget, leading to failures in gadget mode.
Iterate over usb devices and skipping any that are marked host-only when selecting the controller for gadget mode. This ensures that a controller that is marked as device or otg is used for USB gadget functionality.
Quoted 5 lines
Quoted 3 lines
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.
What was the previous incorrect behavior ?
When I did a ums 0 mmc 0, the host only DWC3 controller was selected. It is not host only by itself, but it is marked as host only for our board in the device tree.
Quoted 4 lines
Does your board DT have /aliases { usb0 = &... } entry pointing to the chipidea controller already ? The controller indexing should match the aliases ordering.
Yes we use aliases. Interstingly the dwc3 controller is usb1 and the chipidea controller is usb0.
aliases {
...
usb0 = &usb2;
usb1 = &usb3;
...
};&usb2 {
dr_mode = "otg";
...
};&usb3 {
...
&usb3_dwc3 {
dr_mode = "host";
};
...
};So it seems this ordering is not respected when selecting the controller for gadget mode. I have to test that again. However, I still think host only devices should never be selected for gadget mode which is what this patch tries to address. Or should e.g. ums 1 mmc 0 just fail for host only controllers? In this scenario I assume the ordering is correct so ums 1 would select the dwc3 host only controller.
Regards,
Stefan
Re: [PATCH v2 4/7] usb: skip host-only devices when picking the ehci gadget controller
Quoted 51 lines · Stefan Eichenberger
Quoted 12 lines · Marek Vasut
Quoted 11 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has two USB controllers, a DWC3 controller and a ChipIdea controller. However, U-Boot might select a controller that is marked as host only in the device tree when attempting to set up a USB gadget, leading to failures in gadget mode.
Iterate over usb devices and skipping any that are marked host-only when selecting the controller for gadget mode. This ensures that a controller that is marked as device or otg is used for USB gadget functionality.
Quoted 5 lines
Quoted 3 lines
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.
What was the previous incorrect behavior ?
When I did a ums 0 mmc 0, the host only DWC3 controller was selected. It is not host only by itself, but it is marked as host only for our board in the device tree.
Quoted 4 lines
Does your board DT have /aliases { usb0 = &... } entry pointing to the chipidea controller already ? The controller indexing should match the aliases ordering.
Yes we use aliases. Interstingly the dwc3 controller is usb1 and the chipidea controller is usb0.
aliases { ... usb0 = &usb2; usb1 = &usb3; ... };&usb2 { dr_mode = "otg"; ... };&usb3 { ... &usb3_dwc3 { dr_mode = "host"; }; ... };
Quoted 5 lines
So it seems this ordering is not respected when selecting the controller for gadget mode. I have to test that again. However, I still think host only devices should never be selected for gadget mode which is what this patch tries to address. Or should e.g. ums 1 mmc 0 just fail for host only controllers?
Yes
Quoted 2 lines
In this scenario I assume the ordering is correct so ums 1 would select the dwc3 host only controller.
The ordering should respect the aliases enumeration, so ums 0 ... is CI HDRC and ums 1 is DWC3 . Can you check the U-Boot control DT /aliases node to be sure the ordering there is as expected ?
=> fdt addr $fdtcontroladdr
=> fdt print /aliases
Re: [PATCH v2 4/7] usb: skip host-only devices when picking the ehci gadget controller
Quoted 60 lines · Marek Vasut
Quoted 51 lines · Stefan Eichenberger
Quoted 12 lines · Marek Vasut
Quoted 11 lines · Stefan Eichenberger
From: Stefan Eichenberger <[email protected]>
The i.MX95 SoC has two USB controllers, a DWC3 controller and a ChipIdea controller. However, U-Boot might select a controller that is marked as host only in the device tree when attempting to set up a USB gadget, leading to failures in gadget mode.
Iterate over usb devices and skipping any that are marked host-only when selecting the controller for gadget mode. This ensures that a controller that is marked as device or otg is used for USB gadget functionality.
Quoted 5 lines
Quoted 3 lines
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.
What was the previous incorrect behavior ?
When I did a ums 0 mmc 0, the host only DWC3 controller was selected. It is not host only by itself, but it is marked as host only for our board in the device tree.
Quoted 4 lines
Does your board DT have /aliases { usb0 = &... } entry pointing to the chipidea controller already ? The controller indexing should match the aliases ordering.
Yes we use aliases. Interstingly the dwc3 controller is usb1 and the chipidea controller is usb0.
aliases { ... usb0 = &usb2; usb1 = &usb3; ... };&usb2 { dr_mode = "otg"; ... };&usb3 { ... &usb3_dwc3 { dr_mode = "host"; }; ... };Quoted 5 lines
So it seems this ordering is not respected when selecting the controller for gadget mode. I have to test that again. However, I still think host only devices should never be selected for gadget mode which is what this patch tries to address. Or should e.g. ums 1 mmc 0 just fail for host only controllers?
Yes
Quoted 8 lines
Quoted 2 lines
In this scenario I assume the ordering is correct so ums 1 would select the dwc3 host only controller.
The ordering should respect the aliases enumeration, so ums 0 ... is CI HDRC and ums 1 is DWC3 . Can you check the U-Boot control DT /aliases node to be sure the ordering there is as expected ?
=> fdt addr $fdtcontroladdr
=> fdt print /aliases
aliases {
can0 = "/soc/bus@44000000/can@443a0000";
can1 = "/soc/bus@42000000/can@425b0000";
eeprom0 = "/soc/bus@44000000/i2c@44350000/eeprom@50";
ethernet0 = "/soc/system-controller@4cde0000/pcie@4ca00000/ethernet@0,0";
ethernet1 = "/soc/system-controller@4cde0000/pcie@4ca00000/ethernet@8,0";
i2c0 = "/soc/bus@44000000/i2c@44350000";
i2c1 = "/soc/bus@42000000/i2c@42540000";
i2c2 = "/soc/bus@42000000/i2c@42530000";
i2c3 = "/soc/bus@42000000/i3c@42520000";
i2c4 = "/soc/bus@42000000/i2c@426b0000";
mmc0 = "/soc/bus@42800000/mmc@42850000";
mmc1 = "/soc/bus@42800000/mmc@42860000";
mmc2 = "/soc/bus@42800000/mmc@428b0000";
rtc0 = "/soc/bus@44000000/i2c@44350000/rtc@32";
rtc1 = "/firmware/scmi/protocol@81";
serial0 = "/soc/bus@42000000/serial@42690000";
serial1 = "/soc/bus@42000000/serial@426a0000";
serial2 = "/soc/bus@44000000/serial@44380000";
serial3 = "/soc/bus@44000000/serial@44390000";
serial4 = "/soc/bus@42000000/serial@425a0000";
usb0 = "/soc/usb@4c200000";
usb1 = "/soc/usb@4c010010";
eeprom1 = "/soc/bus@42000000/i2c@42540000/eeprom@57";
};I think I found what I missed. When I was originally testing it, the CI_UDC driver was not a driver model driver, therefore the alias for usb2 (alias usb0) did not work. Now with the driver model driver, it indeed works:
Verdin iMX95 # ums 0 mmc 0
UMS: LUN 0, dev mmc 0, hwpart 0, sector 0x0, count 0x3b48000 \
Verdin iMX95 # ums 1 mmc 0
UMS: LUN 0, dev mmc 0, hwpart 0, sector 0x0, count 0x3b48000 No USB device found
Couldn't init USB controller.
So I can drop this patch with the next series, thanks a lot!
Regards,
Stefan
Re: [PATCH v2 4/7] usb: skip host-only devices when picking the ehci gadget controller
On 9/16/26 2:47 PM, Stefan Eichenberger wrote:
Hello Stefan,
[...]
Quoted 43 lines
Quoted 8 lines
Quoted 2 lines
In this scenario I assume the ordering is correct so ums 1 would select the dwc3 host only controller.
The ordering should respect the aliases enumeration, so ums 0 ... is CI HDRC and ums 1 is DWC3 . Can you check the U-Boot control DT /aliases node to be sure the ordering there is as expected ?
=> fdt addr $fdtcontroladdr
=> fdt print /aliasesaliases { can0 = "/soc/bus@44000000/can@443a0000"; can1 = "/soc/bus@42000000/can@425b0000"; eeprom0 = "/soc/bus@44000000/i2c@44350000/eeprom@50"; ethernet0 = "/soc/system-controller@4cde0000/pcie@4ca00000/ethernet@0,0"; ethernet1 = "/soc/system-controller@4cde0000/pcie@4ca00000/ethernet@8,0"; i2c0 = "/soc/bus@44000000/i2c@44350000"; i2c1 = "/soc/bus@42000000/i2c@42540000"; i2c2 = "/soc/bus@42000000/i2c@42530000"; i2c3 = "/soc/bus@42000000/i3c@42520000"; i2c4 = "/soc/bus@42000000/i2c@426b0000"; mmc0 = "/soc/bus@42800000/mmc@42850000"; mmc1 = "/soc/bus@42800000/mmc@42860000"; mmc2 = "/soc/bus@42800000/mmc@428b0000"; rtc0 = "/soc/bus@44000000/i2c@44350000/rtc@32"; rtc1 = "/firmware/scmi/protocol@81"; serial0 = "/soc/bus@42000000/serial@42690000"; serial1 = "/soc/bus@42000000/serial@426a0000"; serial2 = "/soc/bus@44000000/serial@44380000"; serial3 = "/soc/bus@44000000/serial@44390000"; serial4 = "/soc/bus@42000000/serial@425a0000"; usb0 = "/soc/usb@4c200000"; usb1 = "/soc/usb@4c010010"; eeprom1 = "/soc/bus@42000000/i2c@42540000/eeprom@57"; };I think I found what I missed. When I was originally testing it, the
CI_UDCdriver was not a driver model driver, therefore the alias for usb2 (alias usb0) did not work. Now with the driver model driver, it indeed works:
Verdin iMX95 # ums 0 mmc 0
UMS: LUN 0, dev mmc 0, hwpart 0, sector0x0, count0x3b48000\
Quoted 6 lines
Verdin iMX95 # ums 1 mmc 0
UMS: LUN 0, dev mmc 0, hwpart 0, sector0x0, count0x3b48000No USB device found
Couldn't init USB controller.So I can drop this patch with the next series, thanks a lot!
That is nice, well done.
PATCH v2 5/7 configs: verdin-imx95: enable CI_UDC usb gadget driver
In reply to Stefan EichenbergerFrom: Stefan Eichenberger <[email protected]>
Enable CONFIG_CI_UDC, which now provides a driver model driver for the "fsl,imx27-usb" node. The node is an OTG port, so the EHCI host driver stays bound next to it and "usb start" keeps working.
--- configs/verdin-imx95_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/verdin-imx95_defconfig +1 -0
@@ -179,6 +179,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 v2 6/7 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.
CONFIG_USB_DWC3_GADGET has to be enabled along with it. dwc3-generic.c builds its peripheral driver whenever DM_USB_GADGET is set, and that driver calls dwc3_gadget_uboot_handle_interrupt(), which is only built with USB_DWC3_GADGET:
drivers/usb/dwc3/dwc3-generic.c:220: undefined reference to `dwc3_gadget_uboot_handle_interrupt'
--- arch/arm/dts/imx95-verdin-wifi-dev-u-boot.dtsi | 8 -------- configs/verdin-imx95_defconfig | 2 +- 2 files changed, 1 insertion(+), 9 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 -1
@@ -172,7 +172,7 @@ 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
PATCH v2 7/7 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.
Also enable support for DM_USB_GADGET now that the ui_udc driver supports the driver model.
--- 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
@@ -165,8 +165,12 @@ 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 +CONFIG_USB_DWC3=y +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