Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
* [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P
@ 2026-11-23 10:47 Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 01/11] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths Faisal Hassan
                   ` (10 more replies)
  0 siblings, 11 replies; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan

On Qualcomm automotive SoCs such as SA8255P, the USB controller runs in
a Linux VM while the platform resources that the controller depends on
(clocks, interconnects, resets, regulators and the GDSC) are owned and
sequenced by firmware running in a separate VM:

    +----------------+          SCMI          +------------------+
    |    Linux VM    |  <------------------>  |    Firmware VM   |
    |                |                        |                  |
    | dwc3-qcom.c    |                        | clocks           |
    |  "power" PD    |----------------------->| interconnects    |
    |  "bus"   PD    |----------------------->| resets           |
    |                |                        | regulators/GDSC  |
    +----------------+                        +------------------+

Linux has no direct access to these resources; it can only vote for
two abstracted power domains exposed over the SCMI power-domain
protocol:

  - "power": gates the power supply (GDSC) to the USB controller
  - "bus":   gates the clocks and interconnects used for data transfer

Register accesses through the controller require "power" to be voted
on; "bus" additionally requires "power". The vote policy implemented
in this series is:

  - Enable order: power, then bus
  - Disable order: bus, then power
  - Runtime suspend/resume vote only "bus" -- "power" stays on so that
    accesses that can legitimately happen while runtime suspended
    keep working.
  - System suspend/resume vote both domains.

The two domains are attached with PD_FLAG_NO_DEV_LINK because runtime
suspend and system suspend require different supplier states for the
same consumer, which a plain device-link cannot express; the driver
manages the runtime PM references for each attached domain explicitly
instead.

SA8255P also needs platform-specific handling on top of this. Automotive
platform requirements call for powering down the controller's GDSC and
entering VDDmin on the APPS side during system suspend, so the
controller loses all of its state, including the Qscratch programming,
regardless of whether wakeup is enabled. Runtime suspend does not remove
power. System resume therefore has to:

  - reset the controller and have dwc3 core reinitialize it
    (needs_full_reinit),
  - reset the xHC, using the existing XHCI_RESET_ON_RESUME quirk, which
    dwc3 can now request through a device property, and
  - restore the VBUS override when the controller is not in host mode.

Dependencies: this series is based on usb-next plus
"usb: dwc3: qcom: Add support to skip phy management by USB core" [2]
from Krishna Kurapati (Acked-by: Thinh Nguyen, not yet applied), which
introduces the skip_phy_init property and the property array size used
here, so that patch needs to be applied first.

The PIPE_UTMI_CLK_SEL restore that earlier versions carried is dropped
in favour of "usb: dwc3: qcom: Restore UTMI PIPE clock on resume" [3]
from Filippo Falezza, which is still under review. That restore has to
run after the controller reset added in patch 7, as the reset returns
Qscratch to its defaults.

Patch overview:

  Patch 1: Refactor dwc3_qcom_suspend()/dwc3_qcom_resume() to take a
           pm_message_t instead of a bool, so the runtime-PM vs
           system-PM path can be told apart with PMSG_IS_AUTO(), which
           later patches rely on.
  Patch 2: Disarm the wakeup interrupts when system suspend runs
           without wakeup on a runtime-suspended host, as they would
           otherwise stay armed as wakeup sources.
  Patch 3: Track whether the wakeup interrupts are armed so enable and
           disable stay balanced across runtime and system PM, and
           stay disarmed if resume fails.
  Patch 4: New devicetree binding, qcom,sa8255p-dwc3.yaml, requiring
           "power"/"bus" power-domains and the USB PHYs for
           firmware-managed platforms.
  Patch 5: Teach xhci-plat to set XHCI_RESET_ON_RESUME from a device
           property.
  Patch 6: Add xhci_reset_on_resume to struct dwc3_properties and
           forward it to xhci-plat.
  Patch 7: Recover the controller after power loss in system suspend:
           reset it on system resume, set needs_full_reinit and
           xhci_reset_on_resume, and skip direct_complete so the
           resume callback always runs. Replaces broken_suspend with
           power_lost_in_suspend.
  Patch 8: Restore the VBUS override after system resume.
  Patch 9: Assert the controller reset on remove and probe failure.
  Patch 10: Firmware-managed "power"/"bus" domain voting for SA8255P,
           wired into probe/remove/suspend/resume, with the probe
           error paths and the system-suspend-after-runtime-suspend
           case keeping the votes balanced.
  Patch 11: Enable the VBUS override at probe when the default role is
           peripheral.

Testing:

  Tested on SA8255P Ride, with usb_0 in peripheral mode and usb_1 in
  host mode:
  - usb_1: runtime suspend on device disconnect and resume on connect,
    system suspend and resume with the controller active and while
    runtime suspended, and 20x system suspend/resume
  - usb_0: runtime suspend after unbinding the UDC, system suspend and
    resume with the gadget bound and while runtime suspended (the host
    re-enumerates the gadget), and 15x UDC unbind/bind

  System suspend was run with pm_test=platform, so the SoC did not lose
  power. Recovery after a real power loss and remote wakeup from system
  suspend were not tested.

Changes in v5:
  - Patch 1: moved to the start of the series; carries Acked-by from
    Thinh and Reviewed-by from Krishna.
  - Patch 2: new; disarm the wakeup interrupts in system suspend when
    the device is not wakeup capable. [Peter]
  - Patch 3: now follows patches 1 and 2. [Peter]
  - Patch 4: no change; added Reviewed-by from Krzysztof.
  - Patch 5: no change; added Reviewed-by from Peter.
  - Patches 6-8: the v4 broken-suspend patch is split into the dwc3
    xHCI-reset plumbing, the power-loss recovery (broken_suspend is
    renamed power_lost_in_suspend, and the PIPE_UTMI_CLK_SEL restore is
    dropped, see above) and the VBUS override restore. [Peter]
  - Patch 9: new. The controller reset on remove and probe failure was
    part of the firmware-managed patch and now applies to all
    platforms. [Peter]
  - Patch 10: attach the domains with devm_pm_domain_attach_list(), hide
    the firmware-managed handling behind the resource enable/disable
    helpers, return early from dwc3_qcom_interconnect_init(), and index
    the domains with an enum. [Peter]
  - Patch 11: program the VBUS override once, after the initial role
    has been determined, instead of from the role-specific branches.
    [Peter]
  - Link to v4: https://lore.kernel.org/all/cover.1793212717.git.faisal.hassan@oss.qualcomm.com/

Changes in v4:
  - Patch 3: addressed Krzysztof's review of the binding. [Krzysztof]
    - Fixed the interrupts to exactly six, with the names listed in the
      schema, instead of a variable count.
    - Fixed phys to two entries, named usb2-phy and usb3-phy, and made
      phys and phy-names required.
    - Dropped the redundant minItems from power-domains and the
      explicit "clocks/interconnects: false" properties.
    - Kept "bus" as the second power domain name. Unlike the "perf"
      domains used by other sa8255 bindings, which are SCMI performance
      protocol domains with OPP levels, it is a plain SCMI power domain
      that is only switched on and off. Noted this in the description.
  - Updated the patch 3 commit message to match the binding. Rebased on
    the latest usb-next; no other changes.
  - Link to v3: https://lore.kernel.org/all/20261010053246.2991984-1-faisal.hassan@oss.qualcomm.com/

Changes in v3:
  - Dropped the software node used to pass xhci-reset-on-resume from
    dwc3-qcom to the dwc3 core, together with its probe/remove
    handling. The flag is now a field in struct dwc3_properties
    (xhci_reset_on_resume), set through the glue driver's probe data
    and forwarded to xhci-plat by dwc3 host.c. This avoids the software
    node lifetime problems that led to the revert of the earlier
    approach. The old patch 5 is merged into the broken-suspend patch.
    [Thinh]
  - Renamed the flag to xhci_reset_on_resume and placed it with the
    other quirk bits in struct dwc3. [Thinh]
  - Depend on Krishna's skip-phy patch [2]; the property array in dwc3
    host.c now has 9 slots (8 properties plus the terminator) to cover
    all quirks that can be set together.
  - Patch 1: changed approach. Instead of re-enabling the wakeup
    interrupts when resume fails, track whether they are armed
    (wakeup_irqs_armed) so enable/disable are idempotent, and always
    disarm them on resume, not only for host mode with wakeup enabled.
    On a failed resume they stay disarmed, since a level-triggered
    wakeup line could otherwise keep firing.
  - Patch 2: dropped the wakeup value derived from the PM message in
    the resume path, as patch 1 now disarms the interrupts
    unconditionally.
  - Patch 3: interrupts were minItems 1/maxItems 6 and are now
    minItems 5 with the names listed in the schema; added dma-coherent;
    dropped the free-form descriptions of power-domains,
    power-domain-names and resets.
  - Patch 5: also set needs_full_reinit so dwc3 core re-initializes the
    controller on system resume even in host mode with wakeup enabled;
    restore Qscratch (PIPE_UTMI_CLK_SEL, VBUS_VALID) on every system
    resume rather than depending on wakeup, only forcing VBUS_VALID
    outside host mode, and never on runtime resume; skip
    dwc3_pm_prepare() so the resume callback always runs.
  - Patch 6: dwc3_qcom_domains_put() no longer returns an error: the
    runtime PM usage count is dropped even when put_sync() fails, so
    failures are only warned about and cannot unbalance the next vote.
    System suspend of a runtime-suspended device now also drops the
    "power" vote that runtime suspend keeps, so system resume stays
    balanced. Probe error paths now assert the reset again. The
    remove path is simplified accordingly.
  - Patch 7: new.
  - Link to v2: https://lore.kernel.org/all/20260903153827.3463313-1-faisal.hassan@oss.qualcomm.com/

Changes in v2:
  - Reworked the resource model from OPP-based performance-state
    voting to plain power-domain ON/OFF voting via "power" and "bus"
    domains, addressing Bjorn's objection that OPP levels conflate
    performance-state selection with power-state signaling. [Bjorn]
  - Documented the PD_FLAG_NO_DEV_LINK rationale (asymmetric runtime
    suspend vs system suspend supplier state) in the firmware-managed
    patch.
  - Validate the number of attached domains against what was
    requested instead of assuming attach always returns exactly two.
  - Fixed an unwind bug where a "bus" domain enable failure during
    probe would return without dropping the "power" domain vote.
  - Added the new qcom,sa8255p-dwc3.yaml binding.
  - Terminated the broken-suspend software node's property array and
    fixed a bug where the software-property walk in dwc3 core did not
    continue past the first match.
  - Fixed dwc3_qcom_resume()'s broken-suspend reset to only fire on
    system resume, not runtime resume.
  - Link to v1: https://lore.kernel.org/r/20251127-controller_scmi_upstream-v1-0-38bcca513c28@oss.qualcomm.com

[1] v2: https://lore.kernel.org/all/20260903153827.3463313-1-faisal.hassan@oss.qualcomm.com/
[2] https://lore.kernel.org/all/20260914-xhci-skip-phy-init-v1-1-9c46b31a5a39@oss.qualcomm.com/
[3] https://lore.kernel.org/all/20261027-dwc3-utmi-resume-v1-1-ca9f0aa65783@gmail.com/

Faisal Hassan (11):
  usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths
  usb: dwc3: qcom: Disarm wakeup IRQs on system suspend without wakeup
  usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed
    resume
  dt-bindings: usb: Add qcom,sa8255p-dwc3 for firmware-managed resources
  usb: host: xhci-plat: Support XHCI_RESET_ON_RESUME via device property
  usb: dwc3: Support resetting the xHCI host on system resume
  usb: dwc3: qcom: Recover controller state after power loss in system
    suspend
  usb: dwc3: qcom: Restore VBUS override after system resume
  usb: dwc3: qcom: Assert controller reset on remove and probe failure
  usb: dwc3: qcom: Support firmware-managed resource states for power
    management
  usb: dwc3: qcom: Enable VBUS override at probe for default peripheral
    role

 .../bindings/usb/qcom,sa8255p-dwc3.yaml       | 114 ++++++
 drivers/usb/dwc3/core.c                       |   3 +
 drivers/usb/dwc3/core.h                       |   3 +
 drivers/usb/dwc3/dwc3-qcom.c                  | 355 ++++++++++++++++--
 drivers/usb/dwc3/glue.h                       |   2 +
 drivers/usb/dwc3/host.c                       |   5 +-
 drivers/usb/host/xhci-plat.c                  |   3 +
 7 files changed, 453 insertions(+), 32 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml

-- 
2.34.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v5 01/11] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26  7:40   ` Peter Chen
  2026-11-23 10:47 ` [PATCH v5 02/11] usb: dwc3: qcom: Disarm wakeup IRQs on system suspend without wakeup Faisal Hassan
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan,
	Sriram Dash

The dwc3_qcom_suspend() and dwc3_qcom_resume() functions
handle both system PM and runtime PM paths but cannot
differentiate between them, preventing distinct power
management strategies.

Refactor suspend/resume functions to accept pm_message_t
instead of boolean wakeup flags. Use PMSG_IS_AUTO()
to identify runtime PM (PMSG_AUTO_SUSPEND/RESUME) versus
system PM (PMSG_SUSPEND/RESUME) paths.

Preserve existing wakeup behavior: always enable wakeup
for runtime suspend, check device_may_wakeup() for system
suspend.

Follow dwc3/core.c pattern to enable future per-path
strategies like differentiated power states.

Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Reviewed-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index d44f093ac243..7a7225b900b3 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -335,8 +335,18 @@ static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
 		dwc3_qcom_enable_port_interrupts(&qcom->ports[i]);
 }
 
-static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
+/*
+ * For runtime PM, always enable wakeup.
+ * For system PM, check device wakeup capability.
+ */
+static bool dwc3_qcom_wakeup_enabled(struct dwc3_qcom *qcom, pm_message_t msg)
+{
+	return PMSG_IS_AUTO(msg) || device_may_wakeup(qcom->dev);
+}
+
+static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
 {
+	bool wakeup = dwc3_qcom_wakeup_enabled(qcom, msg);
 	u32 val;
 	int i, ret;
 
@@ -369,8 +379,9 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
 	return 0;
 }
 
-static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)
+static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
 {
+	bool wakeup = dwc3_qcom_wakeup_enabled(qcom, msg);
 	int ret;
 	int i;
 
@@ -750,14 +761,13 @@ static int dwc3_qcom_pm_suspend(struct device *dev)
 {
 	struct dwc3 *dwc = dev_get_drvdata(dev);
 	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
-	bool wakeup = device_may_wakeup(dev);
 	int ret;
 
 	ret = dwc3_pm_suspend(&qcom->dwc);
 	if (ret)
 		return ret;
 
-	ret = dwc3_qcom_suspend(qcom, wakeup);
+	ret = dwc3_qcom_suspend(qcom, PMSG_SUSPEND);
 	if (ret)
 		return ret;
 
@@ -770,10 +780,9 @@ static int dwc3_qcom_pm_resume(struct device *dev)
 {
 	struct dwc3 *dwc = dev_get_drvdata(dev);
 	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
-	bool wakeup = device_may_wakeup(dev);
 	int ret;
 
-	ret = dwc3_qcom_resume(qcom, wakeup);
+	ret = dwc3_qcom_resume(qcom, PMSG_RESUME);
 	if (ret)
 		return ret;
 
@@ -810,7 +819,7 @@ static int dwc3_qcom_runtime_suspend(struct device *dev)
 	if (ret)
 		return ret;
 
-	return dwc3_qcom_suspend(qcom, true);
+	return dwc3_qcom_suspend(qcom, PMSG_AUTO_SUSPEND);
 }
 
 static int dwc3_qcom_runtime_resume(struct device *dev)
@@ -819,7 +828,7 @@ static int dwc3_qcom_runtime_resume(struct device *dev)
 	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
 	int ret;
 
-	ret = dwc3_qcom_resume(qcom, true);
+	ret = dwc3_qcom_resume(qcom, PMSG_AUTO_RESUME);
 	if (ret)
 		return ret;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 02/11] usb: dwc3: qcom: Disarm wakeup IRQs on system suspend without wakeup
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 01/11] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26  7:44   ` Peter Chen
  2026-11-23 10:47 ` [PATCH v5 03/11] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume Faisal Hassan
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan

Runtime suspend always arms the wakeup interrupts in host mode, even if
the device is not wakeup capable. If the controller is still runtime
suspended when system suspend runs without wakeup enabled, the
interrupts stay armed as wakeup sources, so they can still wake the
system. System resume does not disarm them either, as it only does so
when wakeup is enabled, so they remain armed after resume and the next
runtime suspend arms them a second time.

Disarm them in system suspend when the controller is already runtime
suspended and wakeup is not enabled, so the state matches what a system
suspend without a preceding runtime suspend would have left.

Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 7a7225b900b3..18db19cf2065 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -350,8 +350,16 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
 	u32 val;
 	int i, ret;
 
-	if (qcom->is_suspended)
+	if (qcom->is_suspended) {
+		/*
+		 * Runtime suspend arms the wakeup interrupts in host mode
+		 * regardless of the device wakeup setting. If system suspend
+		 * runs without wakeup, disarm them here, as resume will not.
+		 */
+		if (dwc3_qcom_is_host(qcom) && !wakeup)
+			dwc3_qcom_disable_interrupts(qcom);
 		return 0;
+	}
 
 	for (i = 0; i < qcom->num_ports; i++) {
 		val = readl(qcom->qscratch_base + pwr_evnt_irq_stat_reg[i]);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 03/11] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 01/11] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 02/11] usb: dwc3: qcom: Disarm wakeup IRQs on system suspend without wakeup Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26  8:37   ` Peter Chen
  2026-11-23 10:47 ` [PATCH v5 04/11] dt-bindings: usb: Add qcom,sa8255p-dwc3 for firmware-managed resources Faisal Hassan
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan

dwc3_qcom_resume() disables the wakeup interrupts before enabling the
clocks. If clk_bulk_prepare_enable() fails, it returns with them
disabled. The next suspend returns early on is_suspended without
re-enabling them, and the next resume disables them again, so every
failed resume leaves the disable depth one level deeper and host-mode
wakeup is lost for good.

Re-enabling them on the error path is not safe either: the
level-triggered ss_phy interrupt can stay asserted, and the handler
can't make progress while the controller is not resumed, so it would
fire continuously.

Track whether the wakeup interrupts are armed and make enabling and
disabling them idempotent. A failed resume now leaves them disarmed and
balanced, and the next suspend arms them again.

Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 18db19cf2065..e7fadad9a4e1 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -81,6 +81,7 @@ struct dwc3_qcom {
 	enum usb_dr_mode	mode;
 	bool			is_suspended;
 	bool			pm_suspended;
+	bool			wakeup_irqs_armed;
 	struct icc_path		*icc_path_ddr;
 	struct icc_path		*icc_path_apps;
 
@@ -323,16 +324,26 @@ static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
 {
 	int i;
 
+	if (!qcom->wakeup_irqs_armed)
+		return;
+
 	for (i = 0; i < qcom->num_ports; i++)
 		dwc3_qcom_disable_port_interrupts(&qcom->ports[i]);
+
+	qcom->wakeup_irqs_armed = false;
 }
 
 static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
 {
 	int i;
 
+	if (qcom->wakeup_irqs_armed)
+		return;
+
 	for (i = 0; i < qcom->num_ports; i++)
 		dwc3_qcom_enable_port_interrupts(&qcom->ports[i]);
+
+	qcom->wakeup_irqs_armed = true;
 }
 
 /*
@@ -396,6 +407,11 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
 	if (!qcom->is_suspended)
 		return 0;
 
+	/*
+	 * If a later step fails, the wakeup interrupts stay disarmed, as a
+	 * level-triggered wakeup line could otherwise keep firing while the
+	 * controller can't be resumed.
+	 */
 	if (dwc3_qcom_is_host(qcom) && wakeup)
 		dwc3_qcom_disable_interrupts(qcom);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 04/11] dt-bindings: usb: Add qcom,sa8255p-dwc3 for firmware-managed resources
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (2 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 03/11] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 05/11] usb: host: xhci-plat: Support XHCI_RESET_ON_RESUME via device property Faisal Hassan
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Wesley Cheng, Faisal Hassan
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Sriram Dash

On Qualcomm automotive SoC sa8255p, platform resources like clocks,
interconnects, resets, regulators and GDSC are abstracted and managed
collectively by firmware.

Add a new binding file for firmware-managed USB controllers where
access to these resources is exposed as two power domains:
- Power domain: Controls power supply (GDSC) to the USB controller
- Bus domain: Controls clocks and interconnects for data transfer

The binding makes power-domains and power-domain-names properties mandatory
for firmware-managed platforms. Clocks and interconnects are managed by
firmware through these power domains and are therefore not described.

Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 .../bindings/usb/qcom,sa8255p-dwc3.yaml       | 114 ++++++++++++++++++
 1 file changed, 114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml

diff --git a/Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml b/Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml
new file mode 100644
index 000000000000..50361fe97c7a
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml
@@ -0,0 +1,114 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/usb/qcom,sa8255p-dwc3.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm SA8255P USB3 Controller with Firmware-Managed Resources
+
+maintainers:
+  - Wesley Cheng <wesley.cheng@oss.qualcomm.com>
+  - Faisal Hassan <faisal.hassan@oss.qualcomm.com>
+
+description:
+  USB controller on Qualcomm SA8255P automotive SoC where platform resources
+  such as clocks, interconnects, resets, regulators and the GDSC are
+  abstracted and managed collectively by firmware through SCMI (System
+  Control and Management Interface).
+
+  Access to these firmware-managed resources is exposed as two power
+  domains, one gating the power supply (GDSC) to the controller, and one
+  gating the clocks and interconnects used for data transfer.
+  Both are SCMI power domains that are only switched on and off, and
+  neither carries performance levels.
+
+properties:
+  compatible:
+    const: qcom,sa8255p-dwc3
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 6
+
+  interrupt-names:
+    items:
+      - const: dwc_usb3
+      - const: pwr_event
+      - const: hs_phy_irq
+      - const: dp_hs_phy_irq
+      - const: dm_hs_phy_irq
+      - const: ss_phy_irq
+
+  power-domains:
+    maxItems: 2
+
+  power-domain-names:
+    items:
+      - const: power
+      - const: bus
+
+  resets:
+    maxItems: 1
+
+  iommus:
+    maxItems: 1
+
+  phys:
+    maxItems: 2
+
+  phy-names:
+    items:
+      - const: usb2-phy
+      - const: usb3-phy
+
+  dma-coherent: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - power-domains
+  - power-domain-names
+  - resets
+  - phys
+  - phy-names
+
+allOf:
+  - $ref: snps,dwc3-common.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    usb@a800000 {
+        compatible = "qcom,sa8255p-dwc3";
+        reg = <0x0a800000 0x10000>;
+
+        interrupts-extended = <&intc GIC_SPI 349 IRQ_TYPE_LEVEL_HIGH>,
+                              <&intc GIC_SPI 352 IRQ_TYPE_LEVEL_HIGH>,
+                              <&intc GIC_SPI 351 IRQ_TYPE_LEVEL_HIGH>,
+                              <&pdc 8 IRQ_TYPE_EDGE_BOTH>,
+                              <&pdc 7 IRQ_TYPE_EDGE_BOTH>,
+                              <&pdc 13 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-names = "dwc_usb3",
+                          "pwr_event",
+                          "hs_phy_irq",
+                          "dp_hs_phy_irq",
+                          "dm_hs_phy_irq",
+                          "ss_phy_irq";
+
+        power-domains = <&scmi_pd 1>, <&scmi_pd 2>;
+        power-domain-names = "power", "bus";
+        resets = <&scmi_rst 0>;
+
+        iommus = <&apps_smmu 0x0a0 0x0>;
+        phys = <&usb_1_hsphy>, <&usb_1_qmpphy>;
+        phy-names = "usb2-phy", "usb3-phy";
+    };
+...
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 05/11] usb: host: xhci-plat: Support XHCI_RESET_ON_RESUME via device property
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (3 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 04/11] dt-bindings: usb: Add qcom,sa8255p-dwc3 for firmware-managed resources Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 06/11] usb: dwc3: Support resetting the xHCI host on system resume Faisal Hassan
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, Mathias Nyman
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan,
	Sriram Dash

When the USB controller loses power during PM suspend (as occurs
on targets like SA8255P that fully power off the controller),
it generates a Host Controller Error (HCE) on resume requiring
full reinitialization. This is handled by the XHCI_RESET_ON_RESUME
quirk (introduced upstream in 8b328f8002bc).

Read the "xhci-reset-on-resume-quirk" device property to set
XHCI_RESET_ON_RESUME. This allows parent drivers (e.g., dwc3)
to enable the quirk via software nodes.

Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>
---
 drivers/usb/host/xhci-plat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 6fd595f81a30..0093ed24ac3f 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -277,6 +277,9 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
 		if (device_property_read_bool(tmpdev, "xhci-skip-phy-init-quirk"))
 			xhci->quirks |= XHCI_SKIP_PHY_INIT;
 
+		if (device_property_read_bool(tmpdev, "xhci-reset-on-resume-quirk"))
+			xhci->quirks |= XHCI_RESET_ON_RESUME;
+
 		device_property_read_u32(tmpdev, "imod-interval-ns",
 					 &xhci->imod_interval);
 		device_property_read_u16(tmpdev, "num-hc-interrupters",
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 06/11] usb: dwc3: Support resetting the xHCI host on system resume
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (4 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 05/11] usb: host: xhci-plat: Support XHCI_RESET_ON_RESUME via device property Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 07/11] usb: dwc3: qcom: Recover controller state after power loss in system suspend Faisal Hassan
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan,
	Sriram Dash

Some platforms power the controller down during system suspend, which
leaves the xHCI host in a state that needs a full reset on resume.
xhci-plat can already be told to do that with the
"xhci-reset-on-resume-quirk" device property, which sets
XHCI_RESET_ON_RESUME.

Add an xhci_reset_on_resume field to struct dwc3_properties so that a
glue driver can request it, and pass it on to the xhci-plat device as
that property when the host is created.

Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/core.c | 3 +++
 drivers/usb/dwc3/core.h | 3 +++
 drivers/usb/dwc3/glue.h | 2 ++
 drivers/usb/dwc3/host.c | 5 ++++-
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index d9f4e4109abb..d782d5ef9c57 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1697,6 +1697,9 @@ static void dwc3_get_software_properties(struct dwc3 *dwc,
 	if (properties->skip_phy_init)
 		dwc->skip_phy_init = true;
 
+	if (properties->xhci_reset_on_resume)
+		dwc->xhci_reset_on_resume = true;
+
 	dwc->gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED;
 
 	if (properties->gsbuscfg0_reqinfo !=
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 1c8d441ea9f8..3cbe4eeb0a5a 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1177,6 +1177,7 @@ struct dwc3_glue_ops {
  *	3	- Reserved
  * @dis_metastability_quirk: set to disable metastability quirk.
  * @dis_split_quirk: set to disable split boundary.
+ * @xhci_reset_on_resume: set to reset the xHCI host controller on system resume.
  * @enable_usb2_transceiver_delay: Set to insert a delay before the
  *			assertion of the TxValid signal during a HS Chirp.
  * @sys_wakeup: set if the device may do system wakeup.
@@ -1433,6 +1434,8 @@ struct dwc3 {
 	unsigned		dis_metastability_quirk:1;
 
 	unsigned		dis_split_quirk:1;
+	unsigned		xhci_reset_on_resume:1;
+
 	unsigned		enable_usb2_transceiver_delay:1;
 	unsigned		async_callbacks:1;
 	unsigned		sys_wakeup:1;
diff --git a/drivers/usb/dwc3/glue.h b/drivers/usb/dwc3/glue.h
index 72c5593e657a..028a4f8a4fac 100644
--- a/drivers/usb/dwc3/glue.h
+++ b/drivers/usb/dwc3/glue.h
@@ -15,11 +15,13 @@
  * @needs_full_reinit: indicate the controller may not remain power during system
  *			pm and need full initialization
  * @skip_phy_init: skip xHCI PHY initialization on host init
+ * @xhci_reset_on_resume: reset the xHCI host controller on system resume
  */
 struct dwc3_properties {
 	u32 gsbuscfg0_reqinfo;
 	unsigned needs_full_reinit:1;
 	unsigned skip_phy_init:1;
+	unsigned xhci_reset_on_resume:1;
 };
 
 #define DWC3_DEFAULT_PROPERTIES ((struct dwc3_properties){		\
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index 3fb8be8be590..a9c81def13c2 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -130,7 +130,7 @@ static int dwc3_host_get_irq(struct dwc3 *dwc)
 
 int dwc3_host_init(struct dwc3 *dwc)
 {
-	struct property_entry	props[7];
+	struct property_entry	props[9];
 	struct platform_device	*xhci;
 	int			ret, irq;
 	int			prop_idx = 0;
@@ -177,6 +177,9 @@ int dwc3_host_init(struct dwc3 *dwc)
 	if (dwc->skip_phy_init)
 		props[prop_idx++] = PROPERTY_ENTRY_BOOL("xhci-skip-phy-init-quirk");
 
+	if (dwc->xhci_reset_on_resume)
+		props[prop_idx++] = PROPERTY_ENTRY_BOOL("xhci-reset-on-resume-quirk");
+
 	/**
 	 * WORKAROUND: dwc3 revisions <=3.00a have a limitation
 	 * where Port Disable command doesn't work.
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 07/11] usb: dwc3: qcom: Recover controller state after power loss in system suspend
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (5 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 06/11] usb: dwc3: Support resetting the xHCI host on system resume Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26  9:52   ` Peter Chen
  2026-11-23 10:47 ` [PATCH v5 08/11] usb: dwc3: qcom: Restore VBUS override after system resume Faisal Hassan
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, Philipp Zabel
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan,
	Sriram Dash

On SA8255P, automotive platform requirements call for powering down the
controller's GDSC and entering VDDmin on the APPS side during system
suspend. The controller therefore loses all of its state across system
suspend, regardless of whether wakeup is enabled. Runtime suspend does
not remove power.

Add a per-compatible flag, power_lost_in_suspend, and use it to recover:

 - Assert and deassert the controller reset on system resume, so the
   controller starts from a known state. Skip this on runtime resume
   as the controller keeps its state there.
 - Set needs_full_reinit, so dwc3 core reinitializes the controller on
   resume, and xhci_reset_on_resume, so the xHCI host is reset as well.
 - Return 0 from .prepare, so the PM core does not apply direct_complete
   to a runtime-suspended device. The system resume callback must always
   run to reset the controller.

This follows dwc3-imx, which also sets needs_full_reinit because the
controller loses power across system suspend.

Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 47 ++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index e7fadad9a4e1..8e8d7e59c6d5 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -68,6 +68,10 @@ struct dwc3_qcom_port {
 	enum usb_device_speed	usb2_speed;
 };
 
+struct dwc3_qcom_priv_data {
+	bool power_lost_in_suspend;
+};
+
 struct dwc3_qcom {
 	struct device		*dev;
 	void __iomem		*qscratch_base;
@@ -86,6 +90,12 @@ struct dwc3_qcom {
 	struct icc_path		*icc_path_apps;
 
 	enum usb_role		current_role;
+
+	bool			power_lost_in_suspend;
+};
+
+static const struct dwc3_qcom_priv_data sa8255p_dwc3_qcom_priv_data = {
+	.power_lost_in_suspend	= true,
 };
 
 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc)
@@ -407,6 +417,23 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
 	if (!qcom->is_suspended)
 		return 0;
 
+	if (qcom->power_lost_in_suspend && !PMSG_IS_AUTO(msg)) {
+		/* Runtime suspend keeps power, so there is no state to recover */
+		ret = reset_control_assert(qcom->resets);
+		if (ret) {
+			dev_err(qcom->dev, "failed to assert resets, err=%d\n", ret);
+			return ret;
+		}
+
+		usleep_range(10, 1000);
+
+		ret = reset_control_deassert(qcom->resets);
+		if (ret) {
+			dev_err(qcom->dev, "failed to deassert resets, err=%d\n", ret);
+			return ret;
+		}
+	}
+
 	/*
 	 * If a later step fails, the wakeup interrupts stay disarmed, as a
 	 * level-triggered wakeup line could otherwise keep firing while the
@@ -649,6 +676,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	struct dwc3_qcom	*qcom;
 	struct resource		res;
 	struct resource		*r;
+	const struct dwc3_qcom_priv_data *priv_data;
 	int			ret;
 	bool			ignore_pipe_clk;
 	bool			wakeup_source;
@@ -659,6 +687,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
 	qcom->dev = &pdev->dev;
 
+	priv_data = of_device_get_match_data(dev);
+	if (priv_data)
+		qcom->power_lost_in_suspend = priv_data->power_lost_in_suspend;
+
 	qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
 	if (IS_ERR(qcom->resets)) {
 		return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
@@ -741,6 +773,9 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	probe_data.ignore_clocks_and_resets = true;
 	probe_data.properties = DWC3_DEFAULT_PROPERTIES;
 	probe_data.properties.skip_phy_init = true;
+	/* Controller loses power on system suspend, even with wakeup enabled */
+	probe_data.properties.needs_full_reinit = qcom->power_lost_in_suspend;
+	probe_data.properties.xhci_reset_on_resume = qcom->power_lost_in_suspend;
 	ret = dwc3_core_probe(&probe_data);
 	if (ret)  {
 		ret = dev_err_probe(dev, ret, "failed to register DWC3 Core\n");
@@ -829,6 +864,14 @@ static void dwc3_qcom_complete(struct device *dev)
 static int dwc3_qcom_prepare(struct device *dev)
 {
 	struct dwc3 *dwc = dev_get_drvdata(dev);
+	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
+
+	/*
+	 * Resume must always run to reset the controller, so don't let the
+	 * PM core skip it for a runtime-suspended device (direct_complete).
+	 */
+	if (qcom->power_lost_in_suspend)
+		return 0;
 
 	return dwc3_pm_prepare(dwc);
 }
@@ -873,6 +916,10 @@ static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = {
 };
 
 static const struct of_device_id dwc3_qcom_of_match[] = {
+	{
+		.compatible	= "qcom,sa8255p-dwc3",
+		.data		= &sa8255p_dwc3_qcom_priv_data,
+	},
 	{ .compatible = "qcom,snps-dwc3" },
 	{ }
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 08/11] usb: dwc3: qcom: Restore VBUS override after system resume
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (6 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 07/11] usb: dwc3: qcom: Recover controller state after power loss in system suspend Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26  9:54   ` Peter Chen
  2026-11-23 10:47 ` [PATCH v5 09/11] usb: dwc3: qcom: Assert controller reset on remove and probe failure Faisal Hassan
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan,
	Sriram Dash

The controller reset on system resume returns the Qscratch registers to
their power-on defaults, which clears the VBUS valid override that was
set up for device mode. Without it the PHY does not see VBUS and the
gadget fails to enumerate after resume.

Re-enable the override after resume when the controller is not in host
mode.

Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 8e8d7e59c6d5..50fca06c83d4 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -457,6 +457,14 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
 				  PWR_EVNT_LPM_IN_L2_MASK | PWR_EVNT_LPM_OUT_L2_MASK);
 	}
 
+	/*
+	 * The reset above returned Qscratch to its power-on defaults, so
+	 * restore the VBUS valid override set up for device mode.
+	 */
+	if (qcom->power_lost_in_suspend && !PMSG_IS_AUTO(msg) &&
+	    !dwc3_qcom_is_host(qcom))
+		dwc3_qcom_vbus_override_enable(qcom, true);
+
 	qcom->is_suspended = false;
 
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 09/11] usb: dwc3: qcom: Assert controller reset on remove and probe failure
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (7 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 08/11] usb: dwc3: qcom: Restore VBUS override after system resume Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26  9:56   ` Peter Chen
  2026-11-23 10:47 ` [PATCH v5 10/11] usb: dwc3: qcom: Support firmware-managed resource states for power management Faisal Hassan
  2026-11-23 10:47 ` [PATCH v5 11/11] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role Faisal Hassan
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, Philipp Zabel
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan,
	Shazad Hussain, Sriram Dash

