Skip to contentSkip to conversation

USB Fixes for Gadget Mode on DWC3

PATCH In review Chris Morgan 5 participants 17 messages Jan 15 – Feb 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover USB Fixes for Gadget Mode on DWC3

From: Chris Morgan <[email protected]>

In order to get gadget mode functional (for fastboot and ums) I need to pull two patches in from mainline Linux. After applying these two patches to U-Boot I am able to use ums and fastboot on my Anbernic RG353P device for testing purposes.

Changes since V1:
- Take the existing dwc3_core_soft_reset() function from the upstream Linux core.c file. This necessitates including another patch to add support from upstream Linux for the ip and version_type field and accompanying macros and functions to initialize it.
- Specify the timeout changes made in the gadget driver as part of a separate patch and note the change is required.
- Remove change in dwc3_ref_clk_period() as it was not intended to be included.

Chris Morgan (4):
usb: dwc3: core: Add ip and version_type support from Linux
usb: dwc3: Increase DWC3 controller halt timeout
usb: dwc3: gadget: Don't send unintended link state change
usb: dwc3: core: improve reset sequence

 drivers/usb/dwc3/core.c   | 92 +++++++++++++++++++++++++--------------
 drivers/usb/dwc3/core.h   | 60 +++++++++++++++++++++++++
 drivers/usb/dwc3/gadget.c | 20 ++++-----
 drivers/usb/dwc3/gadget.h | 14 ++++++
 4 files changed, 143 insertions(+), 43 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/4 usb: dwc3: core: Add ip and version_type support from Linux

From: Chris Morgan <[email protected]>

Add support for the ip and version_type fields from the Linux version of the dwc3 driver. Included in this is support for a few additional macros in the header from Linux as well.

---
 drivers/usb/dwc3/core.c | 26 ++++++++++++++----
 drivers/usb/dwc3/core.h | 60 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 5 deletions(-)
drivers/usb/dwc3/core.c +21 -5
index 847fa1f82c3..4827c83e96d 100644
@@ -580,6 +580,26 @@ static void dwc3_set_incr_burst_type(struct dwc3 *dwc)
 	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
 }
 
+static bool dwc3_core_is_valid(struct dwc3 *dwc)
+{
+	u32 reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
+	dwc->ip = DWC3_GSNPS_ID(reg);
+
+	/* This should read as U3 followed by revision number */
+	if (DWC3_IP_IS(DWC3)) {
+		dwc->revision = reg;
+	} else if (DWC3_IP_IS(DWC31) || DWC3_IP_IS(DWC32)) {
+		dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER);
+		dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE);
+	} else {
+		return false;
+	}
+
+	return true;
+}
+
 /**
  * dwc3_core_init - Low-level initialization of DWC3 Core
  * @dwc: Pointer to our controller context structure
@@ -592,15 +612,11 @@ static int dwc3_core_init(struct dwc3 *dwc)
 	u32			reg;
 	int			ret;
 
-	reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
-	/* This should read as U3 followed by revision number */
-	if ((reg & DWC3_GSNPSID_MASK) != 0x55330000 &&
-	    (reg & DWC3_GSNPSID_MASK) != 0x33310000) {
+	if (!dwc3_core_is_valid(dwc)) {
 		dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
 		ret = -ENODEV;
 		goto err0;
 	}
-	dwc->revision = reg;
 
 	/* Handle USB2.0-only core configuration */
 	if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
drivers/usb/dwc3/core.h +60 -0

97 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH V2 1/4] usb: dwc3: core: Add ip and version_type support from Linux

Hi Chris,

Thank you for the patch.

Quoted 7 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Add support for the ip and version_type fields from the Linux version of the dwc3 driver. Included in this is support for a few additional macros in the header from Linux as well.

Quoted 5 lines
---
 drivers/usb/dwc3/core.c | 26 ++++++++++++++----
 drivers/usb/dwc3/core.h | 60 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 5 deletions(-)
#3 lore raw

PATCH v2 2/4 usb: dwc3: Increase DWC3 controller halt timeout

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Since EP0 transactions need to be completed before the controller halt sequence is finished, this may take some time depending on the host and the enabled functions. Increase the controller halt timeout, so that we give the controller sufficient time to handle EP0 transfers.

This patch was originally submitted to Linux in 2022, but is required to use USB gadget mode on my device in U-Boot.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=461ee467507cb98a348fa91ff8460908bb0ea423

---
 drivers/usb/dwc3/gadget.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/gadget.c +2 -2
index 2b01113d54c..d2ae892d554 100644
@@ -1396,7 +1396,7 @@ static int dwc3_gadget_set_selfpowered(struct usb_gadget *g,
 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 {
 	u32			reg;
-	u32			timeout = 500;
+	u32			timeout = 2000;
 
 	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 	if (is_on) {
@@ -1425,6 +1425,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
 
 	do {
+		udelay(2000);
 		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
 		if (is_on) {
 			if (!(reg & DWC3_DSTS_DEVCTRLHLT))
@@ -1436,7 +1437,6 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 		timeout--;
 		if (!timeout)
 			return -ETIMEDOUT;
-		udelay(1);
 	} while (1);
 
 	dev_vdbg(dwc->dev, "gadget %s data soft-%s\n",
Signature · 1 line
2.43.0
Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH V2 2/4] usb: dwc3: Increase DWC3 controller halt timeout

Hi Chris,

Thank you for the patch.

Quoted 7 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Since EP0 transactions need to be completed before the controller halt sequence is finished, this may take some time depending on the host and the enabled functions. Increase the controller halt timeout, so that we give the controller sufficient time to handle EP0 transfers.

Quoted 7 lines

This patch was originally submitted to Linux in 2022, but is required to use USB gadget mode on my device in U-Boot.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=461ee467507cb98a348fa91ff8460908bb0ea423

Quoted 4 lines
---
 drivers/usb/dwc3/gadget.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#5 lore raw

PATCH v2 3/4 usb: dwc3: gadget: Don't send unintended link state change

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

DCTL.ULSTCHNGREQ is a write-only field. When doing a read-modify-write to DCTL, the driver must make sure that there's no unintended link state change request from whatever is read from DCTL.ULSTCHNGREQ. Set link state change to no-action when the driver writes to DCTL.

Note that this patch was submitted upstream in Linux in 2020 [1], and I've confirmed I need it in U-Boot to enable gadget mode.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/drivers/usb/dwc3?id=5b738211fb59e114727381d07c647a77c0010996

---
 drivers/usb/dwc3/gadget.c | 16 +++++++---------
 drivers/usb/dwc3/gadget.h | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/usb/dwc3/gadget.c +7 -9
index d2ae892d554..24ae0c232f6 100644
@@ -62,7 +62,7 @@ int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)
 		return -EINVAL;
 	}
 
-	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	dwc3_gadget_dctl_write_safe(dwc, reg);
 
 	return 0;
 }
@@ -1422,7 +1422,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 		dwc->pullups_connected = false;
 	}
 
-	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	dwc3_gadget_dctl_write_safe(dwc, reg);
 
 	do {
 		udelay(2000);
@@ -2137,10 +2137,8 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
 
 	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 	reg &= ~DWC3_DCTL_INITU1ENA;
-	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
-
 	reg &= ~DWC3_DCTL_INITU2ENA;
-	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	dwc3_gadget_dctl_write_safe(dwc, reg);
 
 	dwc3_disconnect_gadget(dwc);
 	dwc->start_config_issued = false;
@@ -2189,7 +2187,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
 
 	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 	reg &= ~DWC3_DCTL_TSTCTRL_MASK;
-	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	dwc3_gadget_dctl_write_safe(dwc, reg);
 	dwc->test_mode = false;
 
 	dwc3_stop_active_transfers(dwc);
@@ -2305,11 +2303,11 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
 		if (dwc->has_lpm_erratum && dwc->revision >= DWC3_REVISION_240A)
 			reg |= DWC3_DCTL_LPM_ERRATA(dwc->lpm_nyet_threshold);
 
-		dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+		dwc3_gadget_dctl_write_safe(dwc, reg);
 	} else {
 		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 		reg &= ~DWC3_DCTL_HIRD_THRES_MASK;
-		dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+		dwc3_gadget_dctl_write_safe(dwc, reg);
 	}
 
 	dep = dwc->eps[0];
@@ -2417,7 +2415,7 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
 
 				reg &= ~u1u2;
 
-				dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+				dwc3_gadget_dctl_write_safe(dwc, reg);
 				break;
 			default:
 				/* do nothing */
