From: Chris Morgan <macroalpha82@gmail.com>
To: u-boot@lists.denx.de
Cc: thinhn@synopsys.com, neil.armstrong@linaro.org,
quic_varada@quicinc.com, felipe.balbi@linux.intel.com,
mkorpershoek@kernel.org, lukma@denx.de, trini@konsulko.com,
marex@denx.de, macromorgan@hotmail.com,
Mian Yousaf Kaukab <yousaf.kaukab@intel.com>
Subject: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence
Date: Thu, 15 Jan 2026 17:01:35 -0600 [thread overview]
Message-ID: <20260115230135.183158-5-macroalpha82@gmail.com> (raw)
In-Reply-To: <20260115230135.183158-1-macroalpha82@gmail.com>
From: Chris Morgan <macromorgan@hotmail.com>
According to Synopsys Databook, we shouldn't be
relying on GCTL.CORESOFTRESET bit as that's only for
debugging purposes. Instead, let's use DCTL.CSFTRST
if we're OTG or PERIPHERAL mode.
Host side block will be reset by XHCI driver if
necessary. Note that this reduces amount of time
spent on dwc3_probe() by a long margin.
We're still gonna wait for reset to finish for a
long time (default to 1ms max), but tests show that
the reset polling loop executed at most 19 times
(modprobe dwc3 && modprobe -r dwc3 executed 1000
times in a row).
Note that this patch was submitted to Linux in 2016 [1], however I can
confirm it is needed to support gadget mode in U-Boot on my device.
While I am referencing this patch from Linux I am in fact taking the
full existing dwc3_core_soft_reset() function from Linux as it exists
in v6.19-rc5, so it may differ slightly from the information in the
2016 patch.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/drivers/usb/dwc3?id=f59dcab176293b646e1358144c93c58c3cda2813
Suggested-by: Mian Yousaf Kaukab <yousaf.kaukab@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
drivers/usb/dwc3/core.c | 66 ++++++++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 4827c83e96d..6f22b9232ba 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -59,40 +59,52 @@ static void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
static int dwc3_core_soft_reset(struct dwc3 *dwc)
{
u32 reg;
+ int retries = 1000;
- /* Before Resetting PHY, put Core in Reset */
- reg = dwc3_readl(dwc->regs, DWC3_GCTL);
- reg |= DWC3_GCTL_CORESOFTRESET;
- dwc3_writel(dwc->regs, DWC3_GCTL, reg);
-
- /* Assert USB3 PHY reset */
- reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
- reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
- dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
+ /*
+ * We're resetting only the device side because, if we're in host mode,
+ * XHCI driver will reset the host block. If dwc3 was configured for
+ * host-only mode, then we can return early.
+ */
+ if (dwc->dr_mode == USB_DR_MODE_HOST)
+ return 0;
- /* Assert USB2 PHY reset */
- reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
- reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
- dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
+ reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+ reg |= DWC3_DCTL_CSFTRST;
+ reg &= ~DWC3_DCTL_RUN_STOP;
+ dwc3_gadget_dctl_write_safe(dwc, reg);
- mdelay(100);
+ /*
+ * For DWC_usb31 controller 1.90a and later, the DCTL.CSFRST bit
+ * is cleared only after all the clocks are synchronized. This can
+ * take a little more than 50ms. Set the polling rate at 20ms
+ * for 10 times instead.
+ */
+ if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
+ retries = 10;
- /* Clear USB3 PHY reset */
- reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
- reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
- dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
+ do {
+ reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+ if (!(reg & DWC3_DCTL_CSFTRST))
+ goto done;
- /* Clear USB2 PHY reset */
- reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
- reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
- dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
+ if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
+ mdelay(20);
+ else
+ udelay(1);
+ } while (--retries);
- mdelay(100);
+ dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n");
+ return -ETIMEDOUT;
- /* After PHYs are stable we can take Core out of reset state */
- reg = dwc3_readl(dwc->regs, DWC3_GCTL);
- reg &= ~DWC3_GCTL_CORESOFTRESET;
- dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+done:
+ /*
+ * For DWC_usb31 controller 1.80a and prior, once DCTL.CSFRST bit
+ * is cleared, we must wait at least 50ms before accessing the PHY
+ * domain (synchronization delay).
+ */
+ if (DWC3_VER_IS_WITHIN(DWC31, ANY, 180A))
+ mdelay(50);
return 0;
}
--
2.43.0
next prev parent reply other threads:[~2026-01-15 23:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 23:01 [PATCH V2 0/4] USB Fixes for Gadget Mode on DWC3 Chris Morgan
2026-01-15 23:01 ` [PATCH V2 1/4] usb: dwc3: core: Add ip and version_type support from Linux Chris Morgan
2026-01-29 8:49 ` Mattijs Korpershoek
2026-01-15 23:01 ` [PATCH V2 2/4] usb: dwc3: Increase DWC3 controller halt timeout Chris Morgan
2026-01-29 8:51 ` Mattijs Korpershoek
2026-01-15 23:01 ` [PATCH V2 3/4] usb: dwc3: gadget: Don't send unintended link state change Chris Morgan
2026-01-29 9:06 ` Mattijs Korpershoek
2026-01-15 23:01 ` Chris Morgan [this message]
2026-01-22 12:15 ` [PATCH V2 4/4] usb: dwc3: core: improve reset sequence Ernest Van Hoecke
2026-01-22 12:34 ` Marek Vasut
2026-01-23 7:24 ` 回复: " Alice Guo (OSS)
2026-01-23 14:12 ` Ernest Van Hoecke
2026-01-27 1:58 ` 回复: " Alice Guo (OSS)
2026-02-05 17:32 ` Ernest Van Hoecke
2026-02-25 11:04 ` 回复: " Alice Guo (OSS)
2026-01-29 9:38 ` Mattijs Korpershoek
2026-01-30 8:00 ` [PATCH V2 0/4] USB Fixes for Gadget Mode on DWC3 Mattijs Korpershoek
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=20260115230135.183158-5-macroalpha82@gmail.com \
--to=macroalpha82@gmail.com \
--cc=felipe.balbi@linux.intel.com \
--cc=lukma@denx.de \
--cc=macromorgan@hotmail.com \
--cc=marex@denx.de \
--cc=mkorpershoek@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=quic_varada@quicinc.com \
--cc=thinhn@synopsys.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=yousaf.kaukab@intel.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