The controller is taken out of reset at probe, but nothing puts it back
into reset when the driver is removed or when probe fails after that
point. The controller is left running when its clocks are gated, and a
later bind starts from whatever state it was left in.

Assert the reset before disabling the clocks on remove and on the probe
error path, so the controller is held in reset while unused.

Co-developed-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
Signed-off-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 50fca06c83d4..61a3e3c38f59 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -804,6 +804,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 remove_core:
 	dwc3_core_remove(&qcom->dwc);
 clk_disable:
+	reset_control_assert(qcom->resets);
 	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
 
 	return ret;
@@ -818,6 +819,7 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
 		return;
 
 	dwc3_core_remove(&qcom->dwc);
+	reset_control_assert(qcom->resets);
 	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
 	dwc3_qcom_interconnect_exit(qcom);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 10/11] usb: dwc3: qcom: Support firmware-managed resource states for power management
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (8 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 09/11] usb: dwc3: qcom: Assert controller reset on remove and probe failure Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26 10:09   ` Peter Chen
  2026-11-23 10:47 ` [PATCH v5 11/11] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role Faisal Hassan
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, Philipp Zabel
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan,
	Shazad Hussain, Sriram Dash

Add support for firmware-managed resource handling in the Qualcomm
DWC3 USB controller driver. On platforms such as SA8255P, controller
resources are abstracted and managed collectively by firmware, and are
exposed to Linux through SCMI-backed power domains.

