MLK-16350-3: ASoC: imx-cs42888: fix clock rate issue
authorShengjiu Wang <shengjiu.wang@freescale.com>
Fri, 1 Sep 2017 05:40:23 +0000 (13:40 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:38:25 +0000 (15:38 -0500)
The rate returned by clk_get_rate in probe function is not correct,
for the power domain in that time may be closed, kernel get 0 rate
from scfw, so move the clk_get_rate to hw_params, in that time, the
power domain should be enabled

Signed-off-by: Shengjiu Wang <shengjiu.wang@freescale.com>
sound/soc/fsl/imx-cs42888.c

index 1e4a805..c70606e 100644 (file)
@@ -32,6 +32,7 @@
 #define SUPPORT_RATE_NUM    10
 
 struct imx_priv {
+       struct clk *codec_clk;
        unsigned int mclk_freq;
        struct platform_device *pdev;
        struct platform_device *asrc_pdev;
@@ -59,6 +60,8 @@ static int imx_cs42888_surround_hw_params(struct snd_pcm_substream *substream,
 
        int ret = 0;
 
+       priv->mclk_freq = clk_get_rate(priv->codec_clk);
+
        if (priv->is_codec_master) {
                /* TDM is not supported by codec in master mode */
                if (enable_tdm) {
@@ -151,7 +154,9 @@ static int imx_cs42888_surround_startup(struct snd_pcm_substream *substream)
        static u32 support_rates[SUPPORT_RATE_NUM];
        int ret;
 
-       if (priv->mclk_freq == 24576000) {
+       priv->mclk_freq = clk_get_rate(priv->codec_clk);
+
+       if (priv->mclk_freq % 24576000 == 0) {
                support_rates[0] = 48000;
                support_rates[1] = 96000;
                support_rates[2] = 192000;
@@ -282,7 +287,6 @@ static int imx_cs42888_probe(struct platform_device *pdev)
        struct platform_device *asrc_pdev = NULL;
        struct i2c_client *codec_dev;
        struct imx_priv *priv = &card_priv;
-       struct clk *codec_clk = NULL;
        int ret;
        u32 width;
 
@@ -353,13 +357,12 @@ static int imx_cs42888_probe(struct platform_device *pdev)
                        priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
        }
 
-       codec_clk = devm_clk_get(&codec_dev->dev, NULL);
-       if (IS_ERR(codec_clk)) {
-               ret = PTR_ERR(codec_clk);
+       priv->codec_clk = devm_clk_get(&codec_dev->dev, NULL);
+       if (IS_ERR(priv->codec_clk)) {
+               ret = PTR_ERR(priv->codec_clk);
                dev_err(&codec_dev->dev, "failed to get codec clk: %d\n", ret);
                goto fail;
        }
-       priv->mclk_freq = clk_get_rate(codec_clk);
 
        priv->is_codec_master = false;
        if (of_property_read_bool(pdev->dev.of_node, "codec-master"))