usb: dwc3: qcom: Add firmware-managed resource support for SA8255P
Subsystems (5)
v4 cover usb: dwc3: qcom: Add firmware-managed resource support for SA8255P
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 requires a few platform-specific fixups on top of this, handled by this series:
- "Broken suspend": APPS/system suspend causes the clock controller to cut all clocks to the controller, putting it into a Power-On Reset state and losing Qscratch programming. Resume must reset the controller, reselect the UTMI clock as the PIPE clock when no SS PHY is present, and reassert VBUS_VALID so the PHYs don't fall back into suspend.
- The loss of power across system suspend also leaves the xHC in an error state on resume, which the existing XHCI_RESET_ON_RESUME quirk handles once dwc3 is taught to request it via a device property.
Dependency: this series applies on top of 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). Patch 5 sets the skip_phy_init property introduced there and will not build without it, so that patch needs to be applied first.
Patch overview:
Patch 1: Track whether the wakeup interrupts are armed so enable and
disable stay balanced across runtime and system PM, and always disarm them on resume. They stay disarmed if the resume fails.
Patch 2: 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 3: New devicetree binding, qcom,sa8255p-dwc3.yaml, requiring
"power"/"bus" power-domains and the USB PHYs for firmware-managed platforms.
Patch 4: Teach xhci-plat to set XHCI_RESET_ON_RESUME from a device
property.
Patch 5: SA8255P broken-suspend handling (reset + PIPE_UTMI_CLK_SEL +
VBUS_VALID fixups on resume). The xhci_reset_on_resume property is added to struct dwc3_properties and forwarded to xhci-plat, and the glue driver sets it, together with needs_full_reinit, through its probe data.
Patch 6: 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 and reset balanced.
Patch 7: Enable the VBUS override at probe when the default role is
peripheral.
Testing:
Tested on SA8255P Ride:
- Driver probe, unbind and rebind
- Runtime suspend and resume
- System suspend and resume
- Host mode enumeration across system suspend/resume
- 20x system suspend/resume with a host attached to the peripheral
port: UDC returns to configured, no soft reset failures
- 20x driver unbind/bind with the gadget enumerated and on the host port
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/[email protected]/
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/[email protected]/
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/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Faisal Hassan (7):
usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed
resume
usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths
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: qcom: Support broken suspend for SA8255P
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 | 411 +++++++++++++++--- drivers/usb/dwc3/glue.h | 2 + drivers/usb/dwc3/host.c | 5 +- drivers/usb/host/xhci-plat.c | 3 + 7 files changed, 482 insertions(+), 59 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml
Signature · 1 line
2.34.1
PATCH v4 1/7 usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume
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. Disarm them in resume regardless of the wakeup setting, so interrupts armed by a runtime suspend are also disarmed when system resume runs with device wakeup disabled.
--- drivers/usb/dwc3/dwc3-qcom.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +18 -2
@@ -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; }static int dwc3_qcom_suspend (struct dwc3_qcom *qcom,bool wakeup)
@@ -377,8 +388,13 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)if (!qcom->is_suspended)return 0 ; -if (dwc3_qcom_is_host (qcom) && wakeup) -dwc3_qcom_disable_interrupts (qcom); +/* +* Wakeup interrupts may have been armed by an earlier runtime suspend +* even if wakeup is now disabled, so always disarm them. On failure +* they stay disarmed, as a level-triggered wakeup line could otherwise +* keep firing while the controller can't be resumed. +*/ +dwc3_qcom_disable_interrupts (qcom); ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks);if (ret <0 )
Signature · 1 line
2.34.1
Re: [PATCH v4 1/7] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume
Quoted 3 lines · Faisal Hassan
dwc3_qcom_resume()disables the wakeup interrupts before enabling the clocks. Ifclk_bulk_prepare_enable()fails, it returns with them disabled.
What's the relationship between clk_bulk_prepare_enable() fails and this patch?
Quoted 62 lines
The next suspend returns early on
is_suspendedwithout 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_phyinterrupt 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. Disarm them in resume regardless of the wakeup setting, so interrupts armed by a runtime suspend are also disarmed when system resume runs with device wakeup disabled.
Signed-off-by Faisal Hassan <[email protected]>--- drivers/usb/dwc3/dwc3-qcom.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-qcom.c +11
-0@@ -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; }static int dwc3_qcom_suspend (struct dwc3_qcom *qcom,bool wakeup)
drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup) · line 393
Quoted 8 lines
drivers/usb/dwc3/dwc3-qcom.c +3
-2@@ -377,8 +388,13 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)if (!qcom->is_suspended)return 0 ; -if (dwc3_qcom_is_host (qcom) && wakeup) -dwc3_qcom_disable_interrupts (qcom); +/* +* Wakeup interrupts may have been armed by an earlier runtime suspend +* even if wakeup is now disabled,
How wakeup interrupt is triggered even the wake interrupt is disabled? Is the hardware default value makes it enabled? If it is, we need to disable all wakeup interrupt at probe, otherwise, there are un-expected wakeup interrupts.
Peter
Quoted 12 lines
so always disarm them. On failure
drivers/usb/dwc3/dwc3-qcom.c +4
-0+* they stay disarmed, as a level-triggered wakeup line could otherwise +* keep firing while the controller can't be resumed. +*/ +dwc3_qcom_disable_interrupts (qcom); ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks);if (ret <0 )Signature · 1 line
2.34.1
Signature · 2 lines
Thanks, Peter Chen
Re: [PATCH v4 1/7] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume
Quoted 7 lines · Peter Chen
Quoted 3 lines · Faisal Hassan
dwc3_qcom_resume()disables the wakeup interrupts before enabling the clocks. Ifclk_bulk_prepare_enable()fails, it returns with them disabled.What's the relationship between
clk_bulk_prepare_enable()fails and this patch?
Hi Peter,
The wakeup interrupts were disarmed before the clock enable. If that failed, is_suspended stayed set, the next suspend returned early, and the next resume disarmed them again. disable_irq_nosync() and disable_irq_wake() nest, so each failed resume left the disable depth one level deeper. This is the rarer case, so I will reword the commit message to lead with the runtime suspend case below.
Quoted 75 lines
Quoted 62 lines
The next suspend returns early on
is_suspendedwithout 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_phyinterrupt 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. Disarm them in resume regardless of the wakeup setting, so interrupts armed by a runtime suspend are also disarmed when system resume runs with device wakeup disabled.
Signed-off-by Faisal Hassan <[email protected]>--- drivers/usb/dwc3/dwc3-qcom.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-qcom.c +11
-0@@ -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; }static int dwc3_qcom_suspend (struct dwc3_qcom *qcom,bool wakeup)drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup) · line 393
Quoted 8 lines
drivers/usb/dwc3/dwc3-qcom.c +3
-2@@ -377,8 +388,13 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)if (!qcom->is_suspended)return 0 ; -if (dwc3_qcom_is_host (qcom) && wakeup) -dwc3_qcom_disable_interrupts (qcom); +/* +* Wakeup interrupts may have been armed by an earlier runtime suspend +* even if wakeup is now disabled, How wakeup interrupt is triggered even the wake interrupt is disabled? Is the hardware default value makes it enabled? If it is, we need to disable all wakeup interrupt at probe, otherwise, there are un-expected wakeup interrupts.
Quoted 2 lines
Peter
They are not. They are requested with IRQF_NO_AUTOEN, so they stay disabled until the first suspend and nothing needs disabling at probe. The issue is that runtime suspend always calls dwc3_qcom_suspend(qcom, true), which arms them in host mode regardless of device_may_wakeup(). The old resume only disarmed them when wakeup was enabled, so a system resume with device wakeup disabled left them armed. The comment read as if the interrupts trigger while disabled, so I will reword it as:
/*
* Runtime suspend arms the wakeup interrupts regardless of the
* device wakeup setting, so always disarm them here. On failure
* they stay disarmed, as a level-triggered wakeup line could
* otherwise keep firing while the controller can't be resumed. */
I will update the subject and commit message for v5 to cover this case.
Thanks,
Faisal
Quoted 13 lines
Quoted 12 lines
so always disarm them. On failure
drivers/usb/dwc3/dwc3-qcom.c +4
-0+* they stay disarmed, as a level-triggered wakeup line could otherwise +* keep firing while the controller can't be resumed. +*/ +dwc3_qcom_disable_interrupts (qcom); ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks);if (ret <0 )Signature · 1 line
2.34.1
Re: [PATCH v4 1/7] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume
Quoted 8 lines · Faisal Hassan
Quoted 7 lines · Peter Chen
Quoted 3 lines · Faisal Hassan
dwc3_qcom_resume()disables the wakeup interrupts before enabling the clocks. Ifclk_bulk_prepare_enable()fails, it returns with them disabled.What's the relationship between
clk_bulk_prepare_enable()fails and this patch?
Quoted 9 lines
Hi Peter,
The wakeup interrupts were disarmed before the clock enable. If that failed,
is_suspendedstayed set, the next suspend returned early, and the next resume disarmed them again.disable_irq_nosync()anddisable_irq_wake()nest, so each failed resume left the disable depth one level deeper. This is the rarer case, so I will reword the commit message to lead with the runtime suspend case below.
Okay, so here you may need another patch for error handling improvement.
Quoted 18 lines
Quoted 15 lines
drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup) · line 392
Quoted 10 lines
} static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)drivers/usb/dwc3/dwc3-qcom.c +3
-2@@ -377,8 +388,13 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)if (!qcom->is_suspended)return 0 ; -if (dwc3_qcom_is_host (qcom) && wakeup) -dwc3_qcom_disable_interrupts (qcom); +/* +* Wakeup interrupts may have been armed by an earlier runtime suspend +* even if wakeup is now disabled, How wakeup interrupt is triggered even the wake interrupt is disabled? Is the hardware default value makes it enabled? If it is, we need to disable all wakeup interrupt at probe, otherwise, there are un-expected wakeup interrupts.
Quoted 2 lines
Peter
Quoted 7 lines
They are not. They are requested with
IRQF_NO_AUTOEN, so they stay disabled until the first suspend and nothing needs disabling at probe. The issue is that runtime suspend always callsdwc3_qcom_suspend(qcom, true), which arms them in host mode regardless ofdevice_may_wakeup(). The old resume only disarmed them when wakeup was enabled, so a system resume with device wakeup disabled left them armed.
Get it.
At your second patch, it already knows the context between runtime and system suspend, you could disable wakeup enable if the device_may_wakeup return false, that could avoid introducing more judgements, and have this patch after your 2nd patch.
Quoted 11 lines
The comment read as if the interrupts trigger while disabled, so I will reword it as:
/*
* Runtime suspend arms the wakeup interrupts regardless of the
* device wakeup setting, so always disarm them here. On failure
* they stay disarmed, as a level-triggered wakeup line could
* otherwise keep firing while the controller can't be resumed. */I will update the subject and commit message for v5 to cover this case.
Signature · 2 lines
Thanks, Peter Chen
Re: [PATCH v4 1/7] usb: dwc3: qcom: Keep wakeup IRQ enable/disable balanced on failed resume
Quoted 19 lines · Peter Chen
Quoted 8 lines · Faisal Hassan
Quoted 7 lines · Peter Chen
Quoted 3 lines · Faisal Hassan
dwc3_qcom_resume()disables the wakeup interrupts before enabling the clocks. Ifclk_bulk_prepare_enable()fails, it returns with them disabled.What's the relationship between
clk_bulk_prepare_enable()fails and this patch?Quoted 9 lines
Hi Peter,
The wakeup interrupts were disarmed before the clock enable. If that failed,
is_suspendedstayed set, the next suspend returned early, and the next resume disarmed them again.disable_irq_nosync()anddisable_irq_wake()nest, so each failed resume left the disable depth one level deeper. This is the rarer case, so I will reword the commit message to lead with the runtime suspend case below.
Quoted 2 lines
Okay, so here you may need another patch for error handling improvement.
Ok, I will put the failed-resume handling (the wakeup interrupts staying disarmed, with arm/disarm kept balanced) in its own patch.
Quoted 26 lines
Quoted 18 lines
Quoted 15 lines
drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup) · line 392
Quoted 10 lines
} static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)drivers/usb/dwc3/dwc3-qcom.c +3
-2@@ -377,8 +388,13 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)if (!qcom->is_suspended)return 0 ; -if (dwc3_qcom_is_host (qcom) && wakeup) -dwc3_qcom_disable_interrupts (qcom); +/* +* Wakeup interrupts may have been armed by an earlier runtime suspend +* even if wakeup is now disabled, How wakeup interrupt is triggered even the wake interrupt is disabled? Is the hardware default value makes it enabled? If it is, we need to disable all wakeup interrupt at probe, otherwise, there are un-expected wakeup interrupts.
Quoted 2 lines
Peter
Quoted 7 lines
They are not. They are requested with
IRQF_NO_AUTOEN, so they stay disabled until the first suspend and nothing needs disabling at probe. The issue is that runtime suspend always callsdwc3_qcom_suspend(qcom, true), which arms them in host mode regardless ofdevice_may_wakeup(). The old resume only disarmed them when wakeup was enabled, so a system resume with device wakeup disabled left them armed.
Quoted 7 lines
Get it.
At your second patch, it already knows the context between runtime and system suspend, you could disable wakeup enable if the
device_may_wakeupreturn false, that could avoid introducing more judgements, and have this patch after your 2nd patch.
Agreed. I will move the PM/runtime split first. Then, in the system suspend path, I will disarm the wakeup interrupts when device_may_wakeup() is false (including when the controller is already runtime suspended and they were armed earlier). The resume side then needs no extra check. The failed-resume handling goes in a separate patch after that.
Thanks,
Faisal
Quoted 12 lines
Quoted 11 lines
The comment read as if the interrupts trigger while disabled, so I will reword it as:
/*
* Runtime suspend arms the wakeup interrupts regardless of the
* device wakeup setting, so always disarm them here. On failure
* they stay disarmed, as a level-triggered wakeup line could
* otherwise keep firing while the controller can't be resumed. */I will update the subject and commit message for v5 to cover this case.
PATCH v4 2/7 usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths
In reply to Faisal HassanThe 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.
--- drivers/usb/dwc3/dwc3-qcom.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +16 -8
@@ -346,14 +346,24 @@ static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom) qcom->wakeup_irqs_armed = true; } -static int dwc3_qcom_suspend (struct dwc3_qcom *qcom,bool wakeup) +static int dwc3_qcom_suspend (struct dwc3_qcom *qcom,pm_message_t msg) {u32 val;int i, ret; +bool wakeup;if (qcom->is_suspended)return 0 ; +/* +* For runtime suspend, always enable wakeup. +* For system suspend, check device wakeup capability. +*/ +if (PMSG_IS_AUTO (msg)) + wakeup = true; +else + wakeup =device_may_wakeup (qcom->dev); +for (i =0 ; i < qcom->num_ports; i++) { val =readl (qcom->qscratch_base + pwr_evnt_irq_stat_reg[i]);if (!(val &PWR_EVNT_LPM_IN_L2_MASK ))
@@ -380,7 +390,7 @@ 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) {int ret;int i;
@@ -766,14 +776,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;
@@ -786,10 +795,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;
@@ -826,7 +834,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)
@@ -835,7 +843,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;
Signature · 1 line
2.34.1
Re: [PATCH v4 2/7] usb: dwc3: qcom: Distinguish PM and runtime suspend/resume paths
Quoted 14 lines · Faisal Hassan
The
dwc3_qcom_suspend()anddwc3_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_tinstead of boolean wakeup flags. UsePMSG_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.
Quoted 7 lines
Follow
dwc3/core.cpattern to enable future per-path strategies like differentiated power states.Co-developed-by Sriram Dash <[email protected]>Signed-off-by Sriram Dash <[email protected]>Signed-off-by Faisal Hassan <[email protected]>Acked-by Thinh Nguyen <[email protected]>
Regards,
Krishna,
Quoted 89 lines
--- drivers/usb/dwc3/dwc3-qcom.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)drivers/usb/dwc3/dwc3-qcom.c +16
-8@@ -346,14 +346,24 @@ static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom) qcom->wakeup_irqs_armed = true; } -static int dwc3_qcom_suspend (struct dwc3_qcom *qcom,bool wakeup) +static int dwc3_qcom_suspend (struct dwc3_qcom *qcom,pm_message_t msg) {u32 val;int i, ret; +bool wakeup;if (qcom->is_suspended)return 0 ; +/* +* For runtime suspend, always enable wakeup. +* For system suspend, check device wakeup capability. +*/ +if (PMSG_IS_AUTO (msg)) + wakeup = true; +else + wakeup =device_may_wakeup (qcom->dev); +for (i =0 ; i < qcom->num_ports; i++) { val =readl (qcom->qscratch_base + pwr_evnt_irq_stat_reg[i]);if (!(val &PWR_EVNT_LPM_IN_L2_MASK ))@@ -380,7 +390,7 @@ 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) {int ret;int i;@@ -766,14 +776,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;@@ -786,10 +795,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;@@ -826,7 +834,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)@@ -835,7 +843,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;
PATCH v4 3/7 dt-bindings: usb: Add qcom,sa8255p-dwc3 for firmware-managed resources
In reply to Faisal HassanOn 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.
--- .../bindings/usb/qcom,sa8255p-dwc3.yaml | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml
Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml new file +114 -0
@@ -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 <[email protected]> + - Faisal Hassan <[email protected]> + +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"; + }; +...
Signature · 1 line
2.34.1
Re: [PATCH v4 3/7] dt-bindings: usb: Add qcom,sa8255p-dwc3 for firmware-managed resources
Quoted 13 lines · Faisal Hassan
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 transferThe 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.
Quoted 7 lines
Co-developed-by Sriram Dash <[email protected]>Signed-off-by Sriram Dash <[email protected]>Signed-off-by Faisal Hassan <[email protected]>--- .../bindings/usb/qcom,sa8255p-dwc3.yaml | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/qcom,sa8255p-dwc3.yaml
Best regards,
Krzysztof
PATCH v4 4/7 usb: host: xhci-plat: Support XHCI_RESET_ON_RESUME via device property
In reply to Faisal HassanWhen 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.
--- drivers/usb/host/xhci-plat.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/host/xhci-plat.c +3 -0
@@ -277,6 +277,9 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const sif (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",
Signature · 1 line
2.34.1
Re: [PATCH v4 4/7] usb: host: xhci-plat: Support XHCI_RESET_ON_RESUME via device property
Quoted 6 lines · Faisal Hassan
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_RESUMEquirk (introduced upstream in8b328f8002bc).
Quoted 7 lines
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 <[email protected]>Signed-off-by Sriram Dash <[email protected]>Signed-off-by Faisal Hassan <[email protected]>
Peter
Quoted 22 lines
--- drivers/usb/host/xhci-plat.c | 3 +++ 1 file changed, 3 insertions(+)drivers/usb/host/xhci-plat.c +3
-0@@ -277,6 +277,9 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const sif (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",Signature · 1 line
2.34.1
Signature · 2 lines
Thanks, Peter Chen
PATCH v4 5/7 usb: dwc3: qcom: Support broken suspend for SA8255P
In reply to Faisal HassanDuring APPS Suspend, the clock controller unit disables all clocks to the CPU and subsystems, causing the controller to enter the Power-On Reset (POR) state. This results in the loss of Qscratch programming.
Upon APPS Resume, the USB controller does not have the proper PIPE_UTMI_CLK_SEL or VBUS_VALID. Hence, if only the High-Speed PHY is used for a controller capable of SuperSpeed operations, the controller will assume it should use the USB3 PHY and not the HS PHY as configured before APPS Suspend. This behavior disrupts the normal operation of the USB controller. Similarly, if the controller was operating in device mode prior to APPS suspend, and VBUS_VALID signal is not set after APPS resume, this will cause the PHYs to transition into the suspend state. This behavior disrupts the normal operation of the USB controller.
Address the issues by ensuring that the PIPE_UTMI_CLK_SEL and VBUS_VALID are handled properly after the system resumes from APPS Suspend. This is crucial for maintaining the correct operational state of the USB controller and preventing unintended suspensions of the PHYs.
Also, as the controller is starting from POR state, make sure the controller Reset is performed.
Because the controller is reset on every system resume, the Qscratch restore is done whether or not wakeup was enabled, and dwc3 core is told via needs_full_reinit to fully re-initialize the core on system resume even in host mode with wakeup enabled. Wakeup on this platform comes from the PHY interrupts routed through PDC, not from the controller staying powered. VBUS_VALID is only forced outside host mode, matching what probe does.
The XHCI controller is reset by the same event, so also set the xhci_reset_on_resume dwc3 property. dwc3 passes it on to the xhci-plat device as xhci-reset-on-resume-quirk, which makes xhci-plat set XHCI_RESET_ON_RESUME.
Also make the .prepare callback return 0 on these platforms. A runtime-suspended device in device mode would otherwise be left in place across system sleep (direct_complete), skipping the system resume callback and with it the reset and Qscratch restore.
--- drivers/usb/dwc3/core.c | 3 + drivers/usb/dwc3/core.h | 3 + drivers/usb/dwc3/dwc3-qcom.c | 107 ++++++++++++++++++++++++++++------- drivers/usb/dwc3/glue.h | 2 + drivers/usb/dwc3/host.c | 5 +- 5 files changed, 98 insertions(+), 22 deletions(-)
drivers/usb/dwc3/core.c +3 -0
@@ -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 !=
drivers/usb/dwc3/core.h +3 -0
@@ -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;
drivers/usb/dwc3/dwc3-qcom.c +86 -21
180 lines not on this page · raw message
drivers/usb/dwc3/glue.h +2 -0
@@ -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){ \
drivers/usb/dwc3/host.c +4 -1
@@ -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.
Signature · 1 line
2.34.1
Re: [PATCH v4 5/7] usb: dwc3: qcom: Support broken suspend for SA8255P
Quoted 38 lines · Faisal Hassan
During APPS Suspend, the clock controller unit disables all clocks to the CPU and subsystems, causing the controller to enter the Power-On Reset (POR) state. This results in the loss of Qscratch programming.
Upon APPS Resume, the USB controller does not have the proper
PIPE_UTMI_CLK_SELorVBUS_VALID. Hence, if only the High-Speed PHY is used for a controller capable of SuperSpeed operations, the controller will assume it should use the USB3 PHY and not the HS PHY as configured before APPS Suspend. This behavior disrupts the normal operation of the USB controller. Similarly, if the controller was operating in device mode prior to APPS suspend, andVBUS_VALIDsignal is not set after APPS resume, this will cause the PHYs to transition into the suspend state. This behavior disrupts the normal operation of the USB controller.Address the issues by ensuring that the
PIPE_UTMI_CLK_SELandVBUS_VALIDare handled properly after the system resumes from APPS Suspend. This is crucial for maintaining the correct operational state of the USB controller and preventing unintended suspensions of the PHYs.Also, as the controller is starting from POR state, make sure the controller Reset is performed.
Because the controller is reset on every system resume, the Qscratch restore is done whether or not wakeup was enabled, and dwc3 core is told via
needs_full_reinitto fully re-initialize the core on system resume even in host mode with wakeup enabled. Wakeup on this platform comes from the PHY interrupts routed through PDC, not from the controller staying powered.VBUS_VALIDis only forced outside host mode, matching what probe does.The XHCI controller is reset by the same event, so also set the
xhci_reset_on_resumedwc3 property. dwc3 passes it on to the xhci-plat device as xhci-reset-on-resume-quirk, which makes xhci-plat setXHCI_RESET_ON_RESUME.
Quoted 4 lines
Also make the .prepare callback return 0 on these platforms. A runtime-suspended device in device mode would otherwise be left in place across system sleep (
direct_complete), skipping the system resume callback and with it the reset and Qscratch restore.
Faisal, there are several issues in this patch, would you try to split them?
- XHCI_RESET_ON_RESUME quirk support for dwc3
- PIPE_UTMI_CLK_SEL restore after system resume, there is a similar submission recently [1]
- VBUS override restore after system resume
- The improvement for system resume dues to HW POR or lost of power.
[1]: https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
struct
dwc3_qcom{drivers/usb/dwc3/dwc3-qcom.c +0
-0struct device *dev;void __iomem *qscratch_base;@@ -86,6 +90,13 @@ struct dwc3_qcom {struct icc_path *icc_path_apps;
drivers/usb/dwc3/dwc3-qcom.c struct dwc3_qcom { · line 100
Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +7
-0enum usb_role current_role; + +bool broken_suspend; +bool ignore_pipe_clk; +}; + +static const struct dwc3_qcom_priv_data sa8255p_dwc3_qcom_priv_data = { + .broken_suspend = true, };
Why you consider it is "broken", or is it a normal resume recovery due to lost of status for controller and PHY? Why other SoCs don't need it?
drivers/usb/dwc3/dwc3-qcom.c static void dwc3_qcom_complete(struct device *dev) · line 883
Quoted 12 lines
drivers/usb/dwc3/dwc3-qcom.c +0
-0static int dwc3_qcom_prepare (struct device *dev) {drivers/usb/dwc3/dwc3-qcom.c +9
-0struct dwc3 *dwc =dev_get_drvdata (dev); +struct dwc3_qcom *qcom =to_dwc3_qcom (dwc); + +/* +* The controller loses power across system suspend, so the system +* resume callback must always run to reset and reprogram it. Don't +* let the PM core leave a runtime-suspended device as-is. +*/ +if (qcom->broken_suspend) +return 0 ;
Why we need this? I see dwc3 core do dwc3_core_init_for_resume at device mode during the resume.
Quoted 3 lines
return
dwc3_pm_prepare(dwc);
}
Signature · 2 lines
Thanks, Peter Chen
Re: [PATCH v4 5/7] usb: dwc3: qcom: Support broken suspend for SA8255P
Quoted 44 lines · Peter Chen
Quoted 38 lines · Faisal Hassan
During APPS Suspend, the clock controller unit disables all clocks to the CPU and subsystems, causing the controller to enter the Power-On Reset (POR) state. This results in the loss of Qscratch programming.
Upon APPS Resume, the USB controller does not have the proper
PIPE_UTMI_CLK_SELorVBUS_VALID. Hence, if only the High-Speed PHY is used for a controller capable of SuperSpeed operations, the controller will assume it should use the USB3 PHY and not the HS PHY as configured before APPS Suspend. This behavior disrupts the normal operation of the USB controller. Similarly, if the controller was operating in device mode prior to APPS suspend, andVBUS_VALIDsignal is not set after APPS resume, this will cause the PHYs to transition into the suspend state. This behavior disrupts the normal operation of the USB controller.Address the issues by ensuring that the
PIPE_UTMI_CLK_SELandVBUS_VALIDare handled properly after the system resumes from APPS Suspend. This is crucial for maintaining the correct operational state of the USB controller and preventing unintended suspensions of the PHYs.Also, as the controller is starting from POR state, make sure the controller Reset is performed.
Because the controller is reset on every system resume, the Qscratch restore is done whether or not wakeup was enabled, and dwc3 core is told via
needs_full_reinitto fully re-initialize the core on system resume even in host mode with wakeup enabled. Wakeup on this platform comes from the PHY interrupts routed through PDC, not from the controller staying powered.VBUS_VALIDis only forced outside host mode, matching what probe does.The XHCI controller is reset by the same event, so also set the
xhci_reset_on_resumedwc3 property. dwc3 passes it on to the xhci-plat device as xhci-reset-on-resume-quirk, which makes xhci-plat setXHCI_RESET_ON_RESUME.Quoted 4 lines
Also make the .prepare callback return 0 on these platforms. A runtime-suspended device in device mode would otherwise be left in place across system sleep (
direct_complete), skipping the system resume callback and with it the reset and Qscratch restore.
Quoted 8 lines
Faisal, there are several issues in this patch, would you try to split them?
-XHCI_RESET_ON_RESUMEquirk support for dwc3
-PIPE_UTMI_CLK_SELrestore after system resume, there is a similar submission recently [1]
- VBUS override restore after system resume
- The improvement for system resume dues to HW POR or lost of power.
Yes. For v5 I will split it into:
1. Controller recovery from power loss across system suspend (reset on system resume, full re-init, the flag and its match data).
2. XHCI_RESET_ON_RESUME support for dwc3.
3. VBUS override restore after system resume.
The PIPE_UTMI_CLK_SEL restore is covered by the submission you pointed to [1]. I will drop it from my series and rebase on top of [1]. The reset in my resume path will be placed before the UTMI clock selection, so [1] still takes effect after the reset.
Quoted 7 lines
Quoted 7 lines
struct dwc3_qcom { struct device *dev; void __iomem *qscratch_base;drivers/usb/dwc3/dwc3-qcom.c +0
-0@@ -86,6 +90,13 @@ struct dwc3_qcom {struct icc_path *icc_path_apps;
Quoted 13 lines
drivers/usb/dwc3/dwc3-qcom.c struct dwc3_qcom { · line 100
Quoted 9 lines
drivers/usb/dwc3/dwc3-qcom.c +7
-0enum usb_role current_role; + +bool broken_suspend; +bool ignore_pipe_clk; +}; + +static const struct dwc3_qcom_priv_data sa8255p_dwc3_qcom_priv_data = { + .broken_suspend = true, };Why you consider it is "broken", or is it a normal resume recovery due to lost of status for controller and PHY? Why other SoCs don't need it?
It is a normal recovery, and "broken" is the wrong name. On this automotive platform the GDSC must be powered down and the APPS enters VDDmin during system suspend, so the controller loses its state, including the Qscratch programming. This is the same case that needs_full_reinit was added for, and dwc3-imx sets it unconditionally and restores its glue registers on resume for the same reason ("Upon power loss any previous configuration is lost, restore it"). I will rename the flag to describe the power loss (power_lost_in_suspend) and reword the subject and commit message.
Quoted 7 lines
Quoted 7 lines
drivers/usb/dwc3/dwc3-qcom.c +0
-0static int dwc3_qcom_prepare (struct device *dev) {struct dwc3 *dwc = dev_get_drvdata(dev);drivers/usb/dwc3/dwc3-qcom.c +4
-0+struct dwc3_qcom *qcom =to_dwc3_qcom (dwc); + +/* +* The controller loses power across system suspend, so the system
Quoted 9 lines
drivers/usb/dwc3/dwc3-qcom.c static void dwc3_qcom_complete(struct device *dev) · line 883
Quoted 5 lines
drivers/usb/dwc3/dwc3-qcom.c +5
-0+* resume callback must always run to reset and reprogram it. Don't +* let the PM core leave a runtime-suspended device as-is. +*/ +if (qcom->broken_suspend) +return 0 ;Why we need this? I see dwc3 core do
dwc3_core_init_for_resumeat device mode during the resume.
That only helps if the system resume callback runs. dwc3_pm_prepare() returns 1 when the controller is in device mode and already runtime suspended, so the PM core takes the direct_complete path and skips the system resume callbacks. Neither the core re-init nor the glue's reset and Qscratch restore would run after the power loss, and the runtime resume path does not do the glue part. Returning 0 from .prepare makes system resume run.
I am going to confirm this on hardware and will put the result in the v5 commit message.
Quoted 4 lines
Quoted 3 lines
return dwc3_pm_prepare(dwc); }
PATCH v4 6/7 usb: dwc3: qcom: Support firmware-managed resource states for power management
In reply to Faisal HassanAdd 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 two domains are voted on and off directly from the PM callbacks through dwc3_qcom_domains_get() and dwc3_qcom_domains_put(). Runtime PM 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 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.
These votes are taken during probe, remove, suspend and resume, enabling coordinated management of grouped resources according to the controller's operational requirements.
Enable firmware-managed resource handling for the "qcom,sa8255p-dwc3" compatible while maintaining backward compatibility with existing platforms that use direct resource control.
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.
While here, assert the controller reset in dwc3_qcom_remove() and on the probe error-unwind path once the controller is powered down. These paths are shared by every qcom,snps-dwc3 platform, not only the firmware-managed ones added here. That is safe for existing platforms, because remove() already fully powers the controller down and a probe failure already leaves it unclocked.
--- drivers/usb/dwc3/dwc3-qcom.c | 252 +++++++++++++++++++++++++++++++---- 1 file changed, 228 insertions(+), 24 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +228 -24
@@ -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 broken_suspend; +bool fw_managed; };struct dwc3_qcom {
@@ -93,14 +95,142 @@ struct dwc3_qcom {bool broken_suspend;bool ignore_pipe_clk; + +bool fw_managed; +struct dev_pm_domain_list *pd_list; };static const struct dwc3_qcom_priv_data sa8255p_dwc3_qcom_priv_data = { .broken_suspend = true, + .fw_managed = true, };#define to_dwc3_qcom (d) container_of((d), struct dwc3_qcom, dwc) +/* +* Firmware-managed resource handling +* +* On platforms where clocks, interconnects, resets and the GDSC for the USB +* controller are owned and sequenced by firmware, access to those resources +* is exposed to Linux as two power domains: +* - pd_list->pd_devs[0] ("power"): the GDSC supplying the controller +* - pd_list->pd_devs[1] ("bus"): the clocks and interconnects used for data +* transfer, which additionally require "power" to be on for register +* accesses to succeed +* +* The two domains are voted on/off directly from each PM callback that needs +* them; there's no attempt to track or name an aggregate device power state, +* since the actual state lives in firmware and is queried by voting through +* runtime PM, not by mirroring it in the driver. +*/ + +/** +* dwc3_qcom_domain_detach() - Detach power domains +* @qcom: Pointer to the dwc3_qcom structure +* +* Detaches all power domains. +*/ +static void dwc3_qcom_domain_detach (struct dwc3_qcom *qcom) +{ +if (qcom->pd_list) +dev_pm_domain_detach_list (qcom->pd_list); +} + +/** +* dwc3_qcom_domain_attach() - Attach power domains +* @qcom: Pointer to the dwc3_qcom structure +* +* Attaches power domains for firmware managed resource handling. +* 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 = { + .pd_flags =PD_FLAG_NO_DEV_LINK , + .pd_names = (const char *[]) {"power" ,"bus" }, + .num_pd_names =2 , + }; +struct device *dev = qcom->dev; +int ret; + + ret =dev_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_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 +* +* Votes runtime PM "on" for the domains this call is responsible for. Each +* call has exactly one matching dwc3_qcom_domains_put() call with the same +* @bus_only value on the corresponding disable path; runtime PM's own usage +* counting is what keeps power on for as long as bus needs it, without the +* driver tracking or assuming any prior domain state itself. +* 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[0 ]; +struct device *bus_dev = qcom->pd_list->pd_devs[1 ]; +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 +* +* Releases the votes taken by the matching dwc3_qcom_domains_get() call. +* Bus is released before power since bus register accesses require power +* to still be on. +* +* pm_runtime_put_sync() drops the usage count even when it returns an error, +* so the votes are released regardless and errors are only reported. Treating +* them as failures would make callers believe the votes are still held and +* unbalance the next dwc3_qcom_domains_get()/put() pair. +*/ +static void dwc3_qcom_domains_put (struct dwc3_qcom *qcom,bool bus_only) +{ +struct device *power_dev = qcom->pd_list->pd_devs[0 ]; +struct device *bus_dev = qcom->pd_list->pd_devs[1 ]; +int ret; + + ret =pm_runtime_put_sync (bus_dev); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable bus domain: %d\n" , ret); + +if (bus_only) +return ; + + ret =pm_runtime_put_sync (power_dev); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable power domain: %d\n" , ret); +} +static inline void dwc3_qcom_setbits (void __iomem *base,u32 offset,u32 val) {u32 reg;
@@ -380,8 +510,20 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)int i, ret;bool wakeup; -if (qcom->is_suspended) +if (qcom->is_suspended) { +/* +* 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. The usage count +* is dropped even if this fails, so don't fail the suspend. +*/ +if (qcom->fw_managed && !PMSG_IS_AUTO (msg)) { + ret =pm_runtime_put_sync (qcom->pd_list->pd_devs[0 ]); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable power domain: %d\n" , ret); + }return 0 ; + }/* * For runtime suspend, always enable wakeup.
@@ -397,11 +539,17 @@ 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); +if (!qcom->fw_managed) { +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); + }else { +/* Runtime suspend keeps power voted on; system suspend drops both. */ +dwc3_qcom_domains_put (qcom,PMSG_IS_AUTO (msg)); + }/* * The role is stable during suspend as role switching is done from a
@@ -456,13 +604,22 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)*/ dwc3_qcom_disable_interrupts (qcom); - ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); -if (ret <0 ) -return ret; +if (!qcom->fw_managed) { + 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); + ret =dwc3_qcom_interconnect_enable (qcom); +if (ret) +dev_warn (qcom->dev,"failed to enable interconnect: %d\n" , ret); + }else { +/* Runtime resume re-votes bus only; system resume votes both. */ + ret =dwc3_qcom_domains_get (qcom,PMSG_IS_AUTO (msg)); +if (ret) { +dev_err (qcom->dev,"failed to enable power domains: %d\n" , ret); +return ret; + } + }/* Clear existing events from PHY related to L2 in/out */ for (i =0 ; i < qcom->num_ports; i++) {
@@ -699,16 +856,21 @@ static int dwc3_qcom_probe(struct platform_device *pdev)if (priv_data) qcom->broken_suspend = priv_data->broken_suspend; +if (priv_data && priv_data->fw_managed) + qcom->fw_managed = priv_data->fw_managed; + 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),"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; + } ret =reset_control_assert (qcom->resets);if (ret) {
@@ -724,9 +886,33 @@ static int dwc3_qcom_probe(struct platform_device *pdev)return ret; } - ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); -if (ret <0 ) -return ret; +if (!qcom->fw_managed) { + ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); +if (ret <0 ) { +reset_control_assert (qcom->resets); +return ret; + } + }else { + ret =dwc3_qcom_domain_attach (qcom); +if (ret) { +dev_err (dev,"Failed to attach domains (%d).\n" , ret); +reset_control_assert (qcom->resets); +return ret; + } + +/* +* pm_runtime_resume_and_get() is correct here regardless of +* whatever state firmware or the bootloader left the domains +* in beforehand. +*/ + ret =dwc3_qcom_domains_get (qcom, false/* bus_only */ ); +if (ret) { +dev_err (dev,"Failed to enable power domains (%d)\n" , ret); +dwc3_qcom_domain_detach (qcom); +reset_control_assert (qcom->resets); +return ret; + } + } r =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!r) {
@@ -790,9 +976,11 @@ static int dwc3_qcom_probe(struct platform_device *pdev) goto clk_disable; } - ret =dwc3_qcom_interconnect_init (qcom); -if (ret) - goto remove_core; +if (!qcom->fw_managed) { + ret =dwc3_qcom_interconnect_init (qcom); +if (ret) + goto remove_core; + } wakeup_source =of_property_read_bool (dev->of_node,"wakeup-source" );device_init_wakeup (&pdev->dev, wakeup_source);
@@ -804,7 +992,14 @@ static int dwc3_qcom_probe(struct platform_device *pdev) remove_core:dwc3_core_remove (&qcom->dwc); clk_disable: -clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); +if (!qcom->fw_managed) { +clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); + }else { +dwc3_qcom_domains_put (qcom, false/* bus_only */ ); +dwc3_qcom_domain_detach (qcom); + } + +reset_control_assert (qcom->resets);return ret; }
@@ -817,9 +1012,18 @@ static void dwc3_qcom_remove(struct platform_device *pdev)if (pm_runtime_resume_and_get (qcom->dev) <0 )return ; +/* Also disables runtime PM and marks the device suspended. */ dwc3_core_remove (&qcom->dwc); -clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); -dwc3_qcom_interconnect_exit (qcom); + +if (!qcom->fw_managed) { +clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); +dwc3_qcom_interconnect_exit (qcom); + }else { +dwc3_qcom_domains_put (qcom, false/* bus_only */ ); +dwc3_qcom_domain_detach (qcom); + } + +reset_control_assert (qcom->resets);pm_runtime_put_noidle (qcom->dev); }
Signature · 1 line
2.34.1
Re: [PATCH v4 6/7] usb: dwc3: qcom: Support firmware-managed resource states for power management
Quoted 53 lines · Faisal Hassan
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 two domains are voted on and off directly from the PM callbacks through
dwc3_qcom_domains_get()anddwc3_qcom_domains_put(). Runtime PM 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
PD_FLAG_NO_DEV_LINKbecause 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.These votes are taken during probe, remove, suspend and resume, enabling coordinated management of grouped resources according to the controller's operational requirements.
Enable firmware-managed resource handling for the "qcom,sa8255p-dwc3" compatible while maintaining backward compatibility with existing platforms that use direct resource control.
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.
Quoted 6 lines
While here, assert the controller reset in
dwc3_qcom_remove()and on the probe error-unwind path once the controller is powered down. These paths are shared by every qcom,snps-dwc3 platform, not only the firmware-managed ones added here. That is safe for existing platforms, becauseremove()already fully powers the controller down and a probe failure already leaves it unclocked.
Since you do controller reset for all platforms, would you please split this patch for:
- Add controller reset for all qcom platforms
- Add firmware-based resource management for auto SoCs
Quoted 38 lines
drivers/usb/dwc3/dwc3-qcom.c +37
-0+/* +* Firmware-managed resource handling +* +* On platforms where clocks, interconnects, resets and the GDSC for the USB +* controller are owned and sequenced by firmware, access to those resources +* is exposed to Linux as two power domains: +* - pd_list->pd_devs[0] ("power"): the GDSC supplying the controller +* - pd_list->pd_devs[1] ("bus"): the clocks and interconnects used for data +* transfer, which additionally require "power" to be on for register +* accesses to succeed +* +* The two domains are voted on/off directly from each PM callback that needs +* them; there's no attempt to track or name an aggregate device power state, +* since the actual state lives in firmware and is queried by voting through +* runtime PM, not by mirroring it in the driver. +*/ + +/** +* dwc3_qcom_domain_detach() - Detach power domains +* @qcom: Pointer to the dwc3_qcom structure +* +* Detaches all power domains. +*/ +static void dwc3_qcom_domain_detach (struct dwc3_qcom *qcom) +{ +if (qcom->pd_list) +dev_pm_domain_detach_list (qcom->pd_list); +} + +/** +* dwc3_qcom_domain_attach() - Attach power domains +* @qcom: Pointer to the dwc3_qcom structure +* +* Attaches power domains for firmware managed resource handling. +* Returns 0 on success, negative error code on failure. +*/ +static int dwc3_qcom_domain_attach (struct dwc3_qcom *qcom)
drivers/usb/dwc3/dwc3-qcom.c struct dwc3_qcom { · line 156
Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +10
-0+{ +struct dev_pm_domain_attach_data pd_data = { + .pd_flags =PD_FLAG_NO_DEV_LINK , + .pd_names = (const char *[]) {"power" ,"bus" }, + .num_pd_names =2 , + }; +struct device *dev = qcom->dev; +int ret; + + ret =dev_pm_domain_attach_list (dev, &pd_data, &qcom->pd_list);
Using devm_pm_domain_attach_list, the dwc3_qcom_domain_detach is not needed any more.
Quoted 258 lines
drivers/usb/dwc3/dwc3-qcom.c +168
-24+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_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 +* +* Votes runtime PM "on" for the domains this call is responsible for. Each +* call has exactly one matching dwc3_qcom_domains_put() call with the same +* @bus_only value on the corresponding disable path; runtime PM's own usage +* counting is what keeps power on for as long as bus needs it, without the +* driver tracking or assuming any prior domain state itself. +* 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[0 ]; +struct device *bus_dev = qcom->pd_list->pd_devs[1 ]; +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 +* +* Releases the votes taken by the matching dwc3_qcom_domains_get() call. +* Bus is released before power since bus register accesses require power +* to still be on. +* +* pm_runtime_put_sync() drops the usage count even when it returns an error, +* so the votes are released regardless and errors are only reported. Treating +* them as failures would make callers believe the votes are still held and +* unbalance the next dwc3_qcom_domains_get()/put() pair. +*/ +static void dwc3_qcom_domains_put (struct dwc3_qcom *qcom,bool bus_only) +{ +struct device *power_dev = qcom->pd_list->pd_devs[0 ]; +struct device *bus_dev = qcom->pd_list->pd_devs[1 ]; +int ret; + + ret =pm_runtime_put_sync (bus_dev); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable bus domain: %d\n" , ret); + +if (bus_only) +return ; + + ret =pm_runtime_put_sync (power_dev); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable power domain: %d\n" , ret); +} +static inline void dwc3_qcom_setbits (void __iomem *base,u32 offset,u32 val) {u32 reg;@@ -380,8 +510,20 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)int i, ret;bool wakeup; -if (qcom->is_suspended) +if (qcom->is_suspended) { +/* +* 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. The usage count +* is dropped even if this fails, so don't fail the suspend. +*/ +if (qcom->fw_managed && !PMSG_IS_AUTO (msg)) { + ret =pm_runtime_put_sync (qcom->pd_list->pd_devs[0 ]); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable power domain: %d\n" , ret); + }return 0 ; + }/* * For runtime suspend, always enable wakeup. @@ -397,11 +539,17 @@ 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); +if (!qcom->fw_managed) { +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); + }else { +/* Runtime suspend keeps power voted on; system suspend drops both. */ +dwc3_qcom_domains_put (qcom,PMSG_IS_AUTO (msg)); + }/* * The role is stable during suspend as role switching is done from a @@ -456,13 +604,22 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)*/ dwc3_qcom_disable_interrupts (qcom); - ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); -if (ret <0 ) -return ret; +if (!qcom->fw_managed) { + 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); + ret =dwc3_qcom_interconnect_enable (qcom); +if (ret) +dev_warn (qcom->dev,"failed to enable interconnect: %d\n" , ret); + }else { +/* Runtime resume re-votes bus only; system resume votes both. */ + ret =dwc3_qcom_domains_get (qcom,PMSG_IS_AUTO (msg)); +if (ret) { +dev_err (qcom->dev,"failed to enable power domains: %d\n" , ret); +return ret; + } + }/* Clear existing events from PHY related to L2 in/out */ for (i =0 ; i < qcom->num_ports; i++) {@@ -699,16 +856,21 @@ static int dwc3_qcom_probe(struct platform_device *pdev)if (priv_data) qcom->broken_suspend = priv_data->broken_suspend; +if (priv_data && priv_data->fw_managed) + qcom->fw_managed = priv_data->fw_managed; + 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),"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; + } ret =reset_control_assert (qcom->resets);if (ret) {@@ -724,9 +886,33 @@ static int dwc3_qcom_probe(struct platform_device *pdev)return ret; } - ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); -if (ret <0 ) -return ret; +if (!qcom->fw_managed) { + ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); +if (ret <0 ) { +reset_control_assert (qcom->resets); +return ret; + } + }else { + ret =dwc3_qcom_domain_attach (qcom); +if (ret) { +dev_err (dev,"Failed to attach domains (%d).\n" , ret); +reset_control_assert (qcom->resets); +return ret; + } + +/* +* pm_runtime_resume_and_get() is correct here regardless of +* whatever state firmware or the bootloader left the domains +* in beforehand. +*/ + ret =dwc3_qcom_domains_get (qcom, false/* bus_only */ ); +if (ret) { +dev_err (dev,"Failed to enable power domains (%d)\n" , ret); +dwc3_qcom_domain_detach (qcom); +reset_control_assert (qcom->resets); +return ret; + } + } r =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!r) {@@ -790,9 +976,11 @@ static int dwc3_qcom_probe(struct platform_device *pdev) goto clk_disable; } - ret =dwc3_qcom_interconnect_init (qcom); -if (ret) - goto remove_core; +if (!qcom->fw_managed) { + ret =dwc3_qcom_interconnect_init (qcom); +if (ret) + goto remove_core; + } wakeup_source =of_property_read_bool (dev->of_node,"wakeup-source" );device_init_wakeup (&pdev->dev, wakeup_source);@@ -804,7 +992,14 @@ static int dwc3_qcom_probe(struct platform_device *pdev) remove_core:dwc3_core_remove (&qcom->dwc); clk_disable: -clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); +if (!qcom->fw_managed) { +clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); + }else { +dwc3_qcom_domains_put (qcom, false/* bus_only */ ); +dwc3_qcom_domain_detach (qcom); + } + +reset_control_assert (qcom->resets);return ret; }@@ -817,9 +1012,18 @@ static void dwc3_qcom_remove(struct platform_device *pdev)if (pm_runtime_resume_and_get (qcom->dev) <0 )return ; +/* Also disables runtime PM and marks the device suspended. */ dwc3_core_remove (&qcom->dwc); -clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); -dwc3_qcom_interconnect_exit (qcom); + +if (!qcom->fw_managed) { +clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks);
drivers/usb/dwc3/dwc3-qcom.c static void dwc3_qcom_remove(struct platform_device *pdev) · line 1029
Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +7
-0+dwc3_qcom_interconnect_exit (qcom); + }else { +dwc3_qcom_domains_put (qcom, false/* bus_only */ ); +dwc3_qcom_domain_detach (qcom); + } + +reset_control_assert (qcom->resets);pm_runtime_put_noidle (qcom->dev); }
There are so many judgements for qcom->fw_managed during the main flow, since there are only resource management difference, is it possible hide the differences for the main flow, and add some qcom USB resource APIs for them, eg:
static void dwc3_qcom_clk_disable(struct dwc3_qcom *qcom, bool bus_only)
{
if (!qcom->fw_managed)
clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
else
dwc3_qcom_domains_put(qcom, is_all);
}For calling dwc3_qcom_interconnect_init(qcom), if it is fw_managed, just boil out.
Signature · 2 lines
Thanks, Peter Chen
Re: [PATCH v4 6/7] usb: dwc3: qcom: Support firmware-managed resource states for power management
Quoted 54 lines · Peter Chen
Quoted 53 lines · Faisal Hassan
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 two domains are voted on and off directly from the PM callbacks through
dwc3_qcom_domains_get()anddwc3_qcom_domains_put(). Runtime PM 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
PD_FLAG_NO_DEV_LINKbecause 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.These votes are taken during probe, remove, suspend and resume, enabling coordinated management of grouped resources according to the controller's operational requirements.
Enable firmware-managed resource handling for the "qcom,sa8255p-dwc3" compatible while maintaining backward compatibility with existing platforms that use direct resource control.
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.
Quoted 6 lines
Quoted 6 lines
While here, assert the controller reset in
dwc3_qcom_remove()and on the probe error-unwind path once the controller is powered down. These paths are shared by every qcom,snps-dwc3 platform, not only the firmware-managed ones added here. That is safe for existing platforms, becauseremove()already fully powers the controller down and a probe failure already leaves it unclocked.
Hi Peter,
Thanks for the review.
Quoted 7 lines
Since you do controller reset for all platforms, would you please split this patch for:
- Add controller reset for all qcom platforms
- Add firmware-based resource management for auto SoCs
Ok, I will move the reset on remove() and on the probe error path into its own patch, ahead of the firmware-managed one.
Quoted 43 lines
Quoted 43 lines
drivers/usb/dwc3/dwc3-qcom.c +42
-0+/* +* Firmware-managed resource handling +* +* On platforms where clocks, interconnects, resets and the GDSC for the USB +* controller are owned and sequenced by firmware, access to those resources +* is exposed to Linux as two power domains: +* - pd_list->pd_devs[0] ("power"): the GDSC supplying the controller +* - pd_list->pd_devs[1] ("bus"): the clocks and interconnects used for data +* transfer, which additionally require "power" to be on for register +* accesses to succeed +* +* The two domains are voted on/off directly from each PM callback that needs +* them; there's no attempt to track or name an aggregate device power state, +* since the actual state lives in firmware and is queried by voting through +* runtime PM, not by mirroring it in the driver. +*/ + +/** +* dwc3_qcom_domain_detach() - Detach power domains +* @qcom: Pointer to the dwc3_qcom structure +* +* Detaches all power domains. +*/ +static void dwc3_qcom_domain_detach (struct dwc3_qcom *qcom) +{ +if (qcom->pd_list) +dev_pm_domain_detach_list (qcom->pd_list); +} + +/** +* dwc3_qcom_domain_attach() - Attach power domains +* @qcom: Pointer to the dwc3_qcom structure +* +* Attaches power domains for firmware managed resource handling. +* 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 = { + .pd_flags =PD_FLAG_NO_DEV_LINK , + .pd_names = (const char *[]) {"power" ,"bus" }, + .num_pd_names =2 ,
Quoted 9 lines
drivers/usb/dwc3/dwc3-qcom.c struct dwc3_qcom { · line 156
Quoted 5 lines
drivers/usb/dwc3/dwc3-qcom.c +5
-0+ }; +struct device *dev = qcom->dev; +int ret; + + ret =dev_pm_domain_attach_list (dev, &pd_data, &qcom->pd_list);Using
devm_pm_domain_attach_list, thedwc3_qcom_domain_detachis not needed any more.
Ok, I will switch to devm_pm_domain_attach_list() and drop dwc3_qcom_domain_detach().
Quoted 274 lines
Quoted 258 lines
drivers/usb/dwc3/dwc3-qcom.c +168
-24+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_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 +* +* Votes runtime PM "on" for the domains this call is responsible for. Each +* call has exactly one matching dwc3_qcom_domains_put() call with the same +* @bus_only value on the corresponding disable path; runtime PM's own usage +* counting is what keeps power on for as long as bus needs it, without the +* driver tracking or assuming any prior domain state itself. +* 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[0 ]; +struct device *bus_dev = qcom->pd_list->pd_devs[1 ]; +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 +* +* Releases the votes taken by the matching dwc3_qcom_domains_get() call. +* Bus is released before power since bus register accesses require power +* to still be on. +* +* pm_runtime_put_sync() drops the usage count even when it returns an error, +* so the votes are released regardless and errors are only reported. Treating +* them as failures would make callers believe the votes are still held and +* unbalance the next dwc3_qcom_domains_get()/put() pair. +*/ +static void dwc3_qcom_domains_put (struct dwc3_qcom *qcom,bool bus_only) +{ +struct device *power_dev = qcom->pd_list->pd_devs[0 ]; +struct device *bus_dev = qcom->pd_list->pd_devs[1 ]; +int ret; + + ret =pm_runtime_put_sync (bus_dev); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable bus domain: %d\n" , ret); + +if (bus_only) +return ; + + ret =pm_runtime_put_sync (power_dev); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable power domain: %d\n" , ret); +} +static inline void dwc3_qcom_setbits (void __iomem *base,u32 offset,u32 val) {u32 reg;@@ -380,8 +510,20 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, pm_message_t msg)int i, ret;bool wakeup; -if (qcom->is_suspended) +if (qcom->is_suspended) { +/* +* 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. The usage count +* is dropped even if this fails, so don't fail the suspend. +*/ +if (qcom->fw_managed && !PMSG_IS_AUTO (msg)) { + ret =pm_runtime_put_sync (qcom->pd_list->pd_devs[0 ]); +if (ret <0 ) +dev_warn (qcom->dev,"failed to disable power domain: %d\n" , ret); + }return 0 ; + }/* * For runtime suspend, always enable wakeup. @@ -397,11 +539,17 @@ 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); +if (!qcom->fw_managed) { +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); + }else { +/* Runtime suspend keeps power voted on; system suspend drops both. */ +dwc3_qcom_domains_put (qcom,PMSG_IS_AUTO (msg)); + }/* * The role is stable during suspend as role switching is done from a @@ -456,13 +604,22 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, pm_message_t msg)*/ dwc3_qcom_disable_interrupts (qcom); - ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); -if (ret <0 ) -return ret; +if (!qcom->fw_managed) { + 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); + ret =dwc3_qcom_interconnect_enable (qcom); +if (ret) +dev_warn (qcom->dev,"failed to enable interconnect: %d\n" , ret); + }else { +/* Runtime resume re-votes bus only; system resume votes both. */ + ret =dwc3_qcom_domains_get (qcom,PMSG_IS_AUTO (msg)); +if (ret) { +dev_err (qcom->dev,"failed to enable power domains: %d\n" , ret); +return ret; + } + }/* Clear existing events from PHY related to L2 in/out */ for (i =0 ; i < qcom->num_ports; i++) {@@ -699,16 +856,21 @@ static int dwc3_qcom_probe(struct platform_device *pdev)if (priv_data) qcom->broken_suspend = priv_data->broken_suspend; +if (priv_data && priv_data->fw_managed) + qcom->fw_managed = priv_data->fw_managed; + 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),"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; + } ret =reset_control_assert (qcom->resets);if (ret) {@@ -724,9 +886,33 @@ static int dwc3_qcom_probe(struct platform_device *pdev)return ret; } - ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); -if (ret <0 ) -return ret; +if (!qcom->fw_managed) { + ret =clk_bulk_prepare_enable (qcom->num_clocks, qcom->clks); +if (ret <0 ) { +reset_control_assert (qcom->resets); +return ret; + } + }else { + ret =dwc3_qcom_domain_attach (qcom); +if (ret) { +dev_err (dev,"Failed to attach domains (%d).\n" , ret); +reset_control_assert (qcom->resets); +return ret; + } + +/* +* pm_runtime_resume_and_get() is correct here regardless of +* whatever state firmware or the bootloader left the domains +* in beforehand. +*/ + ret =dwc3_qcom_domains_get (qcom, false/* bus_only */ ); +if (ret) { +dev_err (dev,"Failed to enable power domains (%d)\n" , ret); +dwc3_qcom_domain_detach (qcom); +reset_control_assert (qcom->resets); +return ret; + } + } r =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!r) {@@ -790,9 +976,11 @@ static int dwc3_qcom_probe(struct platform_device *pdev) goto clk_disable; } - ret =dwc3_qcom_interconnect_init (qcom); -if (ret) - goto remove_core; +if (!qcom->fw_managed) { + ret =dwc3_qcom_interconnect_init (qcom); +if (ret) + goto remove_core; + } wakeup_source =of_property_read_bool (dev->of_node,"wakeup-source" );device_init_wakeup (&pdev->dev, wakeup_source);@@ -804,7 +992,14 @@ static int dwc3_qcom_probe(struct platform_device *pdev) remove_core:dwc3_core_remove (&qcom->dwc); clk_disable: -clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); +if (!qcom->fw_managed) { +clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); + }else { +dwc3_qcom_domains_put (qcom, false/* bus_only */ ); +dwc3_qcom_domain_detach (qcom); + } + +reset_control_assert (qcom->resets);return ret; }@@ -817,9 +1012,18 @@ static void dwc3_qcom_remove(struct platform_device *pdev)if (pm_runtime_resume_and_get (qcom->dev) <0 )return ; +/* Also disables runtime PM and marks the device suspended. */ dwc3_core_remove (&qcom->dwc); -clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks); -dwc3_qcom_interconnect_exit (qcom); + +if (!qcom->fw_managed) { +clk_bulk_disable_unprepare (qcom->num_clocks, qcom->clks);drivers/usb/dwc3/dwc3-qcom.c static void dwc3_qcom_remove(struct platform_device *pdev) · line 1029
Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +7
-0+dwc3_qcom_interconnect_exit (qcom); + }else { +dwc3_qcom_domains_put (qcom, false/* bus_only */ ); +dwc3_qcom_domain_detach (qcom); + } + +reset_control_assert (qcom->resets);pm_runtime_put_noidle (qcom->dev); }There are so many judgements for
qcom->fw_managedduring the main flow, since there are only resource management difference, is it possible hide the differences for the main flow, and add some qcom USB resource APIs for them, eg:static void
dwc3_qcom_clk_disable(struct dwc3_qcom *qcom, bool bus_only)
Quoted 9 lines
{ if (!qcom->fw_managed) clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks); else dwc3_qcom_domains_put(qcom, is_all); }For calling
dwc3_qcom_interconnect_init(qcom), if it isfw_managed, just boil out.
Ok, I will add resource enable/disable helpers that wrap either the clocks and interconnect or the power domain votes, so the suspend, resume, probe and remove paths no longer check fw_managed. dwc3_qcom_interconnect_init() will return early on firmware-managed platforms, as you suggest.
Thanks,
Faisal
PATCH v4 7/7 usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role
In reply to Faisal HassanWhen 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 at probe whenever the initial role is USB_ROLE_DEVICE.
Validated on SA8255P with an HS host attached: 20 unbind/bind and 20 suspend/resume iterations completed with no failures.
--- drivers/usb/dwc3/dwc3-qcom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +4 -2
@@ -953,10 +953,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)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 )) + (usb_get_role_switch_default_mode (dev) ==USB_DR_MODE_HOST )) { qcom->current_role =USB_ROLE_HOST ; -else + }else { qcom->current_role =USB_ROLE_DEVICE ; +dwc3_qcom_vbus_override_enable (qcom, true); + } } qcom->dwc.glue_ops = &dwc3_qcom_glue_ops;
Signature · 1 line
2.34.1
Re: [PATCH v4 7/7] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role
Quoted 22 lines · 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 at probe whenever the initial role is
USB_ROLE_DEVICE.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 <[email protected]>--- drivers/usb/dwc3/dwc3-qcom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-qcom.c +0
-0@@ -953,10 +953,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)dwc3_qcom_vbus_override_enable (qcom, true);
....
drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_probe(struct platform_device *pdev) · line 961
Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +4
-2}else {if ((device_property_read_bool (dev,"usb-role-switch" )) && - (usb_get_role_switch_default_mode (dev) ==USB_DR_MODE_HOST )) + (usb_get_role_switch_default_mode (dev) ==USB_DR_MODE_HOST )) { qcom->current_role =USB_ROLE_HOST ; -else + }else { qcom->current_role =USB_ROLE_DEVICE ; +dwc3_qcom_vbus_override_enable (qcom, true); + }
How about move it and above [....] under device role, let above code purely determine current_role:
if (qcom->current_role == USB_ROLE_DEVICE) dwc3_qcom_vbus_override_enable(qcom, true);
Peter
Signature · 2 lines
Thanks, Peter Chen
Re: [PATCH v4 7/7] usb: dwc3: qcom: Enable VBUS override at probe for default peripheral role
Quoted 26 lines · Peter Chen
Quoted 22 lines · 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 at probe whenever the initial role is
USB_ROLE_DEVICE.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 <[email protected]>--- drivers/usb/dwc3/dwc3-qcom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/usb/dwc3/dwc3-qcom.c +0
-0@@ -953,10 +953,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)dwc3_qcom_vbus_override_enable (qcom, true);....
Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_probe(struct platform_device *pdev) · line 961
Quoted 10 lines
} else { if ((device_property_read_bool(dev, "usb-role-switch")) &&drivers/usb/dwc3/dwc3-qcom.c +4
-2- (usb_get_role_switch_default_mode(dev) == USB_DR_MODE_HOST)) + (usb_get_role_switch_default_mode(dev) == USB_DR_MODE_HOST)) { qcom->current_role = USB_ROLE_HOST; - else + } else { qcom->current_role =USB_ROLE_DEVICE ; +dwc3_qcom_vbus_override_enable (qcom, true); + }
Hi Peter,
Thanks for the review.
Quoted 7 lines
How about move it and above [....] under device role, let above code purely determine
current_role:if (qcom->current_role == USB_ROLE_DEVICE) dwc3_qcom_vbus_override_enable(qcom, true);Peter
Ok, I will make the mode and role-switch code only determine current_role, and enable the VBUS override once afterwards when current_role is USB_ROLE_DEVICE.
Thanks,
Faisal