On SA8255P, resources such as clocks, regulators, resets, TLMM and
interconnects are controlled by firmware. The driver communicates with
firmware through two power domains:

  - "power": controls power supply (GDSC) to the USB controller
  - "bus": controls clocks and interconnects used for data transfer.
    Register accesses through the controller require the "power"
    domain to be enabled.

The clock and interconnect handling in the suspend, resume, probe and
remove paths is moved behind dwc3_qcom_resources_enable() and
dwc3_qcom_resources_disable(). They enable or disable the clocks and
interconnect paths on existing platforms, and vote the two domains on
or off when the resources are firmware-managed. The interconnect paths
are not requested for firmware-managed platforms.

The domains are voted on and off directly through runtime PM, whose
usage counting keeps each domain enabled for as long as it is required;
the driver does not attempt to track or infer any aggregate device power
state, nor does it assume what state firmware or the bootloader left the
domains in before probe.

Runtime suspend/resume vote only the "bus" domain, since the "power"
domain must remain enabled for hardware accesses that can occur while
runtime suspended. System suspend/resume vote both domains.

If system suspend is entered while the device is already runtime
suspended, only the "power" vote is still held, so system suspend
drops just that one. System resume then votes both domains back on,
which keeps the votes balanced across the cycle.

The domains are attached with devm_pm_domain_attach_list() and
PD_FLAG_NO_DEV_LINK, because runtime suspend and system suspend require
different supplier states. Runtime suspend releases only the "bus"
domain while retaining the "power" domain, whereas system suspend
releases both domains. Ordinary device-links would couple both
suppliers to the same consumer runtime PM state and therefore cannot
express the required policy. The driver consequently manages the
runtime PM references for the attached domains explicitly.

pm_runtime_put_sync() drops the domain usage count even when it
returns an error, so failures to vote a domain off are only reported.
Failing suspend on them would leave the driver thinking the votes are
still held and unbalance the next resume/suspend pair.

Enable firmware-managed resource handling for the "qcom,sa8255p-dwc3"
compatible while maintaining backward compatibility with existing
platforms that use direct resource control.

The probe error path now disables the resources through the common
helper, which also disables the interconnect paths. Clear the path
handles when dwc3_qcom_interconnect_init() fails, so the unwind does not
touch handles that were already released or never obtained.

Co-developed-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
Signed-off-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 244 +++++++++++++++++++++++++++++++----
 1 file changed, 222 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 61a3e3c38f59..559de5172e61 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -13,6 +13,7 @@
 #include <linux/kernel.h>
 #include <linux/interconnect.h>
 #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
 #include <linux/phy/phy.h>
 #include <linux/usb/of.h>
 #include <linux/reset.h>
@@ -70,6 +71,7 @@ struct dwc3_qcom_port {
 
 struct dwc3_qcom_priv_data {
 	bool power_lost_in_suspend;
+	bool fw_managed;
 };
 
 struct dwc3_qcom {
@@ -92,10 +94,26 @@ struct dwc3_qcom {
 	enum usb_role		current_role;
 
 	bool			power_lost_in_suspend;
+
+	bool			fw_managed;
+	struct dev_pm_domain_list *pd_list;
+};
+
+/* Firmware-managed power domains, indexed in pd_list->pd_devs[] */
+enum dwc3_qcom_pd {
+	DWC3_QCOM_PD_POWER,
+	DWC3_QCOM_PD_BUS,
+	DWC3_QCOM_NUM_PD,
+};
+
+static const char * const dwc3_qcom_pd_names[] = {
+	[DWC3_QCOM_PD_POWER]	= "power",
+	[DWC3_QCOM_PD_BUS]	= "bus",
 };
 
 static const struct dwc3_qcom_priv_data sa8255p_dwc3_qcom_priv_data = {
 	.power_lost_in_suspend	= true,
+	.fw_managed		= true,
 };
 
 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc)
@@ -169,6 +187,164 @@ static int dwc3_qcom_interconnect_disable(struct dwc3_qcom *qcom)
 	return ret;
 }
 
+/*
+ * Firmware-managed resources
+ *
+ * Firmware owns the clocks, interconnects and GDSC and exposes them as two
+ * power domains:
+ * - DWC3_QCOM_PD_POWER ("power"): the GDSC supplying the controller
+ * - DWC3_QCOM_PD_BUS ("bus"): clocks and interconnects, which also need
+ *   "power" to be on for register accesses to succeed
+ *
+ * The domains are voted directly from the PM callbacks. The driver does not
+ * mirror the aggregate state, as the real state lives in firmware.
+ */
+
+/**
+ * dwc3_qcom_domain_attach() - Attach power domains
+ * @qcom: Pointer to the dwc3_qcom structure
+ *
+ * Attaches power domains for firmware managed resource handling. The
+ * domains are detached automatically when the driver is unbound.
+ * Returns 0 on success, negative error code on failure.
+ */
+static int dwc3_qcom_domain_attach(struct dwc3_qcom *qcom)
+{
+	struct dev_pm_domain_attach_data pd_data = {
+		/* Runtime and system suspend need different supplier states */
+		.pd_flags	= PD_FLAG_NO_DEV_LINK,
+		.pd_names	= dwc3_qcom_pd_names,
+		.num_pd_names	= DWC3_QCOM_NUM_PD,
+	};
+	struct device *dev = qcom->dev;
+	int ret;
+
+	ret = devm_pm_domain_attach_list(dev, &pd_data, &qcom->pd_list);
+	if (ret != pd_data.num_pd_names) {
+		dev_err(dev, "domain attach failed (%d)\n", ret);
+		return ret < 0 ? ret : -ENODEV;
+	}
+
+	return 0;
+}
+
+/**
+ * dwc3_qcom_power_domain_put() - Vote the power domain off
+ * @qcom: Pointer to the dwc3_qcom structure
+ *
+ * pm_runtime_put_sync() drops the usage count even on error, so only warn.
+ * Failing the caller would make it think the vote is still held and
+ * unbalance the next get/put pair.
+ */
+static void dwc3_qcom_power_domain_put(struct dwc3_qcom *qcom)
+{
+	int ret;
+
+	ret = pm_runtime_put_sync(qcom->pd_list->pd_devs[DWC3_QCOM_PD_POWER]);
+	if (ret < 0)
+		dev_warn(qcom->dev, "failed to disable power domain: %d\n", ret);
+}
+
+/**
+ * dwc3_qcom_domains_get() - Vote the firmware-managed domains on
+ * @qcom: Pointer to the dwc3_qcom structure
+ * @bus_only: If true, leave the power domain untouched and only vote bus
+ *
+ * Each call must be paired with dwc3_qcom_domains_put() using the same
+ * @bus_only. Runtime PM usage counting keeps a domain on for as long as it
+ * is needed, regardless of the state firmware left it in.
+ * Returns 0 on success, negative error code on failure.
+ */
+static int dwc3_qcom_domains_get(struct dwc3_qcom *qcom, bool bus_only)
+{
+	struct device *power_dev = qcom->pd_list->pd_devs[DWC3_QCOM_PD_POWER];
+	struct device *bus_dev = qcom->pd_list->pd_devs[DWC3_QCOM_PD_BUS];
+	int ret;
+
+	if (!bus_only) {
+		ret = pm_runtime_resume_and_get(power_dev);
+		if (ret) {
+			dev_err(qcom->dev, "failed to enable power domain: %d\n", ret);
+			return ret;
+		}
+	}
+
+	ret = pm_runtime_resume_and_get(bus_dev);
+	if (ret) {
+		dev_err(qcom->dev, "failed to enable bus domain: %d\n", ret);
+		if (!bus_only)
+			pm_runtime_put_sync(power_dev);
+		return ret;
+	}
+
+	return 0;
+}
+
+/**
+ * dwc3_qcom_domains_put() - Vote the firmware-managed domains off
+ * @qcom: Pointer to the dwc3_qcom structure
+ * @bus_only: If true, leave the power domain untouched and only vote bus
+ *
+ * Bus is released before power, as bus accesses need power to be on.
+ */
+static void dwc3_qcom_domains_put(struct dwc3_qcom *qcom, bool bus_only)
+{
+	int ret;
+
+	ret = pm_runtime_put_sync(qcom->pd_list->pd_devs[DWC3_QCOM_PD_BUS]);
+	if (ret < 0)
+		dev_warn(qcom->dev, "failed to disable bus domain: %d\n", ret);
+
+	if (!bus_only)
+		dwc3_qcom_power_domain_put(qcom);
+}
+
+/**
+ * dwc3_qcom_resources_enable() - Enable clocks and interconnect, or vote domains on
+ * @qcom: Pointer to the dwc3_qcom structure
+ * @bus_only: Firmware-managed only: leave the power domain untouched
+ *
+ * Returns 0 on success, negative error code on failure.
+ */
+static int dwc3_qcom_resources_enable(struct dwc3_qcom *qcom, bool bus_only)
+{
+	int ret;
+
+	if (qcom->fw_managed)
+		return dwc3_qcom_domains_get(qcom, bus_only);
+
+	ret = clk_bulk_prepare_enable(qcom->num_clocks, qcom->clks);
+	if (ret < 0)
+		return ret;
+
+	ret = dwc3_qcom_interconnect_enable(qcom);
+	if (ret)
+		dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
+
+	return 0;
+}
+
+/**
+ * dwc3_qcom_resources_disable() - Undo dwc3_qcom_resources_enable()
+ * @qcom: Pointer to the dwc3_qcom structure
+ * @bus_only: Firmware-managed only: leave the power domain untouched
+ */
+static void dwc3_qcom_resources_disable(struct dwc3_qcom *qcom, bool bus_only)
+{
+	int ret;
+
+	if (qcom->fw_managed) {
+		dwc3_qcom_domains_put(qcom, bus_only);
+		return;
+	}
+
+	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
+
+	ret = dwc3_qcom_interconnect_disable(qcom);
+	if (ret)
+		dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
+}
+
 /**
  * dwc3_qcom_interconnect_init() - Get interconnect path handles
  * and set bandwidth.
@@ -181,10 +357,16 @@ static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
 	struct device *dev = qcom->dev;
 	int ret;
 
+	/* Interconnects are managed by firmware */
+	if (qcom->fw_managed)
+		return 0;
+
 	qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr");
 	if (IS_ERR(qcom->icc_path_ddr)) {
-		return dev_err_probe(dev, PTR_ERR(qcom->icc_path_ddr),
-				     "failed to get usb-ddr path\n");
+		ret = dev_err_probe(dev, PTR_ERR(qcom->icc_path_ddr),
+				    "failed to get usb-ddr path\n");
+		qcom->icc_path_ddr = NULL;
+		return ret;
 	}
 
 	qcom->icc_path_apps = of_icc_get(dev, "apps-usb");
