Skip to contentSkip to conversation

ASoC: core: Add support for DAI multicodec

PATCH Superseded Benoit Cousson 3 participants 12 messages Mar 21, 2014 – Apr 14, 2014

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover ASoC: core: Add support for DAI multicodec

Hi Mark and Liam,

Here is the second version of the multicodec series. I mostly rebased the code to asoc-next, added smaller patches to introduce helpers before the main patch and thus reduce the overal size of that patch and modified the TDM slot fixup.

Please note that I have a very simple setup based on BBB to check if the series is working, so it will be good to test the series on various setup to ensure this is not generating any regression.
Hence the RFT for this version.

The series is based on asoc-v3.15-2-245-g876dea8.

Test and comments are welcome.

Thanks,
Benoit

v1: http://comments.gmane.org/gmane.linux.alsa.devel/120532

v2:
- Split the first version in several patches.
- Remove the TDM fixup

---
Misael Lopez Cruz (6):
ASoC: core: Add helpers for codec and codec_dai search
ASoC: core: Add helpers for codec DAI probe & remove
ASoC: core: Add helper for DAI widgets linking
ASoC: core: Add function for ac97 codec registration
ASoC: core: Add helpers for dai link and aux dev init
ASoC: core: Add support for DAI multicodec

 include/sound/soc-dai.h |   5 +
 include/sound/soc.h     |  16 ++
 sound/soc/soc-core.c    | 578 ++++++++++++++++++++++++++++++++++--------------
 sound/soc/soc-dapm.c    |  39 +++-
 sound/soc/soc-pcm.c     | 438 +++++++++++++++++++++++++-----------
 5 files changed, 761 insertions(+), 315 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH v2 1/6 ASoC: core: Add helpers for codec and codec_dai search

From: Misael Lopez Cruz <[email protected]>

Add dedicated helpers for codec and codec_dai search in preparation for DAI-multicodec. It will help reducing the extra indentation that will be introduced by the iteration over multiple codecs.

Previous implementation unnecessarily kept searching for a matching codec in the remaining register codecs even if it was already found.

Fix that by returning in case of matching.

---
 sound/soc/soc-core.c | 79 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 47 insertions(+), 32 deletions(-)
sound/soc/soc-core.c +47 -32
index b322cf2..ab65137 100644
@@ -854,14 +854,47 @@ EXPORT_SYMBOL_GPL(snd_soc_resume);
 static const struct snd_soc_dai_ops null_dai_ops = {
 };
 
+static struct snd_soc_codec *soc_find_codec(const struct device_node *codec_of_node,
+					    const char *codec_name)
+{
+	struct snd_soc_codec *codec;
+
+	list_for_each_entry(codec, &codec_list, list) {
+		if (codec_of_node) {
+			if (codec->dev->of_node != codec_of_node)
+				continue;
+		} else {
+			if (strcmp(codec->name, codec_name))
+				continue;
+		}
+
+		return codec;
+	}
+
+	return NULL;
+}
+
+static struct snd_soc_dai *soc_find_codec_dai(struct snd_soc_codec *codec,
+					      const char *codec_dai_name)
+{
+	struct snd_soc_dai *codec_dai;
+
+	list_for_each_entry(codec_dai, &codec->component.dai_list, list) {
+		if (!strcmp(codec_dai->name, codec_dai_name)) {
+			return codec_dai;
+		}
+	}
+
+	return NULL;
+}
+
 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 {
 	struct snd_soc_dai_link *dai_link = &card->dai_link[num];
 	struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
 	struct snd_soc_component *component;
-	struct snd_soc_codec *codec;
 	struct snd_soc_platform *platform;
-	struct snd_soc_dai *codec_dai, *cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	const char *platform_name;
 
 	dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
@@ -889,42 +922,24 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 		return -EPROBE_DEFER;
 	}
 
-	/* Find CODEC from registered CODECs */
-	list_for_each_entry(codec, &codec_list, list) {
-		if (dai_link->codec_of_node) {
-			if (codec->dev->of_node != dai_link->codec_of_node)
-				continue;
-		} else {
-			if (strcmp(codec->name, dai_link->codec_name))
-				continue;
-		}
-
-		rtd->codec = codec;
-
-		/*
-		 * CODEC found, so find CODEC DAI from registered DAIs from
-		 * this CODEC
-		 */
-		list_for_each_entry(codec_dai, &codec->component.dai_list, list) {
-			if (!strcmp(codec_dai->name, dai_link->codec_dai_name)) {
-				rtd->codec_dai = codec_dai;
-				break;
-			}
-		}
-
-		if (!rtd->codec_dai) {
-			dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
-				dai_link->codec_dai_name);
-			return -EPROBE_DEFER;
-		}
-	}
-
+	/* Find CODEC from registered list */
+	rtd->codec = soc_find_codec(dai_link->codec_of_node,
+				    dai_link->codec_name);
 	if (!rtd->codec) {
 		dev_err(card->dev, "ASoC: CODEC %s not registered\n",
 			dai_link->codec_name);
 		return -EPROBE_DEFER;
 	}
 
+	/* Find CODEC DAI from registered list */
+	rtd->codec_dai = soc_find_codec_dai(rtd->codec,
+					    dai_link->codec_dai_name);
+	if (!rtd->codec_dai) {
+		dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+			dai_link->codec_dai_name);
+		return -EPROBE_DEFER;
+	}
+
 	/* if there's no platform we match on the empty platform */
 	platform_name = dai_link->platform_name;
 	if (!platform_name && !dai_link->platform_of_node)
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH v2 2/6 ASoC: core: Add helpers for codec DAI probe & remove

In reply to Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

Add helper functions for codec DAI probe and remove in preparation for DAI-multicodec support.

No functional change.

---
 sound/soc/soc-core.c | 74 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 27 deletions(-)
sound/soc/soc-core.c +47 -27
index ab65137..1bcc446 100644
@@ -1010,21 +1010,10 @@ static void soc_remove_codec(struct snd_soc_codec *codec)
 	module_put(codec->dev->driver->owner);
 }
 
-static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
+static void soc_remove_codec_dai(struct snd_soc_dai *codec_dai, int order)
 {
-	struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
-	struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
 	int err;
 
-	/* unregister the rtd device */
-	if (rtd->dev_registered) {
-		device_remove_file(rtd->dev, &dev_attr_pmdown_time);
-		device_remove_file(rtd->dev, &dev_attr_codec_reg);
-		device_unregister(rtd->dev);
-		rtd->dev_registered = 0;
-	}
-
-	/* remove the CODEC DAI */
 	if (codec_dai && codec_dai->probed &&
 			codec_dai->driver->remove_order == order) {
 		if (codec_dai->driver->remove) {
@@ -1037,6 +1026,24 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
 		codec_dai->probed = 0;
 		list_del(&codec_dai->card_list);
 	}
+}
+
+static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
+{
+	struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
+	struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
+	int err;
+
+	/* unregister the rtd device */
+	if (rtd->dev_registered) {
+		device_remove_file(rtd->dev, &dev_attr_pmdown_time);
+		device_remove_file(rtd->dev, &dev_attr_codec_reg);
+		device_unregister(rtd->dev);
+		rtd->dev_registered = 0;
+	}
+
+	/* remove the CODEC DAI */
+	soc_remove_codec_dai(codec_dai, order);
 
 	/* remove the cpu_dai */
 	if (cpu_dai && cpu_dai->probed &&
@@ -1386,6 +1393,31 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num,
 	return 0;
 }
 
+static int soc_probe_codec_dai(struct snd_soc_card *card,
+			       struct snd_soc_dai *codec_dai,
+			       int order)
+{
+	int ret;
+
+	if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
+		if (codec_dai->driver->probe) {
+			ret = codec_dai->driver->probe(codec_dai);
+			if (ret < 0) {
+				dev_err(codec_dai->dev,
+					"ASoC: failed to probe CODEC DAI %s: %d\n",
+					codec_dai->name, ret);
+				return ret;
+			}
+		}
+
+		/* mark codec_dai as probed and add to card dai list */
+		codec_dai->probed = 1;
+		list_add(&codec_dai->card_list, &card->dai_dev_list);
+	}
+
+	return 0;
+}
+
 static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 {
 	struct snd_soc_dai_link *dai_link = &card->dai_link[num];
@@ -1435,21 +1467,9 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 	}
 
 	/* probe the CODEC DAI */
-	if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
-		if (codec_dai->driver->probe) {
-			ret = codec_dai->driver->probe(codec_dai);
-			if (ret < 0) {
-				dev_err(codec_dai->dev,
-					"ASoC: failed to probe CODEC DAI %s: %d\n",
-					codec_dai->name, ret);
-				return ret;
-			}
-		}
-
-		/* mark codec_dai as probed and add to card dai list */
-		codec_dai->probed = 1;
-		list_add(&codec_dai->card_list, &card->dai_dev_list);
-	}
+	ret = soc_probe_codec_dai(card, codec_dai, order);
+	if (ret)
+		return ret;
 
 	/* complete DAI probe during last probe */
 	if (order != SND_SOC_COMP_ORDER_LAST)
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH v2 3/6 ASoC: core: Add helper for DAI widgets linking

In reply to Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

Add a helper for DAI widgets linking in preparation for DAI-multicodec support.

No functional change.

---
 sound/soc/soc-core.c | 64 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 24 deletions(-)
sound/soc/soc-core.c +40 -24
index 1bcc446..1debe3d 100644
@@ -1418,6 +1418,42 @@ static int soc_probe_codec_dai(struct snd_soc_card *card,
 	return 0;
 }
 
+static int soc_link_dai_widgets(struct snd_soc_card *card,
+				struct snd_soc_dai_link *dai_link,
+				struct snd_soc_dai *cpu_dai,
+				struct snd_soc_dai *codec_dai)
+{
+	struct snd_soc_dapm_widget *play_w, *capture_w;
+	int ret;
+
+	/* link the DAI widgets */
+	play_w = codec_dai->playback_widget;
+	capture_w = cpu_dai->capture_widget;
+	if (play_w && capture_w) {
+		ret = snd_soc_dapm_new_pcm(card, dai_link->params,
+					   capture_w, play_w);
+		if (ret != 0) {
+			dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
+				play_w->name, capture_w->name, ret);
+			return ret;
+		}
+	}
+
+	play_w = cpu_dai->playback_widget;
+	capture_w = codec_dai->capture_widget;
+	if (play_w && capture_w) {
+		ret = snd_soc_dapm_new_pcm(card, dai_link->params,
+					   capture_w, play_w);
+		if (ret != 0) {
+			dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
+				play_w->name, capture_w->name, ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 {
 	struct snd_soc_dai_link *dai_link = &card->dai_link[num];
@@ -1426,7 +1462,6 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 	struct snd_soc_platform *platform = rtd->platform;
 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_dapm_widget *play_w, *capture_w;
 	int ret;
 
 	dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
@@ -1507,29 +1542,10 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 						codec2codec_close_delayed_work);
 
 			/* link the DAI widgets */
-			play_w = codec_dai->playback_widget;
-			capture_w = cpu_dai->capture_widget;
-			if (play_w && capture_w) {
-				ret = snd_soc_dapm_new_pcm(card, dai_link->params,
-						   capture_w, play_w);
-				if (ret != 0) {
-					dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
-						play_w->name, capture_w->name, ret);
-					return ret;
-				}
-			}
-
-			play_w = cpu_dai->playback_widget;
-			capture_w = codec_dai->capture_widget;
-			if (play_w && capture_w) {
-				ret = snd_soc_dapm_new_pcm(card, dai_link->params,
-						   capture_w, play_w);
-				if (ret != 0) {
-					dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
-						play_w->name, capture_w->name, ret);
-					return ret;
-				}
-			}
+			ret = soc_link_dai_widgets(card, dai_link,
+					cpu_dai, codec_dai);
+			if (ret)
+				return ret;
 		}
 	}
 
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH v2 4/6 ASoC: core: Add function for ac97 codec registration

In reply to Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

Add codec registration specific function in preparation for DAI-multicodec support.

No functional change.

---
 sound/soc/soc-core.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
sound/soc/soc-core.c +20 -9
index 1debe3d..76fdf43 100644
@@ -1557,14 +1557,15 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 }
 
 #ifdef CONFIG_SND_SOC_AC97_BUS
-static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
+static int soc_register_ac97_codec(struct snd_soc_codec *codec,
+				   struct snd_soc_dai *codec_dai)
 {
 	int ret;
 
 	/* Only instantiate AC97 if not already done by the adaptor
 	 * for the generic AC97 subsystem.
 	 */
-	if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
+	if (codec_dai->driver->ac97_control && !codec->ac97_registered) {
 		/*
 		 * It is possible that the AC97 device is already registered to
 		 * the device subsystem. This happens when the device is created
@@ -1573,28 +1574,38 @@ static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
 		 *
 		 * In those cases we don't try to register the device again.
 		 */
-		if (!rtd->codec->ac97_created)
+		if (!codec->ac97_created)
 			return 0;
 
-		ret = soc_ac97_dev_register(rtd->codec);
+		ret = soc_ac97_dev_register(codec);
 		if (ret < 0) {
-			dev_err(rtd->codec->dev,
+			dev_err(codec->dev,
 				"ASoC: AC97 device register failed: %d\n", ret);
 			return ret;
 		}
 
-		rtd->codec->ac97_registered = 1;
+		codec->ac97_registered = 1;
 	}
 	return 0;
 }
 
-static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
+static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
+{
+	return soc_register_ac97_codec(rtd->codec, rtd->codec_dai);
+}
+
+static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
 {
 	if (codec->ac97_registered) {
 		soc_ac97_dev_unregister(codec);
 		codec->ac97_registered = 0;
 	}
 }
+
+static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
+{
+	soc_unregister_ac97_codec(rtd->codec);
+}
 #endif
 
 static int soc_check_aux_dev(struct snd_soc_card *card, int num)
@@ -1894,7 +1905,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
 			dev_err(card->dev,
 				"ASoC: failed to register AC97: %d\n", ret);
 			while (--i >= 0)
-				soc_unregister_ac97_dai_link(card->rtd[i].codec);
+				soc_unregister_ac97_dai_link(&card->rtd[i]);
 			goto probe_aux_dev_err;
 		}
 	}
@@ -2330,7 +2341,7 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
 {
 	mutex_lock(&codec->mutex);
 #ifdef CONFIG_SND_SOC_AC97_BUS
-	soc_unregister_ac97_dai_link(codec);
+	soc_unregister_ac97_codec(codec);
 #endif
 	kfree(codec->ac97->bus);
 	kfree(codec->ac97);
Signature · 1 line
1.8.3.2
#5 lore raw

PATCH v2 5/6 ASoC: core: Add helpers for dai link and aux dev init

In reply to Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

Separate DAI link and aux dev initialization in preparation for DAI multicodec support.
Since aux dev will remain using single codecs but DAI links will be able to support multiple codecs.

No functional change.

---
 sound/soc/soc-core.c | 74 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 60 insertions(+), 14 deletions(-)
sound/soc/soc-core.c +60 -14
index 76fdf43..cfa481e 100644
@@ -1268,6 +1268,63 @@ static void rtd_release(struct device *dev)
 	kfree(dev);
 }
 
+static int soc_aux_dev_init(struct snd_soc_card *card,
+			    struct snd_soc_codec *codec,
+			    int num)
+{
+	struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
+	struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
+	const char *temp;
+	int ret;
+
+	rtd->card = card;
+
+	temp = codec->name_prefix;
+	codec->name_prefix = NULL;
+
+	/* do machine specific initialization */
+	if (aux_dev->init) {
+		ret = aux_dev->init(&codec->dapm);
+		if (ret < 0)
+			return ret;
+	}
+
+	codec->name_prefix = temp;
+
+	rtd->codec = codec;
+
+	return 0;
+}
+
+static int soc_dai_link_init(struct snd_soc_card *card,
+			     struct snd_soc_codec *codec,
+			     int num)
+{
+	struct snd_soc_dai_link *dai_link =  &card->dai_link[num];
+	struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
+	const char *temp;
+	int ret;
+
+	rtd->card = card;
+
+	/* machine controls, routes and widgets are not prefixed */
+	temp = codec->name_prefix;
+	codec->name_prefix = NULL;
+
+	/* do machine specific initialization */
+	if (dai_link->init) {
+		ret = dai_link->init(rtd);
+		if (ret < 0)
+			return ret;
+	}
+
+	codec->name_prefix = temp;
+
+	rtd->codec = codec;
+
+	return 0;
+}
+
 static int soc_post_component_init(struct snd_soc_card *card,
 				   struct snd_soc_codec *codec,
 				   int num, int dailess)
