From 66881d14d63771e79c0fbd5ad931266f3b8e5b2b Mon Sep 17 00:00:00 2001
From: Shengjiu Wang <shengjiu.wang@nxp.com>
Date: Tue, 17 May 2022 21:11:15 +0800
Subject: [PATCH] LF-6072: ASoC: imx-card: Assign clock rate for PDM format

Previously we only assigned clock rate for 44kHz series sample rate.
But meet issue on i.MX8MM 16KHz case, the calculated mclk_freq is
512KHz, but because root clock divider range limitation, the smallest
mclk rate is 768Hkz, then cause issue. so also assign mclk_freq
for 48kHz series sample rates

Fixes: 3a650ee65b73 ("LF-5909-2: ASoC: imx-card: fix DSD mclk frequency")
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Reviewed-by: Chancel Liu <chancel.liu@nxp.com>
Acked-by: Jason Liu <jason.hui.liu@nxp.com>
---
 sound/soc/fsl/imx-card.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
index be9c2c911b773..70b3b7819868d 100644
--- a/sound/soc/fsl/imx-card.c
+++ b/sound/soc/fsl/imx-card.c
@@ -354,8 +354,12 @@ static int imx_aif_hw_params(struct snd_pcm_substream *substream,
 	else
 		mclk_freq = params_rate(params) * slots * slot_width;
 	/* Use the maximum freq from DSD512 (512*44100 = 22579200) */
-	if (format_is_dsd(params) && (params_rate(params) % 44100 == 0))
-		mclk_freq = 22579200;
+	if (format_is_dsd(params)) {
+		if (params_rate(params) % 11025 == 0)
+			mclk_freq = 22579200;
+		else
+			mclk_freq = 24576000;
+	}
 
 	ret = snd_soc_dai_set_sysclk(cpu_dai, link_data->cpu_sysclk_id, mclk_freq,
 				     SND_SOC_CLOCK_OUT);
-- 
GitLab