@@ -219,6 +401,9 @@ static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
 	icc_put(qcom->icc_path_apps);
 put_path_ddr:
 	icc_put(qcom->icc_path_ddr);
+	/* Leave no stale handles for the error unwind to disable */
+	qcom->icc_path_ddr = NULL;
+	qcom->icc_path_apps = NULL;
 	return ret;
 }
 
@@ -369,7 +554,7 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
 {
 	bool wakeup = dwc3_qcom_wakeup_enabled(qcom, msg);
 	u32 val;
-	int i, ret;
+	int i;
 
 	if (qcom->is_suspended) {
 		/*
@@ -379,6 +564,15 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
 		 */
 		if (dwc3_qcom_is_host(qcom) && !wakeup)
 			dwc3_qcom_disable_interrupts(qcom);
+
+		/*
+		 * Runtime suspend dropped only the bus domain. System suspend
+		 * must drop the power domain too, so that system resume, which
+		 * votes both domains back on, stays balanced.
+		 */
+		if (qcom->fw_managed && !PMSG_IS_AUTO(msg))
+			dwc3_qcom_power_domain_put(qcom);
+
 		return 0;
 	}
 
@@ -387,11 +581,9 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
 		if (!(val & PWR_EVNT_LPM_IN_L2_MASK))
 			dev_err(qcom->dev, "port-%d HS-PHY not in L2\n", i + 1);
 	}
-	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
 
-	ret = dwc3_qcom_interconnect_disable(qcom);
-	if (ret)
-		dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
+	/* Runtime suspend keeps power voted on; system suspend drops both. */
+	dwc3_qcom_resources_disable(qcom, PMSG_IS_AUTO(msg));
 
 	/*
 	 * The role is stable during suspend as role switching is done from a
@@ -442,13 +634,10 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
 	if (dwc3_qcom_is_host(qcom) && wakeup)
 		dwc3_qcom_disable_interrupts(qcom);
 
-	ret = clk_bulk_prepare_enable(qcom->num_clocks, qcom->clks);
-	if (ret < 0)
-		return ret;
-
-	ret = dwc3_qcom_interconnect_enable(qcom);
+	/* Runtime resume re-votes bus only; system resume votes both. */
+	ret = dwc3_qcom_resources_enable(qcom, PMSG_IS_AUTO(msg));
 	if (ret)
-		dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
+		return ret;
 
 	/* Clear existing events from PHY related to L2 in/out */
 	for (i = 0; i < qcom->num_ports; i++) {
@@ -696,8 +885,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	qcom->dev = &pdev->dev;
 
 	priv_data = of_device_get_match_data(dev);
-	if (priv_data)
+	if (priv_data) {
 		qcom->power_lost_in_suspend = priv_data->power_lost_in_suspend;
+		qcom->fw_managed = priv_data->fw_managed;
+	}
 
 	qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
 	if (IS_ERR(qcom->resets)) {
@@ -705,10 +896,16 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 				     "failed to get resets\n");
 	}
 
-	ret = devm_clk_bulk_get_all(&pdev->dev, &qcom->clks);
-	if (ret < 0)
-		return dev_err_probe(dev, ret, "failed to get clocks\n");
-	qcom->num_clocks = ret;
+	if (!qcom->fw_managed) {
+		ret = devm_clk_bulk_get_all(&pdev->dev, &qcom->clks);
+		if (ret < 0)
+			return dev_err_probe(dev, ret, "failed to get clocks\n");
+		qcom->num_clocks = ret;
+	} else {
+		ret = dwc3_qcom_domain_attach(qcom);
+		if (ret)
+			return ret;
+	}
 
 	ret = reset_control_assert(qcom->resets);
 	if (ret) {
@@ -724,9 +921,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = clk_bulk_prepare_enable(qcom->num_clocks, qcom->clks);
-	if (ret < 0)
+	/* Takes the votes whatever state firmware or the bootloader left */
+	ret = dwc3_qcom_resources_enable(qcom, false);
+	if (ret) {
+		reset_control_assert(qcom->resets);
 		return ret;
+	}
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!r) {
@@ -805,7 +1005,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	dwc3_core_remove(&qcom->dwc);
 clk_disable:
 	reset_control_assert(qcom->resets);
-	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
+	dwc3_qcom_resources_disable(qcom, false);
 
 	return ret;
 }
@@ -820,7 +1020,7 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
 
 	dwc3_core_remove(&qcom->dwc);
 	reset_control_assert(qcom->resets);
-	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
+	dwc3_qcom_resources_disable(qcom, false);
 	dwc3_qcom_interconnect_exit(qcom);
 
 	pm_runtime_put_noidle(qcom->dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v5 11/11] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role
  2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
                   ` (9 preceding siblings ...)
  2026-11-23 10:47 ` [PATCH v5 10/11] usb: dwc3: qcom: Support firmware-managed resource states for power management Faisal Hassan
@ 2026-11-23 10:47 ` Faisal Hassan
  2026-11-26 10:12   ` Peter Chen
  10 siblings, 1 reply; 20+ messages in thread
From: Faisal Hassan @ 2026-11-23 10:47 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-arm-msm, linux-kernel, devicetree,
	krishna.kurapati, peter.chen, krzysztof.kozlowski, Faisal Hassan

When the controller is in OTG mode with usb-role-switch and
role-switch-default-mode set to peripheral, the role notifier never sees
a transition at probe, so the QSCRATCH VBUS override is not programmed
and the device never gets a session-valid indication.

Enable the VBUS override once at probe, after the initial role has been
determined, whenever that role is USB_ROLE_DEVICE. This also covers the
dr_mode = "peripheral" case, which previously programmed the override on
its own.

Validated on SA8255P with an HS host attached: 20 unbind/bind and 20
suspend/resume iterations completed with no failures.

Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 559de5172e61..22b6c7ca0297 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -964,7 +964,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 		qcom->current_role = USB_ROLE_HOST;
 	} else if (qcom->mode == USB_DR_MODE_PERIPHERAL) {
 		qcom->current_role = USB_ROLE_DEVICE;
-		dwc3_qcom_vbus_override_enable(qcom, true);
 	} else {
 		if ((device_property_read_bool(dev, "usb-role-switch")) &&
 		    (usb_get_role_switch_default_mode(dev) == USB_DR_MODE_HOST))
@@ -973,6 +972,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 			qcom->current_role = USB_ROLE_DEVICE;
 	}
 
+	/* Force the VBUS valid indication to the PHYs in device mode */
+	if (qcom->current_role == USB_ROLE_DEVICE)
+		dwc3_qcom_vbus_override_enable(qcom, true);
+
 	qcom->dwc.glue_ops = &dwc3_qcom_glue_ops;
 
 	qcom->dwc.dev = dev;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 01/11] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths
  2026-11-23 10:47 ` [PATCH v5 01/11] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths Faisal Hassan
@ 2026-11-26  7:40   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26  7:40 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, linux-usb, linux-arm-msm, linux-kernel,
	devicetree, krishna.kurapati, krzysztof.kozlowski, Sriram Dash

On 26-11-23 16:17:16, Faisal Hassan wrote:
> The dwc3_qcom_suspend() and dwc3_qcom_resume() functions
> handle both system PM and runtime PM paths but cannot
> differentiate between them, preventing distinct power
> management strategies.
> 
> Refactor suspend/resume functions to accept pm_message_t
> instead of boolean wakeup flags. Use PMSG_IS_AUTO()
> to identify runtime PM (PMSG_AUTO_SUSPEND/RESUME) versus
> system PM (PMSG_SUSPEND/RESUME) paths.
> 
> Preserve existing wakeup behavior: always enable wakeup
> for runtime suspend, check device_may_wakeup() for system
> suspend.
> 
> Follow dwc3/core.c pattern to enable future per-path
> strategies like differentiated power states.
> 
> Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
> Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> Reviewed-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>

Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>

Peter
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 25 +++++++++++++++++--------
>  1 file changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index d44f093ac243..7a7225b900b3 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -335,8 +335,18 @@ static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
>  		dwc3_qcom_enable_port_interrupts(&qcom->ports[i]);
>  }
>  
> -static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
> +/*
> + * For runtime PM, always enable wakeup.
> + * For system PM, check device wakeup capability.
> + */
> +static bool dwc3_qcom_wakeup_enabled(struct dwc3_qcom *qcom, pm_message_t msg)
> +{
> +	return PMSG_IS_AUTO(msg) || device_may_wakeup(qcom->dev);
> +}
> +
> +static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
>  {
> +	bool wakeup = dwc3_qcom_wakeup_enabled(qcom, msg);
>  	u32 val;
>  	int i, ret;
>  
> @@ -369,8 +379,9 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
>  	return 0;
>  }
>  
> -static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)
> +static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
>  {
> +	bool wakeup = dwc3_qcom_wakeup_enabled(qcom, msg);
>  	int ret;
>  	int i;
>  
> @@ -750,14 +761,13 @@ static int dwc3_qcom_pm_suspend(struct device *dev)
>  {
>  	struct dwc3 *dwc = dev_get_drvdata(dev);
>  	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
> -	bool wakeup = device_may_wakeup(dev);
>  	int ret;
>  
>  	ret = dwc3_pm_suspend(&qcom->dwc);
>  	if (ret)
>  		return ret;
>  
> -	ret = dwc3_qcom_suspend(qcom, wakeup);
> +	ret = dwc3_qcom_suspend(qcom, PMSG_SUSPEND);
>  	if (ret)
>  		return ret;
>  
> @@ -770,10 +780,9 @@ static int dwc3_qcom_pm_resume(struct device *dev)
>  {
>  	struct dwc3 *dwc = dev_get_drvdata(dev);
>  	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
> -	bool wakeup = device_may_wakeup(dev);
>  	int ret;
>  
> -	ret = dwc3_qcom_resume(qcom, wakeup);
> +	ret = dwc3_qcom_resume(qcom, PMSG_RESUME);
>  	if (ret)
>  		return ret;
>  
> @@ -810,7 +819,7 @@ static int dwc3_qcom_runtime_suspend(struct device *dev)
>  	if (ret)
>  		return ret;
>  
> -	return dwc3_qcom_suspend(qcom, true);
> +	return dwc3_qcom_suspend(qcom, PMSG_AUTO_SUSPEND);
>  }
>  
>  static int dwc3_qcom_runtime_resume(struct device *dev)
> @@ -819,7 +828,7 @@ static int dwc3_qcom_runtime_resume(struct device *dev)
>  	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
>  	int ret;
>  
> -	ret = dwc3_qcom_resume(qcom, true);
> +	ret = dwc3_qcom_resume(qcom, PMSG_AUTO_RESUME);
>  	if (ret)
>  		return ret;
>  
> -- 
> 2.34.1
> 

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 02/11] usb: dwc3: qcom: Disarm wakeup IRQs on system suspend without wakeup
  2026-11-23 10:47 ` [PATCH v5 02/11] usb: dwc3: qcom: Disarm wakeup IRQs on system suspend without wakeup Faisal Hassan
