diff mbox series

[2/4] ASoC: simple-card: add simple_link_init()

Message ID 87a6p3cq44.wl-kuninori.morimoto.gx@renesas.com
State New
Headers show
Series ASoC: simple-card / audio-graph re-cleanup | expand

Commit Message

Kuninori Morimoto May 10, 2021, 1:52 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

This patch adds simple_link_init() and share dai_link setting code.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/simple-card.c | 62 +++++++++++++++++----------------
 1 file changed, 32 insertions(+), 30 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 5288aacfc628..c9edde04a4a9 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -156,6 +156,28 @@  static int simple_parse_node(struct asoc_simple_priv *priv,
 	return 0;
 }
 
+static int simple_link_init(struct asoc_simple_priv *priv,
+			    struct device_node *node,
+			    struct device_node *codec,
+			    struct link_info *li,
+			    char *prefix,
+			    char *name)
+{
+	struct device *dev = simple_priv_to_dev(priv);
+	struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
+	int ret;
+
+	ret = asoc_simple_parse_daifmt(dev, node, codec,
+				       prefix, &dai_link->dai_fmt);
+	if (ret < 0)
+		return 0;
+
+	dai_link->init			= asoc_simple_dai_init;
+	dai_link->ops			= &simple_ops;
+
+	return asoc_simple_set_dailink_name(dev, dai_link, name);
+}
+
 static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 				   struct device_node *np,
 				   struct device_node *codec,
@@ -170,6 +192,7 @@  static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 	struct device_node *top = dev->of_node;
 	struct device_node *node = of_get_parent(np);
 	char *prefix = "";
+	char dai_name[64];
 	int ret;
 
 	dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
@@ -187,13 +210,9 @@  static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 
 		/*
 		 * next simple_parse_node() might remove cpus->dai_name.
-		 * set dailink_name before it.
+		 * get dai_name before it.
 		 */
-		ret = asoc_simple_set_dailink_name(dev, dai_link,
-						   "fe.%s",
-						   cpus->dai_name);
-		if (ret < 0)
-			goto out_put_node;
+		snprintf(dai_name, sizeof(dai_name), "fe.%s", cpus->dai_name);
 
 		ret = simple_parse_node(priv, np, li, prefix, 1);
 		if (ret < 0)
@@ -209,11 +228,7 @@  static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 
 		cconf	= simple_props_to_codec_conf(dai_props, 0);
 
-		ret = asoc_simple_set_dailink_name(dev, dai_link,
-						   "be.%s",
-						   codecs->dai_name);
-		if (ret < 0)
-			goto out_put_node;
+		snprintf(dai_name, sizeof(dai_name), "be.%s", codecs->dai_name);
 
 		ret = simple_parse_node(priv, np, li, prefix, 0);
 		if (ret < 0)
@@ -230,15 +245,9 @@  static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 
 	simple_parse_convert(dev, np, &dai_props->adata);
 
-	ret = asoc_simple_parse_daifmt(dev, node, codec,
-				       prefix, &dai_link->dai_fmt);
-	if (ret < 0)
-		goto out_put_node;
-
 	snd_soc_dai_link_set_capabilities(dai_link);
 
-	dai_link->ops			= &simple_ops;
-	dai_link->init			= asoc_simple_dai_init;
+	ret = simple_link_init(priv, node, codec, li, prefix, dai_name);
 
 out_put_node:
 	li->link++;
@@ -261,6 +270,7 @@  static int simple_dai_link_of(struct asoc_simple_priv *priv,
 	struct device_node *cpu = NULL;
 	struct device_node *node = NULL;
 	struct device_node *plat = NULL;
+	char dai_name[64];
 	char prop[128];
 	char *prefix = "";
 	int ret;
@@ -277,19 +287,12 @@  static int simple_dai_link_of(struct asoc_simple_priv *priv,
 	snprintf(prop, sizeof(prop), "%splat", prefix);
 	plat = of_get_child_by_name(node, prop);
 
-	ret = asoc_simple_parse_daifmt(dev, node, codec,
-				       prefix, &dai_link->dai_fmt);
-	if (ret < 0)
-		goto dai_link_of_err;
-
 	/*
 	 * next simple_parse_node() might remove cpus->dai_name.
-	 * set dailink_name before it.
+	 * get dai_name before it.
 	 */
-	ret = asoc_simple_set_dailink_name(dev, dai_link, "%s-%s",
-					   cpus->dai_name, codecs->dai_name);
-	if (ret < 0)
-		goto dai_link_of_err;
+	snprintf(dai_name, sizeof(dai_name),
+		 "%s-%s", cpus->dai_name, codecs->dai_name);
 
 	ret = simple_parse_node(priv, cpu, li, prefix, 1);
 	if (ret < 0)
@@ -303,8 +306,7 @@  static int simple_dai_link_of(struct asoc_simple_priv *priv,
 	if (ret < 0)
 		goto dai_link_of_err;
 
-	dai_link->ops = &simple_ops;
-	dai_link->init = asoc_simple_dai_init;
+	ret = simple_link_init(priv, node, codec, li, prefix, dai_name);
 
 dai_link_of_err:
 	of_node_put(plat);