aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>2021-10-18 14:47:21 +0100
committerSrinivas Kandagatla <srinivas.kandagatla@linaro.org>2021-12-10 14:07:34 +0000
commit5b730c1049676cba3e3628cb9f39af27155fb748 (patch)
treee8e7124a9d4b8b6a69bf03ed293f07a6511529e2
parentaedcc1c44f569822ecdd718dcc35c6f09df1148c (diff)
ASoC: codecs: tx-macro: add runtime pm support
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
-rw-r--r--sound/soc/codecs/lpass-tx-macro.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/sound/soc/codecs/lpass-tx-macro.c b/sound/soc/codecs/lpass-tx-macro.c
index a4c0a155af56..0d8aa27385e5 100644
--- a/sound/soc/codecs/lpass-tx-macro.c
+++ b/sound/soc/codecs/lpass-tx-macro.c
@@ -6,6 +6,7 @@
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
@@ -1686,6 +1687,7 @@ static int swclk_gate_enable(struct clk_hw *hw)
struct tx_macro *tx = to_tx_macro(hw);
struct regmap *regmap = tx->regmap;
+ clk_prepare_enable(tx->clks[2].clk);
tx_macro_mclk_enable(tx, true);
if (tx->reset_swr)
regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
@@ -1712,6 +1714,7 @@ static void swclk_gate_disable(struct clk_hw *hw)
CDC_TX_SWR_CLK_EN_MASK, 0x0);
tx_macro_mclk_enable(tx, false);
+ clk_disable_unprepare(tx->clks[2].clk);
}
static int swclk_gate_is_enabled(struct clk_hw *hw)
@@ -1749,7 +1752,7 @@ static struct clk *tx_macro_register_mclk_output(struct tx_macro *tx)
struct clk_init_data init;
int ret;
- parent_clk_name = __clk_get_name(tx->clks[2].clk);
+ parent_clk_name = __clk_get_name(tx->clks[3].clk);
init.name = clk_name;
init.ops = &swclk_gate_ops;
@@ -1828,7 +1831,7 @@ static int tx_macro_probe(struct platform_device *pdev)
tx->dev = dev;
/* set MCLK and NPL rates */
- clk_set_rate(tx->clks[2].clk, MCLK_FREQ);
+ clk_set_rate(tx->clks[2].clk, 2 * MCLK_FREQ);
clk_set_rate(tx->clks[3].clk, 2 * MCLK_FREQ);
ret = clk_bulk_prepare_enable(TX_NUM_CLKS_MAX, tx->clks);
@@ -1842,6 +1845,13 @@ static int tx_macro_probe(struct platform_device *pdev)
ARRAY_SIZE(tx_macro_dai));
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:
clk_bulk_disable_unprepare(TX_NUM_CLKS_MAX, tx->clks);
@@ -1860,6 +1870,37 @@ static int tx_macro_remove(struct platform_device *pdev)
return 0;
}
+static int __maybe_unused tx_macro_runtime_suspend(struct device *dev)
+{
+ struct tx_macro *tx = dev_get_drvdata(dev);
+
+ regcache_cache_only(tx->regmap, true);
+ regcache_mark_dirty(tx->regmap);
+
+ clk_disable_unprepare(tx->clks[2].clk);
+ clk_disable_unprepare(tx->clks[3].clk);
+ clk_disable_unprepare(tx->clks[4].clk);
+
+ return 0;
+}
+
+static int __maybe_unused tx_macro_runtime_resume(struct device *dev)
+{
+ struct tx_macro *tx = dev_get_drvdata(dev);
+
+ clk_prepare_enable(tx->clks[2].clk);
+ clk_prepare_enable(tx->clks[3].clk);
+ clk_prepare_enable(tx->clks[4].clk);
+ regcache_cache_only(tx->regmap, false);
+ regcache_sync(tx->regmap);
+
+ return 0;
+}
+
+static const struct dev_pm_ops tx_macro_pm_ops = {
+ SET_RUNTIME_PM_OPS(tx_macro_runtime_suspend, tx_macro_runtime_resume, NULL)
+};
+
static const struct of_device_id tx_macro_dt_match[] = {
{ .compatible = "qcom,sc7280-lpass-tx-macro" },
{ .compatible = "qcom,sm8250-lpass-tx-macro" },
@@ -1871,6 +1912,7 @@ static struct platform_driver tx_macro_driver = {
.name = "tx_macro",
.of_match_table = tx_macro_dt_match,
.suppress_bind_attrs = true,
+ .pm = &tx_macro_pm_ops,
},
.probe = tx_macro_probe,
.remove = tx_macro_remove,