diff mbox series

[01/10] ASoC: codecs: va-macro: add runtime pm support

Message ID 20220221131037.8809-2-srinivas.kandagatla@linaro.org (mailing list archive)
State New, archived
Headers show
Series ASoC: codec: add pm runtime support for Qualcomm codecs | expand

Commit Message

Srinivas Kandagatla Feb. 21, 2022, 1:10 p.m. UTC
Add pm runtime support to VA Macro.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 sound/soc/codecs/lpass-va-macro.c | 36 +++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Mark Brown Feb. 21, 2022, 3:24 p.m. UTC | #1
On Mon, Feb 21, 2022 at 01:10:28PM +0000, Srinivas Kandagatla wrote:

> +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);

This magic number stuff is going to be excessively fragile, and the fact
that this is sometimes managed via the bulk APIs and sometimes not isn't
going to help either.  Either all the clocks should be managed here or
this should be pulled out of the array.

Also consider error checking.
Srinivas Kandagatla Feb. 21, 2022, 3:27 p.m. UTC | #2
Thanks Mark,

On 21/02/2022 15:24, Mark Brown wrote:
> On Mon, Feb 21, 2022 at 01:10:28PM +0000, Srinivas Kandagatla wrote:
> 
>> +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);
> 
> This magic number stuff is going to be excessively fragile, and the fact

I agree, will try to clean this up properly in next spin.

> that this is sometimes managed via the bulk APIs and sometimes not isn't
> going to help either.  Either all the clocks should be managed here or
> this should be pulled out of the array.
> 
> Also consider error checking.
will do,

--srin
diff mbox series

Patch

diff --git a/sound/soc/codecs/lpass-va-macro.c b/sound/soc/codecs/lpass-va-macro.c
index e14c277e6a8b..0fd0139e8229 100644
--- a/sound/soc/codecs/lpass-va-macro.c
+++ b/sound/soc/codecs/lpass-va-macro.c
@@ -9,6 +9,7 @@ 
 #include <linux/of_clk.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <sound/soc.h>
@@ -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,