@ 2026-11-26  7:44   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26  7:44 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, linux-usb, linux-arm-msm, linux-kernel,
	devicetree, krishna.kurapati, krzysztof.kozlowski

On 26-11-23 16:17:17, Faisal Hassan wrote:
> Runtime suspend always arms the wakeup interrupts in host mode, even if
> the device is not wakeup capable. If the controller is still runtime
> suspended when system suspend runs without wakeup enabled, the
> interrupts stay armed as wakeup sources, so they can still wake the
> system. System resume does not disarm them either, as it only does so
> when wakeup is enabled, so they remain armed after resume and the next
> runtime suspend arms them a second time.
> 
> Disarm them in system suspend when the controller is already runtime
> suspended and wakeup is not enabled, so the state matches what a system
> suspend without a preceding runtime suspend would have left.
> 
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>

Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>

Peter
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 7a7225b900b3..18db19cf2065 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -350,8 +350,16 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
>  	u32 val;
>  	int i, ret;
>  
> -	if (qcom->is_suspended)
> +	if (qcom->is_suspended) {
> +		/*
> +		 * Runtime suspend arms the wakeup interrupts in host mode
> +		 * regardless of the device wakeup setting. If system suspend
> +		 * runs without wakeup, disarm them here, as resume will not.
> +		 */
> +		if (dwc3_qcom_is_host(qcom) && !wakeup)
> +			dwc3_qcom_disable_interrupts(qcom);
>  		return 0;
> +	}
>  
>  	for (i = 0; i < qcom->num_ports; i++) {
>  		val = readl(qcom->qscratch_base + pwr_evnt_irq_stat_reg[i]);
> -- 
> 2.34.1
> 

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 03/11] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume
  2026-11-23 10:47 ` [PATCH v5 03/11] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume Faisal Hassan
@ 2026-11-26  8:37   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26  8:37 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, linux-usb, linux-arm-msm, linux-kernel,
	devicetree, krishna.kurapati, krzysztof.kozlowski

On 26-11-23 16:17:18, Faisal Hassan wrote:
> dwc3_qcom_resume() disables the wakeup interrupts before enabling the
> clocks. If clk_bulk_prepare_enable() fails, it returns with them
> disabled. The next suspend returns early

Have you run out this sequence at hardware? I find the dwc3 core suspend
(dwc3_pm_suspend) has not guarded for is_suspended, it should run into
some problems, eg visiting register with clocks off, etc. It is predate
issue, not related to your patch.

> on is_suspended without
> re-enabling them, and the next resume disables them again, so every
> failed resume leaves the disable depth one level deeper and host-mode
> wakeup is lost for good.
> 
> Re-enabling them on the error path is not safe either: the
> level-triggered ss_phy interrupt can stay asserted, and the handler
> can't make progress while the controller is not resumed, so it would
> fire continuously.
> 
> Track whether the wakeup interrupts are armed and make enabling and
> disabling them idempotent. A failed resume now leaves them disarmed and
> balanced, and the next suspend arms them again.
> 
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>

Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>

Peter
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 18db19cf2065..e7fadad9a4e1 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -81,6 +81,7 @@ struct dwc3_qcom {
>  	enum usb_dr_mode	mode;
>  	bool			is_suspended;
>  	bool			pm_suspended;
> +	bool			wakeup_irqs_armed;
>  	struct icc_path		*icc_path_ddr;
>  	struct icc_path		*icc_path_apps;
>  
> @@ -323,16 +324,26 @@ static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
>  {
>  	int i;
>  
> +	if (!qcom->wakeup_irqs_armed)
> +		return;
> +
>  	for (i = 0; i < qcom->num_ports; i++)
>  		dwc3_qcom_disable_port_interrupts(&qcom->ports[i]);
> +
> +	qcom->wakeup_irqs_armed = false;
>  }
>  
>  static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
>  {
>  	int i;
>  
> +	if (qcom->wakeup_irqs_armed)
> +		return;
> +
>  	for (i = 0; i < qcom->num_ports; i++)
>  		dwc3_qcom_enable_port_interrupts(&qcom->ports[i]);
> +
> +	qcom->wakeup_irqs_armed = true;
>  }
>  
>  /*
> @@ -396,6 +407,11 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
>  	if (!qcom->is_suspended)
>  		return 0;
>  
> +	/*
> +	 * If a later step fails, the wakeup interrupts stay disarmed, as a
> +	 * level-triggered wakeup line could otherwise keep firing while the
> +	 * controller can't be resumed.
> +	 */
>  	if (dwc3_qcom_is_host(qcom) && wakeup)
>  		dwc3_qcom_disable_interrupts(qcom);
>  
> -- 
> 2.34.1
> 

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 07/11] usb: dwc3: qcom: Recover controller state after power loss in system suspend
  2026-11-23 10:47 ` [PATCH v5 07/11] usb: dwc3: qcom: Recover controller state after power loss in system suspend Faisal Hassan
@ 2026-11-26  9:52   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26  9:52 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, Philipp Zabel, linux-usb, linux-arm-msm,
	linux-kernel, devicetree, krishna.kurapati, krzysztof.kozlowski,
	Sriram Dash

On 26-11-23 16:17:22, Faisal Hassan wrote:
> On SA8255P, automotive platform requirements call for powering down the
> controller's GDSC and entering VDDmin on the APPS side during system
> suspend. The controller therefore loses all of its state across system
> suspend, regardless of whether wakeup is enabled. Runtime suspend does
> not remove power.
> 
> Add a per-compatible flag, power_lost_in_suspend, and use it to recover:
> 
>  - Assert and deassert the controller reset on system resume, so the
>    controller starts from a known state. Skip this on runtime resume
>    as the controller keeps its state there.
>  - Set needs_full_reinit, so dwc3 core reinitializes the controller on
>    resume, and xhci_reset_on_resume, so the xHCI host is reset as well.
>  - Return 0 from .prepare, so the PM core does not apply direct_complete
>    to a runtime-suspended device. The system resume callback must always
>    run to reset the controller.
> 
> This follows dwc3-imx, which also sets needs_full_reinit because the
> controller loses power across system suspend.
> 
> Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 47 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index e7fadad9a4e1..8e8d7e59c6d5 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -68,6 +68,10 @@ struct dwc3_qcom_port {
>  	enum usb_device_speed	usb2_speed;
>  };
>  
> +struct dwc3_qcom_priv_data {
> +	bool power_lost_in_suspend;
> +};
> +
>  struct dwc3_qcom {
>  	struct device		*dev;
>  	void __iomem		*qscratch_base;
> @@ -86,6 +90,12 @@ struct dwc3_qcom {
>  	struct icc_path		*icc_path_apps;
>  
>  	enum usb_role		current_role;
> +
> +	bool			power_lost_in_suspend;
> +};
> +
> +static const struct dwc3_qcom_priv_data sa8255p_dwc3_qcom_priv_data = {
> +	.power_lost_in_suspend	= true,
>  };
>  
>  #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc)
> @@ -407,6 +417,23 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
>  	if (!qcom->is_suspended)
>  		return 0;
>  
> +	if (qcom->power_lost_in_suspend && !PMSG_IS_AUTO(msg)) {
> +		/* Runtime suspend keeps power, so there is no state to recover */
> +		ret = reset_control_assert(qcom->resets);
> +		if (ret) {
> +			dev_err(qcom->dev, "failed to assert resets, err=%d\n", ret);
> +			return ret;
> +		}
> +
> +		usleep_range(10, 1000);
> +
> +		ret = reset_control_deassert(qcom->resets);
> +		if (ret) {
> +			dev_err(qcom->dev, "failed to deassert resets, err=%d\n", ret);
> +			return ret;
> +		}
> +	}
> +
>  	/*
>  	 * If a later step fails, the wakeup interrupts stay disarmed, as a
>  	 * level-triggered wakeup line could otherwise keep firing while the
> @@ -649,6 +676,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	struct dwc3_qcom	*qcom;
>  	struct resource		res;
>  	struct resource		*r;
> +	const struct dwc3_qcom_priv_data *priv_data;
>  	int			ret;
>  	bool			ignore_pipe_clk;
>  	bool			wakeup_source;
> @@ -659,6 +687,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  
>  	qcom->dev = &pdev->dev;
>  
> +	priv_data = of_device_get_match_data(dev);
> +	if (priv_data)
> +		qcom->power_lost_in_suspend = priv_data->power_lost_in_suspend;
> +
>  	qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
>  	if (IS_ERR(qcom->resets)) {
>  		return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
> @@ -741,6 +773,9 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	probe_data.ignore_clocks_and_resets = true;
>  	probe_data.properties = DWC3_DEFAULT_PROPERTIES;
>  	probe_data.properties.skip_phy_init = true;
> +	/* Controller loses power on system suspend, even with wakeup enabled */
> +	probe_data.properties.needs_full_reinit = qcom->power_lost_in_suspend;
> +	probe_data.properties.xhci_reset_on_resume = qcom->power_lost_in_suspend;

There is a xhci_power_lost flag support patch for dwc3 at [1], do we still need
"xhci_reset_on_resume" or could totally re-use it?

[1] https://lore.kernel.org/all/20261125181116.121-1-26rote@gmail.com/

Peter
>  	ret = dwc3_core_probe(&probe_data);
>  	if (ret)  {
>  		ret = dev_err_probe(dev, ret, "failed to register DWC3 Core\n");
> @@ -829,6 +864,14 @@ static void dwc3_qcom_complete(struct device *dev)
>  static int dwc3_qcom_prepare(struct device *dev)
>  {
>  	struct dwc3 *dwc = dev_get_drvdata(dev);
> +	struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
> +
> +	/*
> +	 * Resume must always run to reset the controller, so don't let the
> +	 * PM core skip it for a runtime-suspended device (direct_complete).
> +	 */
> +	if (qcom->power_lost_in_suspend)
> +		return 0;
>  
>  	return dwc3_pm_prepare(dwc);
>  }
> @@ -873,6 +916,10 @@ static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = {
>  };
>  
>  static const struct of_device_id dwc3_qcom_of_match[] = {
> +	{
> +		.compatible	= "qcom,sa8255p-dwc3",
> +		.data		= &sa8255p_dwc3_qcom_priv_data,
> +	},
>  	{ .compatible = "qcom,snps-dwc3" },
>  	{ }
>  };
> -- 
> 2.34.1
> 

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 08/11] usb: dwc3: qcom: Restore VBUS override after system resume
  2026-11-23 10:47 ` [PATCH v5 08/11] usb: dwc3: qcom: Restore VBUS override after system resume Faisal Hassan
@ 2026-11-26  9:54   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26  9:54 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, linux-usb, linux-arm-msm, linux-kernel,
	devicetree, krishna.kurapati, krzysztof.kozlowski, Sriram Dash

On 26-11-23 16:17:23, Faisal Hassan wrote:
> The controller reset on system resume returns the Qscratch registers to
> their power-on defaults, which clears the VBUS valid override that was
> set up for device mode. Without it the PHY does not see VBUS and the
> gadget fails to enumerate after resume.
> 
> Re-enable the override after resume when the controller is not in host
> mode.
> 
> Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 8e8d7e59c6d5..50fca06c83d4 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -457,6 +457,14 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
>  				  PWR_EVNT_LPM_IN_L2_MASK | PWR_EVNT_LPM_OUT_L2_MASK);
>  	}
>  
> +	/*
> +	 * The reset above returned Qscratch to its power-on defaults, so
> +	 * restore the VBUS valid override set up for device mode.
> +	 */
> +	if (qcom->power_lost_in_suspend && !PMSG_IS_AUTO(msg) &&
> +	    !dwc3_qcom_is_host(qcom))
> +		dwc3_qcom_vbus_override_enable(qcom, true);
> +
>  	qcom->is_suspended = false;
>  

Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 09/11] usb: dwc3: qcom: Assert controller reset on remove and probe failure
  2026-11-23 10:47 ` [PATCH v5 09/11] usb: dwc3: qcom: Assert controller reset on remove and probe failure Faisal Hassan
@ 2026-11-26  9:56   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26  9:56 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, Philipp Zabel, linux-usb, linux-arm-msm,
	linux-kernel, devicetree, krishna.kurapati, krzysztof.kozlowski,
	Shazad Hussain, Sriram Dash

On 26-11-23 16:17:24, Faisal Hassan wrote:
> The controller is taken out of reset at probe, but nothing puts it back
> into reset when the driver is removed or when probe fails after that
> point. The controller is left running when its clocks are gated, and a
> later bind starts from whatever state it was left in.
> 
> Assert the reset before disabling the clocks on remove and on the probe
> error path, so the controller is held in reset while unused.
> 
> Co-developed-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
> Signed-off-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
> Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 50fca06c83d4..61a3e3c38f59 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -804,6 +804,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  remove_core:
>  	dwc3_core_remove(&qcom->dwc);
>  clk_disable:
> +	reset_control_assert(qcom->resets);
>  	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
>  
>  	return ret;
> @@ -818,6 +819,7 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
>  		return;
>  
>  	dwc3_core_remove(&qcom->dwc);
> +	reset_control_assert(qcom->resets);
>  	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
>  	dwc3_qcom_interconnect_exit(qcom);
>  

Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 10/11] usb: dwc3: qcom: Support firmware-managed resource states for power management
  2026-11-23 10:47 ` [PATCH v5 10/11] usb: dwc3: qcom: Support firmware-managed resource states for power management Faisal Hassan
@ 2026-11-26 10:09   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26 10:09 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, Philipp Zabel, linux-usb, linux-arm-msm,
	linux-kernel, devicetree, krishna.kurapati, krzysztof.kozlowski,
	Shazad Hussain, Sriram Dash

On 26-11-23 16:17:25, Faisal Hassan wrote:
> Add support for firmware-managed resource handling in the Qualcomm
> DWC3 USB controller driver. On platforms such as SA8255P, controller
> resources are abstracted and managed collectively by firmware, and are
> exposed to Linux through SCMI-backed power domains.
> 
> On SA8255P, resources such as clocks, regulators, resets, TLMM and
> interconnects are controlled by firmware. The driver communicates with
> firmware through two power domains:
> 
>   - "power": controls power supply (GDSC) to the USB controller
>   - "bus": controls clocks and interconnects used for data transfer.
>     Register accesses through the controller require the "power"
>     domain to be enabled.
> 
> The clock and interconnect handling in the suspend, resume, probe and
> remove paths is moved behind dwc3_qcom_resources_enable() and
> dwc3_qcom_resources_disable(). They enable or disable the clocks and
> interconnect paths on existing platforms, and vote the two domains on
> or off when the resources are firmware-managed. The interconnect paths
> are not requested for firmware-managed platforms.
> 
> The domains are voted on and off directly through runtime PM, whose
> usage counting keeps each domain enabled for as long as it is required;
> the driver does not attempt to track or infer any aggregate device power
> state, nor does it assume what state firmware or the bootloader left the
> domains in before probe.
> 
> Runtime suspend/resume vote only the "bus" domain, since the "power"
> domain must remain enabled for hardware accesses that can occur while
> runtime suspended. System suspend/resume vote both domains.
> 
> If system suspend is entered while the device is already runtime
> suspended, only the "power" vote is still held, so system suspend
> drops just that one. System resume then votes both domains back on,
> which keeps the votes balanced across the cycle.
> 
> The domains are attached with devm_pm_domain_attach_list() and
> PD_FLAG_NO_DEV_LINK, because runtime suspend and system suspend require
> different supplier states. Runtime suspend releases only the "bus"
> domain while retaining the "power" domain, whereas system suspend
> releases both domains. Ordinary device-links would couple both
> suppliers to the same consumer runtime PM state and therefore cannot
> express the required policy. The driver consequently manages the
> runtime PM references for the attached domains explicitly.
> 
> pm_runtime_put_sync() drops the domain usage count even when it
> returns an error, so failures to vote a domain off are only reported.
> Failing suspend on them would leave the driver thinking the votes are
> still held and unbalance the next resume/suspend pair.
> 
> Enable firmware-managed resource handling for the "qcom,sa8255p-dwc3"
> compatible while maintaining backward compatibility with existing
> platforms that use direct resource control.
> 
> The probe error path now disables the resources through the common
> helper, which also disables the interconnect paths. Clear the path
> handles when dwc3_qcom_interconnect_init() fails, so the unwind does not
> touch handles that were already released or never obtained.
> 
> Co-developed-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
> Signed-off-by: Shazad Hussain <shazad.hussain@oss.qualcomm.com>
> Co-developed-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Sriram Dash <sriram.dash@oss.qualcomm.com>
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>

Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>

Peter
> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 244 +++++++++++++++++++++++++++++++----
>  1 file changed, 222 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 61a3e3c38f59..559de5172e61 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -13,6 +13,7 @@
>  #include <linux/kernel.h>
>  #include <linux/interconnect.h>
>  #include <linux/platform_device.h>
> +#include <linux/pm_domain.h>
>  #include <linux/phy/phy.h>
>  #include <linux/usb/of.h>
>  #include <linux/reset.h>
> @@ -70,6 +71,7 @@ struct dwc3_qcom_port {
>  
>  struct dwc3_qcom_priv_data {
>  	bool power_lost_in_suspend;
> +	bool fw_managed;
>  };
>  
>  struct dwc3_qcom {
> @@ -92,10 +94,26 @@ struct dwc3_qcom {
>  	enum usb_role		current_role;
>  
>  	bool			power_lost_in_suspend;
> +
> +	bool			fw_managed;
> +	struct dev_pm_domain_list *pd_list;
> +};
> +
> +/* Firmware-managed power domains, indexed in pd_list->pd_devs[] */
> +enum dwc3_qcom_pd {
> +	DWC3_QCOM_PD_POWER,
> +	DWC3_QCOM_PD_BUS,
> +	DWC3_QCOM_NUM_PD,
> +};
> +
> +static const char * const dwc3_qcom_pd_names[] = {
> +	[DWC3_QCOM_PD_POWER]	= "power",
> +	[DWC3_QCOM_PD_BUS]	= "bus",
>  };
>  
>  static const struct dwc3_qcom_priv_data sa8255p_dwc3_qcom_priv_data = {
>  	.power_lost_in_suspend	= true,
> +	.fw_managed		= true,
>  };
>  
>  #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc)
> @@ -169,6 +187,164 @@ static int dwc3_qcom_interconnect_disable(struct dwc3_qcom *qcom)
>  	return ret;
>  }
>  
> +/*
> + * Firmware-managed resources
> + *
> + * Firmware owns the clocks, interconnects and GDSC and exposes them as two
> + * power domains:
> + * - DWC3_QCOM_PD_POWER ("power"): the GDSC supplying the controller
> + * - DWC3_QCOM_PD_BUS ("bus"): clocks and interconnects, which also need
> + *   "power" to be on for register accesses to succeed
> + *
> + * The domains are voted directly from the PM callbacks. The driver does not
> + * mirror the aggregate state, as the real state lives in firmware.
> + */
> +
> +/**
> + * dwc3_qcom_domain_attach() - Attach power domains
> + * @qcom: Pointer to the dwc3_qcom structure
> + *
> + * Attaches power domains for firmware managed resource handling. The
> + * domains are detached automatically when the driver is unbound.
> + * Returns 0 on success, negative error code on failure.
> + */
> +static int dwc3_qcom_domain_attach(struct dwc3_qcom *qcom)
> +{
> +	struct dev_pm_domain_attach_data pd_data = {
> +		/* Runtime and system suspend need different supplier states */
> +		.pd_flags	= PD_FLAG_NO_DEV_LINK,
> +		.pd_names	= dwc3_qcom_pd_names,
> +		.num_pd_names	= DWC3_QCOM_NUM_PD,
> +	};
> +	struct device *dev = qcom->dev;
> +	int ret;
> +
> +	ret = devm_pm_domain_attach_list(dev, &pd_data, &qcom->pd_list);
> +	if (ret != pd_data.num_pd_names) {
> +		dev_err(dev, "domain attach failed (%d)\n", ret);
> +		return ret < 0 ? ret : -ENODEV;
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * dwc3_qcom_power_domain_put() - Vote the power domain off
> + * @qcom: Pointer to the dwc3_qcom structure
> + *
> + * pm_runtime_put_sync() drops the usage count even on error, so only warn.
> + * Failing the caller would make it think the vote is still held and
> + * unbalance the next get/put pair.
> + */
> +static void dwc3_qcom_power_domain_put(struct dwc3_qcom *qcom)
> +{
> +	int ret;
> +
> +	ret = pm_runtime_put_sync(qcom->pd_list->pd_devs[DWC3_QCOM_PD_POWER]);
> +	if (ret < 0)
> +		dev_warn(qcom->dev, "failed to disable power domain: %d\n", ret);
> +}
> +
> +/**
> + * dwc3_qcom_domains_get() - Vote the firmware-managed domains on
> + * @qcom: Pointer to the dwc3_qcom structure
> + * @bus_only: If true, leave the power domain untouched and only vote bus
> + *
> + * Each call must be paired with dwc3_qcom_domains_put() using the same
> + * @bus_only. Runtime PM usage counting keeps a domain on for as long as it
> + * is needed, regardless of the state firmware left it in.
> + * Returns 0 on success, negative error code on failure.
> + */
> +static int dwc3_qcom_domains_get(struct dwc3_qcom *qcom, bool bus_only)
> +{
> +	struct device *power_dev = qcom->pd_list->pd_devs[DWC3_QCOM_PD_POWER];
> +	struct device *bus_dev = qcom->pd_list->pd_devs[DWC3_QCOM_PD_BUS];
> +	int ret;
> +
> +	if (!bus_only) {
> +		ret = pm_runtime_resume_and_get(power_dev);
> +		if (ret) {
> +			dev_err(qcom->dev, "failed to enable power domain: %d\n", ret);
> +			return ret;
> +		}
> +	}
> +
> +	ret = pm_runtime_resume_and_get(bus_dev);
> +	if (ret) {
> +		dev_err(qcom->dev, "failed to enable bus domain: %d\n", ret);
> +		if (!bus_only)
> +			pm_runtime_put_sync(power_dev);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +/**
> + * dwc3_qcom_domains_put() - Vote the firmware-managed domains off
> + * @qcom: Pointer to the dwc3_qcom structure
> + * @bus_only: If true, leave the power domain untouched and only vote bus
> + *
> + * Bus is released before power, as bus accesses need power to be on.
> + */
> +static void dwc3_qcom_domains_put(struct dwc3_qcom *qcom, bool bus_only)
> +{
> +	int ret;
> +
> +	ret = pm_runtime_put_sync(qcom->pd_list->pd_devs[DWC3_QCOM_PD_BUS]);
> +	if (ret < 0)
> +		dev_warn(qcom->dev, "failed to disable bus domain: %d\n", ret);
> +
> +	if (!bus_only)
> +		dwc3_qcom_power_domain_put(qcom);
> +}
> +
> +/**
> + * dwc3_qcom_resources_enable() - Enable clocks and interconnect, or vote domains on
> + * @qcom: Pointer to the dwc3_qcom structure
> + * @bus_only: Firmware-managed only: leave the power domain untouched
> + *
> + * Returns 0 on success, negative error code on failure.
> + */
> +static int dwc3_qcom_resources_enable(struct dwc3_qcom *qcom, bool bus_only)
> +{
> +	int ret;
> +
> +	if (qcom->fw_managed)
> +		return dwc3_qcom_domains_get(qcom, bus_only);
> +
> +	ret = clk_bulk_prepare_enable(qcom->num_clocks, qcom->clks);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = dwc3_qcom_interconnect_enable(qcom);
> +	if (ret)
> +		dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
> +
> +	return 0;
> +}
> +
> +/**
> + * dwc3_qcom_resources_disable() - Undo dwc3_qcom_resources_enable()
> + * @qcom: Pointer to the dwc3_qcom structure
> + * @bus_only: Firmware-managed only: leave the power domain untouched
> + */
> +static void dwc3_qcom_resources_disable(struct dwc3_qcom *qcom, bool bus_only)
> +{
> +	int ret;
> +
> +	if (qcom->fw_managed) {
> +		dwc3_qcom_domains_put(qcom, bus_only);
> +		return;
> +	}
> +
> +	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
> +
> +	ret = dwc3_qcom_interconnect_disable(qcom);
> +	if (ret)
> +		dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
> +}
> +
>  /**
>   * dwc3_qcom_interconnect_init() - Get interconnect path handles
>   * and set bandwidth.
> @@ -181,10 +357,16 @@ static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
>  	struct device *dev = qcom->dev;
>  	int ret;
>  
> +	/* Interconnects are managed by firmware */
> +	if (qcom->fw_managed)
> +		return 0;
> +
>  	qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr");
>  	if (IS_ERR(qcom->icc_path_ddr)) {
> -		return dev_err_probe(dev, PTR_ERR(qcom->icc_path_ddr),
> -				     "failed to get usb-ddr path\n");
> +		ret = dev_err_probe(dev, PTR_ERR(qcom->icc_path_ddr),
> +				    "failed to get usb-ddr path\n");
> +		qcom->icc_path_ddr = NULL;
> +		return ret;
>  	}
>  
>  	qcom->icc_path_apps = of_icc_get(dev, "apps-usb");
> @@ -219,6 +401,9 @@ static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
>  	icc_put(qcom->icc_path_apps);
>  put_path_ddr:
>  	icc_put(qcom->icc_path_ddr);
> +	/* Leave no stale handles for the error unwind to disable */
> +	qcom->icc_path_ddr = NULL;
> +	qcom->icc_path_apps = NULL;
>  	return ret;
>  }
>  
> @@ -369,7 +554,7 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
>  {
>  	bool wakeup = dwc3_qcom_wakeup_enabled(qcom, msg);
>  	u32 val;
> -	int i, ret;
> +	int i;
>  
>  	if (qcom->is_suspended) {
>  		/*
> @@ -379,6 +564,15 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
>  		 */
>  		if (dwc3_qcom_is_host(qcom) && !wakeup)
>  			dwc3_qcom_disable_interrupts(qcom);
> +
> +		/*
> +		 * Runtime suspend dropped only the bus domain. System suspend
> +		 * must drop the power domain too, so that system resume, which
> +		 * votes both domains back on, stays balanced.
> +		 */
> +		if (qcom->fw_managed && !PMSG_IS_AUTO(msg))
> +			dwc3_qcom_power_domain_put(qcom);
> +
>  		return 0;
>  	}
>  
> @@ -387,11 +581,9 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)
>  		if (!(val & PWR_EVNT_LPM_IN_L2_MASK))
>  			dev_err(qcom->dev, "port-%d HS-PHY not in L2\n", i + 1);
>  	}
> -	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
>  
> -	ret = dwc3_qcom_interconnect_disable(qcom);
> -	if (ret)
> -		dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
> +	/* Runtime suspend keeps power voted on; system suspend drops both. */
> +	dwc3_qcom_resources_disable(qcom, PMSG_IS_AUTO(msg));
>  
>  	/*
>  	 * The role is stable during suspend as role switching is done from a
> @@ -442,13 +634,10 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)
>  	if (dwc3_qcom_is_host(qcom) && wakeup)
>  		dwc3_qcom_disable_interrupts(qcom);
>  
> -	ret = clk_bulk_prepare_enable(qcom->num_clocks, qcom->clks);
> -	if (ret < 0)
> -		return ret;
> -
> -	ret = dwc3_qcom_interconnect_enable(qcom);
> +	/* Runtime resume re-votes bus only; system resume votes both. */
> +	ret = dwc3_qcom_resources_enable(qcom, PMSG_IS_AUTO(msg));
>  	if (ret)
> -		dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
> +		return ret;
>  
>  	/* Clear existing events from PHY related to L2 in/out */
>  	for (i = 0; i < qcom->num_ports; i++) {
> @@ -696,8 +885,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	qcom->dev = &pdev->dev;
>  
>  	priv_data = of_device_get_match_data(dev);
> -	if (priv_data)
> +	if (priv_data) {
>  		qcom->power_lost_in_suspend = priv_data->power_lost_in_suspend;
> +		qcom->fw_managed = priv_data->fw_managed;
> +	}
>  
>  	qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
>  	if (IS_ERR(qcom->resets)) {
> @@ -705,10 +896,16 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  				     "failed to get resets\n");
>  	}
>  
> -	ret = devm_clk_bulk_get_all(&pdev->dev, &qcom->clks);
> -	if (ret < 0)
> -		return dev_err_probe(dev, ret, "failed to get clocks\n");
> -	qcom->num_clocks = ret;
> +	if (!qcom->fw_managed) {
> +		ret = devm_clk_bulk_get_all(&pdev->dev, &qcom->clks);
> +		if (ret < 0)
> +			return dev_err_probe(dev, ret, "failed to get clocks\n");
> +		qcom->num_clocks = ret;
> +	} else {
> +		ret = dwc3_qcom_domain_attach(qcom);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	ret = reset_control_assert(qcom->resets);
>  	if (ret) {
> @@ -724,9 +921,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	ret = clk_bulk_prepare_enable(qcom->num_clocks, qcom->clks);
> -	if (ret < 0)
> +	/* Takes the votes whatever state firmware or the bootloader left */
> +	ret = dwc3_qcom_resources_enable(qcom, false);
> +	if (ret) {
> +		reset_control_assert(qcom->resets);
>  		return ret;
> +	}
>  
>  	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!r) {
> @@ -805,7 +1005,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  	dwc3_core_remove(&qcom->dwc);
>  clk_disable:
>  	reset_control_assert(qcom->resets);
> -	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
> +	dwc3_qcom_resources_disable(qcom, false);
>  
>  	return ret;
>  }
> @@ -820,7 +1020,7 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
>  
>  	dwc3_core_remove(&qcom->dwc);
>  	reset_control_assert(qcom->resets);
> -	clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
> +	dwc3_qcom_resources_disable(qcom, false);
>  	dwc3_qcom_interconnect_exit(qcom);
>  
>  	pm_runtime_put_noidle(qcom->dev);
> -- 
> 2.34.1
> 

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v5 11/11] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role
  2026-11-23 10:47 ` [PATCH v5 11/11] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role Faisal Hassan
