From e7da0ac1ae2a864e1545a4a8f352772aac319c0e Mon Sep 17 00:00:00 2001 From: Srinivas Kandagatla Date: Mon, 18 Oct 2021 14:33:54 +0100 Subject: ASoC: codecs: va-macro: add runtime pm support Signed-off-by: Srinivas Kandagatla --- sound/soc/codecs/lpass-va-macro.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/lpass-va-macro.c b/sound/soc/codecs/lpass-va-macro.c index 11147e35689b..4a9142ebd279 100644 --- a/sound/soc/codecs/lpass-va-macro.c +++ b/sound/soc/codecs/lpass-va-macro.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1426,7 +1427,7 @@ static int va_macro_probe(struct platform_device *pdev) } /* mclk rate */ - clk_set_rate(va->clks[1].clk, VA_MACRO_MCLK_FREQ); + clk_set_rate(va->clks[1].clk, 2 * VA_MACRO_MCLK_FREQ); ret = clk_bulk_prepare_enable(VA_NUM_CLKS_MAX, va->clks); if (ret) return ret; @@ -1454,6 +1455,12 @@ static int va_macro_probe(struct platform_device *pdev) if (ret) goto err; + 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); + return ret; err: @@ -1471,6 +1478,34 @@ static int va_macro_remove(struct platform_device *pdev) return 0; } +static int __maybe_unused va_macro_runtime_suspend(struct device *dev) +{ + struct va_macro *va = dev_get_drvdata(dev); + + regcache_cache_only(va->regmap, true); + regcache_mark_dirty(va->regmap); + + clk_disable_unprepare(va->clks[2].clk); + + return 0; +} + +static int __maybe_unused va_macro_runtime_resume(struct device *dev) +{ + struct va_macro *va = dev_get_drvdata(dev); + + clk_prepare_enable(va->clks[2].clk); + + regcache_cache_only(va->regmap, false); + regcache_sync(va->regmap); + return 0; +} + + +static const struct dev_pm_ops va_macro_pm_ops = { + SET_RUNTIME_PM_OPS(va_macro_runtime_suspend, va_macro_runtime_resume, NULL) +}; + static const struct of_device_id va_macro_dt_match[] = { { .compatible = "qcom,sc7280-lpass-va-macro" }, { .compatible = "qcom,sm8250-lpass-va-macro" }, @@ -1483,6 +1518,7 @@ static struct platform_driver va_macro_driver = { .name = "va_macro", .of_match_table = va_macro_dt_match, .suppress_bind_attrs = true, + .pm = &va_macro_pm_ops, }, .probe = va_macro_probe, .remove = va_macro_remove, -- cgit v1.2.3