Commit 0e66a2c6 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-core.c: cleanup soc_dai_link_sanity_check()

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: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87o7l9blsn.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 521d675d
......@@ -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;
}
/**
......
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