Skip to content

Commit bfc4922

Browse files
Ajay Kumar NandamRaviHothi
authored andcommitted
FROMLIST: ASoC: codecs: lpass-wsa-macro: Switch to PM clock framework for runtime PM
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. Link: https://lore.kernel.org/all/20260413121824.375473-2-ajay.nandam@oss.qualcomm.com/ Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
1 parent cad3efc commit bfc4922

1 file changed

Lines changed: 37 additions & 81 deletions

File tree

sound/soc/codecs/lpass-wsa-macro.c

Lines changed: 37 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sound/soc-dapm.h>
1515
#include <linux/pm_runtime.h>
1616
#include <linux/of_platform.h>
17+
#include <linux/pm_clock.h>
1718
#include <sound/tlv.h>
1819

1920
#include "lpass-macro-common.h"
@@ -2638,15 +2639,15 @@ static const struct snd_soc_dapm_route wsa_audio_map[] = {
26382639
static int wsa_swrm_clock(struct wsa_macro *wsa, bool enable)
26392640
{
26402641
struct regmap *regmap = wsa->regmap;
2642+
int ret;
26412643

2642-
if (enable) {
2643-
int ret;
2644+
ret = pm_runtime_get_sync(wsa->dev);
2645+
if (ret < 0) {
2646+
pm_runtime_put_noidle(wsa->dev);
2647+
return ret;
2648+
}
26442649

2645-
ret = clk_prepare_enable(wsa->mclk);
2646-
if (ret) {
2647-
dev_err(wsa->dev, "failed to enable mclk\n");
2648-
return ret;
2649-
}
2650+
if (enable) {
26502651
wsa_macro_mclk_enable(wsa, true);
26512652

26522653
regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
@@ -2657,9 +2658,10 @@ static int wsa_swrm_clock(struct wsa_macro *wsa, bool enable)
26572658
regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
26582659
CDC_WSA_SWR_CLK_EN_MASK, 0);
26592660
wsa_macro_mclk_enable(wsa, false);
2660-
clk_disable_unprepare(wsa->mclk);
26612661
}
26622662

2663+
pm_runtime_mark_last_busy(wsa->dev);
2664+
pm_runtime_put_autosuspend(wsa->dev);
26632665
return 0;
26642666
}
26652667

@@ -2885,25 +2887,23 @@ static int wsa_macro_probe(struct platform_device *pdev)
28852887
clk_set_rate(wsa->mclk, WSA_MACRO_MCLK_FREQ);
28862888
clk_set_rate(wsa->npl, WSA_MACRO_MCLK_FREQ);
28872889

2888-
ret = clk_prepare_enable(wsa->macro);
2890+
ret = devm_pm_clk_create(dev);
28892891
if (ret)
2890-
goto err;
2892+
return ret;
28912893

2892-
ret = clk_prepare_enable(wsa->dcodec);
2893-
if (ret)
2894-
goto err_dcodec;
2894+
ret = of_pm_clk_add_clks(dev);
2895+
if (ret < 0)
2896+
return ret;
28952897

2896-
ret = clk_prepare_enable(wsa->mclk);
2897-
if (ret)
2898-
goto err_mclk;
2898+
pm_runtime_set_autosuspend_delay(dev, 3000);
2899+
pm_runtime_use_autosuspend(dev);
2900+
pm_runtime_enable(dev);
28992901

2900-
ret = clk_prepare_enable(wsa->npl);
2901-
if (ret)
2902-
goto err_npl;
29032902

2904-
ret = clk_prepare_enable(wsa->fsgen);
2905-
if (ret)
2906-
goto err_fsgen;
2903+
ret = pm_runtime_resume_and_get(dev);
2904+
if (ret < 0) {
2905+
goto err_rpm_disable;
2906+
}
29072907

29082908
/* reset swr ip */
29092909
regmap_update_bits(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
@@ -2920,44 +2920,26 @@ static int wsa_macro_probe(struct platform_device *pdev)
29202920
wsa_macro_dai,
29212921
ARRAY_SIZE(wsa_macro_dai));
29222922
if (ret)
2923-
goto err_clkout;
2924-
2925-
pm_runtime_set_autosuspend_delay(dev, 3000);
2926-
pm_runtime_use_autosuspend(dev);
2927-
pm_runtime_mark_last_busy(dev);
2928-
pm_runtime_set_active(dev);
2929-
pm_runtime_enable(dev);
2923+
goto err_rpm_put;
29302924

29312925
ret = wsa_macro_register_mclk_output(wsa);
29322926
if (ret)
2933-
goto err_clkout;
2927+
goto err_rpm_put;
29342928

2935-
return 0;
2929+
pm_runtime_mark_last_busy(dev);
2930+
pm_runtime_put_autosuspend(dev);
29362931

2937-
err_clkout:
2938-
clk_disable_unprepare(wsa->fsgen);
2939-
err_fsgen:
2940-
clk_disable_unprepare(wsa->npl);
2941-
err_npl:
2942-
clk_disable_unprepare(wsa->mclk);
2943-
err_mclk:
2944-
clk_disable_unprepare(wsa->dcodec);
2945-
err_dcodec:
2946-
clk_disable_unprepare(wsa->macro);
2947-
err:
2932+
return 0;
2933+
err_rpm_put:
2934+
pm_runtime_put_noidle(dev);
2935+
err_rpm_disable:
2936+
pm_runtime_disable(dev);
29482937
return ret;
2949-
29502938
}
29512939