drivers/usb/dwc3/gadget.h +14 -0
index f28a9755dcb..e4f5a096956 100644
@@ -104,4 +104,18 @@ static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number)
 	return DWC3_DEPCMD_GET_RSC_IDX(res_id);
 }
 
+/**
+ * dwc3_gadget_dctl_write_safe - write to DCTL safe from link state change
+ * @dwc: pointer to our context structure
+ * @value: value to write to DCTL
+ *
+ * Use this function when doing read-modify-write to DCTL. It will not
+ * send link state change request.
+ */
+static inline void dwc3_gadget_dctl_write_safe(struct dwc3 *dwc, u32 value)
+{
+	value &= ~DWC3_DCTL_ULSTCHNGREQ_MASK;
+	dwc3_writel(dwc->regs, DWC3_DCTL, value);
+}
+
 #endif /* __DRIVERS_USB_DWC3_GADGET_H */
Signature · 1 line
2.43.0
Reviewed-by on v2 3/4
#6 lore raw

Re: [PATCH V2 3/4] usb: dwc3: gadget: Don't send unintended link state change

Hi Chris,

Thank you for the patch.

Quoted 7 lines · Chris Morgan

From: Chris Morgan <[email protected]>

DCTL.ULSTCHNGREQ is a write-only field. When doing a read-modify-write to DCTL, the driver must make sure that there's no unintended link state change request from whatever is read from DCTL.ULSTCHNGREQ. Set link state change to no-action when the driver writes to DCTL.

Quoted 7 lines

Note that this patch was submitted upstream in Linux in 2020 [1], and I've confirmed I need it in U-Boot to enable gadget mode.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/drivers/usb/dwc3?id=5b738211fb59e114727381d07c647a77c0010996

Quoted 5 lines
---
 drivers/usb/dwc3/gadget.c | 16 +++++++---------
 drivers/usb/dwc3/gadget.h | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 9 deletions(-)
#7 lore raw

PATCH v2 4/4 usb: dwc3: core: improve reset sequence

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

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

---
 drivers/usb/dwc3/core.c | 66 ++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 27 deletions(-)
drivers/usb/dwc3/core.c +39 -27
index 4827c83e96d..6f22b9232ba 100644
@@ -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;
 }
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 17 lines · Chris Morgan

From: Chris Morgan <[email protected]>

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).

Quoted 9 lines

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

Hi Chris,

Thanks for your work here. We also have issues with gadget mode on the iMX95 DWC3 IP, noticed on our Aquila iMX95 SoM. This patch series fixes our issues, but only with a small change:

Quoted 6 lines
drivers/usb/dwc3/core.c +2 -3
-	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);

drivers/usb/dwc3/core.c static void dwc3_set_mode(struct dwc3 *dwc, u32 mode) · line 107

Quoted 10 lines
drivers/usb/dwc3/core.c +8 -2
-	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);

On the iMX95 I also need this delay to get everything functional. If I remove the conditional version check here, it works well. 'dwc->revision' is 0x5533330B.

Is anyone aware of the DWC3 requirements on the iMX95?

Thanks and kind regards,
Ernest

#9 lore raw

Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 55 lines · Ernest Van Hoecke
Quoted 17 lines · Chris Morgan

From: Chris Morgan <[email protected]>

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).

Quoted 9 lines

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

Hi Chris,

Thanks for your work here. We also have issues with gadget mode on the iMX95 DWC3 IP, noticed on our Aquila iMX95 SoM. This patch series fixes our issues, but only with a small change:

Quoted 6 lines
drivers/usb/dwc3/core.c +2 -3
-	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);

drivers/usb/dwc3/core.c static void dwc3_set_mode(struct dwc3 *dwc, u32 mode) · line 107

Quoted 10 lines
drivers/usb/dwc3/core.c +8 -2
-	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);

On the iMX95 I also need this delay to get everything functional. If I remove the conditional version check here, it works well. 'dwc->revision' is 0x5533330B.

Quoted 1 line

Is anyone aware of the DWC3 requirements on the iMX95?

Likely Alice or Peng.

#10 lore raw

回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 70 lines

-----邮件原件-----
发件人: U-Boot <[email protected]> 代表 Marek Vasut 发送时间: 2026年1月22日 20:34
收件人: Ernest Van Hoecke <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 7 lines · Ernest Van Hoecke
Quoted 6 lines · Chris Morgan

From: Chris Morgan <[email protected]>

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.

Quoted 6 lines
Quoted 6 lines

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

