Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [PATCH 02/14] ASoC: soc-core.c: cleanup soc_dai_link_sanity_check()
Date: Wed, 21 Jun 2023 02:18:17 +0000	[thread overview]
Message-ID: <87o7l9blsn.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87r0q5blta.wl-kuninori.morimoto.gx@renesas.com>

Required CPU/Codec/Platform dlc (snd_soc_dai_link_component) are similar
but not same, and very complex. Current implementation is very confusable
and it will be more complex if multi Component was supported.
This patch cleanup it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-core.c | 131 ++++++++++++++++++++++++-------------------
 1 file changed, 72 insertions(+), 59 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index b25c26deef63..4b66c6d87fa2 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -238,6 +238,21 @@ static inline void snd_soc_debugfs_exit(void) { }
 
 #endif
 
+static inline int snd_soc_dlc_component_is_empty(struct snd_soc_dai_link_component *dlc)
+{
+	return !(dlc->name || dlc->of_node);
+}
+
+static inline int snd_soc_dlc_component_is_invalid(struct snd_soc_dai_link_component *dlc)
+{
+	return (dlc->name && dlc->of_node);
+}
+
+static inline int snd_soc_dlc_dai_is_empty(struct snd_soc_dai_link_component *dlc)
+{
+	return !dlc->dai_name;
+}
+
 static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
 				     struct snd_soc_component *component)
 {
@@ -829,102 +844,100 @@ static int soc_dai_link_sanity_check(struct snd_soc_card *card,
 				     struct snd_soc_dai_link *link)
 {
 	int i;
-	struct snd_soc_dai_link_component *cpu, *codec, *platform;
+	struct snd_soc_dai_link_component *dlc;
 
-	for_each_link_codecs(link, i, codec) {
+	/* Codec check */
+	for_each_link_codecs(link, i, dlc) {
 		/*
 		 * Codec must be specified by 1 of name or OF node,
 		 * not both or neither.
 		 */
-		if (!!codec->name == !!codec->of_node) {
-			dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
-				link->name);
-			return -EINVAL;
-		}
+		if (snd_soc_dlc_component_is_invalid(dlc))
+			goto component_invalid;
+
+		if (snd_soc_dlc_component_is_empty(dlc))
+			goto component_empty;
 
 		/* Codec DAI name must be specified */
-		if (!codec->dai_name) {
-			dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
-				link->name);
-			return -EINVAL;
-		}
+		if (snd_soc_dlc_dai_is_empty(dlc))
+			goto dai_empty;
 
 		/*
 		 * Defer card registration if codec component is not added to
 		 * component list.
 		 */
-		if (!soc_find_component(codec)) {
-			dev_dbg(card->dev,
-				"ASoC: codec component %s not found for link %s\n",
-				codec->name, link->name);
-			return -EPROBE_DEFER;
-		}
+		if (!soc_find_component(dlc))
+			goto component_not_find;
 	}
 
-	for_each_link_platforms(link, i, platform) {
+	/* Platform check */
+	for_each_link_platforms(link, i, dlc) {
 		/*
 		 * Platform may be specified by either name or OF node, but it
 		 * can be left unspecified, then no components will be inserted
 		 * in the rtdcom list
 		 */
-		if (!!platform->name == !!platform->of_node) {
-			dev_err(card->dev,
-				"ASoC: Neither/both platform name/of_node are set for %s\n",
-				link->name);
-			return -EINVAL;
-		}
+		if (snd_soc_dlc_component_is_invalid(dlc))
+			goto component_invalid;
+
+		if (snd_soc_dlc_component_is_empty(dlc))
+			goto component_empty;
 
 		/*
 		 * Defer card registration if platform component is not added to
 		 * component list.
 		 */
-		if (!soc_find_component(platform)) {
-			dev_dbg(card->dev,
-				"ASoC: platform component %s not found for link %s\n",
-				platform->name, link->name);
-			return -EPROBE_DEFER;
-		}
+		if (!soc_find_component(dlc))
+			goto component_not_find;
 	}
 
-	for_each_link_cpus(link, i, cpu) {
+	/* CPU check */
+	for_each_link_cpus(link, i, dlc) {
 		/*
 		 * CPU device may be specified by either name or OF node, but
 		 * can be left unspecified, and will be matched based on DAI
 		 * name alone..
 		 */
-		if (cpu->name && cpu->of_node) {
-			dev_err(card->dev,
-				"ASoC: Neither/both cpu name/of_node are set for %s\n",
-				link->name);
-			return -EINVAL;
-		}
+		if (snd_soc_dlc_component_is_invalid(dlc))
+			goto component_invalid;
 
-		/*
-		 * Defer card registration if cpu dai component is not added to
-		 * component list.
-		 */
-		if ((cpu->of_node || cpu->name) &&
-		    !soc_find_component(cpu)) {
-			dev_dbg(card->dev,
-				"ASoC: cpu component %s not found for link %s\n",
-				cpu->name, link->name);
-			return -EPROBE_DEFER;
-		}
 
-		/*
-		 * At least one of CPU DAI name or CPU device name/node must be
-		 * specified
-		 */
-		if (!cpu->dai_name &&
-		    !(cpu->name || cpu->of_node)) {
-			dev_err(card->dev,
-				"ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
-				link->name);
-			return -EINVAL;
+		if (snd_soc_dlc_component_is_empty(dlc)) {
+			/*
+			 * At least one of CPU DAI name or CPU device name/node must be specified
+			 */
+			if (snd_soc_dlc_dai_is_empty(dlc))
+				goto component_dai_empty;
+		} else {
+			/*
+			 * Defer card registration if Component is not added
+			 */
+			if (!soc_find_component(dlc))
+				goto component_not_find;
 		}
 	}
 
 	return 0;
+
+component_invalid:
+	dev_err(card->dev, "ASoC: Both Component name/of_node are set for %s\n", link->name);
+	return -EINVAL;
+
+component_empty:
+	dev_err(card->dev, "ASoC: Neither Component name/of_node are set for %s\n", link->name);
+	return -EINVAL;
+
+component_not_find:
+	dev_err(card->dev, "ASoC: Component %s not found for link %s\n", dlc->name, link->name);
+	return -EPROBE_DEFER;
+
+dai_empty:
+	dev_err(card->dev, "ASoC: DAI name is not set for %s\n", link->name);
+	return -EINVAL;
+
+component_dai_empty:
+	dev_err(card->dev, "ASoC: Neither DAI/Component name/of_node are set for %s\n", link->name);
+	return -EINVAL;
 }
 
 /**
-- 
2.25.1


  parent reply	other threads:[~2023-06-21  2:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21  2:17 [PATCH 00/14] ASoC: add multi Component support Kuninori Morimoto
2023-06-21  2:18 ` [PATCH 01/14] ASoC: soc-core.c: initialize dlc on snd_soc_get_dai_id() Kuninori Morimoto
2023-06-21  2:18 ` Kuninori Morimoto [this message]
2023-06-21  2:18 ` [PATCH 03/14] ASoC: soc-dai.c: add DAI get/match functions Kuninori Morimoto
2023-07-09 21:44   ` Mark Brown
2023-06-21  2:18 ` [PATCH 04/14] ASoC: soc-core.c: enable multi Component Kuninori Morimoto
2023-06-21  2:18 ` [PATCH 05/14] ASoC: soc-core.c: add snd_soc_get_dai_via_args() Kuninori Morimoto
2023-06-21  2:18 ` [PATCH 06/14] ASoC: soc-core.c: add snd_soc_dlc_use_cpu_as_platform() Kuninori Morimoto
2023-06-21  2:18 ` [PATCH 07/14] ASoC: soc-core.c: add snd_soc_copy_dai_args() Kuninori Morimoto
2023-06-21  2:19 ` [PATCH 08/14] ASoC: simple-card-utils.c: enable multi Component support Kuninori Morimoto
2023-06-21  2:19 ` [PATCH 09/14] ASoC: simple-card.c: " Kuninori Morimoto
2023-06-21  2:19 ` [PATCH 10/14] ASoC: rsnd: use DAI driver ID instead of DAI ID Kuninori Morimoto
2023-06-21  2:19 ` [PATCH 11/14] ASoC: rsnd: cleanup rsnd_dai_of_node() Kuninori Morimoto
2023-06-21  2:19 ` [PATCH 12/14] ASoC: rsnd: enable multi Component support for Audio Graph Card/Card2 Kuninori Morimoto
2023-06-21  2:19 ` [PATCH 13/14] ASoC: dt-bindings: renesas,rsnd.yaml: add common port-def Kuninori Morimoto
2023-06-21 10:04   ` Krzysztof Kozlowski
2023-06-21  2:19 ` [PATCH 14/14] ASoC: dt-bindings: renesas,rsnd.yaml: enable multi ports for multi Component support Kuninori Morimoto
2023-06-21 10:05   ` Krzysztof Kozlowski
2023-06-21 23:09     ` Kuninori Morimoto
2023-07-12 11:47 ` [PATCH 00/14] ASoC: add " 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=87o7l9blsn.wl-kuninori.morimoto.gx@renesas.com \
    --to=kuninori.morimoto.gx@renesas.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    /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