* [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 13:04 [PATCH v5 0/3] ASoC: qcom: lpass: Switch VA/WSA macros to PM clock framework Ajay Kumar Nandam
@ 2026-05-22 13:04 ` Ajay Kumar Nandam
2026-05-22 13:17 ` Mark Brown
2026-05-22 13:25 ` Konrad Dybcio
2026-05-22 13:04 ` [PATCH v5 2/3] ASoC: codecs: lpass-va-macro: " Ajay Kumar Nandam
` (2 subsequent siblings)
3 siblings, 2 replies; 12+ messages in thread
From: Ajay Kumar Nandam @ 2026-05-22 13:04 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla
Cc: linux-sound, linux-kernel, linux-arm-msm, mohammad.rafi.shaik,
ajay.nandam
Convert the LPASS WSA macro codec driver to use the PM clock framework
for runtime power management.
The driver now relies on pm_clk helpers and runtime PM instead of
manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
clocks. Runtime suspend and resume handling is delegated to the PM
core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
PM callbacks continue to manage regcache state.
This ensures clocks are enabled only when the WSA macro is active,
improves power efficiency on LPASS platforms supporting LPI/island
modes, and aligns the driver with common ASoC runtime PM patterns used
across Qualcomm LPASS codec drivers.
Keep the SWR gate runtime-PM reference from SWR clock enable until
disable so autosuspend does not gate clocks while SWR is prepared.
Add a PM dependency for SND_SOC_LPASS_WSA_MACRO so PM clock helpers are
available when this driver is built.
Suggested-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
sound/soc/codecs/Kconfig | 1 +
sound/soc/codecs/lpass-wsa-macro.c | 119 ++++++++++++------------------
2 files changed, 47 insertions(+), 73 deletions(-)
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 6f587e39223b..4e17119f2f9e 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -2861,7 +2861,8 @@ config SND_SOC_LPASS_MACRO_COMMON
config SND_SOC_LPASS_WSA_MACRO
depends on COMMON_CLK
+ depends on PM
select REGMAP_MMIO
select SND_SOC_LPASS_MACRO_COMMON
tristate "Qualcomm WSA Macro in LPASS(Low Power Audio SubSystem)"
diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index 5ad0448af649..598292fe3219 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -14,6 +14,7 @@
#include <sound/soc-dapm.h>
#include <linux/pm_runtime.h>
#include <linux/of_platform.h>
+#include <linux/pm_clock.h>
#include <sound/tlv.h>
#include "lpass-macro-common.h"
@@ -2529,15 +2530,13 @@ static const struct snd_soc_dapm_route wsa_audio_map[] = {
static int wsa_swrm_clock(struct wsa_macro *wsa, bool enable)
{
struct regmap *regmap = wsa->regmap;
+ int ret;
if (enable) {
- int ret;
-
- ret = clk_prepare_enable(wsa->mclk);
- if (ret) {
- dev_err(wsa->dev, "failed to enable mclk\n");
+ ret = pm_runtime_resume_and_get(wsa->dev);
+ if (ret < 0)
return ret;
- }
+
wsa_macro_mclk_enable(wsa, true);
regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
@@ -2548,7 +2547,10 @@ static int wsa_swrm_clock(struct wsa_macro *wsa, bool enable)
regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
CDC_WSA_SWR_CLK_EN_MASK, 0);
wsa_macro_mclk_enable(wsa, false);
- clk_disable_unprepare(wsa->mclk);
+
+ ret = pm_runtime_put_autosuspend(wsa->dev);
+ if (ret < 0)
+ dev_warn(wsa->dev, "runtime PM put failed: %d\n", ret);
}
return 0;
@@ -2774,25 +2776,23 @@ static int wsa_macro_probe(struct platform_device *pdev)
clk_set_rate(wsa->mclk, WSA_MACRO_MCLK_FREQ);
clk_set_rate(wsa->npl, WSA_MACRO_MCLK_FREQ);
- ret = clk_prepare_enable(wsa->macro);
- if (ret)
- goto err;
-
- ret = clk_prepare_enable(wsa->dcodec);
+ ret = devm_pm_clk_create(dev);
if (ret)
- goto err_dcodec;
+ return ret;
- ret = clk_prepare_enable(wsa->mclk);
- if (ret)
- goto err_mclk;
+ ret = of_pm_clk_add_clks(dev);
+ if (ret < 0)
+ return ret;
- ret = clk_prepare_enable(wsa->npl);
+ pm_runtime_set_autosuspend_delay(dev, 100);
+ pm_runtime_use_autosuspend(dev);
+ ret = devm_pm_runtime_enable(dev);
if (ret)
- goto err_npl;
+ return ret;
- ret = clk_prepare_enable(wsa->fsgen);
- if (ret)
- goto err_fsgen;
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret < 0)
+ return ret;
/* reset swr ip */
regmap_update_bits(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
@@ -2809,56 +2809,41 @@ static int wsa_macro_probe(struct platform_device *pdev)
wsa_macro_dai,
ARRAY_SIZE(wsa_macro_dai));
if (ret)
- goto err_clkout;
-
- pm_runtime_set_autosuspend_delay(dev, 3000);
- pm_runtime_use_autosuspend(dev);
- pm_runtime_mark_last_busy(dev);
- pm_runtime_set_active(dev);
- pm_runtime_enable(dev);
+ goto err_rpm_put;
ret = wsa_macro_register_mclk_output(wsa);
if (ret)
- goto err_clkout;
+ goto err_rpm_put;
- return 0;
+ ret = pm_runtime_put_autosuspend(dev);
+ if (ret < 0)
+ dev_warn(dev, "runtime PM put failed after probe: %d\n", ret);
-err_clkout:
- clk_disable_unprepare(wsa->fsgen);
-err_fsgen:
- clk_disable_unprepare(wsa->npl);
-err_npl:
- clk_disable_unprepare(wsa->mclk);
-err_mclk:
- clk_disable_unprepare(wsa->dcodec);
-err_dcodec:
- clk_disable_unprepare(wsa->macro);
-err:
+ return 0;
+err_rpm_put:
+ if (pm_runtime_put_sync_suspend(dev) < 0)
+ dev_warn(dev, "runtime PM sync suspend failed in probe unwind\n");
return ret;
-
}
static void wsa_macro_remove(struct platform_device *pdev)
{
- struct wsa_macro *wsa = dev_get_drvdata(&pdev->dev);
-
- clk_disable_unprepare(wsa->macro);
- clk_disable_unprepare(wsa->dcodec);
- clk_disable_unprepare(wsa->mclk);
- clk_disable_unprepare(wsa->npl);
- clk_disable_unprepare(wsa->fsgen);
}
static int wsa_macro_runtime_suspend(struct device *dev)
{
struct wsa_macro *wsa = dev_get_drvdata(dev);
+ int ret;
regcache_cache_only(wsa->regmap, true);
- regcache_mark_dirty(wsa->regmap);
- clk_disable_unprepare(wsa->fsgen);
- clk_disable_unprepare(wsa->npl);
- clk_disable_unprepare(wsa->mclk);
+ ret = pm_clk_suspend(dev);
+ if (ret) {
+ regcache_cache_only(wsa->regmap, false);
+ return ret;
+ }
+
+ regcache_mark_dirty(wsa->regmap);
return 0;
}
@@ -2868,35 +2853,27 @@ static int wsa_macro_runtime_resume(struct device *dev)
struct wsa_macro *wsa = dev_get_drvdata(dev);
- int ret;
+ int ret, sret;
- ret = clk_prepare_enable(wsa->mclk);
+ ret = pm_clk_resume(dev);
if (ret) {
- dev_err(dev, "unable to prepare mclk\n");
+ regcache_cache_only(wsa->regmap, true);
+ regcache_mark_dirty(wsa->regmap);
return ret;
}
+ regcache_cache_only(wsa->regmap, false);
- ret = clk_prepare_enable(wsa->npl);
- if (ret) {
- dev_err(dev, "unable to prepare mclkx2\n");
- goto err_npl;
- }
-
- ret = clk_prepare_enable(wsa->fsgen);
+ ret = regcache_sync(wsa->regmap);
if (ret) {
- dev_err(dev, "unable to prepare fsgen\n");
- goto err_fsgen;
+ regcache_cache_only(wsa->regmap, true);
+ regcache_mark_dirty(wsa->regmap);
+ sret = pm_clk_suspend(dev);
+ if (sret)
+ dev_err(dev,
+ "failed to suspend clocks after regcache sync failure: %d\n",
+ sret);
+ return ret;
}
- regcache_cache_only(wsa->regmap, false);
- regcache_sync(wsa->regmap);
-
return 0;
-err_fsgen:
- clk_disable_unprepare(wsa->npl);
-err_npl:
- clk_disable_unprepare(wsa->mclk);
-
- return ret;
}
static const struct dev_pm_ops wsa_macro_pm_ops = {
--
2.34.1
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 13:04 ` [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM Ajay Kumar Nandam
@ 2026-05-22 13:17 ` Mark Brown
2026-05-22 14:37 ` Konrad Dybcio
2026-05-22 19:18 ` Ajay Kumar Nandam
2026-05-22 13:25 ` Konrad Dybcio
1 sibling, 2 replies; 12+ messages in thread
From: Mark Brown @ 2026-05-22 13:17 UTC (permalink / raw)
To: Ajay Kumar Nandam
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla, linux-sound, linux-kernel, linux-arm-msm,
mohammad.rafi.shaik
[-- Attachment #1: Type: text/plain, Size: 840 bytes --]
On Fri, May 22, 2026 at 06:34:40PM +0530, Ajay Kumar Nandam wrote:
> The driver now relies on pm_clk helpers and runtime PM instead of
> manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
> clocks. Runtime suspend and resume handling is delegated to the PM
> core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
> PM callbacks continue to manage regcache state.
> config SND_SOC_LPASS_WSA_MACRO
> depends on COMMON_CLK
> + depends on PM
> select REGMAP_MMIO
> select SND_SOC_LPASS_MACRO_COMMON
> tristate "Qualcomm WSA Macro in LPASS(Low Power Audio SubSystem)"
Shouldn't this be PM_CLK? That's what the APIs are actually conditional
on, currently this will work out since PM_CLK depends on PM and HAVE_CLK
but the indirection leaves a window for things to break in future.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 13:17 ` Mark Brown
@ 2026-05-22 14:37 ` Konrad Dybcio
2026-05-22 19:19 ` Ajay Kumar Nandam
2026-05-22 19:18 ` Ajay Kumar Nandam
1 sibling, 1 reply; 12+ messages in thread
From: Konrad Dybcio @ 2026-05-22 14:37 UTC (permalink / raw)
To: Mark Brown, Ajay Kumar Nandam
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla, linux-sound, linux-kernel, linux-arm-msm,
mohammad.rafi.shaik
On 5/22/26 3:17 PM, Mark Brown wrote:
> On Fri, May 22, 2026 at 06:34:40PM +0530, Ajay Kumar Nandam wrote:
>
>> The driver now relies on pm_clk helpers and runtime PM instead of
>> manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
>> clocks. Runtime suspend and resume handling is delegated to the PM
>> core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
>> PM callbacks continue to manage regcache state.
>
>> config SND_SOC_LPASS_WSA_MACRO
>> depends on COMMON_CLK
>> + depends on PM
>> select REGMAP_MMIO
>> select SND_SOC_LPASS_MACRO_COMMON
>> tristate "Qualcomm WSA Macro in LPASS(Low Power Audio SubSystem)"
>
> Shouldn't this be PM_CLK? That's what the APIs are actually conditional
> on, currently this will work out since PM_CLK depends on PM and HAVE_CLK
> but the indirection leaves a window for things to break in future.
Yeah, leaving it as-is sounds like a bad idea
Konrad
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 14:37 ` Konrad Dybcio
@ 2026-05-22 19:19 ` Ajay Kumar Nandam
0 siblings, 0 replies; 12+ messages in thread
From: Ajay Kumar Nandam @ 2026-05-22 19:19 UTC (permalink / raw)
To: Konrad Dybcio, Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla, linux-sound, linux-kernel, linux-arm-msm,
mohammad.rafi.shaik
On 5/22/2026 8:07 PM, Konrad Dybcio wrote:
> On 5/22/26 3:17 PM, Mark Brown wrote:
>> On Fri, May 22, 2026 at 06:34:40PM +0530, Ajay Kumar Nandam wrote:
>>
>>> The driver now relies on pm_clk helpers and runtime PM instead of
>>> manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
>>> clocks. Runtime suspend and resume handling is delegated to the PM
>>> core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
>>> PM callbacks continue to manage regcache state.
>>
>>> config SND_SOC_LPASS_WSA_MACRO
>>> depends on COMMON_CLK
>>> + depends on PM
>>> select REGMAP_MMIO
>>> select SND_SOC_LPASS_MACRO_COMMON
>>> tristate "Qualcomm WSA Macro in LPASS(Low Power Audio SubSystem)"
>>
>> Shouldn't this be PM_CLK? That's what the APIs are actually conditional
>> on, currently this will work out since PM_CLK depends on PM and HAVE_CLK
>> but the indirection leaves a window for things to break in future.
>
> Yeah, leaving it as-is sounds like a bad idea
ACK, will update in V6
Thanks
Ajay Kumar
>
> Konrad
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 13:17 ` Mark Brown
2026-05-22 14:37 ` Konrad Dybcio
@ 2026-05-22 19:18 ` Ajay Kumar Nandam
1 sibling, 0 replies; 12+ messages in thread
From: Ajay Kumar Nandam @ 2026-05-22 19:18 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla, linux-sound, linux-kernel, linux-arm-msm,
mohammad.rafi.shaik
On 5/22/2026 6:47 PM, Mark Brown wrote:
> On Fri, May 22, 2026 at 06:34:40PM +0530, Ajay Kumar Nandam wrote:
>
>> The driver now relies on pm_clk helpers and runtime PM instead of
>> manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
>> clocks. Runtime suspend and resume handling is delegated to the PM
>> core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
>> PM callbacks continue to manage regcache state.
>
>> config SND_SOC_LPASS_WSA_MACRO
>> depends on COMMON_CLK
>> + depends on PM
>> select REGMAP_MMIO
>> select SND_SOC_LPASS_MACRO_COMMON
>> tristate "Qualcomm WSA Macro in LPASS(Low Power Audio SubSystem)"
>
> Shouldn't this be PM_CLK? That's what the APIs are actually conditional
> on, currently this will work out since PM_CLK depends on PM and HAVE_CLK
> but the indirection leaves a window for things to break in future.
ACK, agreed with your statement will update in V6
Thanks
Ajay Kumar
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 13:04 ` [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM Ajay Kumar Nandam
2026-05-22 13:17 ` Mark Brown
@ 2026-05-22 13:25 ` Konrad Dybcio
2026-05-22 19:26 ` Ajay Kumar Nandam
1 sibling, 1 reply; 12+ messages in thread
From: Konrad Dybcio @ 2026-05-22 13:25 UTC (permalink / raw)
To: Ajay Kumar Nandam, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Srinivas Kandagatla
Cc: linux-sound, linux-kernel, linux-arm-msm, mohammad.rafi.shaik
On 5/22/26 3:04 PM, Ajay Kumar Nandam wrote:
> Convert the LPASS WSA macro codec driver to use the PM clock framework
> for runtime power management.
>
> The driver now relies on pm_clk helpers and runtime PM instead of
> manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
> clocks. Runtime suspend and resume handling is delegated to the PM
> core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
> PM callbacks continue to manage regcache state.
>
> This ensures clocks are enabled only when the WSA macro is active,
> improves power efficiency on LPASS platforms supporting LPI/island
> modes, and aligns the driver with common ASoC runtime PM patterns used
> across Qualcomm LPASS codec drivers.
>
> Keep the SWR gate runtime-PM reference from SWR clock enable until
> disable so autosuspend does not gate clocks while SWR is prepared.
>
> Add a PM dependency for SND_SOC_LPASS_WSA_MACRO so PM clock helpers are
> available when this driver is built.
>
> Suggested-by: Mark Brown <broonie@kernel.org>
You added this tag, but was the entire content of this patch sparked
by Mark's suggestion?
Konrad
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 13:25 ` Konrad Dybcio
@ 2026-05-22 19:26 ` Ajay Kumar Nandam
2026-05-25 13:07 ` Konrad Dybcio
0 siblings, 1 reply; 12+ messages in thread
From: Ajay Kumar Nandam @ 2026-05-22 19:26 UTC (permalink / raw)
To: Konrad Dybcio, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Srinivas Kandagatla
Cc: linux-sound, linux-kernel, linux-arm-msm, mohammad.rafi.shaik
On 5/22/2026 6:55 PM, Konrad Dybcio wrote:
> On 5/22/26 3:04 PM, Ajay Kumar Nandam wrote:
>> Convert the LPASS WSA macro codec driver to use the PM clock framework
>> for runtime power management.
>>
>> The driver now relies on pm_clk helpers and runtime PM instead of
>> manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
>> clocks. Runtime suspend and resume handling is delegated to the PM
>> core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
>> PM callbacks continue to manage regcache state.
>>
>> This ensures clocks are enabled only when the WSA macro is active,
>> improves power efficiency on LPASS platforms supporting LPI/island
>> modes, and aligns the driver with common ASoC runtime PM patterns used
>> across Qualcomm LPASS codec drivers.
>>
>> Keep the SWR gate runtime-PM reference from SWR clock enable until
>> disable so autosuspend does not gate clocks while SWR is prepared.
>>
>> Add a PM dependency for SND_SOC_LPASS_WSA_MACRO so PM clock helpers are
>> available when this driver is built.
>>
>> Suggested-by: Mark Brown <broonie@kernel.org>
>
> You added this tag, but was the entire content of this patch sparked
> by Mark's suggestion?
Apologies for not including the Reviewed-by tag earlier — that was an
oversight on my end.
Thanks
Ajay Kumar
>
> Konrad
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
2026-05-22 19:26 ` Ajay Kumar Nandam
@ 2026-05-25 13:07 ` Konrad Dybcio
0 siblings, 0 replies; 12+ messages in thread
From: Konrad Dybcio @ 2026-05-25 13:07 UTC (permalink / raw)
To: Ajay Kumar Nandam, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Srinivas Kandagatla
Cc: linux-sound, linux-kernel, linux-arm-msm, mohammad.rafi.shaik
On 5/22/26 9:26 PM, Ajay Kumar Nandam wrote:
>
>
> On 5/22/2026 6:55 PM, Konrad Dybcio wrote:
>> On 5/22/26 3:04 PM, Ajay Kumar Nandam wrote:
>>> Convert the LPASS WSA macro codec driver to use the PM clock framework
>>> for runtime power management.
>>>
>>> The driver now relies on pm_clk helpers and runtime PM instead of
>>> manually enabling and disabling macro, dcodec, mclk, npl, and fsgen
>>> clocks. Runtime suspend and resume handling is delegated to the PM
>>> core via pm_clk_suspend() and pm_clk_resume(), while existing runtime
>>> PM callbacks continue to manage regcache state.
>>>
>>> This ensures clocks are enabled only when the WSA macro is active,
>>> improves power efficiency on LPASS platforms supporting LPI/island
>>> modes, and aligns the driver with common ASoC runtime PM patterns used
>>> across Qualcomm LPASS codec drivers.
>>>
>>> Keep the SWR gate runtime-PM reference from SWR clock enable until
>>> disable so autosuspend does not gate clocks while SWR is prepared.
>>>
>>> Add a PM dependency for SND_SOC_LPASS_WSA_MACRO so PM clock helpers are
>>> available when this driver is built.
>>>
>>> Suggested-by: Mark Brown <broonie@kernel.org>
>>
>> You added this tag, but was the entire content of this patch sparked
>> by Mark's suggestion?
>
> Apologies for not including the Reviewed-by tag earlier — that was an oversight on my end.
I'm not sure we're on the same page. Please read:
https://docs.kernel.org/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes
Konrad
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v5 2/3] ASoC: codecs: lpass-va-macro: Switch to PM clock framework for runtime PM
2026-05-22 13:04 [PATCH v5 0/3] ASoC: qcom: lpass: Switch VA/WSA macros to PM clock framework Ajay Kumar Nandam
2026-05-22 13:04 ` [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM Ajay Kumar Nandam
@ 2026-05-22 13:04 ` Ajay Kumar Nandam
2026-05-22 13:04 ` [PATCH v5 3/3] ASoC: codecs: lpass-wsa-macro: Use devm_clk_hw_register() for MCLK output Ajay Kumar Nandam
2026-05-22 13:24 ` [PATCH v5 0/3] ASoC: qcom: lpass: Switch VA/WSA macros to PM clock framework Mark Brown
3 siblings, 0 replies; 12+ messages in thread
From: Ajay Kumar Nandam @ 2026-05-22 13:04 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla
Cc: linux-sound, linux-kernel, linux-arm-msm, mohammad.rafi.shaik,
ajay.nandam
Convert the LPASS VA macro codec driver to use the PM clock framework
for runtime power management.
The driver now relies on pm_clk helpers and runtime PM instead of
manually enabling and disabling macro, dcodec, mclk, and npl clocks.
All clock control during runtime suspend and resume is delegated to
the PM core via pm_clk_suspend() and pm_clk_resume().
This change ensures clocks are only enabled when the VA macro is
active, improves power efficiency on LPASS platforms supporting
LPI/island modes, and aligns the driver with common ASoC runtime PM
patterns used across Qualcomm LPASS codec drivers.
Take a runtime-PM reference in fsgen_gate_enable() for all VA variants,
including non-SWR-master configurations, and release it in
fsgen_gate_disable() so PM-clock-managed clocks stay active while fsgen
is enabled.
Add a PM dependency for SND_SOC_LPASS_VA_MACRO so PM clock helpers are
available when this driver is built.
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
sound/soc/codecs/Kconfig | 1 +
sound/soc/codecs/lpass-va-macro.c | 133 +++++++++++++++++----------------
2 files changed, 71 insertions(+), 63 deletions(-)
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 4e17119f2f9e..e73667b87fd8 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -2867,7 +2867,8 @@ config SND_SOC_LPASS_WSA_MACRO
config SND_SOC_LPASS_VA_MACRO
depends on COMMON_CLK
+ depends on PM
select REGMAP_MMIO
select SND_SOC_LPASS_MACRO_COMMON
tristate "Qualcomm VA Macro in LPASS(Low Power Audio SubSystem)"
diff --git a/sound/soc/codecs/lpass-va-macro.c b/sound/soc/codecs/lpass-va-macro.c
index 528d5b167ecf..64a06d9ed6c8 100644
--- a/sound/soc/codecs/lpass-va-macro.c
+++ b/sound/soc/codecs/lpass-va-macro.c
@@ -11,6 +11,7 @@
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/pm_clock.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <sound/soc.h>
@@ -1348,32 +1349,56 @@ static int fsgen_gate_enable(struct clk_hw *hw)
struct regmap *regmap = va->regmap;
int ret, rpm_ret;
- if (va->has_swr_master) {
- ret = clk_prepare_enable(va->mclk);
- if (ret)
- return ret;
- }
+ ret = pm_runtime_resume_and_get(va->dev);
+ if (ret < 0)
+ return ret;
ret = va_macro_mclk_enable(va, true);
+ if (ret) {
+ rpm_ret = pm_runtime_put_autosuspend(va->dev);
+ if (rpm_ret < 0)
+ dev_warn(va->dev,
+ "runtime PM put failed in fsgen enable unwind: %d\n",
+ rpm_ret);
+ return ret;
+ }
if (va->has_swr_master)
regmap_update_bits(regmap, CDC_VA_CLK_RST_CTRL_SWR_CONTROL,
CDC_VA_SWR_CLK_EN_MASK, CDC_VA_SWR_CLK_ENABLE);
- return ret;
+ return 0;
}
static void fsgen_gate_disable(struct clk_hw *hw)
{
struct va_macro *va = to_va_macro(hw);
struct regmap *regmap = va->regmap;
+ int ret;
if (va->has_swr_master)
regmap_update_bits(regmap, CDC_VA_CLK_RST_CTRL_SWR_CONTROL,
CDC_VA_SWR_CLK_EN_MASK, 0x0);
va_macro_mclk_enable(va, false);
- if (va->has_swr_master)
- clk_disable_unprepare(va->mclk);
+
+ ret = pm_runtime_put_autosuspend(va->dev);
+ if (ret < 0)
+ dev_warn(va->dev, "runtime PM put failed in fsgen disable: %d\n", ret);
+}
+
+static int va_macro_setup_pm_clocks(struct device *dev)
+{
+ int ret;
+
+ ret = devm_pm_clk_create(dev);
+ if (ret)
+ return ret;
+
+ ret = of_pm_clk_add_clks(dev);
+ if (ret < 0)
+ return ret;
+
+ return 0;
}
static int fsgen_gate_is_enabled(struct clk_hw *hw)
@@ -1534,6 +1559,7 @@ static int va_macro_probe(struct platform_device *pdev)
void __iomem *base;
u32 sample_rate = 0;
int ret;
+ int rpm_ret;
va = devm_kzalloc(dev, sizeof(*va), GFP_KERNEL);
if (!va)
@@ -1601,22 +1627,20 @@ static int va_macro_probe(struct platform_device *pdev)
clk_set_rate(va->npl, 2 * VA_MACRO_MCLK_FREQ);
}
- ret = clk_prepare_enable(va->macro);
+ ret = va_macro_setup_pm_clocks(dev);
if (ret)
goto err;
- ret = clk_prepare_enable(va->dcodec);
- if (ret)
- goto err_dcodec;
-
- ret = clk_prepare_enable(va->mclk);
+ pm_runtime_set_autosuspend_delay(dev, 100);
+ pm_runtime_use_autosuspend(dev);
+ ret = devm_pm_runtime_enable(dev);
if (ret)
- goto err_mclk;
+ goto err;
- if (va->has_npl_clk) {
- ret = clk_prepare_enable(va->npl);
- if (ret)
- goto err_npl;
+ rpm_ret = pm_runtime_resume_and_get(dev);
+ if (rpm_ret < 0) {
+ ret = rpm_ret;
+ goto err;
}
/**
@@ -1629,7 +1653,7 @@ static int va_macro_probe(struct platform_device *pdev)
/* read version from register */
ret = va_macro_set_lpass_codec_version(va);
if (ret)
- goto err_clkout;
+ goto err_rpm_put;
}
if (va->has_swr_master) {
@@ -1659,35 +1683,28 @@ static int va_macro_probe(struct platform_device *pdev)
va_macro_dais,
ARRAY_SIZE(va_macro_dais));
if (ret)
- goto err_clkout;
-
- pm_runtime_set_autosuspend_delay(dev, 3000);
- pm_runtime_use_autosuspend(dev);
- pm_runtime_mark_last_busy(dev);
- pm_runtime_set_active(dev);
- pm_runtime_enable(dev);
+ goto err_rpm_put;
ret = va_macro_register_fsgen_output(va);
if (ret)
- goto err_clkout;
+ goto err_rpm_put;
va->fsgen = devm_clk_hw_get_clk(dev, &va->hw, "fsgen");
if (IS_ERR(va->fsgen)) {
ret = PTR_ERR(va->fsgen);
- goto err_clkout;
+ goto err_rpm_put;
}
+ rpm_ret = pm_runtime_put_autosuspend(dev);
+ if (rpm_ret < 0)
+ dev_warn(dev, "runtime PM put failed after probe: %d\n", rpm_ret);
+
return 0;
-err_clkout:
- if (va->has_npl_clk)
- clk_disable_unprepare(va->npl);
-err_npl:
- clk_disable_unprepare(va->mclk);
-err_mclk:
- clk_disable_unprepare(va->dcodec);
-err_dcodec:
- clk_disable_unprepare(va->macro);
+err_rpm_put:
+ rpm_ret = pm_runtime_put_sync_suspend(dev);
+ if (rpm_ret < 0)
+ dev_warn(dev, "runtime PM sync suspend failed in probe unwind: %d\n", rpm_ret);
err:
lpass_macro_pds_exit(va->pds);
@@ -1698,27 +1715,23 @@ static void va_macro_remove(struct platform_device *pdev)
{
struct va_macro *va = dev_get_drvdata(&pdev->dev);
- if (va->has_npl_clk)
- clk_disable_unprepare(va->npl);
-
- clk_disable_unprepare(va->mclk);
- clk_disable_unprepare(va->dcodec);
- clk_disable_unprepare(va->macro);
-
lpass_macro_pds_exit(va->pds);
}
static int va_macro_runtime_suspend(struct device *dev)
{
struct va_macro *va = dev_get_drvdata(dev);
+ int ret;
regcache_cache_only(va->regmap, true);
- regcache_mark_dirty(va->regmap);
- if (va->has_npl_clk)
- clk_disable_unprepare(va->npl);
+ ret = pm_clk_suspend(dev);
+ if (ret) {
+ regcache_cache_only(va->regmap, false);
+ return ret;
+ }
- clk_disable_unprepare(va->mclk);
+ regcache_mark_dirty(va->regmap);
return 0;
}
@@ -1728,24 +1741,26 @@ static int va_macro_runtime_resume(struct device *dev)
struct va_macro *va = dev_get_drvdata(dev);
- int ret;
+ int ret, sret;
- ret = clk_prepare_enable(va->mclk);
- if (ret) {
- dev_err(va->dev, "unable to prepare mclk\n");
+ ret = pm_clk_resume(dev);
+ if (ret) {
+ regcache_cache_only(va->regmap, true);
+ regcache_mark_dirty(va->regmap);
return ret;
- }
+ }
-
- if (va->has_npl_clk) {
- ret = clk_prepare_enable(va->npl);
- if (ret) {
- clk_disable_unprepare(va->mclk);
- dev_err(va->dev, "unable to prepare npl\n");
- return ret;
- }
- }
regcache_cache_only(va->regmap, false);
- regcache_sync(va->regmap);
+
+ ret = regcache_sync(va->regmap);
+ if (ret) {
+ regcache_cache_only(va->regmap, true);
+ regcache_mark_dirty(va->regmap);
+ sret = pm_clk_suspend(dev);
+ if (sret)
+ dev_err(va->dev,
+ "failed to suspend clocks after regcache sync failure: %d\n",
+ sret);
+ return ret;
+ }
return 0;
}
--
2.34.1
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH v5 3/3] ASoC: codecs: lpass-wsa-macro: Use devm_clk_hw_register() for MCLK output
2026-05-22 13:04 [PATCH v5 0/3] ASoC: qcom: lpass: Switch VA/WSA macros to PM clock framework Ajay Kumar Nandam
2026-05-22 13:04 ` [PATCH v5 1/3] ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM Ajay Kumar Nandam
2026-05-22 13:04 ` [PATCH v5 2/3] ASoC: codecs: lpass-va-macro: " Ajay Kumar Nandam
@ 2026-05-22 13:04 ` Ajay Kumar Nandam
2026-05-22 13:24 ` [PATCH v5 0/3] ASoC: qcom: lpass: Switch VA/WSA macros to PM clock framework Mark Brown
3 siblings, 0 replies; 12+ messages in thread
From: Ajay Kumar Nandam @ 2026-05-22 13:04 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla
Cc: linux-sound, linux-kernel, linux-arm-msm, mohammad.rafi.shaik,
ajay.nandam, Konrad Dybcio
The WSA macro driver registers the MCLK output clock using
clk_hw_register(), but does not explicitly unregister it in the remove
path or on probe failure.
Switch to devm_clk_hw_register() to make the registration resource-managed
so the clk_hw is automatically unregistered when the device is unbound or
probe fails. This fixes the missing unregister cleanup in remove/probe-fail
paths and simplifies error handling.
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
---
sound/soc/codecs/lpass-wsa-macro.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index 598292fe3219..3081c115d584 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -2658,7 +2658,7 @@ static int wsa_macro_register_mclk_output(struct wsa_macro *wsa)
init.num_parents = 1;
wsa->hw.init = &init;
hw = &wsa->hw;
- ret = clk_hw_register(wsa->dev, hw);
+ ret = devm_clk_hw_register(wsa->dev, hw);
if (ret)
return ret;
--
2.34.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 0/3] ASoC: qcom: lpass: Switch VA/WSA macros to PM clock framework
2026-05-22 13:04 [PATCH v5 0/3] ASoC: qcom: lpass: Switch VA/WSA macros to PM clock framework Ajay Kumar Nandam
` (2 preceding siblings ...)
2026-05-22 13:04 ` [PATCH v5 3/3] ASoC: codecs: lpass-wsa-macro: Use devm_clk_hw_register() for MCLK output Ajay Kumar Nandam
@ 2026-05-22 13:24 ` Mark Brown
3 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2026-05-22 13:24 UTC (permalink / raw)
To: Ajay Kumar Nandam
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Srinivas Kandagatla, linux-sound, linux-kernel, linux-arm-msm,
mohammad.rafi.shaik
[-- Attachment #1: Type: text/plain, Size: 253 bytes --]
On Fri, May 22, 2026 at 06:34:39PM +0530, Ajay Kumar Nandam wrote:
> This series converts LPASS WSA and VA macro codec drivers to the PM
> clock framework for runtime PM clock handling.
This doesn't apply against current code, please check and resend.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread