Skip to contentSkip to conversation

ASoC: SOF: add a helper to get topology configured mclk

PATCH In review Kai Vehmanen 2 participants 3 messages Mar 19, 2021 – Mar 22, 2021

Subsystems (4)
lore
Share & tools
lore

Kai Vehmanen

author maintainer
#0 lore raw

PATCH 1/2 ASoC: SOF: add a helper to get topology configured mclk

From: Keyon Jie <[email protected]>

Add helper sof_dai_ssp_mclk to get the topology configured MCLK from a pcm_runtime, return 0 if it is not available, and error if the dai type is not SSP at the moment.

Export the helper for external use, e.g. from machine drivers.

---
 include/sound/sof.h       |  1 +
 sound/soc/sof/sof-audio.c | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
include/sound/sof.h +1 -0
index 646a655c3c6b..b93bb8038080 100644
@@ -103,5 +103,6 @@ struct sof_dev_desc {
 int sof_nocodec_setup(struct device *dev, const struct snd_sof_dsp_ops *ops,
 		      int (*pcm_dai_link_fixup)(struct snd_soc_pcm_runtime *rtd,
 						struct snd_pcm_hw_params *params));
+int sof_dai_get_mclk(struct snd_soc_pcm_runtime *rtd);
 
 #endif
sound/soc/sof/sof-audio.c +27 -0
index 3277489fee5e..928d7a46d820 100644
@@ -433,6 +433,33 @@ struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
 	return NULL;
 }
 
+/*
+ * Helper to get SSP MCLK from a pcm_runtime.
+ * Return 0 if not exist.
+ */
+int sof_dai_get_mclk(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_component *component =
+		snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
+	struct snd_sof_dai *dai =
+		snd_sof_find_dai(component, (char *)rtd->dai_link->name);
+
+	/* use the tplg configured mclk if existed */
+	if (!dai || !dai->dai_config)
+		return 0;
+
+	switch (dai->dai_config->type) {
+	case SOF_DAI_INTEL_SSP:
+		return dai->dai_config->ssp.mclk_rate;
+	default:
+		/* not yet implemented for platforms other than the above */
+		dev_err(rtd->dev, "mclk for dai_config->type %d not supported yet!\n",
+			dai->dai_config->type);
+		return -EINVAL;
+	}
+}
+EXPORT_SYMBOL(sof_dai_get_mclk);
+
 /*
  * SOF Driver enumeration.
  */

base-commit: bb9faeccbd6c05c6c2525be90f663f8694dd8bf6

Signature · 1 line
2.29.2
author maintainer
#1 lore raw

PATCH 2/2 ASoC: intel: sof_rt5682: use the topology mclk

From: Keyon Jie <[email protected]>

We should use the topology configured mclk if it existed, which can make sure we are aligned with the FW side about the mclk usage.

---
 sound/soc/intel/boards/sof_rt5682.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
sound/soc/intel/boards/sof_rt5682.c +14 -2
index f4b898c1719f..58548ea0d915 100644
@@ -16,6 +16,7 @@
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
+#include <sound/sof.h>
 #include <sound/rt5682.h>
 #include <sound/soc-acpi.h>
 #include "../../codecs/rt1015.h"
@@ -268,10 +269,21 @@ static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
 		}
 
 		clk_id = RT5682_PLL1_S_MCLK;
-		if (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ)
+
+		/* get the tplg configured mclk. */
+		clk_freq = sof_dai_get_mclk(rtd);
+
+		/* mclk from the quirk is the first choice */
+		if (sof_rt5682_quirk & SOF_RT5682_MCLK_24MHZ) {
+			if (clk_freq != 24000000)
+				dev_warn(rtd->dev, "configure wrong mclk in tplg, please use 24MHz.\n");
 			clk_freq = 24000000;
-		else
+		} else if (clk_freq == 0) {
+			/* use default mclk if not specified correct in topology */
 			clk_freq = 19200000;
+		} else if (clk_freq < 0) {
+			return clk_freq;
+		}
 	} else {
 		clk_id = RT5682_PLL1_S_BCLK1;
 		clk_freq = params_rate(params) * 50;
Signature · 1 line
2.29.2
maintainer
#2 lore raw
In reply to Kai Vehmanen
Quoted 5 lines · Kai Vehmanen

Add helper sof_dai_ssp_mclk to get the topology configured MCLK from a pcm_runtime, return 0 if it is not available, and error if the dai type is not SSP at the moment.

Export the helper for external use, e.g. from machine drivers.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: SOF: add a helper to get topology configured mclk

      commit: b951b51e2ca4d37dc9781e14d8a49d2f2b7e715b
[2/2] ASoC: intel: sof_rt5682: use the topology mclk
      commit: bf939446c357242b3306e88c5f48976940d29679

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark