[PATCH v5 07/11] usb: dwc3: qcom: Recover controller state after power loss in system suspend
From: Faisal Hassan
Date: Mon Nov 23 2026 - 05:48:57 EST
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@xxxxxxxxxxxxxxxx>
Signed-off-by: Sriram Dash <sriram.dash@xxxxxxxxxxxxxxxx>
Signed-off-by: Faisal Hassan <faisal.hassan@xxxxxxxxxxxxxxxx>
---
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