alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] sound/soc: only first codec is master in multicodec setup
@ 2019-11-20 20:23 Johannes Krude
  2020-05-08 17:13 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Krude @ 2019-11-20 20:23 UTC (permalink / raw)
  To: alsa-devel; +Cc: Mark Brown, Liam Girdwood

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@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

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-11 21:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 20:23 [alsa-devel] [PATCH] sound/soc: only first codec is master in multicodec setup Johannes Krude
2020-05-08 17:13 ` Mark Brown
2020-05-11 21:34   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).