[alsa-devel] [PATCH 06/21] ASoC: soc-core: call soc_bind_dai_link() under snd_soc_add_dai_link()

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Oct 9 06:30:14 CEST 2019


From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>

If we focus to soc_bind_dai_link() at snd_soc_instantiate_card(),
we will notice very complex operation.

static int snd_soc_instantiate_card(...)
{
	...
	/*
	 * (1) find component via card pre-linked dai_link
	 *
	 * find component (CPU/Codec/Platform) via card pre-linked
	 * dai_link, and connect found component to *rtd*.
	 * for_each_card_prelinks() is dai_link loop for card pre-linked
	 */
	for_each_card_prelinks(card, i, dai_link) {
		ret = soc_bind_dai_link(card, dai_link);
		...
	}
	...
	/*
	 * (2) connect card pre-linked dai_link to card list
	 *
	 * connect all card pre-linked dai_link to *card list*.
	 */
	for_each_card_prelinks(card, i, dai_link) {
		ret = snd_soc_add_dai_link(card, dai_link);
		...
	}
	...
	/*
	 * (3) probe binded component
	 *
	 * probe *rtd* connected component. This means, connected
	 * component at (1) is the probe target.
	 *
	 * At this component probe, topology may add new dai_link to
	 * *card list* by using snd_soc_add_dai_link() which is
	 * used at (2).
	 */
	ret = soc_probe_link_components(card);
	...

	/*
	 * (4) find component again
	 *
	 * find component again. card pre-linked dai_link listed components
	 * are already found at (1), but topology added one via (3) is not
	 * yet found. Here try to find component for it.
	 *
	 * for_each_card_links() here means *card list* loop,
	 * which is connected via (2) and (3).
	 * It ignores already added one, this means it ignores component
	 * which is connected at (1).
	 * Thus, find target here is new added one at (3).
	 */
	for_each_card_links(card, dai_link) {
		ret = soc_bind_dai_link(card, dai_link);
		...
	}
	...
}

It is doing very complex method.
The problem is finding component for "card pre-linked" (= (1)) and
"topology added dai_link" (= (3)) are separated.
If we can "find component" when dai_link is connected to "card list",
the code will be very simple. This patch fixup it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 sound/soc/soc-core.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4edac93..a0c80f7 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1409,6 +1409,8 @@ EXPORT_SYMBOL_GPL(snd_soc_disconnect_sync);
 int snd_soc_add_dai_link(struct snd_soc_card *card,
 		struct snd_soc_dai_link *dai_link)
 {
+	int ret;
+
 	if (dai_link->dobj.type
 	    && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
 		dev_err(card->dev, "Invalid dai link type %d\n",
@@ -1424,6 +1426,10 @@ int snd_soc_add_dai_link(struct snd_soc_card *card,
 	if (dai_link->dobj.type && card->add_dai_link)
 		card->add_dai_link(card, dai_link);
 
+	ret = soc_bind_dai_link(card, dai_link);
+	if (ret < 0)
+		return ret;
+
 	/* see for_each_card_links */
 	list_add_tail(&dai_link->list, &card->dai_link_list);
 
@@ -1996,13 +2002,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
 	/* check whether any platform is ignore machine FE and using topology */
 	soc_check_tplg_fes(card);
 
-	/* bind DAIs */
-	for_each_card_prelinks(card, i, dai_link) {
-		ret = soc_bind_dai_link(card, dai_link);
-		if (ret != 0)
-			goto probe_end;
-	}
-
 	/* bind aux_devs too */
 	ret = soc_bind_aux_dev(card);
 	if (ret < 0)
@@ -2060,16 +2059,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
 	if (ret < 0)
 		goto probe_end;
 
-	/*
-	 * Find new DAI links added during probing components and bind them.
-	 * Components with topology may bring new DAIs and DAI links.
-	 */
-	for_each_card_links(card, dai_link) {
-		ret = soc_bind_dai_link(card, dai_link);
-		if (ret)
-			goto probe_end;
-	}
-
 	/* probe all DAI links on this card */
 	ret = soc_probe_link_dais(card);
 	if (ret < 0) {
-- 
2.7.4



More information about the Alsa-devel mailing list