[PATCH RFC 1/2] usb: dwc3: Let the glue keep the host bus suspended across suspend-to-idle
From: Arun Iyengar via B4 Relay
Date: Thu Nov 12 2026 - 03:47:51 EST
From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
In host mode, dwc3_suspend_common() tears the core down for system
suspend (dwc3_core_exit(): PHYs off, core reset) unless the controller
is a wakeup source. By then xhci-plat has already suspended the bus:
the root ports and every device behind them are in U3/suspend and
expect to keep their power session (Documentation/driver-api/usb/
persist.rst). Resetting the core ends all of them. On resume xhci-plat
finds a reset controller ("root hub lost power or was reset") and the
USB core has to reset-resume every device, which only works for devices
that come back within the 2 s that usb_port_resume() waits for a
connection.
Devices that are cut off in U3 do not necessarily come back that fast.
On an Orange Pi 5 (RK3588S) a SanDisk Extreme drive on the Type-A USB3
port only connects again ~3 s after resume, and a card reader behind a
USB3 hub loses VBUS when the hub is reset and needs ~2.35 s. Both are
disconnected and enumerated again on every resume, which kills a
filesystem mounted on them. With the bus kept suspended they resume
from U3 in milliseconds.
Whether the bus can be kept is a property of the platform, not of the
dwc3 core: in suspend-to-idle some glue drivers still assert resets or
switch off PHY supplies in their own suspend callbacks, some power
domains are switched off, and some platforms rely on the PHYs being
powered off to reach their low-power state (c4a5153e87fd ("usb: dwc3:
core: Power-off core/PHYs on system_suspend in host mode")). So make it
an opt-in: a glue driver whose platform keeps the controller, its PHYs
and its power domain powered across suspend-to-idle sets
keep_host_bus_in_s2idle in dwc3_properties, and only then does the core
keep the suspended bus in suspend-to-idle, as it does for wakeup. It
also marks the device as being on the awake path so that a power domain
with GENPD_FLAG_ACTIVE_WAKEUP stays on. Resume re-initialises the core
exactly when suspend tore it down, which xhci_power_lost now records.
Nothing changes for platforms that do not set the flag, nor for
suspend-to-RAM, hibernation and needs_full_reinit controllers.
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/usb/dwc3/core.c | 41 +++++++++++++++++++++++++++++++++++++----
drivers/usb/dwc3/core.h | 3 +++
drivers/usb/dwc3/glue.h | 7 +++++++
3 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index bc9ce8dce0c6..21746fc8624a 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -16,6 +16,7 @@
#include <linux/spinlock.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/suspend.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/io.h>
@@ -1694,6 +1695,9 @@ static void dwc3_get_software_properties(struct dwc3 *dwc,
if (properties->needs_full_reinit)
dwc->needs_full_reinit = true;
+ if (properties->keep_host_bus_in_s2idle)
+ dwc->keep_host_bus_in_s2idle = true;
+
dwc->gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED;
if (properties->gsbuscfg0_reqinfo !=
@@ -2554,6 +2558,30 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
return ret;
}
+/*
+ * In host mode, system suspend suspends the bus: xhci-plat puts the root ports
+ * and with them every attached device into U3/suspend, and the USB core
+ * expects them to keep that power session (see
+ * Documentation/driver-api/usb/persist.rst). Tearing the core down ends all of
+ * them: the devices then have to go through a reset-resume, and one that takes
+ * longer to come back than the USB core waits for is disconnected, e.g. with a
+ * mounted filesystem.
+ *
+ * The core is kept when it is a wakeup source, and in suspend-to-idle on
+ * platforms whose glue says that the controller, its PHYs and its power domain
+ * stay powered then (keep_host_bus_in_s2idle). Everywhere else it is torn down
+ * so the PHYs can be powered off.
+ */
+static bool dwc3_host_keep_core(struct dwc3 *dwc)
+{
+ if (dwc->needs_full_reinit)
+ return false;
+ if (device_may_wakeup(dwc->dev))
+ return true;
+ return dwc->keep_host_bus_in_s2idle &&
+ pm_suspend_target_state == PM_SUSPEND_TO_IDLE;
+}
+
static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
{
u32 reg;
@@ -2584,14 +2612,20 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
dwc3_core_exit(dwc);
break;
case DWC3_GCTL_PRTCAP_HOST:
- if (!PMSG_IS_AUTO(msg) &&
- (!device_may_wakeup(dwc->dev) || dwc->needs_full_reinit)) {
+ if (!PMSG_IS_AUTO(msg) && !dwc3_host_keep_core(dwc)) {
dwc3_core_exit(dwc);
dwc->xhci_power_lost = 1;
break;
}
dwc->xhci_power_lost = 0;
+ /*
+ * The core and its PHYs stay powered to keep the suspended bus:
+ * keep the power domain on as well.
+ */
+ if (!PMSG_IS_AUTO(msg))
+ device_set_awake_path(dwc->dev);
+
/* Let controller to suspend HSPHY before PHY driver suspends */
if (dwc->dis_u2_susphy_quirk ||
dwc->dis_enblslpm_quirk) {
@@ -2650,8 +2684,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
dwc3_gadget_resume(dwc);
break;
case DWC3_GCTL_PRTCAP_HOST:
- if (!PMSG_IS_AUTO(msg) &&
- (!device_may_wakeup(dwc->dev) || dwc->needs_full_reinit)) {
+ if (!PMSG_IS_AUTO(msg) && dwc->xhci_power_lost) {
ret = dwc3_core_init_for_resume(dwc);
if (ret)
return ret;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 94408958e9a1..ee1afa0d106a 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1137,6 +1137,8 @@ struct dwc3_glue_ops {
* @usb2_gadget_lpm_disable: set to disable usb2 lpm for gadget
* @needs_full_reinit: set to indicate the core may lose power and need full
* initialization during system pm
+ * @keep_host_bus_in_s2idle: set if the platform keeps the controller powered
+ * across suspend-to-idle, so the host bus stays suspended
* @disable_scramble_quirk: set if we enable the disable scramble quirk
* @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
* @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
@@ -1407,6 +1409,7 @@ struct dwc3 {
unsigned usb2_lpm_disable:1;
unsigned usb2_gadget_lpm_disable:1;
unsigned needs_full_reinit:1;
+ unsigned keep_host_bus_in_s2idle:1;
unsigned disable_scramble_quirk:1;
unsigned u2exit_lfps_quirk:1;
diff --git a/drivers/usb/dwc3/glue.h b/drivers/usb/dwc3/glue.h
index d738e1739ae0..130c455d9c4e 100644
--- a/drivers/usb/dwc3/glue.h
+++ b/drivers/usb/dwc3/glue.h
@@ -14,10 +14,17 @@
* @gsbuscfg0_reqinfo: Value to be programmed in the GSBUSCFG0.REQINFO field
* @needs_full_reinit: indicate the controller may not remain power during system
* pm and need full initialization
+ * @keep_host_bus_in_s2idle: indicate the controller, its PHYs and its power
+ * domain stay powered across suspend-to-idle when the core
+ * keeps them on, so a suspended host bus can be kept
+ * instead of being torn down. Set it only if the USB power
+ * domain, if there is one, stays on in suspend-to-idle for
+ * a device on the awake path (GENPD_FLAG_ACTIVE_WAKEUP)
*/
struct dwc3_properties {
u32 gsbuscfg0_reqinfo;
unsigned needs_full_reinit:1;
+ unsigned keep_host_bus_in_s2idle:1;
};
#define DWC3_DEFAULT_PROPERTIES ((struct dwc3_properties){ \
--
2.55.0