[PATCH v6 02/11] usb: dwc2: keep TOUTCAL canary valid after PHY init
From: Fabrice Gasnier
Date: Wed Nov 25 2026 - 11:34:02 EST
dwc2_resume() uses GUSBCFG.TOUTCAL as a canary for register loss during
system resume. PHY initialization can reset the core and clear TOUTCAL.
In dual-role device mode without a gadget driver, TOUTCAL can also remain
at its power-on value of zero. Either case can make resume falsely detect
register loss.
Run PHY initialization before setting TOUTCAL in
dwc2_hsotg_core_init_disconnected(), and initialize TOUTCAL in
dwc2_gusbcfg_init() after PHY setup. This keeps the canary nonzero after
PHY initialization and in driverless dual-role device mode.
Fixes: ba6e518d136b ("usb: dwc2: Implement recovery after PM domain off")
Cc: stable@xxxxxxxxxxxxxxx
Closes: https://lore.kernel.org/linux-usb/sashiko-outbox-219256@xxxxxxxxxx/
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@xxxxxxxxxxx>
---
Changes in v6:
- New patch to address 1st finding of the Sashiko review of "usb: dwc2:
fix recovery after PM domain off".
---
drivers/usb/dwc2/gadget.c | 4 ++--
drivers/usb/dwc2/hcd.c | 7 +++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 02c93a41043a..5e75d6975baa 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3461,6 +3461,8 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
}
}
+ dwc2_phy_init(hsotg, true);
+
/*
* we must now enable ep0 ready for host detection and then
* set configuration.
@@ -3484,8 +3486,6 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
usbcfg |= GUSBCFG_SRPCAP;
dwc2_writel(hsotg, usbcfg, GUSBCFG);
- dwc2_phy_init(hsotg, true);
-
if (!is_usb_reset) {
dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON);
if (hsotg->params.eusb2_disc)
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index db6126cd72c8..0d20b9de857a 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -128,6 +128,13 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
break;
}
+ /*
+ * dwc2_resume() uses TOUTCAL to detect register loss. Set it here
+ * for dual-role device mode before a gadget driver binds.
+ */
+ usbcfg &= ~GUSBCFG_TOUTCAL_MASK;
+ usbcfg |= GUSBCFG_TOUTCAL(7);
+
dwc2_writel(hsotg, usbcfg, GUSBCFG);
}
--
2.43.0