MLK-17034-5: ASoC: fsl_mqs: Move clock operation to pm runtime function
authorShengjiu Wang <shengjiu.wang@nxp.com>
Wed, 29 Nov 2017 07:32:21 +0000 (15:32 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Tue, 20 Mar 2018 19:49:48 +0000 (14:49 -0500)
In imx8 when systerm enter suspend state, the power of subsystem will be
off, The clock enable state will be lost after resume, but the runtime
resume function will be called after resume by pm, so need to move clock
enablement to runtime resume and clock disablement to runtime suspend.
Then after resume the clock enable state can be recovered.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
sound/soc/codecs/fsl_mqs.c

index 4bc47ee..09eb1d5 100644 (file)
@@ -144,12 +144,6 @@ static int fsl_mqs_startup(struct snd_pcm_substream *substream,
        struct snd_soc_codec *codec = dai->codec;
        struct fsl_mqs *mqs_priv = snd_soc_codec_get_drvdata(codec);
 
-       if (mqs_priv->ipg)
-               clk_prepare_enable(mqs_priv->ipg);
-
-       if (mqs_priv->mclk)
-               clk_prepare_enable(mqs_priv->mclk);
-
        if (mqs_priv->use_gpr)
                regmap_update_bits(mqs_priv->gpr, IOMUXC_GPR2, IMX6SX_GPR2_MQS_EN_MASK,
                                        1 << IMX6SX_GPR2_MQS_EN_SHIFT);
@@ -172,16 +166,12 @@ static void fsl_mqs_shutdown(struct snd_pcm_substream *substream,
        else
                regmap_update_bits(mqs_priv->regmap, REG_MQS_CTRL,
                                        MQS_EN_MASK, 0);
-
-       if (mqs_priv->mclk)
-               clk_disable_unprepare(mqs_priv->mclk);
-
-       if (mqs_priv->ipg)
-               clk_disable_unprepare(mqs_priv->ipg);
 }
 
 
-static struct snd_soc_codec_driver soc_codec_fsl_mqs;
+static struct snd_soc_codec_driver soc_codec_fsl_mqs = {
+       .idle_bias_off = true,
+};
 
 static const struct snd_soc_dai_ops fsl_mqs_dai_ops = {
        .startup = fsl_mqs_startup,
@@ -291,9 +281,38 @@ out:
 static int fsl_mqs_remove(struct platform_device *pdev)
 {
        snd_soc_unregister_codec(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int fsl_mqs_runtime_resume(struct device *dev)
+{
+       struct fsl_mqs *mqs_priv = dev_get_drvdata(dev);
+
+       if (mqs_priv->ipg)
+               clk_prepare_enable(mqs_priv->ipg);
+
+       if (mqs_priv->mclk)
+               clk_prepare_enable(mqs_priv->mclk);
+
        return 0;
 }
 
+static int fsl_mqs_runtime_suspend(struct device *dev)
+{
+       struct fsl_mqs *mqs_priv = dev_get_drvdata(dev);
+
+       if (mqs_priv->mclk)
+               clk_disable_unprepare(mqs_priv->mclk);
+
+       if (mqs_priv->ipg)
+               clk_disable_unprepare(mqs_priv->ipg);
+
+       return 0;
+}
+#endif
+
 #ifdef CONFIG_PM_SLEEP
 static int fsl_mqs_resume(struct device *dev)
 {
@@ -325,6 +344,9 @@ static int fsl_mqs_suspend(struct device *dev)
 #endif
 
 static const struct dev_pm_ops fsl_mqs_pm_ops = {
+       SET_RUNTIME_PM_OPS(fsl_mqs_runtime_suspend,
+                          fsl_mqs_runtime_resume,
+                          NULL)
        SET_SYSTEM_SLEEP_PM_OPS(fsl_mqs_suspend, fsl_mqs_resume)
 };