Quoted 41 lines
Quoted 9 lines

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.

Quoted 4 lines

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/pa
tch/drivers/usb/dwc3?id=f59dcab176293b646e1358144c93c58c3cda2813

Hi Chris,

Thanks for your work here. We also have issues with gadget mode on the iMX95 DWC3 IP, noticed on our Aquila iMX95 SoM. This patch series fixes our issues, but only with a small change:

Quoted 6 lines
drivers/usb/dwc3/core.c +2 -3
-	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);

drivers/usb/dwc3/core.c static void dwc3_set_mode(struct dwc3 *dwc, u32 mode) · line 107

Quoted 10 lines
drivers/usb/dwc3/core.c +8 -2
-	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);

On the iMX95 I also need this delay to get everything functional. If I remove the conditional version check here, it works well. 'dwc->revision' is 0x5533330B.

Quoted 2 lines
Quoted 1 line

Is anyone aware of the DWC3 requirements on the iMX95?

Likely Alice or Peng.

Hi Ernest,

Thank you for your feedback on i.MX95.

I tested this patch series on the i.MX95 19x19 EVK board with USB SDP boot over the USB3 interface, and it works correctly without the additional delay.

The Universal Serial Bus 3.0 Controller on i.MX95 does not need this delay in my testing. Could you please verify that the Universal Serial Bus 3.0 PHY is configured correctly in your setup?

Best regards,
Alice Guo

#11 lore raw

Re: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 75 lines · Alice Guo (OSS)
Quoted 70 lines

-----邮件原件-----
发件人: U-Boot <[email protected]> 代表 Marek Vasut 发送时间: 2026年1月22日 20:34
收件人: Ernest Van Hoecke <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 7 lines · Ernest Van Hoecke
Quoted 6 lines · Chris Morgan

From: Chris Morgan <[email protected]>

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.

Quoted 6 lines
Quoted 6 lines

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

Quoted 41 lines
Quoted 9 lines

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.

Quoted 4 lines

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/pa
tch/drivers/usb/dwc3?id=f59dcab176293b646e1358144c93c58c3cda2813

Hi Chris,

Thanks for your work here. We also have issues with gadget mode on the iMX95 DWC3 IP, noticed on our Aquila iMX95 SoM. This patch series fixes our issues, but only with a small change:

Quoted 6 lines
drivers/usb/dwc3/core.c +2 -3
-	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);

drivers/usb/dwc3/core.c static void dwc3_set_mode(struct dwc3 *dwc, u32 mode) · line 107

Quoted 10 lines
drivers/usb/dwc3/core.c +8 -2
-	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);

On the iMX95 I also need this delay to get everything functional. If I remove the conditional version check here, it works well. 'dwc->revision' is 0x5533330B.

Quoted 2 lines
Quoted 1 line

Is anyone aware of the DWC3 requirements on the iMX95?

Likely Alice or Peng.

Hi Ernest,

Quoted 8 lines

Thank you for your feedback on i.MX95.

I tested this patch series on the i.MX95 19x19 EVK board with USB SDP boot over the USB3 interface, and it works correctly without the additional delay.

The Universal Serial Bus 3.0 Controller on i.MX95 does not need this delay in my testing. Could you please verify that the Universal Serial Bus 3.0 PHY is configured correctly in your setup?

Best regards,
Alice Guo

Hi Alice,

I spent some time testing again and comparing the differences between 19x19 EVK and our Aquila iMX95 device trees to make sure the DWC3 and DWC3 PHY configs were the same, and I cannot get the USB gadget to function without this delay in U-Boot proper. It works in the U-Boot SPL, does it also work in U-Boot proper for the EVK, or just the SPL?

If there really is some difference here I can dig up an EVK and continue my testing. Thank you for your help.

Kind regards,
Ernest

#12 lore raw

回复: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 117 lines

-----邮件原件-----
发件人: Ernest Van Hoecke <[email protected]>
发送时间: 2026年1月23日 22:13
收件人: Alice Guo (OSS) <[email protected]>
抄送: Marek Vasut <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 16 lines · Alice Guo (OSS)
Quoted 16 lines

-----邮件原件-----
发件人: U-Boot <[email protected]> 代表 Marek Vasut 发送时间: 2026年1月22日 20:34
收件人: Ernest Van Hoecke <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 1 line · Ernest Van Hoecke

