alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Krude <johannes@krude.de>
To: alsa-devel@alsa-project.org
Cc: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Subject: [alsa-devel] [PATCH] sound/soc: only first codec is master in multicodec setup
Date: Wed, 20 Nov 2019 21:23:34 +0100	[thread overview]
Message-ID: <20191120202334.GA4579@phlox.h.transitiv.net> (raw)

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

             reply	other threads:[~2019-11-20 20:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 20:23 Johannes Krude [this message]
2020-05-08 17:13 ` [PATCH] sound/soc: only first codec is master in multicodec setup Mark Brown
2020-05-11 21:34   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191120202334.GA4579@phlox.h.transitiv.net \
    --to=johannes@krude.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).