Skip to content

Commit 0d3a682

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 fb8efcc commit 0d3a682

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"
@@ -2529,15 +2530,15 @@ static const struct snd_soc_dapm_route wsa_audio_map[] = {
25292530
static int wsa_swrm_clock(struct wsa_macro *wsa, bool enable)
25302531
{
25312532
struct regmap *regmap = wsa->regmap;
2533+
int ret;
25322534

2533-
if (enable) {
2534-
int ret;
2535+
ret = pm_runtime_get_sync(wsa->dev);
2536+
if (ret < 0) {
2537+
pm_runtime_put_noidle(wsa->dev);
2538+
return ret;
2539+
}
25352540

2536-
ret = clk_prepare_enable(wsa->mclk);
2537-
if (ret) {
2538-
dev_err(wsa->dev, "failed to enable mclk\n");
2539-
return ret;
2540-
}
2541+
if (enable) {
25412542
wsa_macro_mclk_enable(wsa, true);
25422543

25432544
regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
@@ -2548,9 +2549,10 @@ static int wsa_swrm_clock(struct wsa_macro *wsa, bool enable)
25482549
regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
25492550
CDC_WSA_SWR_CLK_EN_MASK, 0);
25502551
wsa_macro_mclk_enable(wsa, false);
2551-
clk_disable_unprepare(wsa->mclk);
25522552
}
25532553

2554+
pm_runtime_mark_last_busy(wsa->dev);
2555+
pm_runtime_put_autosuspend(wsa->dev);
25542556
return 0;
25552557
}
25562558

@@ -2774,25 +2776,23 @@ static int wsa_macro_probe(struct platform_device *pdev)
27742776
clk_set_rate(wsa->mclk, WSA_MACRO_MCLK_FREQ);
27752777
clk_set_rate(wsa->npl, WSA_MACRO_MCLK_FREQ);
27762778

2777-
ret = clk_prepare_enable(wsa->macro);
2779+
ret = devm_pm_clk_create(dev);
27782780
if (ret)
2779-
goto err;
2781+
return ret;
27802782

2781-
ret = clk_prepare_enable(wsa->dcodec);
2782-
if (ret)
2783-
goto err_dcodec;
2783+
ret = of_pm_clk_add_clks(dev);
2784+
if (ret < 0)
2785+
return ret;
27842786

2785-
ret = clk_prepare_enable(wsa->mclk);
2786-
if (ret)
2787-
goto err_mclk;
2787+
pm_runtime_set_autosuspend_delay(dev, 3000);
2788+
pm_runtime_use_autosuspend(dev);
2789+
pm_runtime_enable(dev);
27882790

2789-
ret = clk_prepare_enable(wsa->npl);
2790-
if (ret)
2791-
goto err_npl;
27922791

2793-
ret = clk_prepare_enable(wsa->fsgen);
2794-
if (ret)
2795-
goto err_fsgen;
2792+
ret = pm_runtime_resume_and_get(dev);
2793+
if (ret < 0) {
2794+
goto err_rpm_disable;
2795+
}
27962796

27972797
/* reset swr ip */
27982798
regmap_update_bits(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
@@ -2809,44 +2809,26 @@ static int wsa_macro_probe(struct platform_device *pdev)
28092809
wsa_macro_dai,
28102810
ARRAY_SIZE(wsa_macro_dai));
28112811
if (ret)
2812-
goto err_clkout;
2813-
2814-
pm_runtime_set_autosuspend_delay(dev, 3000);
2815-
pm_runtime_use_autosuspend(dev);
2816-
pm_runtime_mark_last_busy(dev);
2817-
pm_runtime_set_active(dev);
2818-
pm_runtime_enable(dev);
2812+
goto err_rpm_put;
28192813

28202814
ret = wsa_macro_register_mclk_output(wsa);
28212815
if (ret)
2822-
goto err_clkout;
2816+
goto err_rpm_put;
28232817

2824-
return 0;
2818+
pm_runtime_mark_last_busy(dev);
2819+
pm_runtime_put_autosuspend(dev);
28252820

2826-
err_clkout:
2827-
clk_disable_unprepare(wsa->fsgen);
2828-
err_fsgen:
2829-
clk_disable_unprepare(wsa->npl);
2830-
err_npl:
2831-
clk_disable_unprepare(wsa->mclk);
2832-
err_mclk:
2833-
clk_disable_unprepare(wsa->dcodec);
2834-
err_dcodec:
2835-
clk_disable_unprepare(wsa->macro);
2836-
err:
2821+
return 0;
2822+
err_rpm_put:
2823+
pm_runtime_put_noidle(dev);
2824+
err_rpm_disable:
2825+
pm_runtime_disable(dev);
28372826
return ret;
2838-
28392827
}
28402828

28412829
static void wsa_macro_remove(struct platform_device *pdev)
28422830
{
2843-
struct wsa_macro *wsa = dev_get_drvdata(&pdev->dev);
2844-
2845-
clk_disable_unprepare(wsa->macro);
2846-
clk_disable_unprepare(wsa->dcodec);
2847-
clk_disable_unprepare(wsa->mclk);
2848-
clk_disable_unprepare(wsa->npl);
2849-
clk_disable_unprepare(wsa->fsgen);
2831+
pm_runtime_disable(&pdev->dev);
28502832
}
28512833

28522834
static int wsa_macro_runtime_suspend(struct device *dev)
@@ -2856,46 +2838,20 @@ static int wsa_macro_runtime_suspend(struct device *dev)
28562838
regcache_cache_only(wsa->regmap, true);
28572839
regcache_mark_dirty(wsa->regmap);
28582840

2859-
clk_disable_unprepare(wsa->fsgen);
2860-
clk_disable_unprepare(wsa->npl);
2861-
clk_disable_unprepare(wsa->mclk);
2862-
2863-
return 0;
2841+
return pm_clk_suspend(dev);
28642842
}
28652843

28662844
static int wsa_macro_runtime_resume(struct device *dev)
28672845
{
28682846
struct wsa_macro *wsa = dev_get_drvdata(dev);
28692847
int ret;
28702848

2871-
ret = clk_prepare_enable(wsa->mclk);
2872-
if (ret) {
2873-
dev_err(dev, "unable to prepare mclk\n");
2874-
return ret;
2875-
}
2876-
2877-
ret = clk_prepare_enable(wsa->npl);
2878-
if (ret) {
2879-
dev_err(dev, "unable to prepare mclkx2\n");
2880-
goto err_npl;
2881-
}
2882-
2883-
ret = clk_prepare_enable(wsa->fsgen);
2884-
if (ret) {
2885-
dev_err(dev, "unable to prepare fsgen\n");
2886-
goto err_fsgen;
2887-
}
2888-
28892849
regcache_cache_only(wsa->regmap, false);
2890-
regcache_sync(wsa->regmap);
2891-
2892-
return 0;
2893-
err_fsgen:
2894-
clk_disable_unprepare(wsa->npl);
2895-
err_npl:
2896-
clk_disable_unprepare(wsa->mclk);
2850+
ret = pm_clk_resume(dev);
2851+
if (ret)
2852+
return ret;
28972853

2898-
return ret;
2854+
return regcache_sync(wsa->regmap);
28992855
}
29002856

29012857
static const struct dev_pm_ops wsa_macro_pm_ops = {

0 commit comments

Comments
 (0)