Commit e443c205 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-core: don't call snd_soc_dapm_new_dai_widgets() at snd_soc_register_dai()

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: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87sgn2251p.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5d075197
...@@ -1326,9 +1326,9 @@ struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card, ...@@ -1326,9 +1326,9 @@ struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
int id, const char *name, int id, const char *name,
const char *stream_name); const char *stream_name);
int snd_soc_register_dai(struct snd_soc_component *component, struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv, struct snd_soc_dai_driver *dai_drv,
bool legacy_dai_naming); bool legacy_dai_naming);
void snd_soc_unregister_dai(struct snd_soc_dai *dai); void snd_soc_unregister_dai(struct snd_soc_dai *dai);
struct snd_soc_dai *snd_soc_find_dai( struct snd_soc_dai *snd_soc_find_dai(
......
...@@ -2603,37 +2603,18 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); ...@@ -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 * These DAIs's widgets will be freed in the card cleanup and the DAIs
* will be freed in the component cleanup. * will be freed in the component cleanup.
*/ */
int snd_soc_register_dai(struct snd_soc_component *component, struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv, struct snd_soc_dai_driver *dai_drv,
bool legacy_dai_naming) 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) { if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) {
dev_err(component->dev, "Invalid dai type %d\n", dev_err(component->dev, "Invalid dai type %d\n",
dai_drv->dobj.type); dai_drv->dobj.type);
return -EINVAL; return NULL;
} }
lockdep_assert_held(&client_mutex); lockdep_assert_held(&client_mutex);
dai = soc_add_dai(component, dai_drv, legacy_dai_naming); return 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;
} }
EXPORT_SYMBOL_GPL(snd_soc_register_dai); EXPORT_SYMBOL_GPL(snd_soc_register_dai);
......
...@@ -1800,6 +1800,9 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg, ...@@ -1800,6 +1800,9 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg,
struct snd_soc_dai_driver *dai_drv; struct snd_soc_dai_driver *dai_drv;
struct snd_soc_pcm_stream *stream; struct snd_soc_pcm_stream *stream;
struct snd_soc_tplg_stream_caps *caps; 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; int ret;
dai_drv = kzalloc(sizeof(struct snd_soc_dai_driver), GFP_KERNEL); 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, ...@@ -1842,7 +1845,19 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg,
list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list); list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list);
/* register the DAI to the component */ /* 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, static void set_link_flags(struct snd_soc_dai_link *link,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment