From: Stefan Eichenberger <eichest@gmail.com>
To: francesco.dolcini@toradex.com, trini@konsulko.com,
ilias.apalodimas@linaro.org, sbabic@nabladev.com,
festevam@gmail.com, uboot-imx@nxp.com,
marek.vasut+usb@mailbox.org, lukma@denx.de,
mkorpershoek@kernel.org, antoine.gouby@toradex.com,
alice.guo@nxp.com, stefan.eichenberger@toradex.com,
sjg@chromium.org, emanuele.ghidoli@toradex.com,
franz.schnyder@toradex.com, pbrobinson@gmail.com,
quentin.schulz@cherry.de, jbx6244@gmail.com, ye.li@nxp.com,
xu.yang_2@nxp.com, bmeng.cn@gmail.com, xypron.glpk@gmx.de,
hayashi.kunihiko@socionext.com, sean.anderson@linux.dev
Cc: u-boot@lists.u-boot-project.org
Subject: [PATCH v2 3/7] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array
Date: Mon, 14 Sep 2026 09:42:45 +0200 [thread overview]
Message-ID: <20260914074314.12522-4-eichest@gmail.com> (raw)
In-Reply-To: <20260914074314.12522-1-eichest@gmail.com>
From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
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.
Fixes: c6583354b7c1 ("usb: dwc3: Look up reference clock DT phandle in both controller DT nodes")
Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
---
drivers/usb/dwc3/dwc3-generic.c | 47 ++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 2356b3bc0aa..704dd242553 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -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;
--
2.55.0
next prev parent reply other threads:[~2026-09-14 14:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 7:42 [PATCH v2 0/7] usb: fix DWC3/gadget issues and enable USB on Toradex i.MX95 boards Stefan Eichenberger
2026-09-14 7:42 ` [PATCH v2 1/7] usb: ci_udc: add driver model support Stefan Eichenberger
2026-09-14 7:42 ` [PATCH v2 2/7] usb: ehci-mx6: bind the ChipIdea gadget driver Stefan Eichenberger
2026-09-14 7:42 ` Stefan Eichenberger [this message]
2026-09-14 19:26 ` [PATCH v2 3/7] usb: dwc3-generic: fix ref clock lookup indexing wrong clk_bulk array Marek Vasut
2026-09-15 7:44 ` Stefan Eichenberger
2026-09-15 14:22 ` Marek Vasut
2026-09-14 7:42 ` [PATCH v2 4/7] usb: skip host-only devices when picking the ehci gadget controller Stefan Eichenberger
2026-09-14 19:31 ` Marek Vasut
2026-09-15 7:57 ` Stefan Eichenberger
2026-09-15 14:24 ` Marek Vasut
2026-09-16 12:47 ` Stefan Eichenberger
2026-09-16 14:29 ` Marek Vasut
2026-09-14 7:42 ` [PATCH v2 5/7] configs: verdin-imx95: enable CI_UDC usb gadget driver Stefan Eichenberger
2026-09-14 7:42 ` [PATCH v2 6/7] toradex: verdin-imx95: enable DWC3 USB controller support Stefan Eichenberger
2026-09-14 7:42 ` [PATCH v2 7/7] toradex: smarc-imx95: " Stefan Eichenberger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260914074314.12522-4-eichest@gmail.com \
--to=eichest@gmail.com \
--cc=alice.guo@nxp.com \
--cc=antoine.gouby@toradex.com \
--cc=bmeng.cn@gmail.com \
--cc=emanuele.ghidoli@toradex.com \
--cc=festevam@gmail.com \
--cc=francesco.dolcini@toradex.com \
--cc=franz.schnyder@toradex.com \
--cc=hayashi.kunihiko@socionext.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jbx6244@gmail.com \
--cc=lukma@denx.de \
--cc=marek.vasut+usb@mailbox.org \
--cc=mkorpershoek@kernel.org \
--cc=pbrobinson@gmail.com \
--cc=quentin.schulz@cherry.de \
--cc=sbabic@nabladev.com \
--cc=sean.anderson@linux.dev \
--cc=sjg@chromium.org \
--cc=stefan.eichenberger@toradex.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=uboot-imx@nxp.com \
--cc=xu.yang_2@nxp.com \
--cc=xypron.glpk@gmx.de \
--cc=ye.li@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox