All of 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>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Subject: [alsa-devel] [PATCH v3 16/19] ASoC: soc-core: don't call snd_soc_dapm_new_dai_widgets() at snd_soc_register_dai()
Date: 05 Nov 2019 15:47:14 +0900	[thread overview]
Message-ID: <87sgn2251p.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87ftj23jph.wl-kuninori.morimoto.gx@renesas.com>

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

ALSA SoC has 2 functions.
snd_soc_register_dai()  is used from topology
snd_soc_register_dais() is used from snd_soc_add_component()

In general, people think like _dai() is called from _dais()
with for loop. But in reality, these are very similar
but different implementation.
We shouldn't have duplicated and confusing implementation.

snd_soc_register_dai() is now used from topology.
But to reduce duplicated code, it should be used from _dais(), too.

Because of topology side specific reason,
it is calling snd_soc_dapm_new_dai_widgets(),
but it is not needed _dais() side.

This patch factorizes snd_soc_register_dai() to
topology / _dais() common part, and topology specific part.
And do topology specific part at soc-topology.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
v2 -> v3
	- add Reviewed-by
	- directly return soc_add_dai()

 include/sound/soc.h      |  6 +++---
 sound/soc/soc-core.c     | 29 +++++------------------------
 sound/soc/soc-topology.c | 17 ++++++++++++++++-
 3 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 766fa81..4e38ee6 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1326,9 +1326,9 @@ struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
 					       int id, const char *name,
 					       const char *stream_name);
 
-int snd_soc_register_dai(struct snd_soc_component *component,
-			 struct snd_soc_dai_driver *dai_drv,
-			 bool legacy_dai_naming);
+struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
+					 struct snd_soc_dai_driver *dai_drv,
+					 bool legacy_dai_naming);
 void snd_soc_unregister_dai(struct snd_soc_dai *dai);
 
 struct snd_soc_dai *snd_soc_find_dai(
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 6f4933f..55b13c0 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2603,37 +2603,18 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  * These DAIs's widgets will be freed in the card cleanup and the DAIs
  * will be freed in the component cleanup.
  */
-int snd_soc_register_dai(struct snd_soc_component *component,
-			 struct snd_soc_dai_driver *dai_drv,
-			 bool legacy_dai_naming)
+struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
+					 struct snd_soc_dai_driver *dai_drv,
+					 bool legacy_dai_naming)
 {
-	struct snd_soc_dapm_context *dapm =
-		snd_soc_component_get_dapm(component);
-	struct snd_soc_dai *dai;
-	int ret;
-
 	if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) {
 		dev_err(component->dev, "Invalid dai type %d\n",
 			dai_drv->dobj.type);
-		return -EINVAL;
+		return NULL;
 	}
 
 	lockdep_assert_held(&client_mutex);
-	dai = soc_add_dai(component, dai_drv, legacy_dai_naming);
-	if (!dai)
-		return -ENOMEM;
-
-	/*
-	 * Create the DAI widgets here. After adding DAIs, topology may
-	 * also add routes that need these widgets as source or sink.
-	 */
-	ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
-	if (ret != 0) {
-		dev_err(component->dev,
-			"Failed to create DAI widgets %d\n", ret);
-	}
-
-	return ret;
+	return soc_add_dai(component, dai_drv, legacy_dai_naming);
 }
 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
 
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index b6e1456..81d2af0 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -1800,6 +1800,9 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg,
 	struct snd_soc_dai_driver *dai_drv;
 	struct snd_soc_pcm_stream *stream;
 	struct snd_soc_tplg_stream_caps *caps;
+	struct snd_soc_dai *dai;
+	struct snd_soc_dapm_context *dapm =
+		snd_soc_component_get_dapm(tplg->comp);
 	int ret;
 
 	dai_drv = kzalloc(sizeof(struct snd_soc_dai_driver), GFP_KERNEL);
@@ -1842,7 +1845,19 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg,
 	list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list);
 
 	/* register the DAI to the component */
-	return snd_soc_register_dai(tplg->comp, dai_drv, false);
+	dai = snd_soc_register_dai(tplg->comp, dai_drv, false);
+	if (!dai)
+		return -ENOMEM;
+
+	/* Create the DAI widgets here */
+	ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
+	if (ret != 0) {
+		dev_err(dai->dev, "Failed to create DAI widgets %d\n", ret);
+		snd_soc_unregister_dai(dai);
+		return ret;
+	}
+
+	return ret;
 }
 
 static void set_link_flags(struct snd_soc_dai_link *link,
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  parent reply	other threads:[~2019-11-05  6:57 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05  6:45 [alsa-devel] [PATCH v3 00/19] ASoC: soc-core cleanup - step 4 Kuninori Morimoto
2019-11-05  6:45 ` [alsa-devel] [PATCH v3 01/19] ASoC: soc-core: move soc_init_dai_link() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: move soc_init_dai_link()" to the asoc tree Mark Brown
2019-11-05  6:45 ` [alsa-devel] [PATCH v3 02/19] ASoC: soc-core: tidyup soc_init_dai_link() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: tidyup soc_init_dai_link()" to the asoc tree Mark Brown
2019-11-11 14:43   ` [PATCH v3 02/19] ASoC: soc-core: tidyup soc_init_dai_link() Jon Hunter
2019-11-11 14:43     ` [alsa-devel] " Jon Hunter
2019-11-12  0:24     ` Kuninori Morimoto
2019-11-12  0:24       ` [alsa-devel] " Kuninori Morimoto
2019-11-12 10:51       ` Jon Hunter
2019-11-12 10:51         ` [alsa-devel] " Jon Hunter
2019-11-13  0:29         ` Kuninori Morimoto
2019-11-13  0:29           ` [alsa-devel] " Kuninori Morimoto
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 03/19] ASoC: soc-core: typo fix at soc_dai_link_sanity_check() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: typo fix at soc_dai_link_sanity_check()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 04/19] ASoC: soc-core: remove duplicated soc_is_dai_link_bound() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: remove duplicated soc_is_dai_link_bound()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 05/19] ASoC: soc-core: call soc_bind_dai_link() under snd_soc_add_dai_link() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: call soc_bind_dai_link() under snd_soc_add_dai_link()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 06/19] ASoC: soc-core: add soc_unbind_dai_link() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: add soc_unbind_dai_link()" to the asoc tree Mark Brown
2019-11-12  5:21   ` [alsa-devel] [PATCH v3 06/19] ASoC: soc-core: add soc_unbind_dai_link() Pierre-Louis Bossart
2019-11-12  5:37     ` Kuninori Morimoto
2019-11-12  5:50       ` Kuninori Morimoto
2019-11-12  6:42         ` Kuninori Morimoto
2019-11-12 17:11           ` Pierre-Louis Bossart
2019-11-12 19:03             ` Mark Brown
2019-11-12 21:08               ` Pierre-Louis Bossart
2019-11-13  4:37                 ` Kuninori Morimoto
2019-11-13  5:57                   ` Takashi Iwai
2019-11-13  6:33                     ` Kuninori Morimoto
2019-11-13 16:05                   ` Pierre-Louis Bossart
2019-11-14  0:18                     ` Kuninori Morimoto
2019-11-14  1:03                       ` Kuninori Morimoto
2019-11-16  0:19                         ` Pierre-Louis Bossart
2019-11-18  0:47                           ` Kuninori Morimoto
2019-11-18 15:14                             ` Pierre-Louis Bossart
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 07/19] ASoC: soc-core: move snd_soc_lookup_component() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: move snd_soc_lookup_component()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 08/19] ASoC: soc-core: tidyup snd_soc_lookup_component() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: tidyup snd_soc_lookup_component()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 09/19] ASoC: soc-core: add snd_soc_del_component_unlocked() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: add snd_soc_del_component_unlocked()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 10/19] ASoC: soc-core: remove snd_soc_component_add/del() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: remove snd_soc_component_add/del()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 11/19] ASoC: soc-core: use snd_soc_lookup_component() at snd_soc_unregister_component() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: use snd_soc_lookup_component() at snd_soc_unregister_component()" to the asoc tree Mark Brown
2019-11-05  6:46 ` [alsa-devel] [PATCH v3 12/19] ASoC: soc-core: move snd_soc_register_dai() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: move snd_soc_register_dai()" to the asoc tree Mark Brown
2019-11-05  6:47 ` [alsa-devel] [PATCH v3 13/19] ASoC: soc-core: move snd_soc_unregister_dais() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: move snd_soc_unregister_dais()" to the asoc tree Mark Brown
2019-11-05  6:47 ` [alsa-devel] [PATCH v3 14/19] ASoC: soc-core: add snd_soc_unregister_dai() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: add snd_soc_unregister_dai()" to the asoc tree Mark Brown
2019-11-05  6:47 ` [alsa-devel] [PATCH v3 15/19] ASoC: soc-core: have legacy_dai_naming at snd_soc_register_dai() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: have legacy_dai_naming at snd_soc_register_dai()" to the asoc tree Mark Brown
2019-11-05  6:47 ` Kuninori Morimoto [this message]
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: don't call snd_soc_dapm_new_dai_widgets() " Mark Brown
2019-11-05  6:47 ` [alsa-devel] [PATCH v3 17/19] ASoC: soc-core: call snd_soc_register_dai() from snd_soc_register_dais() Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: call snd_soc_register_dai() from snd_soc_register_dais()" to the asoc tree Mark Brown
2019-11-05  6:47 ` [alsa-devel] [PATCH v3 18/19] ASoC: soc-core: remove topology specific operation Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc-core: remove topology specific operation" to the asoc tree Mark Brown
2019-11-05  6:47 ` [alsa-devel] [PATCH v3 19/19] ASoC: soc.h: dobj is used only when SND_SOC_TOPOLOGY Kuninori Morimoto
2019-11-05 23:51   ` [alsa-devel] Applied "ASoC: soc.h: dobj is used only when SND_SOC_TOPOLOGY" to the asoc tree Mark Brown
2019-11-05 16:18 ` [alsa-devel] [PATCH v3 00/19] ASoC: soc-core cleanup - step 4 Ranjani Sridharan

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=87sgn2251p.wl-kuninori.morimoto.gx@renesas.com \
    --to=kuninori.morimoto.gx@renesas.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.