[PATCH 6/6] ASoC: simple-card: cleanup graph_for_each_link()
Kuninori Morimoto
kuninori.morimoto.gx at renesas.com
Fri Mar 26 04:26:40 CET 2021
From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
simple-card checks DT links 2 times. 1st is for counting DAIs / links
to allocating memory, 2nd is for detecting DAIs.
To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case,
it uses loops 2 times.
Because of this kind of complex background, it needs to use local
varuable for it, and each call-back functions need to care about it.
Now, 1st and 2nd DT link check are using same order,
thus we can share same code. This patch do it.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
sound/soc/generic/simple-card.c | 125 ++++++++++++++++----------------
1 file changed, 61 insertions(+), 64 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index f53f76ee0a8b..41aa40765a8d 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -129,15 +129,6 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
char *prefix = "";
int ret;
- /*
- * |CPU |Codec : turn
- * CPU |Pass |return
- * Codec |return|Pass
- * np
- */
- if (li->cpu == (np == codec))
- return 0;
-
dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
li->link++;
@@ -260,15 +251,6 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
char *prefix = "";
int ret, single_cpu;
- /*
- * |CPU |Codec : turn
- * CPU |Pass |return
- * Codec |return|return
- * np
- */
- if (!li->cpu || np == codec)
- return 0;
-
cpu = np;
node = of_get_parent(np);
li->link++;
@@ -342,7 +324,7 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
return ret;
}
-static int simple_for_each_link(struct asoc_simple_priv *priv,
+static int __simple_for_each_link(struct asoc_simple_priv *priv,
struct link_info *li,
int (*func_noml)(struct asoc_simple_priv *priv,
struct device_node *np,
@@ -402,11 +384,26 @@ static int simple_for_each_link(struct asoc_simple_priv *priv,
*/
if (dpcm_selectable &&
(num > 2 ||
- adata.convert_rate || adata.convert_channels))
- ret = func_dpcm(priv, np, codec, li, is_top);
+ adata.convert_rate || adata.convert_channels)) {
+ /*
+ * np
+ * |1(CPU)|0(Codec) li->cpu
+ * CPU |Pass |return
+ * Codec |return|Pass
+ */
+ if (li->cpu != (np == codec))
+ ret = func_dpcm(priv, np, codec, li, is_top);
/* else normal sound */
- else
- ret = func_noml(priv, np, codec, li, is_top);
+ } else {
+ /*
+ * np
+ * |1(CPU)|0(Codec) li->cpu
+ * CPU |Pass |return
+ * Codec |return|return
+ */
+ if (li->cpu && (np != codec))
+ ret = func_noml(priv, np, codec, li, is_top);
+ }
if (ret < 0) {
of_node_put(codec);
@@ -424,6 +421,39 @@ static int simple_for_each_link(struct asoc_simple_priv *priv,
return ret;
}
+static int simple_for_each_link(struct asoc_simple_priv *priv,
+ struct link_info *li,
+ int (*func_noml)(struct asoc_simple_priv *priv,
+ struct device_node *np,
+ struct device_node *codec,
+ struct link_info *li, bool is_top),
+ int (*func_dpcm)(struct asoc_simple_priv *priv,
+ struct device_node *np,
+ struct device_node *codec,
+ struct link_info *li, bool is_top))
+{
+ int ret;
+ /*
+ * Detect all CPU first, and Detect all Codec 2nd.
+ *
+ * In Normal sound case, all DAIs are detected
+ * as "CPU-Codec".
+ *
+ * In DPCM sound case,
+ * all CPUs are detected as "CPU-dummy", and
+ * all Codecs are detected as "dummy-Codec".
+ * To avoid random sub-device numbering,
+ * detect "dummy-Codec" in last;
+ */
+ for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
+ ret = __simple_for_each_link(priv, li, func_noml, func_dpcm);
+ if (ret < 0)
+ break;
+ }
+
+ return ret;
+}
+
static int simple_parse_of(struct asoc_simple_priv *priv)
{
struct device *dev = simple_priv_to_dev(priv);
@@ -449,25 +479,11 @@ static int simple_parse_of(struct asoc_simple_priv *priv)
/* Single/Muti DAI link(s) & New style of DT node */
memset(&li, 0, sizeof(li));
- for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
- /*
- * Detect all CPU first, and Detect all Codec 2nd.
- *
- * In Normal sound case, all DAIs are detected
- * as "CPU-Codec".
- *
- * In DPCM sound case,
- * all CPUs are detected as "CPU-dummy", and
- * all Codecs are detected as "dummy-Codec".
- * To avoid random sub-device numbering,
- * detect "dummy-Codec" in last;
- */
- ret = simple_for_each_link(priv, &li,
- simple_dai_link_of,
- simple_dai_link_of_dpcm);
- if (ret < 0)
- return ret;
- }
+ ret = simple_for_each_link(priv, &li,
+ simple_dai_link_of,
+ simple_dai_link_of_dpcm);
+ if (ret < 0)
+ return ret;
ret = asoc_simple_parse_card_name(card, PREFIX);
if (ret < 0)
@@ -483,15 +499,6 @@ static int simple_count_noml(struct asoc_simple_priv *priv,
struct device_node *codec,
struct link_info *li, bool is_top)
{
- /*
- * |CPU |Codec : turn
- * CPU |Pass |return
- * Codec |return|return
- * np
- */
- if (!li->cpu || np == codec)
- return 0;
-
li->link += 1;
li->dais += 2;
@@ -503,15 +510,6 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv,
struct device_node *codec,
struct link_info *li, bool is_top)
{
- /*
- * |CPU |Codec : turn
- * CPU |Pass |return
- * Codec |return|Pass
- * np
- */
- if (li->cpu == (np == codec))
- return 0;
-
if (li->cpu) {
li->link++; /* CPU-dummy */
li->dais++;
@@ -583,10 +581,9 @@ static void simple_get_dais_count(struct asoc_simple_priv *priv,
return;
}
- for (li->cpu = 1; li->cpu >= 0; li->cpu--)
- simple_for_each_link(priv, li,
- simple_count_noml,
- simple_count_dpcm);
+ simple_for_each_link(priv, li,
+ simple_count_noml,
+ simple_count_dpcm);
dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
li->link, li->dais, li->conf);
--
2.25.1
More information about the Alsa-devel
mailing list