@@ -1275,38 +1332,27 @@ static int soc_post_component_init(struct snd_soc_card *card,
 	struct snd_soc_dai_link *dai_link = NULL;
 	struct snd_soc_aux_dev *aux_dev = NULL;
 	struct snd_soc_pcm_runtime *rtd;
-	const char *temp, *name;
+	const char *name;
 	int ret = 0;
 
 	if (!dailess) {
 		dai_link = &card->dai_link[num];
 		rtd = &card->rtd[num];
 		name = dai_link->name;
+		ret = soc_dai_link_init(card, codec, num);
 	} else {
 		aux_dev = &card->aux_dev[num];
 		rtd = &card->rtd_aux[num];
 		name = aux_dev->name;
+		ret = soc_aux_dev_init(card, codec, num);
 	}
-	rtd->card = card;
-
-	/* machine controls, routes and widgets are not prefixed */
-	temp = codec->name_prefix;
-	codec->name_prefix = NULL;
 
-	/* do machine specific initialization */
-	if (!dailess && dai_link->init)
-		ret = dai_link->init(rtd);
-	else if (dailess && aux_dev->init)
-		ret = aux_dev->init(&codec->dapm);
 	if (ret < 0) {
 		dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
 		return ret;
 	}
-	codec->name_prefix = temp;
 
 	/* register the rtd device */
-	rtd->codec = codec;
-
 	rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
 	if (!rtd->dev)
 		return -ENOMEM;
Signature · 1 line
1.8.3.2
maintainer
#6 lore raw

Re: [RFT v2 5/6] ASoC: core: Add helpers for dai link and aux dev init

Quoted 6 lines · Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

Separate DAI link and aux dev initialization in preparation for DAI multicodec support.
Since aux dev will remain using single codecs but DAI links will be able to support multiple codecs.

I applied everything up to here. This one didn't apply, probably due to context changes but I didn't make any real effort to understand the issue.

#7 lore raw

Re: [RFT v2 5/6] ASoC: core: Add helpers for dai link and aux dev init

Hi Mark,

Quoted 11 lines · Mark Brown
Quoted 6 lines · Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

Separate DAI link and aux dev initialization in preparation for DAI multicodec support.
Since aux dev will remain using single codecs but DAI links will be able to support multiple codecs.

I applied everything up to here. This one didn't apply, probably due to context changes but I didn't make any real effort to understand the issue.

Yep, I've just seen that. It is indeed a small move in the previous context code.

I'm still in the process of updating the series based on Lars comments, but was somehow too busy the last 2 weeks to complete the changes. I should be able to post the update this week.

Sorry for the delay.

Thanks,
Benoit

Signature · 4 lines
Benoît Cousson
BayLibre
Embedded Linux Technology Lab
www.baylibre.com
#8 lore raw

PATCH v2 6/6 ASoC: core: Add support for DAI multicodec

In reply to Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.

Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new 'snd_soc_dai_link_codec' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node or codec_name).

CPU DAI in a multicodec DAI link can have more channels than what each CODEC has. The number of channels each CODEC is responsible for is machine specific, hence it's fixed up in machine drivers in a similar way to what DPCM does.

Fix a trailing space in the header as well.

[[email protected]: Change tdm mask fixup, add missing iteration over codecs array]

---
 include/sound/soc-dai.h |   5 +
 include/sound/soc.h     |  16 ++
 sound/soc/soc-core.c    | 356 ++++++++++++++++++++++++++-------------
 sound/soc/soc-dapm.c    |  39 +++--
 sound/soc/soc-pcm.c     | 438 +++++++++++++++++++++++++++++++++---------------
 5 files changed, 596 insertions(+), 258 deletions(-)
include/sound/soc-dai.h +5 -0
index 2f66d5e..5391e70 100644
@@ -274,6 +274,11 @@ struct snd_soc_dai {
 	struct snd_soc_codec *codec;
 	struct snd_soc_component *component;
 
+	/* CODEC TDM slot masks and params (for fixup) */
+	unsigned int tx_mask;
+	unsigned int rx_mask;
+	struct snd_pcm_hw_params params[2];
+
 	struct snd_soc_card *card;
 
 	struct list_head list;
include/sound/soc.h +16 -0
index 0b83168..fd14ec6 100644
@@ -830,6 +830,15 @@ struct snd_soc_platform_driver {
 	int (*bespoke_trigger)(struct snd_pcm_substream *, int);
 };
 
+struct snd_soc_dai_link_codec {
+	const char *codec_name;
+	const struct device_node *codec_of_node;
+	const char *codec_dai_name;
+
+	struct snd_soc_codec *codec;
+	struct snd_soc_dai *codec_dai;
+};
+
 struct snd_soc_platform {
 	const char *name;
 	int id;
@@ -878,6 +887,10 @@ struct snd_soc_dai_link {
 	const struct device_node *codec_of_node;
 	/* You MUST specify the DAI name within the codec */
 	const char *codec_dai_name;
+
+	struct snd_soc_dai_link_codec *codecs;
+	int num_codecs;
+
 	/*
 	 * You MAY specify the link's platform/PCM/DMA driver, either by
 	 * device name, or by DT/OF node, but not both. Some forms of link
@@ -1067,6 +1080,9 @@ struct snd_soc_pcm_runtime {
 	struct snd_soc_dai *codec_dai;
 	struct snd_soc_dai *cpu_dai;
 
+	struct snd_soc_dai_link_codec *codecs;
+	int num_codecs;
+
 	struct delayed_work delayed_work;
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs_dpcm_root;
sound/soc/soc-core.c +243 -113

641 lines not on this page · raw message

sound/soc/soc-dapm.c +28 -11
index c8a780d..6c6b7bea 100644
@@ -2143,12 +2143,8 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm,
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
 
-/* show dapm widget status in sys fs */
-static ssize_t dapm_widget_show(struct device *dev,
-	struct device_attribute *attr, char *buf)
+static ssize_t dapm_widget_show_codec(struct snd_soc_codec *codec, char *buf)
 {
-	struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
-	struct snd_soc_codec *codec =rtd->codec;
 	struct snd_soc_dapm_widget *w;
 	int count = 0;
 	char *state = "not set";
@@ -2201,6 +2197,22 @@ static ssize_t dapm_widget_show(struct device *dev,
 	return count;
 }
 
+/* show dapm widget status in sys fs */
+static ssize_t dapm_widget_show(struct device *dev,
+	struct device_attribute *attr, char *buf)
+{
+	struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
+	struct snd_soc_codec *codec;
+	int i, count = 0;
+
+	for (i = 0; i < rtd->num_codecs; i++) {
+		codec = rtd->codecs[i].codec;
+		count += dapm_widget_show_codec(codec, buf + count);
+	}
+
+	return count;
+}
+
 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
 
 int snd_soc_dapm_sys_add(struct device *dev)
@@ -3510,13 +3522,12 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card)
 	}
 }
 
-static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
-	int event)
+static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
+				  struct snd_soc_dai *cpu_dai,
+				  struct snd_soc_dai *codec_dai,
+				  int stream, int event)
 {
-
 	struct snd_soc_dapm_widget *w_cpu, *w_codec;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_dai *codec_dai = rtd->codec_dai;
 
 	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		w_cpu = cpu_dai->playback_widget;
@@ -3582,9 +3593,15 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
 			      int event)
 {
 	struct snd_soc_card *card = rtd->card;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *codec_dai;
+	int i;
 
 	mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
-	soc_dapm_stream_event(rtd, stream, event);
+	for (i = 0; i < rtd->num_codecs; i++) {
+		codec_dai = rtd->codecs[i].codec_dai;
+		soc_dapm_stream_event(rtd, cpu_dai, codec_dai, stream, event);
+	}
 	mutex_unlock(&card->dapm_mutex);
 }
 
sound/soc/soc-pcm.c +304 -134

735 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#9 lore raw
Quoted 14 lines · Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.

Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new 'snd_soc_dai_link_codec' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node or codec_name).

Quoted 6 lines