@ 2026-11-26 10:12   ` Peter Chen
  0 siblings, 0 replies; 20+ messages in thread
From: Peter Chen @ 2026-11-26 10:12 UTC (permalink / raw)
  To: Faisal Hassan
  Cc: Thinh.Nguyen, gregkh, linux-usb, linux-arm-msm, linux-kernel,
	devicetree, krishna.kurapati, krzysztof.kozlowski

On 26-11-23 16:17:26, Faisal Hassan wrote:
> When the controller is in OTG mode with usb-role-switch and
> role-switch-default-mode set to peripheral, the role notifier never sees
> a transition at probe, so the QSCRATCH VBUS override is not programmed
> and the device never gets a session-valid indication.
> 
> Enable the VBUS override once at probe, after the initial role has been
> determined, whenever that role is USB_ROLE_DEVICE. This also covers the
> dr_mode = "peripheral" case, which previously programmed the override on
> its own.
> 
> Validated on SA8255P with an HS host attached: 20 unbind/bind and 20
> suspend/resume iterations completed with no failures.
> 
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>

Reviewed-by: Peter Chen <peter.chen@oss.qualcomm.com>

Peter

> ---
>  drivers/usb/dwc3/dwc3-qcom.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 559de5172e61..22b6c7ca0297 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -964,7 +964,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  		qcom->current_role = USB_ROLE_HOST;
>  	} else if (qcom->mode == USB_DR_MODE_PERIPHERAL) {
>  		qcom->current_role = USB_ROLE_DEVICE;
> -		dwc3_qcom_vbus_override_enable(qcom, true);
>  	} else {
>  		if ((device_property_read_bool(dev, "usb-role-switch")) &&
>  		    (usb_get_role_switch_default_mode(dev) == USB_DR_MODE_HOST))
> @@ -973,6 +972,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
>  			qcom->current_role = USB_ROLE_DEVICE;
>  	}
>  
> +	/* Force the VBUS valid indication to the PHYs in device mode */
> +	if (qcom->current_role == USB_ROLE_DEVICE)
> +		dwc3_qcom_vbus_override_enable(qcom, true);
> +
>  	qcom->dwc.glue_ops = &dwc3_qcom_glue_ops;
>  
>  	qcom->dwc.dev = dev;
> -- 
> 2.34.1
> 

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2026-11-26 10:12 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 10:47 [PATCH v5 00/11] usb: dwc3: qcom: Add firmware-managed resource support for SA8255P Faisal Hassan
2026-11-23 10:47 ` [PATCH v5 01/11] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths Faisal Hassan
2026-11-26  7:40   ` Peter Chen
2026-11-23 10:47 ` [PATCH v5 02/11] usb: dwc3: qcom: Disarm wakeup IRQs on system suspend without wakeup Faisal Hassan
2026-11-26  7:44   ` Peter Chen
2026-11-23 10:47 ` [PATCH v5 03/11] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume Faisal Hassan
2026-11-26  8:37   ` Peter Chen
2026-11-23 10:47 ` [PATCH v5 04/11] dt-bindings: usb: Add qcom,sa8255p-dwc3 for firmware-managed resources Faisal Hassan
2026-11-23 10:47 ` [PATCH v5 05/11] usb: host: xhci-plat: Support XHCI_RESET_ON_RESUME via device property Faisal Hassan
2026-11-23 10:47 ` [PATCH v5 06/11] usb: dwc3: Support resetting the xHCI host on system resume Faisal Hassan
2026-11-23 10:47 ` [PATCH v5 07/11] usb: dwc3: qcom: Recover controller state after power loss in system suspend Faisal Hassan
2026-11-26  9:52   ` Peter Chen
2026-11-23 10:47 ` [PATCH v5 08/11] usb: dwc3: qcom: Restore VBUS override after system resume Faisal Hassan
2026-11-26  9:54   ` Peter Chen
2026-11-23 10:47 ` [PATCH v5 09/11] usb: dwc3: qcom: Assert controller reset on remove and probe failure Faisal Hassan
2026-11-26  9:56   ` Peter Chen
2026-11-23 10:47 ` [PATCH v5 10/11] usb: dwc3: qcom: Support firmware-managed resource states for power management Faisal Hassan
2026-11-26 10:09   ` Peter Chen
2026-11-23 10:47 ` [PATCH v5 11/11] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role Faisal Hassan
2026-11-26 10:12   ` Peter Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox