The sysclk frequency can be calculated from sample rate multiply ratio.
When sysclk_freq is not configured, but sysclk_ratio is configured, then
calculate sysclk frequency according to sysclk_ratio.

Apply this change for wm8524 codec.

Signed-off-by: Shengjiu Wang <shengjiu.w...@nxp.com>
---
 sound/soc/fsl/fsl-asoc-card.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index ab583b432c60..71113886e494 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -63,6 +63,7 @@ struct codec_priv {
  * @sysclk_freq: SYSCLK rates for set_sysclk()
  * @sysclk_dir: SYSCLK directions for set_sysclk()
  * @sysclk_id: SYSCLK ids for set_sysclk()
+ * @sysclk_ratio: SYSCLK ratio on sample rate
  * @slot_width: Slot width of each frame
  * @slot_num: Number of slots of each frame
  *
@@ -72,6 +73,7 @@ struct cpu_priv {
        unsigned long sysclk_freq[2];
        u32 sysclk_dir[2];
        u32 sysclk_id[2];
+       u32 sysclk_ratio[2];
        u32 slot_width;
        u32 slot_num;
 };
@@ -176,7 +178,7 @@ static int fsl_asoc_card_hw_params(struct snd_pcm_substream 
*substream,
        struct snd_soc_dai *codec_dai;
        struct cpu_priv *cpu_priv = &priv->cpu_priv;
        struct device *dev = rtd->card->dev;
-       unsigned int pll_out;
+       unsigned int pll_out, sysclk_freq;
        int codec_idx;
        int ret;
 
@@ -187,9 +189,14 @@ static int fsl_asoc_card_hw_params(struct 
snd_pcm_substream *substream,
        if (fsl_asoc_card_is_ac97(priv))
                return 0;
 
+       if (!cpu_priv->sysclk_freq[tx] && cpu_priv->sysclk_ratio[tx])
+               sysclk_freq = priv->sample_rate * cpu_priv->sysclk_ratio[tx];
+       else
+               sysclk_freq = cpu_priv->sysclk_freq[tx];
+
        /* Specific configurations of DAIs starts from here */
        ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_cpu(rtd, 0), 
cpu_priv->sysclk_id[tx],
-                                    cpu_priv->sysclk_freq[tx],
+                                    sysclk_freq,
                                     cpu_priv->sysclk_dir[tx]);
        if (ret && ret != -ENOTSUPP) {
                dev_err(dev, "failed to set sysclk for cpu dai\n");
@@ -799,6 +806,8 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
                priv->cpu_priv.slot_width = 32;
                priv->card.dapm_routes = audio_map_tx;
                priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
+               priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
+               priv->cpu_priv.sysclk_ratio[TX] = 256;
        } else if (of_device_is_compatible(np, "fsl,imx-audio-si476x")) {
                codec_dai_name[0] = "si476x-codec";
                priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
-- 
2.34.1


Reply via email to