CPU DAI in a multicodec DAI link can have more channels than what each CODEC has. The number of channels each CODEC is responsible for is machine specific, hence it's fixed up in machine drivers in a similar way to what DPCM does.

Fix a trailing space in the header as well.

This has been a feature that has been missing for quite a while, thanks for taking care of this. There are a few things that need to be fixed, but nothing that's not fixable.

I'd expect that after this patch has been applied there are no more usages of rtd->codec_dai. There are some though.

soc_pcm_params_symmetry() and soc_pcm_has_symmetry(), this should be trivial just loop over all the codecs.

rtd_get_codec_widget() this should be slightly restructured and merged with rtd_get_cpu_widget() to have a single function that takes a DAI and returns the widget. And then in dpcm_prune_paths() loop over all the codecs and only prune if neither of them are in the list.

dpcm_get_be() loop over all the codecs if you find one where the widget matches return the be.

soc_dpcm_be_digital_mute() mute all codecs.

snd_soc_dapm_connect_dai_link_widgets() needs to add a route for each codec DAI to the CPU DAI

A few places in soc-compress.c, but which should all be very similar to soc-pcm.c

I haven't fully understood how exactly the channel fixup works, so I didn't comment on it yet.

Quoted 36 lines

[[email protected]: Change tdm mask fixup, add missing iteration over codecs array]

---
  include/sound/soc-dai.h |   5 +
  include/sound/soc.h     |  16 ++
  sound/soc/soc-core.c    | 356 ++++++++++++++++++++++++++-------------
  sound/soc/soc-dapm.c    |  39 +++--
  sound/soc/soc-pcm.c     | 438 +++++++++++++++++++++++++++++++++---------------
  5 files changed, 596 insertions(+), 258 deletions(-)
include/sound/soc-dai.h +5 -0
index 2f66d5e..5391e70 100644
@@ -274,6 +274,11 @@ struct snd_soc_dai {
  	struct snd_soc_codec *codec;
  	struct snd_soc_component *component;
 
+	/* CODEC TDM slot masks and params (for fixup) */
+	unsigned int tx_mask;
+	unsigned int rx_mask;
+	struct snd_pcm_hw_params params[2];
+
  	struct snd_soc_card *card;
 
  	struct list_head list;
include/sound/soc.h +0 -0
index 0b83168..fd14ec6 100644

include/sound/soc.h struct snd_soc_platform_driver { · line 833

Quoted 4 lines
include/sound/soc.h +1 -0
@@ -830,6 +830,15 @@ struct snd_soc_platform_driver {
  	int (*bespoke_trigger)(struct snd_pcm_substream *, int);
  };
 
+struct snd_soc_dai_link_codec {

For the sake of symmetry maybe name this snd_soc_dai_link_component and drop the 'codec_' prefix in front of the struct fields. There is no reason why this couldn't be used for CPU dais as well at some point.

include/sound/soc.h struct snd_soc_platform_driver { · line 836

Quoted 3 lines
include/sound/soc.h +3 -0
+	const char *codec_name;
+	const struct device_node *codec_of_node;
+	const char *codec_dai_name;

I'd like to see this split up into the descriptive part that holds the name, of_node etc, and the runtime data that holds the pointer to the DAIs. The descriptive part goes in the dai_link struct the. The pointers to the DAIs go into the snd_soc_pcm_runtime struct. This is how it is used the only place where you need both is in soc_bind_dai_link.

include/sound/soc.h struct snd_soc_platform_driver { · line 838

Quoted 2 lines
include/sound/soc.h +2 -0
+
+	struct snd_soc_codec *codec;

We are trying to remove the asymmetry between the CPU side DAI and the CODEC side DAI of the DAI link. E.g. the cpu_dai can also be a CODEC. The only reason why there still is a codec pointer in the snd_soc_pcm_runtime struct is because there are still a few places where it is used (and for auxdevs). But we shouldn't mimic this for new code. Just use codec_dai->codec instead when you actually need a pointer to the codec.

include/sound/soc.h struct snd_soc_dai_link { · line 892

Quoted 13 lines
include/sound/soc.h +6 -0
+	struct snd_soc_dai *codec_dai;
+};
+
  struct snd_soc_platform {
  	const char *name;
  	int id;
@@ -878,6 +887,10 @@ struct snd_soc_dai_link {
  	const struct device_node *codec_of_node;
  	/* You MUST specify the DAI name within the codec */
  	const char *codec_dai_name;
+
+	struct snd_soc_dai_link_codec *codecs;
+	int num_codecs;

unsigned int

include/sound/soc.h struct snd_soc_pcm_runtime { · line 1083

Quoted 9 lines
include/sound/soc.h +2 -0
+
  	/*
  	 * You MAY specify the link's platform/PCM/DMA driver, either by
  	 * device name, or by DT/OF node, but not both. Some forms of link
@@ -1067,6 +1080,9 @@ struct snd_soc_pcm_runtime {
  	struct snd_soc_dai *codec_dai;
  	struct snd_soc_dai *cpu_dai;
 
+	struct snd_soc_dai_link_codec *codecs;

With the changes suggested above this simply becomes:

	struct snd_soc_dai **codec_dais;

Which should also make the code shorter at places since

include/sound/soc.h struct snd_soc_pcm_runtime { · line 1084

Quoted 1 line
include/sound/soc.h +1 -0
+	int num_codecs;

unsigned int

Quoted 8 lines
include/sound/soc.h +1 -0
+
  	struct delayed_work delayed_work;
  #ifdef CONFIG_DEBUG_FS
  	struct dentry *debugfs_dpcm_root;
sound/soc/soc-core.c +0 -0
index cfa481e..6b6fc39 100644

[...]

Quoted 18 lines
sound/soc/soc-core.c +9 -7
+	/* Find CODEC from registered CODECs */
+	for (i = 0; i < rtd->num_codecs; i++) {
+		codecs[i].codec = soc_find_codec(codecs[i].codec_of_node,
+						 codecs[i].codec_name);
+		if (!codecs[i].codec) {
+			dev_err(card->dev, "ASoC: CODEC %s not registered\n",
+				codecs[i].codec_name);
+			return -EPROBE_DEFER;
+		}
  	}
 
-	/* Find CODEC DAI from registered list */
-	rtd->codec_dai = soc_find_codec_dai(rtd->codec,
-					    dai_link->codec_dai_name);
-	if (!rtd->codec_dai) {
-		dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
-			dai_link->codec_dai_name);
-		return -EPROBE_DEFER;

sound/soc/soc-core.c static int soc_bind_dai_link(struct snd_soc_card *card, int num) · line 970

Quoted 10 lines
sound/soc/soc-core.c +9 -0
+	for (i = 0; i < rtd->num_codecs; i++) {
+		codecs[i].codec_dai = soc_find_codec_dai(
+						codecs[i].codec,
+						codecs[i].codec_dai_name);
+		if (!codecs[i].codec_dai) {
+			dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+				codecs[i].codec_dai_name);
+			return -EPROBE_DEFER;
+		}
  	}

I suggest to restructure this to:

	for (i = 0; i < rtd->num_codecs; i++) {
		rtd->codec_dais[i] = soc_find_codec_dai(codecs[i]);
		if (!rtd->codecs_dais[i])
			...
	}

And in soc_find_codec_dai lookup both the CODEC and the DAI

[...]

Quoted 7 lines
sound/soc/soc-core.c +2 -2
+static int soc_dai_link_init(struct snd_soc_card *card, int num)
  {
  	struct snd_soc_dai_link *dai_link =  &card->dai_link[num];
  	struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
-	const char *temp;
-	int ret;
+	struct snd_soc_dai_link_codec *codecs = rtd->codecs;

sound/soc/soc-core.c static int soc_aux_dev_init(struct snd_soc_card *card, · line 1347

Quoted 10 lines
sound/soc/soc-core.c +4 -3
+	const char **temp;
+	int i, ret;
 
  	rtd->card = card;
 
-	/* machine controls, routes and widgets are not prefixed */
-	temp = codec->name_prefix;
-	codec->name_prefix = NULL;
+	temp = devm_kzalloc(card->dev, rtd->num_codecs * sizeof(char *),
+			    GFP_KERNEL);

There is a patch http://permalink.gmane.org/gmane.linux.alsa.devel/120606 which removes the temporary name_prefix = NULL. Having that patch applied first should make this a lot simpler. I don't think you'd even need patch 5 then since this doesn't need to actually loop over all the CODECs anymore.

sound/soc/soc-core.c static int soc_aux_dev_init(struct snd_soc_card *card, · line 1353

Quoted 6 lines
sound/soc/soc-core.c +6 -0
+	if (!temp)
+		return -ENOMEM;
+
+	for (i = 0; i < rtd->num_codecs; i++) {
+		/* Make sure all DAPM widgets are instantiated */
+		snd_soc_dapm_new_widgets(codecs[i].codec->dapm.card);

We remove this per component snd_soc_dapm_new_widgets() calls a while ago, there is now only one call to snd_soc_dapm_new_widgets() once all components have been initialized.

Quoted 22 lines
sound/soc/soc-core.c +8 -2
+
+		/* machine controls, routes and widgets are not prefixed */
+		temp[i] = codecs[i].codec->name_prefix;
+		codecs[i].codec->name_prefix = NULL;
+	}
 
  	/* do machine specific initialization */
  	if (dai_link->init) {
@@ -1318,15 +1364,15 @@ static int soc_dai_link_init(struct snd_soc_card *card,
  			return ret;
  	}
 
-	codec->name_prefix = temp;
+	for (i = 0; i < rtd->num_codecs; i++)
+		codecs[i].codec->name_prefix = temp[i];
 
-	rtd->codec = codec;
+	devm_kfree(card->dev, temp);
 
  	return 0;
  }
 

[...]

Quoted 4 lines
sound/soc/soc-dapm.c +0 -0
index c8a780d..6c6b7bea 100644

[...]

Quoted 17 lines
sound/soc/soc-dapm.c +4 -5
-static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
-	int event)
+static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
+				  struct snd_soc_dai *cpu_dai,
+				  struct snd_soc_dai *codec_dai,
+				  int stream, int event)
  {
-
  	struct snd_soc_dapm_widget *w_cpu, *w_codec;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_dai *codec_dai = rtd->codec_dai;
 
  	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  		w_cpu = cpu_dai->playback_widget;
@@ -3582,9 +3593,15 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
  			      int event)
  {

sound/soc/soc-dapm.c void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, · line 3603

Quoted 10 lines
sound/soc/soc-dapm.c +6 -1
  	struct snd_soc_card *card = rtd->card;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *codec_dai;
+	int i;
 
  	mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
-	soc_dapm_stream_event(rtd, stream, event);
+	for (i = 0; i < rtd->num_codecs; i++) {
+		codec_dai = rtd->codecs[i].codec_dai;
+		soc_dapm_stream_event(rtd, cpu_dai, codec_dai, stream, event);

This needs some refactoring. The looping over all the CODEC should be moved into soc_dapm_stream_event(). We don't want to call seperatly for each CODEC dapm_power_widgets().

Quoted 8 lines
sound/soc/soc-dapm.c +1 -0
+	}
  	mutex_unlock(&card->dapm_mutex);
  }
 
sound/soc/soc-pcm.c +0 -0
index 330eaf0..01d6dd0 100644

[...]

Quoted 3 lines
sound/soc/soc-pcm.c +0 -0
@@ -78,24 +83,30 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream)
  void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
  {

[...]

Quoted 3 lines
  }

+

Extra newline

Quoted 7 lines

/**
* snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay
* @rtd: The ASoC PCM runtime that should be checked.

sound/soc/soc-pcm.c +0 -0
@@ -107,11 +118,16 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
   */
  bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
  {

sound/soc/soc-pcm.c void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) · line 128

Quoted 10 lines
sound/soc/soc-pcm.c +5 -2
+	struct snd_soc_dai_link_codec *codecs = rtd->codecs;
+	int i, ignore = 0;
+
  	if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
  		return true;
 
-	return rtd->cpu_dai->component->ignore_pmdown_time &&
-			rtd->codec_dai->component->ignore_pmdown_time;
+	for (i = 0; (i < rtd->num_codecs) && !ignore; i++)
+		ignore |= codecs[i].codec_dai->component->ignore_pmdown_time;

This should be "ignore = 1" and then ignore &= ... for each CODEC. We only want to ignore the power down delay if all components agree that they do not need it.

Quoted 8 lines
sound/soc/soc-pcm.c +2 -0
+
+	return rtd->cpu_dai->component->ignore_pmdown_time && ignore;
  }
 
  /**
@@ -310,32 +326,66 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
  	}
  }

[...]

sound/soc/soc-pcm.c static int soc_pcm_open(struct snd_pcm_substream *substream) · line 495

Quoted 2 lines
sound/soc/soc-pcm.c +1 -1
-	soc_pcm_apply_msb(substream, codec_dai);
+	soc_pcm_apply_msb(substream, codecs[0].codec_dai);

I think how this should work is that there should only be a msb constraint if all the CODEC DAIs have a msb contraint and then it should be the maximum over all the contraints.

Quoted 2 lines
  	soc_pcm_apply_msb(substream, cpu_dai);

[...]

Quoted 48 lines

/*
* Called by ALSA when the hardware params are set by application. This
* function can also be called multiple times and can allocate buffers

sound/soc/soc-pcm.c +25 -8
@@ -667,9 +766,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
  {
  	struct snd_soc_pcm_runtime *rtd = substream->private_data;
  	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_dai_link_codec *codecs = rtd->codecs;
  	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_dai *codec_dai = rtd->codec_dai;
-	int ret = 0;
+	int i, ret = 0;
 
  	mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
 
@@ -686,13 +785,39 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
  		}
  	}
 
-	if (codec_dai->driver->ops && codec_dai->driver->ops->hw_params) {
-		ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai);
-		if (ret < 0) {
-			dev_err(codec_dai->dev, "ASoC: can't set %s hw params:"
-				" %d\n", codec_dai->name, ret);
-			goto codec_err;
+	for (i = 0; i < rtd->num_codecs; i++) {
+		struct snd_soc_dai *codec_dai = codecs[i].codec_dai;
+		struct snd_pcm_hw_params *codec_params;
+
+		codec_params = &codec_dai->params[substream->stream];
+
+		/* copy params for each codec */
+		memcpy(codec_params, params, sizeof(struct snd_pcm_hw_params));
+
+		/* fixup params based on TDM slot masks */
+		if (codec_dai->tx_mask)
+			soc_pcm_codec_params_fixup(codec_params,
+						   codec_dai->tx_mask);
+		if (codec_dai->rx_mask)
+			soc_pcm_codec_params_fixup(codec_params,
+						   codec_dai->rx_mask);
+
+		if (codec_dai->driver->ops &&
+		    codec_dai->driver->ops->hw_params) {
+			ret = codec_dai->driver->ops->hw_params(substream,
+						codec_params, codec_dai);
+			if (ret < 0) {
+				dev_err(codec_dai->dev,

sound/soc/soc-pcm.c static int soc_pcm_hw_params(struct snd_pcm_substream *substream, · line 820

Quoted 10 lines
sound/soc/soc-pcm.c +9 -0
+					"ASoC: can't set %s hw params: %d\n",
+					codec_dai->name, ret);
+				goto codec_err;
+			}
  		}
+
+		codec_dai->rate = params_rate(codec_params);
+		codec_dai->channels = params_channels(codec_params);
+		codec_dai->sample_bits = snd_pcm_format_physical_width(
+						params_format(codec_params));

Those should only be set if all of the hw_params calls succeeded.

Quoted 3 lines
sound/soc/soc-pcm.c +0 -0
  	}
 
  	if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) {

[...]

sound/soc/soc-pcm.c static int soc_pcm_hw_free(struct snd_pcm_substream *substream) · line 897

Quoted 11 lines
sound/soc/soc-pcm.c +3 -4
@@ -764,16 +892,21 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
  		cpu_dai->sample_bits = 0;
  	}
 
-	if (codec_dai->active == 1) {
-		codec_dai->rate = 0;
-		codec_dai->channels = 0;
-		codec_dai->sample_bits = 0;
+	for (i = 0; i < rtd->num_codecs; i++) {
+		codec_dai = codecs[i].codec_dai;
+		if (codec_dai->active == 1)

Missing brackets

Quoted 5 lines
sound/soc/soc-pcm.c +3 -0
+			codec_dai->rate = 0;
+			codec_dai->channels = 0;
+			codec_dai->sample_bits = 0;
  	}
 

[...]

Quoted 24 lines
sound/soc/soc-pcm.c +4 -7
@@ -2193,22 +2353,29 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
  int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
  {
  	struct snd_soc_platform *platform = rtd->platform;
-	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	struct snd_soc_dai_link_codec *codecs = rtd->codecs;
+	struct snd_soc_dai *codec_dai;
  	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  	struct snd_pcm *pcm;
  	char new_name[64];
  	int ret = 0, playback = 0, capture = 0;
+	int i;
 
  	if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
  		playback = rtd->dai_link->dpcm_playback;
  		capture = rtd->dai_link->dpcm_capture;
  	} else {
-		if (codec_dai->driver->playback.channels_min &&
-		    cpu_dai->driver->playback.channels_min)
-			playback = 1;
-		if (codec_dai->driver->capture.channels_min &&
-		    cpu_dai->driver->capture.channels_min)
-			capture = 1;
+		for (i = 0; i < rtd->num_codecs; i++) {

sound/soc/soc-pcm.c static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream) · line 2378

Quoted 10 lines
sound/soc/soc-pcm.c +10 -0
+			codec_dai = codecs[i].codec_dai;
+			if (codec_dai->driver->playback.channels_min &&
+			    cpu_dai->driver->playback.channels_min)
+				playback++;
+			if (codec_dai->driver->capture.channels_min &&
+			    cpu_dai->driver->capture.channels_min)
+				capture++;
+		}
+		capture = (rtd->num_codecs == capture);
+		playback = (rtd->num_codecs == playback);

Hm... I'd say the runtime should support playback or capture if at least one of the codecs support playback or capture. Not only if all of them support it.

Quoted 3 lines
sound/soc/soc-pcm.c +0 -0
  	}
 
  	if (rtd->dai_link->playback_only) {

[...]

#10 lore raw

Hi Lars,

Quoted 20 lines · Lars-Peter Clausen
Quoted 19 lines · Benoit Cousson

From: Misael Lopez Cruz <[email protected]>

DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.

Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new 'snd_soc_dai_link_codec' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node or codec_name).

CPU DAI in a multicodec DAI link can have more channels than what each CODEC has. The number of channels each CODEC is responsible for is machine specific, hence it's fixed up in machine drivers in a similar way to what DPCM does.

Quoted 5 lines
Quoted 1 line

Fix a trailing space in the header as well.

This has been a feature that has been missing for quite a while, thanks for taking care of this. There are a few things that need to be fixed, but nothing that's not fixable.

Cool, great :-)

Quoted 3 lines

I'd expect that after this patch has been applied there are no more usages of rtd->codec_dai. There are some though.

Oops, Misa already pointed me to few more that were missing in the v1, but it looks like I missed some more.

Quoted 11 lines

soc_pcm_params_symmetry() and soc_pcm_has_symmetry(), this should be trivial just loop over all the codecs.

rtd_get_codec_widget() this should be slightly restructured and merged with rtd_get_cpu_widget() to have a single function that takes a DAI and returns the widget. And then in dpcm_prune_paths() loop over all the codecs and only prune if neither of them are in the list.

dpcm_get_be() loop over all the codecs if you find one where the widget matches return the be.

Quoted 7 lines

soc_dpcm_be_digital_mute() mute all codecs.

snd_soc_dapm_connect_dai_link_widgets() needs to add a route for each codec DAI to the CPU DAI

A few places in soc-compress.c, but which should all be very similar to soc-pcm.c

I'll go through all these parts and fix them all.

Quoted 43 lines

I haven't fully understood how exactly the channel fixup works, so I didn't comment on it yet.

Quoted 40 lines

[[email protected]: Change tdm mask fixup, add missing iteration over codecs array]

---
  include/sound/soc-dai.h |   5 +
  include/sound/soc.h     |  16 ++
  sound/soc/soc-core.c    | 356 ++++++++++++++++++++++++++-------------
  sound/soc/soc-dapm.c    |  39 +++--
  sound/soc/soc-pcm.c     | 438
+++++++++++++++++++++++++++++++++---------------
  5 files changed, 596 insertions(+), 258 deletions(-)
include/sound/soc-dai.h +5 -0
index 2f66d5e..5391e70 100644
@@ -274,6 +274,11 @@ struct snd_soc_dai {
      struct snd_soc_codec *codec;
      struct snd_soc_component *component;
 
+    /* CODEC TDM slot masks and params (for fixup) */
+    unsigned int tx_mask;
+    unsigned int rx_mask;
+    struct snd_pcm_hw_params params[2];
+
      struct snd_soc_card *card;
 
      struct list_head list;
include/sound/soc.h +0 -0
index 0b83168..fd14ec6 100644
@@ -830,6 +830,15 @@ struct snd_soc_platform_driver {
      int (*bespoke_trigger)(struct snd_pcm_substream *, int);
  };
 
Quoted 5 lines

include/sound/soc.h struct snd_soc_platform_driver { · line 833

Quoted 1 line
include/sound/soc.h +1 -0
+struct snd_soc_dai_link_codec {

For the sake of symmetry maybe name this snd_soc_dai_link_component and drop the 'codec_' prefix in front of the struct fields. There is no reason why this couldn't be used for CPU dais as well at some point.

OK, good point.

Quoted 9 lines

include/sound/soc.h struct snd_soc_platform_driver { · line 836

Quoted 3 lines
include/sound/soc.h +3 -0
+    const char *codec_name;
+    const struct device_node *codec_of_node;
+    const char *codec_dai_name;

I'd like to see this split up into the descriptive part that holds the name, of_node etc, and the runtime data that holds the pointer to the DAIs. The descriptive part goes in the dai_link struct the. The pointers to the DAIs go into the snd_soc_pcm_runtime struct. This is how it is used the only place where you need both is in soc_bind_dai_link.

OK, let me try to clarify that. You suggest to create that struct:

+struct snd_soc_dai_link_component {

+    const char *name;
+    const struct device_node *of_node;
+    const char *dai_name;

+}

to be inside the snd_soc_dai_link.

And inside the snd_soc_pcm_runtime, to replace these ones
+ struct snd_soc_dai_link_codec *codecs;
+ int num_codecs;

with a direct pointers to codecs dais?

+ struct snd_soc_dai **codecs_dai;
+ int num_codecs;

Is that correct ?

Quoted 10 lines

include/sound/soc.h struct snd_soc_platform_driver { · line 838

Quoted 2 lines
include/sound/soc.h +2 -0
+
+    struct snd_soc_codec *codec;

We are trying to remove the asymmetry between the CPU side DAI and the CODEC side DAI of the DAI link. E.g. the cpu_dai can also be a CODEC. The only reason why there still is a codec pointer in the snd_soc_pcm_runtime struct is because there are still a few places where it is used (and for auxdevs). But we shouldn't mimic this for new code. Just use codec_dai->codec instead when you actually need a pointer to the codec.

OK, good to know.

Quoted 16 lines
Quoted 8 lines
include/sound/soc.h +3 -0
+    struct snd_soc_dai *codec_dai;
+};
+
  struct snd_soc_platform {
      const char *name;
      int id;

include/sound/soc.h struct snd_soc_dai_link { · line 892

Quoted 6 lines
include/sound/soc.h +3 -0
@@ -878,6 +887,10 @@ struct snd_soc_dai_link {
      const struct device_node *codec_of_node;
      /* You MUST specify the DAI name within the codec */
      const char *codec_dai_name;
+
+    struct snd_soc_dai_link_codec *codecs;
+    int num_codecs;

unsigned int

OK

Quoted 13 lines

include/sound/soc.h struct snd_soc_pcm_runtime { · line 1083

Quoted 10 lines
include/sound/soc.h +2 -0
+
      /*
       * You MAY specify the link's platform/PCM/DMA driver, either by
       * device name, or by DT/OF node, but not both. Some forms of link
@@ -1067,6 +1080,9 @@ struct snd_soc_pcm_runtime {
      struct snd_soc_dai *codec_dai;
      struct snd_soc_dai *cpu_dai;
 
+    struct snd_soc_dai_link_codec *codecs;

With the changes suggested above this simply becomes:

Quoted 7 lines
     struct snd_soc_dai **codec_dais;

Which should also make the code shorter at places since

include/sound/soc.h struct snd_soc_pcm_runtime { · line 1084

Quoted 1 line
include/sound/soc.h +1 -0
+    int num_codecs;

unsigned int

OK

Quoted 82 lines
Quoted 9 lines
include/sound/soc.h +1 -0
+
      struct delayed_work delayed_work;
  #ifdef CONFIG_DEBUG_FS
      struct dentry *debugfs_dpcm_root;
sound/soc/soc-core.c +0 -0
index cfa481e..6b6fc39 100644

[...]

Quoted 18 lines
sound/soc/soc-core.c +9 -7
+    /* Find CODEC from registered CODECs */
+    for (i = 0; i < rtd->num_codecs; i++) {
+        codecs[i].codec = soc_find_codec(codecs[i].codec_of_node,
+                         codecs[i].codec_name);
+        if (!codecs[i].codec) {
+            dev_err(card->dev, "ASoC: CODEC %s not registered\n",
+                codecs[i].codec_name);
+            return -EPROBE_DEFER;
+        }
      }
 
-    /* Find CODEC DAI from registered list */
-    rtd->codec_dai = soc_find_codec_dai(rtd->codec,
-                        dai_link->codec_dai_name);
-    if (!rtd->codec_dai) {
-        dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
-            dai_link->codec_dai_name);
-        return -EPROBE_DEFER;

sound/soc/soc-core.c static int soc_bind_dai_link(struct snd_soc_card *card, int num) · line 970

Quoted 10 lines
sound/soc/soc-core.c +9 -0
+    for (i = 0; i < rtd->num_codecs; i++) {
+        codecs[i].codec_dai = soc_find_codec_dai(
+                        codecs[i].codec,
+                        codecs[i].codec_dai_name);
+        if (!codecs[i].codec_dai) {
+            dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+                codecs[i].codec_dai_name);
+            return -EPROBE_DEFER;
+        }
      }

I suggest to restructure this to:

     for (i = 0; i < rtd->num_codecs; i++) {
         rtd->codec_dais[i] = soc_find_codec_dai(codecs[i]);
         if (!rtd->codecs_dais[i])
             ...
     }

And in soc_find_codec_dai lookup both the CODEC and the DAI

[...]

Quoted 7 lines
sound/soc/soc-core.c +2 -2
+static int soc_dai_link_init(struct snd_soc_card *card, int num)
  {
      struct snd_soc_dai_link *dai_link =  &card->dai_link[num];
      struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
-    const char *temp;
-    int ret;
+    struct snd_soc_dai_link_codec *codecs = rtd->codecs;

sound/soc/soc-core.c static int soc_aux_dev_init(struct snd_soc_card *card, · line 1347

Quoted 10 lines
sound/soc/soc-core.c +4 -3
+    const char **temp;
+    int i, ret;
 
      rtd->card = card;
 
-    /* machine controls, routes and widgets are not prefixed */
-    temp = codec->name_prefix;
-    codec->name_prefix = NULL;
+    temp = devm_kzalloc(card->dev, rtd->num_codecs * sizeof(char *),
+                GFP_KERNEL);

There is a patch
http://permalink.gmane.org/gmane.linux.alsa.devel/120606 which removes the temporary name_prefix = NULL. Having that patch applied first should make this a lot simpler. I don't think you'd even need patch 5 then since this doesn't need to actually loop over all the CODECs anymore.

sound/soc/soc-core.c static int soc_aux_dev_init(struct snd_soc_card *card, · line 1353

Quoted 6 lines
sound/soc/soc-core.c +6 -0
+    if (!temp)
+        return -ENOMEM;
+
+    for (i = 0; i < rtd->num_codecs; i++) {
+        /* Make sure all DAPM widgets are instantiated */
+        snd_soc_dapm_new_widgets(codecs[i].codec->dapm.card);
Quoted 3 lines

We remove this per component snd_soc_dapm_new_widgets() calls a while ago, there is now only one call to snd_soc_dapm_new_widgets() once all components have been initialized.

This is probably a leftover from the original 3.8 series. Sorry about that.

Quoted 54 lines
Quoted 24 lines
sound/soc/soc-core.c +8 -2
+
+        /* machine controls, routes and widgets are not prefixed */
+        temp[i] = codecs[i].codec->name_prefix;
+        codecs[i].codec->name_prefix = NULL;
+    }
 
      /* do machine specific initialization */
      if (dai_link->init) {
@@ -1318,15 +1364,15 @@ static int soc_dai_link_init(struct
 snd_soc_card *card,
              return ret;
      }
 
-    codec->name_prefix = temp;
+    for (i = 0; i < rtd->num_codecs; i++)
+        codecs[i].codec->name_prefix = temp[i];
 
-    rtd->codec = codec;
+    devm_kfree(card->dev, temp);
 
      return 0;
  }
 

[...]

Quoted 4 lines
sound/soc/soc-dapm.c +0 -0
index c8a780d..6c6b7bea 100644

[...]

Quoted 24 lines

-static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,

sound/soc/soc-dapm.c +7 -4
-    int event)
+static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
+                  struct snd_soc_dai *cpu_dai,
+                  struct snd_soc_dai *codec_dai,
+                  int stream, int event)
  {
-
      struct snd_soc_dapm_widget *w_cpu, *w_codec;
-    struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-    struct snd_soc_dai *codec_dai = rtd->codec_dai;
 
      if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
          w_cpu = cpu_dai->playback_widget;
@@ -3582,9 +3593,15 @@ void snd_soc_dapm_stream_event(struct
 snd_soc_pcm_runtime *rtd, int stream,
                    int event)
  {
      struct snd_soc_card *card = rtd->card;
+    struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+    struct snd_soc_dai *codec_dai;
+    int i;
 
Quoted 9 lines

sound/soc/soc-dapm.c void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, · line 3603

Quoted 5 lines
sound/soc/soc-dapm.c +3 -1
      mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
-    soc_dapm_stream_event(rtd, stream, event);
+    for (i = 0; i < rtd->num_codecs; i++) {
+        codec_dai = rtd->codecs[i].codec_dai;
+        soc_dapm_stream_event(rtd, cpu_dai, codec_dai, stream, event);

This needs some refactoring. The looping over all the CODEC should be moved into soc_dapm_stream_event(). We don't want to call seperatly for each CODEC dapm_power_widgets().

OK.

Quoted 38 lines
Quoted 9 lines
sound/soc/soc-dapm.c +1 -0
+    }
      mutex_unlock(&card->dapm_mutex);
  }
sound/soc/soc-pcm.c +0 -0
index 330eaf0..01d6dd0 100644

[...]

Quoted 5 lines
sound/soc/soc-pcm.c +0 -0
@@ -78,24 +83,30 @@ void snd_soc_runtime_activate(struct
 snd_soc_pcm_runtime *rtd, int stream)
  void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int
 stream)
  {

[...]

Quoted 3 lines
  }

+

Extra newline

Quoted 16 lines

/**
* snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore
the power down delay
* @rtd: The ASoC PCM runtime that should be checked.

sound/soc/soc-pcm.c +3 -0
@@ -107,11 +118,16 @@ void snd_soc_runtime_deactivate(struct
 snd_soc_pcm_runtime *rtd, int stream)
   */
  bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime
 *rtd)
  {
+    struct snd_soc_dai_link_codec *codecs = rtd->codecs;
+    int i, ignore = 0;
+
      if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
          return true;
 
Quoted 8 lines

sound/soc/soc-pcm.c void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) · line 128

Quoted 4 lines
sound/soc/soc-pcm.c +2 -2
-    return rtd->cpu_dai->component->ignore_pmdown_time &&
-            rtd->codec_dai->component->ignore_pmdown_time;
+    for (i = 0; (i < rtd->num_codecs) && !ignore; i++)
+        ignore |= codecs[i].codec_dai->component->ignore_pmdown_time;

This should be "ignore = 1" and then ignore &= ... for each CODEC. We only want to ignore the power down delay if all components agree that they do not need it.

OK.

Quoted 76 lines
Quoted 10 lines
sound/soc/soc-pcm.c +2 -0
+
+    return rtd->cpu_dai->component->ignore_pmdown_time && ignore;
  }

/**

sound/soc/soc-pcm.c +0 -0
@@ -310,32 +326,66 @@ static void soc_pcm_apply_msb(struct
 snd_pcm_substream *substream,
      }
  }

[...]

sound/soc/soc-pcm.c static int soc_pcm_open(struct snd_pcm_substream *substream) · line 495

Quoted 2 lines
sound/soc/soc-pcm.c +1 -1
-    soc_pcm_apply_msb(substream, codec_dai);
+    soc_pcm_apply_msb(substream, codecs[0].codec_dai);

I think how this should work is that there should only be a msb constraint if all the CODEC DAIs have a msb contraint and then it should be the maximum over all the contraints.

Quoted 2 lines
      soc_pcm_apply_msb(substream, cpu_dai);

[...]

Quoted 55 lines

/*
* Called by ALSA when the hardware params are set by application. This
* function can also be called multiple times and can allocate buffers

sound/soc/soc-pcm.c +29 -8
@@ -667,9 +766,9 @@ static int soc_pcm_hw_params(struct
 snd_pcm_substream *substream,
  {
      struct snd_soc_pcm_runtime *rtd = substream->private_data;
      struct snd_soc_platform *platform = rtd->platform;
+    struct snd_soc_dai_link_codec *codecs = rtd->codecs;
      struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-    struct snd_soc_dai *codec_dai = rtd->codec_dai;
-    int ret = 0;
+    int i, ret = 0;
 
      mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
@@ -686,13 +785,39 @@ static int soc_pcm_hw_params(struct
 snd_pcm_substream *substream,
          }
      }
 
-    if (codec_dai->driver->ops && codec_dai->driver->ops->hw_params) {
-        ret = codec_dai->driver->ops->hw_params(substream, params,
 codec_dai);
-        if (ret < 0) {
-            dev_err(codec_dai->dev, "ASoC: can't set %s hw params:"
-                " %d\n", codec_dai->name, ret);
-            goto codec_err;
+    for (i = 0; i < rtd->num_codecs; i++) {
+        struct snd_soc_dai *codec_dai = codecs[i].codec_dai;
+        struct snd_pcm_hw_params *codec_params;
+
+        codec_params = &codec_dai->params[substream->stream];
+
+        /* copy params for each codec */
+        memcpy(codec_params, params, sizeof(struct snd_pcm_hw_params));
+
+        /* fixup params based on TDM slot masks */
+        if (codec_dai->tx_mask)
+            soc_pcm_codec_params_fixup(codec_params,
+                           codec_dai->tx_mask);
+        if (codec_dai->rx_mask)
+            soc_pcm_codec_params_fixup(codec_params,
+                           codec_dai->rx_mask);
+
+        if (codec_dai->driver->ops &&
+            codec_dai->driver->ops->hw_params) {
+            ret = codec_dai->driver->ops->hw_params(substream,
+                        codec_params, codec_dai);
+            if (ret < 0) {
+                dev_err(codec_dai->dev,
+                    "ASoC: can't set %s hw params: %d\n",
+                    codec_dai->name, ret);
+                goto codec_err;
+            }
Quoted 8 lines

sound/soc/soc-pcm.c static int soc_pcm_hw_params(struct snd_pcm_substream *substream, · line 820

Quoted 6 lines
sound/soc/soc-pcm.c +5 -0
          }
+
+        codec_dai->rate = params_rate(codec_params);
+        codec_dai->channels = params_channels(codec_params);
+        codec_dai->sample_bits = snd_pcm_format_physical_width(
+                        params_format(codec_params));

Those should only be set if all of the hw_params calls succeeded.

OK.

Quoted 10 lines
Quoted 4 lines
sound/soc/soc-pcm.c +0 -0
      }
      if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) {

[...]

Quoted 5 lines
sound/soc/soc-pcm.c +0 -0
@@ -764,16 +892,21 @@ static int soc_pcm_hw_free(struct
 snd_pcm_substream *substream)
          cpu_dai->sample_bits = 0;
      }
 
Quoted 9 lines

sound/soc/soc-pcm.c static int soc_pcm_hw_free(struct snd_pcm_substream *substream) · line 897

Quoted 7 lines
sound/soc/soc-pcm.c +3 -4
-    if (codec_dai->active == 1) {
-        codec_dai->rate = 0;
-        codec_dai->channels = 0;
-        codec_dai->sample_bits = 0;
+    for (i = 0; i < rtd->num_codecs; i++) {
+        codec_dai = codecs[i].codec_dai;
+        if (codec_dai->active == 1)

Missing brackets

Ooops, I missed it :-(

Quoted 38 lines
Quoted 6 lines
sound/soc/soc-pcm.c +3 -0
+            codec_dai->rate = 0;
+            codec_dai->channels = 0;
+            codec_dai->sample_bits = 0;
      }
 

[...]

Quoted 31 lines
sound/soc/soc-pcm.c +10 -7
@@ -2193,22 +2353,29 @@ static int dpcm_fe_dai_close(struct
 snd_pcm_substream *fe_substream)
  int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
  {
      struct snd_soc_platform *platform = rtd->platform;
-    struct snd_soc_dai *codec_dai = rtd->codec_dai;
+    struct snd_soc_dai_link_codec *codecs = rtd->codecs;
+    struct snd_soc_dai *codec_dai;
      struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
      struct snd_pcm *pcm;
      char new_name[64];
      int ret = 0, playback = 0, capture = 0;
+    int i;
 
      if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
          playback = rtd->dai_link->dpcm_playback;
          capture = rtd->dai_link->dpcm_capture;
      } else {
-        if (codec_dai->driver->playback.channels_min &&
-            cpu_dai->driver->playback.channels_min)
-            playback = 1;
-        if (codec_dai->driver->capture.channels_min &&
-            cpu_dai->driver->capture.channels_min)
-            capture = 1;
+        for (i = 0; i < rtd->num_codecs; i++) {
+            codec_dai = codecs[i].codec_dai;
+            if (codec_dai->driver->playback.channels_min &&
+                cpu_dai->driver->playback.channels_min)
+                playback++;
+            if (codec_dai->driver->capture.channels_min &&
+                cpu_dai->driver->capture.channels_min)
Quoted 8 lines

sound/soc/soc-pcm.c static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream) · line 2378

Quoted 4 lines
sound/soc/soc-pcm.c +4 -0
+                capture++;
+        }
+        capture = (rtd->num_codecs == capture);
+        playback = (rtd->num_codecs == playback);

Hm... I'd say the runtime should support playback or capture if at least one of the codecs support playback or capture. Not only if all of them support it.

OK.

Thanks for the exhaustive review and comments. I'll fix them and repost ASAP.

Regards,
Benoit

Signature · 4 lines
Benoît Cousson
BayLibre
Embedded Linux Technology Lab
www.baylibre.com
#11 lore raw

On 03/25/2014 02:10 PM, Benoit Cousson wrote:
[...]

Quoted 37 lines
Quoted 5 lines
Quoted 1 line

+struct snd_soc_dai_link_codec {

For the sake of symmetry maybe name this snd_soc_dai_link_component and drop the 'codec_' prefix in front of the struct fields. There is no reason why this couldn't be used for CPU dais as well at some point.

OK, good point.

Quoted 9 lines

include/sound/soc.h struct snd_soc_platform_driver { · line 836

Quoted 3 lines
include/sound/soc.h +3 -0
+    const char *codec_name;
+    const struct device_node *codec_of_node;
+    const char *codec_dai_name;

I'd like to see this split up into the descriptive part that holds the name, of_node etc, and the runtime data that holds the pointer to the DAIs. The descriptive part goes in the dai_link struct the. The pointers to the DAIs go into the snd_soc_pcm_runtime struct. This is how it is used the only place where you need both is in soc_bind_dai_link.

OK, let me try to clarify that. You suggest to create that struct:

(quoted diff) +5 -0
+struct snd_soc_dai_link_component {
+    const char *name;
+    const struct device_node *of_node;
+    const char *dai_name;
+}

to be inside the snd_soc_dai_link.

And inside the snd_soc_pcm_runtime, to replace these ones

(quoted diff) +2 -0
+    struct snd_soc_dai_link_codec *codecs;
+    int num_codecs;

with a direct pointers to codecs dais?

(quoted diff) +2 -0
+    struct snd_soc_dai **codecs_dai;
+    int num_codecs;
Quoted 1 line

Is that correct ?

Yes. Should be unsigned int though ;)

- Lars