Add LPASS VA CSR HeartBeat pulse clock support
v16 cover Add LPASS VA CSR HeartBeat pulse clock support
The LPASS VA CSR block contains rate generator hardware that produces a HeartBeat Pulse (also known as RateGen Pulse). This pulse synchronizes the start of the DMAs and Codec Interfaces for the audio usecases and can serve as a periodic wakeup source for the DSP.
This series adds the DT binding and driver support to model this rate generator as a clock provider.
Patch 1 adds the YAML binding for the new qcom,hawi-lpass-va-csr clock provider node under Documentation/devicetree/bindings/clock/.
Patch 2 adds the lpass-va-csr driver under drivers/clk/qcom that registers the lpass-heartbeat-pulse clock and enables/disables the rate generator via regmap when the clock consumer requests it.
Changes in v16:
- Rebase the series on linux-next next-20261202.
- Rename the registered heartbeat clock to lpass-heartbeat-pulse (Srinivas).
- Move the match-data lookup after allocation and drop the unreachable missing match-data error path (Srinivas).
- Use a shared runtime PM put error path after pm_runtime_resume_and_get() (Srinivas).
- Add Srinivas and Prasad review and test tags from v15 patch replies.
- Link to v15: https://patch.msgid.link/[email protected]
Changes in v15:
- Rebase the series on linux-next next-20261127.
- Drop Prasad's Reviewed-by and Tested-by tags from the individual
patches because the tags were provided as a reply to the cover letter rather than the patch mails (Krzysztof).
- No code changes.
- Link to v14: https://patch.msgid.link/[email protected]
Changes in v14:
- Rebase the series on linux-next next-20261119.
- Add Prasad's Reviewed-by and Tested-by tags.
- Resolve the Makefile context against latest linux-next by keeping the
new entry in the existing CONFIG_QCOM_CLK_* block; no functional
driver changes.
- Link to v13: https://patch.msgid.link/[email protected]
Changes in v13:
- Rebase the series on linux-next next-20261104.
- Create and populate the PM clock list before enabling runtime PM so runtime resume cannot touch VA CSR registers before the LPASS vote
clocks are available (Sashiko).
- Drop the regmap cache for the LPASS rate generator registers to avoid stale LPASS_RATE_GEN_CTRL state after LPASS register context loss (Sashiko).
- Use runtime PM force suspend and resume for system sleep, and restore LPASS_RATE_GEN_CTRL on resume when the heartbeat clock was enabled
before LPASS register context loss.
- Link to v12: https://patch.msgid.link/[email protected]
Changes in v12:
- Rebase the series on linux-next next-20261020.
- Depend on PM_CLK so COMPILE_TEST builds cannot select the driver when pm_clk_suspend() and pm_clk_resume() are unavailable (Sashiko, LKP).
- Link to v11: https://patch.msgid.link/[email protected]
Changes in v11:
- Rebase the series on linux-next next-20261009.
- Drop the custom heartbeat prepare/unprepare callbacks and rely on CCF provider runtime PM handling (Ajay).
- Restore the rate generator counter and delay registers from the
runtime resume callback after the LPASS vote clocks are enabled
(Sashiko).
- Add an of_device_get_match_data() NULL guard (Sashiko).
- Link to v10: https://patch.msgid.link/[email protected]
Changes in v10:
- Rebase the series on linux-next next-20260929.
- Add clk_is_enabled_regmap() to report the heartbeat gate state for clk_disable_unused() (Sashiko).
- Add Rob's Reviewed-by tag to the binding patch.
- Link to v9: https://patch.msgid.link/[email protected]
Changes in v9:
- Rebase the series on linux-next next-20260928.
- Add runtime PM callbacks so the LPASS LPR and audio vote clocks are enabled by pm_runtime_resume_and_get() before touching VA CSR
registers.
- Keep the LPASS vote clocks enabled across heartbeat clock
enable/disable register accesses by taking a runtime PM reference from the heartbeat clock prepare path.
- Use synchronous runtime PM put on probe success and error paths.
- Drop the one-use runtime PM error label while keeping synchronous puts (Konrad).
- Wrap the runtime PM ops with pm_ptr() from HTML review.
- Link to v8: https://patch.msgid.link/[email protected]
Changes in v8:
- Rebase the series on linux-next next-20260916.
- Require the LPASS LPR and audio vote clocks to access VA CSR
register space safely.
- Attach the DT vote clocks to runtime PM and resume the device before
programming the rate generator registers.
- Program the counter and delay registers once during probe.
- Use qcom's simple regmap gate ops for the enable bit (Srinivas).
- Drop the unreachable of_device_get_match_data() NULL check (Srinivas).
- Drop stale Reviewed-by/Tested-by tags after the binding and driver
changes.
- Link to v7: https://patch.msgid.link/20260831-heartbeat-v7-next-20260828-v7-0-e3ffeac46a51@oss.qualcomm.com
Changes in v7:
- Rebase the series on linux-next next-20260828.
- Add Prasad's Reviewed-by and Tested-by tags to patch 2.
- Link to v6: https://patch.msgid.link/20260821-heartbeat-v6-next-20260821-send-v6-0-62c5df84ce21@oss.qualcomm.com
Changes in v6:
- Rebase the series on linux-next next-20260821.
- Capitalize Hawi in binding text (Bjorn).
- Simplify the binding example by removing the soc wrapper and
two-cell address/size setup (Bjorn).
- Keep the full VA CSR register window in the binding and describe it
as the VA CSR register block after Konrad clarified the earlier
register-range concern (Bjorn, Konrad).
- Link to v5: https://patch.msgid.link/[email protected]
Changes in v5:
- Add explicit ARM64 Kconfig gating and Qualcomm default-module policy
for QCOM_CLK_LPASS_HEARTBEAT_PULSE to align with nearby qcom clock
entries.
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Rename the binding filename and schema ID to hawi-specific naming:
qcom,lpass-va-csr.yaml -> qcom,hawi-lpass-va-csr.yaml (Krzysztof).
- Rename Kconfig symbol QCOM_CLK_LPASS_VA_CSR to QCOM_CLK_LPASS_HEARTBEAT_PULSE (Konrad).
- Add devm_pm_runtime_enable() in the lpass-va-csr probe path.
- Drop the qcom,lpass-va-macro binding extension patch; it will be
resubmitted with the Hawi DTSI changes.
- Drop sound/soc/codecs/Kconfig select wiring to keep this series
clock-only (Konrad).
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Move the qcom,lpass-va-csr binding under Documentation/devicetree/bindings/clock/ (Krzysztof).
- Move the driver under drivers/clk/qcom/ (Krzysztof).
- Improve the schema description and use generic clock-controller node naming (Krzysztof).
- Use additionalProperties: false and keep compatibles sorted.
Changes in v2:
- Split the qcom,lpass-va-csr and qcom,lpass-va-macro bindings into separate patches.
Changes in v1:
- Initial version
---
Sarath Ganapathiraju (2):
dt-bindings: clock: qcom: Add LPASS VA CSR HeartBeat pulse clock
clk: qcom: Add LPASS VA CSR heartbeat pulse clock
.../bindings/clock/qcom,hawi-lpass-va-csr.yaml | 62 ++++++ drivers/clk/qcom/Kconfig | 15 ++ drivers/clk/qcom/Makefile | 1 + drivers/clk/qcom/lpass-va-csr.c | 209 +++++++++++++++++++++ 4 files changed, 287 insertions(+)
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20260917-master-6c2778f57a9a
Best regards,
Signature · 1 line
Sarath Ganapathiraju <[email protected]>
PATCH v16 1/2 dt-bindings: clock: qcom: Add LPASS VA CSR HeartBeat pulse clock
Add a binding for the Qualcomm LPASS VA CSR rate generator node that exposes the lpass-heartbeat-pulse clock on Hawi.
The HeartBeat Pulse, also known as RateGen Pulse, synchronizes the start of DMAs and Codec Interfaces for the audio usecase and can serve as a periodic wakeup source for the DSP.
Require the LPASS LPR and audio vote clocks to access VA CSR register space safely.
--- .../bindings/clock/qcom,hawi-lpass-va-csr.yaml | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/clock/qcom,hawi-lpass-va-csr.yaml new file +62 -0
@@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/qcom,hawi-lpass-va-csr.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm LPASS VA CSR heartbeat pulse clock provider + +maintainers: + - Srinivas Kandagatla <[email protected]> + - Sarath Ganapathiraju <[email protected]> + +description: + The Hawi LPASS (Low Power Audio Subsystem) VA CSR block contains a + rate generator that produces a periodic HeartBeat Pulse, also known + as the RateGen Pulse. This pulse synchronizes the start of DMAs and + Codec Interfaces for audio usecases and can serve as a periodic wakeup + source for the DSP. + +properties: + compatible: + enum: + - qcom,hawi-lpass-va-csr + + reg: + maxItems: 1 + description: Address and size of the VA CSR register block. + + clocks: + items: + - description: LPASS LPR (Low Power Resource) voting clock + - description: LPASS Audio voting clock + + clock-names: + items: + - const: lpr + - const: audio + + "#clock-cells": + const: 0 + +required: + - compatible + - reg + - clocks + - clock-names + - "#clock-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/sound/qcom,q6dsp-lpass-ports.h> + + clock-controller@7ee0000 { + compatible = "qcom,hawi-lpass-va-csr"; + reg = <0x07ee0000 0xe000>; + clocks = <&q6prmcc LPASS_HW_LPR_VOTE LPASS_CLK_ATTRIBUTE_COUPLE_NO>, + <&q6prmcc LPASS_HW_DCODEC_VOTE LPASS_CLK_ATTRIBUTE_COUPLE_NO>; + clock-names = "lpr", "audio"; + #clock-cells = <0>; + };
Signature · 1 line
2.34.1
PATCH v16 2/2 clk: qcom: Add LPASS VA CSR heartbeat pulse clock
In reply to Sarath GanapathirajuThe HeartBeat Pulse, also known as RateGen Pulse, synchronizes the start of DMAs and Codec Interfaces for the audio usecases and can serve as a periodic wakeup source for the DSP.
Add the LPASS VA CSR driver that models the rate generator as a clock provider so consumers can enable and disable it through the common clock framework.
Attach the DT vote clocks to runtime PM and program the rate generator counter and delay registers from runtime resume after the votes are enabled. This restores the state if the LPASS register context is lost across runtime suspend.
Rely on the clock core provider runtime PM handling around clock prepare and unprepare to keep the votes active for regmap gate accesses. Use the same runtime suspend and resume callbacks for system sleep so the vote clocks are enabled before restoring the rate generator after suspend. Track the heartbeat gate state in the clock callbacks and restore LPASS_RATE_GEN_CTRL on resume when the clock was enabled before the LPASS register context was lost.
--- drivers/clk/qcom/Kconfig | 15 +++ drivers/clk/qcom/Makefile | 1 + drivers/clk/qcom/lpass-va-csr.c | 209 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+)
drivers/clk/qcom/Kconfig +15 -0
@@ -2159,6 +2159,21 @@ config CLK_GFM_LPASS_SM8250 Support for the Glitch Free Mux (GFM) Low power audio subsystem (LPASS) clocks found on SM8250 SoCs. +config QCOM_CLK_LPASS_HEARTBEAT_PULSE + tristate "Qualcomm LPASS VA CSR heartbeat pulse clock provider" + depends on COMMON_CLK + depends on ARM64 || COMPILE_TEST + depends on PM_CLK + select REGMAP_MMIO + default m if ARCH_QCOM + help + Qualcomm LPASS VA CSR block contains the rate generator hardware + that produces the HeartBeat Pulse (also known as RateGen Pulse). + This driver models the rate generator as a clock provider so + that consumers can enable or disable it via the common clock + framework, and it can be used to synchronize the start of DMAs + and Codec Interfaces or as a periodic wakeup source for the DSP. + config SM_VIDEOCC_8450 tristate "SM8450 Video Clock Controller" depends on ARM64 || COMPILE_TEST
drivers/clk/qcom/Makefile +1 -0
@@ -112,6 +112,7 @@ obj-$(CONFIG_QCOM_A7PLL) += a7-pll.o obj-$(CONFIG_QCOM_CLK_APCS_MSM8916) += apcs-msm8916.o obj-$(CONFIG_QCOM_CLK_APCC_MSM8996) += apcs-msm8996.o clk-cpu-8996.o clk-cbf-8996.o obj-$(CONFIG_QCOM_CLK_APCS_SDX55) += apcs-sdx55.o +obj-$(CONFIG_QCOM_CLK_LPASS_HEARTBEAT_PULSE) += lpass-va-csr.o obj-$(CONFIG_QCOM_CLK_RPM) += clk-rpm.o obj-$(CONFIG_QCOM_CLK_RPMH) += clk-rpmh.o obj-$(CONFIG_QCOM_CLK_SMD_RPM) += clk-smd-rpm.o
drivers/clk/qcom/lpass-va-csr.c new file +209 -0
209 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v16 2/2] clk: qcom: Add LPASS VA CSR heartbeat pulse clock
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] clk: qcom: AB-BA deadlock between prepare_lock and lpass-va-csr runtime PM - [Medium] clk: qcom…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] clk: qcom: AB-BA deadlock between prepare_lock and lpass-va-csr runtime PM
- [Medium] clk: qcom: missing NULL check on match data in lpass_va_csr_probe()
- [Medium] clk: qcom: unsynchronized hb_enabled race in lpass_va_csr_runtime_resume()
- [Low] clk: qcom: unguarded regmap debugfs MMIO reads in lpass-va-csr --
commit 6181a29fe3667ab7db1605811f8d478d055d71b8
Author: Sarath Ganapathiraju <[email protected]>
clk: qcom: Add LPASS VA CSR heartbeat pulse clock
This commit adds the Qualcomm LPASS VA CSR driver that models the heartbeat pulse rate generator as a common clock provider, using runtime PM and PM clocks to manage the vote clocks and restore register state across suspend and resume.
Quoted 6 lines
drivers/clk/qcom/lpass-va-csr.c new file +0
-0@@ -0,0 +1,209 @@
[ ... ]
drivers/clk/qcom/lpass-va-csr.c line 41
Quoted 7 lines
drivers/clk/qcom/lpass-va-csr.c new file +7
-0+static const struct regmap_config lpass_rate_gen_regmap_config = { + .name ="lpass_rate_gen" , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .max_register =LPASS_RATE_GEN_MAX_REG , +};
[Severity: Low]
Can reading the regmap debugfs registers file trigger unclocked MMIO reads while the device is runtime-suspended?
lpass_rate_gen_regmap_config leaves readable_reg and rd_table unset, and lpass_va_csr_runtime_suspend() calls pm_clk_suspend() without putting the regmap into cache-only mode. Reading /sys/kernel/debug/regmap/<dev>-lpass_rate_gen/registers calls regmap_read_debugfs() without resuming runtime PM, issuing raw MMIO readl() accesses across 0x0000..0xd010 with the LPASS vote clocks disabled, which can cause bus errors, SErrors, or hangs (and even when clocked, reads unrelated VA CSR offsets outside the three rate generator registers).
Restricting readable registers with readable_reg or rd_table and toggling regcache_cache_only() in runtime suspend and resume would prevent this.
[ ... ]
Quoted 5 lines
drivers/clk/qcom/lpass-va-csr.c new file +5
-0+ ret =regmap_write (csr->hb.regmap,LPASS_RATE_GEN_COUNTER_0 , + data->counter_0); +if (ret) + goto err_pm_clk_suspend; +
drivers/clk/qcom/lpass-va-csr.c line 103
Quoted 10 lines
drivers/clk/qcom/lpass-va-csr.c new file +10
-0+ ret =regmap_write (csr->hb.regmap,LPASS_RATE_GEN_DELAY , data->delay); +if (ret) + goto err_pm_clk_suspend; + +if (csr->hb_enabled) { + ret =regmap_update_bits (csr->hb.regmap,LPASS_RATE_GEN_CTRL , +LPASS_RG_CTRL_EN ,LPASS_RG_CTRL_EN ); +if (ret) + goto err_pm_clk_suspend; + }
[Severity: Medium]
Can csr->hb_enabled and the rate generator register restore race with atomic clk_enable() or clk_disable() during system resume?
DEFINE_RUNTIME_DEV_PM_OPS() hooks pm_runtime_force_resume() into regular .resume, which runs after device IRQs and secondary CPUs are already re-enabled. If a consumer kept the clock prepared across suspend, an atomic clk_disable() can interleave with lpass_va_csr_runtime_resume():
CPU0 CPU1 (or <hardirq>)lpass_va_csr_runtime_resume()
if (csr->hb_enabled) /* true */
clk_disable()
lpass_va_csr_hb_disable()
clk_disable_regmap()
csr->hb_enabled = false regmap_update_bits(...CTRL_EN) <-- re-enables disabled clock
This leaves LPASS_RG_CTRL_EN set in hardware while csr->hb_enabled is false and the clock framework considers it disabled. Similarly, a concurrent clk_enable() after pm_clk_resume() can set LPASS_RG_CTRL_EN before COUNTER_0 and DELAY are restored.
Protecting csr->hb_enabled and the register updates in lpass_va_csr_hb_enable(), lpass_va_csr_hb_disable(), and the post-resume restore path with a spinlock using spin_lock_irqsave() would close this race.
[ ... ]
drivers/clk/qcom/lpass-va-csr.c line 134
Quoted 1 line
drivers/clk/qcom/lpass-va-csr.c new file +1
-0+ data =of_device_get_match_data (dev);
[Severity: Medium]
Should data be checked for NULL here?
If the driver is bound via sysfs driver_override to a non-matching DT platform device that has an MMIO resource and a clocks property, of_device_get_match_data() returns NULL and lpass_va_csr_runtime_resume() dereferences data->counter_0 during pm_runtime_resume_and_get(), causing a NULL pointer dereference.
[ ... ]
Quoted 7 lines
drivers/clk/qcom/lpass-va-csr.c new file +7
-0+ ret =devm_pm_runtime_enable (dev); +if (ret) +return dev_err_probe (dev, ret,"failed to enable PM runtime\n" ); + + ret =pm_runtime_resume_and_get (dev); +if (ret) +return ret;
drivers/clk/qcom/lpass-va-csr.c line 178
Quoted 10 lines
drivers/clk/qcom/lpass-va-csr.c new file +10
-0+ + ret =devm_clk_register_regmap (dev, &csr->hb); +if (ret) + goto err_pm_runtime_put; + + ret =devm_of_clk_add_hw_provider (dev, of_clk_hw_simple_get, &csr->hb.hw); +if (ret) + goto err_pm_runtime_put; + +pm_runtime_put_sync (dev);
[Severity: High]
Does enabling runtime PM before devm_clk_register_regmap() create an ABBA deadlock between the clock framework's global prepare_lock and this device's runtime PM transitions?
Because runtime PM is enabled when devm_clk_register_regmap() runs, the clock core sets core->rpm_enabled = true and calls pm_runtime_resume_and_get() and pm_runtime_put_sync() while holding prepare_lock in clk_core_prepare() and clk_core_unprepare(). At the same time, the DT vote clocks attached via of_pm_clk_add_clks() (clk_vote_q6dsp_ops) implement only .prepare and .unprepare, so pm_clk_resume() and pm_clk_suspend() call clk_prepare_enable() and clk_disable_unprepare(), which acquire prepare_lock from inside the runtime PM callbacks.
Any runtime PM transition started outside prepare_lock, such as pm_runtime_put_sync(dev) here after devm_of_clk_add_hw_provider() has published the clock, can deadlock against a concurrent clk_prepare():
CPU0 CPU1
---- ----rpm_suspend() [RPM_SUSPENDING]
lock(&prepare_lock)
pm_clk_suspend()
clk_disable_unprepare()
lock(&prepare_lock)
rpm_resume() [waits on RPM_SUSPENDING]
*** DEADLOCK ***
CPU0: lpass_va_csr_probe() -> pm_runtime_put_sync() ->
lpass_va_csr_runtime_suspend() -> pm_clk_suspend() ->
clk_disable_unprepare()CPU1: clk_prepare() -> clk_core_prepare() -> clk_pm_runtime_get() ->
rpm_resume()
Once this hits, both threads hang permanently along with all clock prepare, unprepare, set_rate, and registration operations kernel-wide.
Registering the clock with core->rpm_enabled = true also causes clk_summary, clk_dump, and clk_disable_unused to perform unnecessary synchronous ADSP GPR IPC wakeups and register writes on this device.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Quoted 9 lines · Sarath Ganapathiraju
The LPASS VA CSR block contains rate generator hardware that produces a HeartBeat Pulse (also known as RateGen Pulse). This pulse synchronizes the start of the DMAs and Codec Interfaces for the audio usecases and can serve as a periodic wakeup source for the DSP.
This series adds the DT binding and driver support to model this rate generator as a clock provider.
[...]
Applied, thanks!
[1/2] dt-bindings: clock: qcom: Add LPASS VA CSR HeartBeat pulse clock
commit: 0fc82950266029e9f952c0f717713708adf89e34
[2/2] clk: qcom: Add LPASS VA CSR heartbeat pulse clock
commit: 1068a36a941fb71b383d7dbf77a0234c6af4001aBest regards,
Signature · 1 line
Bjorn Andersson <[email protected]>