On Thu, Jan 15, 2026 at 05:01:35PM -0600, Chris Morgan wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chris Morgan <[email protected]>

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.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 4 lines
Quoted 4 lines

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.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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.gi
t/pa

tch/drivers/usb/dwc3?id=f59dcab176293b646e1358144c93c58c3cda2813

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 1 line

Hi Chris,

Thanks for your work here. We also have issues with gadget mode on the
iMX95 DWC3 IP, noticed on our Aquila iMX95 SoM. This patch series fixes our issues, but only with a small change:

Quoted 6 lines
drivers/usb/dwc3/core.c +2 -3
-	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);

drivers/usb/dwc3/core.c static void dwc3_set_mode(struct dwc3 *dwc, u32 mode) · line 107

Quoted 10 lines
drivers/usb/dwc3/core.c +8 -2
-	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);

On the iMX95 I also need this delay to get everything functional. If I remove the conditional version check here, it works well. 'dwc->revision' is 0x5533330B.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

Is anyone aware of the DWC3 requirements on the iMX95?

Likely Alice or Peng.

Hi Ernest,

Thank you for your feedback on i.MX95.

I tested this patch series on the i.MX95 19x19 EVK board with USB SDP boot

over the USB3 interface, and it works correctly without the additional delay.

Quoted 2 lines

The Universal Serial Bus 3.0 Controller on i.MX95 does not need this delay in

my testing. Could you please verify that the Universal Serial Bus 3.0 PHY is configured correctly in your setup?

Quoted 3 lines

Best regards,
Alice Guo

Hi Alice,

I spent some time testing again and comparing the differences between 19x19 EVK and our Aquila iMX95 device trees to make sure the DWC3 and DWC3 PHY configs were the same, and I cannot get the USB gadget to function without this delay in U-Boot proper. It works in the U-Boot SPL, does it also work in U-Boot proper for the EVK, or just the SPL?

Quoted 5 lines

If there really is some difference here I can dig up an EVK and continue my testing. Thank you for your help.

Kind regards,
Ernest

Hi Ernest,

I tested the UMS feature in U-Boot proper, and it works correctly without this delay.

Best regards,
Alice Guo

#13 lore raw

Re: 回复: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 123 lines · Alice Guo (OSS)
Quoted 117 lines

-----邮件原件-----
发件人: Ernest Van Hoecke <[email protected]>
发送时间: 2026年1月23日 22:13
收件人: Alice Guo (OSS) <[email protected]>
抄送: Marek Vasut <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 16 lines · Alice Guo (OSS)
Quoted 16 lines

-----邮件原件-----
发件人: U-Boot <[email protected]> 代表 Marek Vasut 发送时间: 2026年1月22日 20:34
收件人: Ernest Van Hoecke <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 1 line · Ernest Van Hoecke

On Thu, Jan 15, 2026 at 05:01:35PM -0600, Chris Morgan wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Chris Morgan <[email protected]>

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.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 4 lines
Quoted 4 lines

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.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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.gi
t/pa

tch/drivers/usb/dwc3?id=f59dcab176293b646e1358144c93c58c3cda2813

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 1 line

Hi Chris,

Thanks for your work here. We also have issues with gadget mode on the
iMX95 DWC3 IP, noticed on our Aquila iMX95 SoM. This patch series fixes our issues, but only with a small change:

Quoted 6 lines
(quoted diff) +2 -3
-	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);

Review

Quoted 10 lines
(quoted diff) +8 -2
-	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);

On the iMX95 I also need this delay to get everything functional. If I remove the conditional version check here, it works well. 'dwc->revision' is 0x5533330B.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

Is anyone aware of the DWC3 requirements on the iMX95?

Likely Alice or Peng.

Hi Ernest,

Thank you for your feedback on i.MX95.

I tested this patch series on the i.MX95 19x19 EVK board with USB SDP boot

over the USB3 interface, and it works correctly without the additional delay.

Quoted 2 lines

The Universal Serial Bus 3.0 Controller on i.MX95 does not need this delay in

my testing. Could you please verify that the Universal Serial Bus 3.0 PHY is configured correctly in your setup?

Quoted 3 lines

Best regards,
Alice Guo

Hi Alice,

I spent some time testing again and comparing the differences between 19x19 EVK and our Aquila iMX95 device trees to make sure the DWC3 and DWC3 PHY configs were the same, and I cannot get the USB gadget to function without this delay in U-Boot proper. It works in the U-Boot SPL, does it also work in U-Boot proper for the EVK, or just the SPL?

Quoted 5 lines

If there really is some difference here I can dig up an EVK and continue my testing. Thank you for your help.

Kind regards,
Ernest

Quoted 6 lines

Hi Ernest,

I tested the UMS feature in U-Boot proper, and it works correctly without this delay.

Best regards,
Alice Guo

Hi Alice,

Thanks for testing. I can confirm that UMS works. I also tested DFU, and that also works fine.

The issue turned out to be that we are using fastboot. Fastboot only works with this additional delay. And even then, it does not work every time when using the fastboot command after U-Boot proper has started.

I figured out that this is because all functions of the fastboot gadget config are SuperSpeed capable, while DFU or UMS fall back to a maximum of high speed in 'drivers/usb/gadget/composite.c:usb_add_config()'.

The following hack, for example, fixes fastboot consistently:

drivers/usb/gadget/composite.c +1 -1
index 04b85419931e..314143321546 100644
@@ -539,7 +539,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
 	 */
 	if (gadget_is_superspeed(cdev->gadget)) {
 		list_for_each_entry(f, &config->functions, list) {
-			if (!f->ss_descriptors)
+			if (true)
 				cdev->gadget->max_speed =
 					USB_SPEED_HIGH;
 		}

Note that I have 'phy-imx8mq-usb.c' enabled in my config and device tree. I tried various quirks as well, to me the PHY seems fine, but something is still strange with DWC3 on iMX95 when using SuperSpeed.

Thanks and kind regards,
Ernest

#14 lore raw

回复: 回复: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 187 lines

-----邮件原件-----
发件人: Ernest Van Hoecke <[email protected]>
发送时间: 2026年2月6日 1:33
收件人: Alice Guo (OSS) <[email protected]>
抄送: Marek Vasut <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: 回复: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 11 lines · Alice Guo (OSS)
Quoted 11 lines

-----邮件原件-----
发件人: Ernest Van Hoecke <[email protected]> 发送时间: 2026年1月23日 22:13
收件人: Alice Guo (OSS) <[email protected]>
抄送: Marek Vasut <[email protected]>; Chris Morgan <[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen

<[email protected]>;

Quoted 8 lines
Quoted 8 lines

Mian Yousaf Kaukab <[email protected]>
主题: Re: 回复: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 4 lines · Alice Guo (OSS)
Quoted 4 lines

-----邮件原件-----
发件人: U-Boot <[email protected]> 代表 Marek Vasut 发送时间: 2026年1月22日 20:34
收件人: Ernest Van Hoecke <[email protected]>; Chris

Morgan

Quoted 59 lines
Quoted 59 lines
Quoted 14 lines
Quoted 14 lines

<[email protected]>; Peng Fan (OSS) <[email protected]>; Alice Guo <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Thinh Nguyen <[email protected]>; Mian Yousaf Kaukab <[email protected]>
主题: Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

Quoted 3 lines · Ernest Van Hoecke
Quoted 2 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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.

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 5 lines
Quoted 5 lines

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.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

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/linu
x.gi
t/pa

tch/drivers/usb/dwc3?id=f59dcab176293b646e1358144c93c58c3cda2813

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 1 line

Hi Chris,

Thanks for your work here. We also have issues with gadget mode on the
iMX95 DWC3 IP, noticed on our Aquila iMX95 SoM. This patch series fixes our issues, but only with a small change:

Quoted 4 lines
(quoted diff) +2 -1
-	mdelay(100);
+	dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n");
+	return -ETIMEDOUT;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +3 -4
-	/* 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

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	 * is cleared, we must wait at least 50ms before accessing the

PHY

Quoted 41 lines
Quoted 41 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	 * domain (synchronization delay).
+	 */
+	if (DWC3_VER_IS_WITHIN(DWC31, ANY, 180A))
+		mdelay(50);

On the iMX95 I also need this delay to get everything functional. If I remove the conditional version check here, it works well. 'dwc->revision' is 0x5533330B.

Is anyone aware of the DWC3 requirements on the iMX95?

Quoted 8 lines
Quoted 1 line

Likely Alice or Peng.

Hi Ernest,

Thank you for your feedback on i.MX95.

I tested this patch series on the i.MX95 19x19 EVK board with USB SDP boot

over the USB3 interface, and it works correctly without the additional delay.

Quoted 3 lines

The Universal Serial Bus 3.0 Controller on i.MX95 does not need this delay in

my testing. Could you please verify that the Universal Serial Bus 3.0 PHY is configured correctly in your setup?

Quoted 3 lines

Best regards,
Alice Guo

Hi Alice,

I spent some time testing again and comparing the differences between
19x19 EVK and our Aquila iMX95 device trees to make sure the DWC3 and
DWC3 PHY configs were the same, and I cannot get the USB gadget to function without this delay in U-Boot proper. It works in the U-Boot SPL, does it also work in U-Boot proper for the EVK, or just the SPL?

If there really is some difference here I can dig up an EVK and continue my testing. Thank you for your help.

Quoted 6 lines
Quoted 2 lines

Kind regards,
Ernest

Hi Ernest,

I tested the UMS feature in U-Boot proper, and it works correctly without this

delay.

Quoted 3 lines

Best regards,
Alice Guo

Hi Alice,

Thanks for testing. I can confirm that UMS works. I also tested DFU, and that also works fine.

The issue turned out to be that we are using fastboot. Fastboot only works with this additional delay. And even then, it does not work every time when using the fastboot command after U-Boot proper has started.

I figured out that this is because all functions of the fastboot gadget config are SuperSpeed capable, while DFU or UMS fall back to a maximum of high speed in 'drivers/usb/gadget/composite.c:usb_add_config()'.

The following hack, for example, fixes fastboot consistently:

drivers/usb/gadget/composite.c +1 -1
index 04b85419931e..314143321546 100644
@@ -539,7 +539,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
 	 */
 	if (gadget_is_superspeed(cdev->gadget)) {
 		list_for_each_entry(f, &config->functions, list) {
-			if (!f->ss_descriptors)
+			if (true)
 				cdev->gadget->max_speed =
 					USB_SPEED_HIGH;
 		}
Quoted 6 lines

Note that I have 'phy-imx8mq-usb.c' enabled in my config and device tree. I tried various quirks as well, to me the PHY seems fine, but something is still strange with DWC3 on iMX95 when using SuperSpeed.

Thanks and kind regards,
Ernest

Hi Ernest,

Sorry for the late reply - I was away on holiday leave.

Thank you for sharing your findings and the detailed analysis. However, I'm seeing slightly different results with fastboot on my end.

In my testing, fastboot boot Image works reliably without forcing the gadget to High-Speed mode. Even with SuperSpeed enabled, the download and boot sequence completes successfully. To verify the actual negotiated USB link speed, I ran lsusb -t on the host side, which confirmed that the device is negotiating SuperSpeed (5 Gbps) correctly. Fastboot continues to work as expected in this mode on my setup.

If you have a specific sequence or condition that reproduces the issue on your side, I'd be happy to run the same test on my setup and compare results.

Best regards,
Alice Guo

Reviewed-by on v2 4/4
#15 lore raw

Re: [PATCH V2 4/4] usb: dwc3: core: improve reset sequence

In reply to Chris Morgan

Hi Chris,

Thank you for the patch.

Quoted 24 lines · Chris Morgan

From: Chris Morgan <[email protected]>

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.

Quoted 5 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/drivers/usb/dwc3?id=f59dcab176293b646e1358144c93c58c3cda2813

Quoted 4 lines
---
 drivers/usb/dwc3/core.c | 66 ++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 27 deletions(-)
#16 lore raw
In reply to Chris Morgan

Hi,

Quoted 8 lines · Chris Morgan

From: Chris Morgan <[email protected]>

In order to get gadget mode functional (for fastboot and ums) I need to pull two patches in from mainline Linux. After applying these two patches to U-Boot I am able to use ums and fastboot on my Anbernic RG353P device for testing purposes.

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)

[1/4] usb: dwc3: core: Add ip and version_type support from Linux

      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/add7152eb071619efa150e4b7503f9f333133dbb
[2/4] usb: dwc3: Increase DWC3 controller halt timeout
      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/7590f29e2cd72fb8ed50efde3cdb786d74dc1f10
[3/4] usb: dwc3: gadget: Don't send unintended link state change
      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/de69f14a0991f3b9afe78dc0721a9184d297e303
[4/4] usb: dwc3: core: improve reset sequence
      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/aef270254f0feaad54837d3fbbc04ad0c060d3fa

--
Mattijs