[alsa-devel] [PATCH] sound/soc: only first codec is master in multicodec setup

Johannes Krude johannes at krude.de
Wed Nov 20 21:23:34 CET 2019


When using multiple codecs, at most one codec should generate the master
clock. All codecs except the first are therefore configured for slave
mode. Before this patch all codecs in a multicodec setup had to be 
slaves. This is needed when e.g., connecting multiple sound hats for 
simultaneous playback to the raspberry pi I2S output and one of the 
sound hats generates the I2S clocks 
(https://github.com/raspberrypi/linux/pull/3337).

I checked the raspberry pi kernel tree for multicodec usage with
`fgrep num_codecs -R sound/soc/` and verified that all existing 
multicodec drivers with hardcoded format have indeed configured all 
codecs for slave mode. Doing a similar check on the current for-5.5 tree 
is more difficult since .num_codecs is now hidden behind a preprocessor 
macro.

Signed-off-by: Johannes Krude <johannes at krude.de>
---
 sound/soc/soc-core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 058e038df..cb8952527 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1688,6 +1688,14 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
+		unsigned int codec_dai_fmt = dai_fmt;
+
-		ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+		// there can only be one master when using multiple codecs
+		if (i && (codec_dai_fmt & SND_SOC_DAIFMT_MASTER_MASK)) {
+			codec_dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
+			codec_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
+		}
+
+		ret = snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
 		if (ret != 0 && ret != -ENOTSUPP) {
 			dev_warn(codec_dai->dev,
 				 "ASoC: Failed to set DAI format: %d\n", ret);
-- 
2.17.1



More information about the Alsa-devel mailing list