29522940
static void wsa_macro_remove(struct platform_device *pdev)
29532941
{
2954-
struct wsa_macro *wsa = dev_get_drvdata(&pdev->dev);
2955-
2956-
clk_disable_unprepare(wsa->macro);
2957-
clk_disable_unprepare(wsa->dcodec);
2958-
clk_disable_unprepare(wsa->mclk);
2959-
clk_disable_unprepare(wsa->npl);
2960-
clk_disable_unprepare(wsa->fsgen);
2942+
pm_runtime_disable(&pdev->dev);
29612943
}
29622944

29632945
static int wsa_macro_runtime_suspend(struct device *dev)
@@ -2967,46 +2949,20 @@ static int wsa_macro_runtime_suspend(struct device *dev)
29672949
regcache_cache_only(wsa->regmap, true);
29682950
regcache_mark_dirty(wsa->regmap);
29692951

2970-
clk_disable_unprepare(wsa->fsgen);
2971-
clk_disable_unprepare(wsa->npl);
2972-
clk_disable_unprepare(wsa->mclk);
2973-
2974-
return 0;
2952+
return pm_clk_suspend(dev);
29752953
}
29762954

29772955
static int wsa_macro_runtime_resume(struct device *dev)
29782956
{
29792957
struct wsa_macro *wsa = dev_get_drvdata(dev);
29802958
int ret;
29812959

2982-
ret = clk_prepare_enable(wsa->mclk);
2983-
if (ret) {
2984-
dev_err(dev, "unable to prepare mclk\n");
2985-
return ret;
2986-
}
2987-
2988-
ret = clk_prepare_enable(wsa->npl);
2989-
if (ret) {
2990-
dev_err(dev, "unable to prepare mclkx2\n");
2991-
goto err_npl;
2992-
}
2993-
2994-
ret = clk_prepare_enable(wsa->fsgen);
2995-
if (ret) {
2996-
dev_err(dev, "unable to prepare fsgen\n");
2997-
goto err_fsgen;
2998-
}
2999-
30002960
regcache_cache_only(wsa->regmap, false);
3001-
regcache_sync(wsa->regmap);
3002-
3003-
return 0;
3004-
err_fsgen:
3005-
clk_disable_unprepare(wsa->npl);
3006-
err_npl:
3007-
clk_disable_unprepare(wsa->mclk);
2961+
ret = pm_clk_resume(dev);
2962+
if (ret)
2963+
return ret;
30082964

3009-
return ret;
2965+
return regcache_sync(wsa->regmap);
30102966
}
30112967

30122968
static const struct dev_pm_ops wsa_macro_pm_ops = {

0 commit comments

Comments
 (0)