mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://lore.kernel.org/r/87o7l9blsn.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
		
							parent
							
								
									521d675d24
								
							
						
					
					
						commit
						0e66a2c694
					
				
					 1 changed files with 72 additions and 59 deletions
				
			
		| 
						 | 
					@ -238,6 +238,21 @@ static inline void snd_soc_debugfs_exit(void) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#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,
 | 
					static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
 | 
				
			||||||
				     struct snd_soc_component *component)
 | 
									     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)
 | 
									     struct snd_soc_dai_link *link)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						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,
 | 
							 * Codec must be specified by 1 of name or OF node,
 | 
				
			||||||
		 * not both or neither.
 | 
							 * not both or neither.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (!!codec->name == !!codec->of_node) {
 | 
							if (snd_soc_dlc_component_is_invalid(dlc))
 | 
				
			||||||
			dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
 | 
								goto component_invalid;
 | 
				
			||||||
				link->name);
 | 
					
 | 
				
			||||||
			return -EINVAL;
 | 
							if (snd_soc_dlc_component_is_empty(dlc))
 | 
				
			||||||
		}
 | 
								goto component_empty;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Codec DAI name must be specified */
 | 
							/* Codec DAI name must be specified */
 | 
				
			||||||
		if (!codec->dai_name) {
 | 
							if (snd_soc_dlc_dai_is_empty(dlc))
 | 
				
			||||||
			dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
 | 
								goto dai_empty;
 | 
				
			||||||
				link->name);
 | 
					 | 
				
			||||||
			return -EINVAL;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Defer card registration if codec component is not added to
 | 
							 * Defer card registration if codec component is not added to
 | 
				
			||||||
		 * component list.
 | 
							 * component list.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (!soc_find_component(codec)) {
 | 
							if (!soc_find_component(dlc))
 | 
				
			||||||
			dev_dbg(card->dev,
 | 
								goto component_not_find;
 | 
				
			||||||
				"ASoC: codec component %s not found for link %s\n",
 | 
					 | 
				
			||||||
				codec->name, link->name);
 | 
					 | 
				
			||||||
			return -EPROBE_DEFER;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	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
 | 
							 * Platform may be specified by either name or OF node, but it
 | 
				
			||||||
		 * can be left unspecified, then no components will be inserted
 | 
							 * can be left unspecified, then no components will be inserted
 | 
				
			||||||
		 * in the rtdcom list
 | 
							 * in the rtdcom list
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (!!platform->name == !!platform->of_node) {
 | 
							if (snd_soc_dlc_component_is_invalid(dlc))
 | 
				
			||||||
			dev_err(card->dev,
 | 
								goto component_invalid;
 | 
				
			||||||
				"ASoC: Neither/both platform name/of_node are set for %s\n",
 | 
					
 | 
				
			||||||
				link->name);
 | 
							if (snd_soc_dlc_component_is_empty(dlc))
 | 
				
			||||||
			return -EINVAL;
 | 
								goto component_empty;
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Defer card registration if platform component is not added to
 | 
							 * Defer card registration if platform component is not added to
 | 
				
			||||||
		 * component list.
 | 
							 * component list.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (!soc_find_component(platform)) {
 | 
							if (!soc_find_component(dlc))
 | 
				
			||||||
			dev_dbg(card->dev,
 | 
								goto component_not_find;
 | 
				
			||||||
				"ASoC: platform component %s not found for link %s\n",
 | 
					 | 
				
			||||||
				platform->name, link->name);
 | 
					 | 
				
			||||||
			return -EPROBE_DEFER;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	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
 | 
							 * CPU device may be specified by either name or OF node, but
 | 
				
			||||||
		 * can be left unspecified, and will be matched based on DAI
 | 
							 * can be left unspecified, and will be matched based on DAI
 | 
				
			||||||
		 * name alone..
 | 
							 * name alone..
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (cpu->name && cpu->of_node) {
 | 
							if (snd_soc_dlc_component_is_invalid(dlc))
 | 
				
			||||||
			dev_err(card->dev,
 | 
								goto component_invalid;
 | 
				
			||||||
				"ASoC: Neither/both cpu name/of_node are set for %s\n",
 | 
					 | 
				
			||||||
				link->name);
 | 
					 | 
				
			||||||
			return -EINVAL;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
					 | 
				
			||||||
		 * 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;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							if (snd_soc_dlc_component_is_empty(dlc)) {
 | 
				
			||||||
		 * At least one of CPU DAI name or CPU device name/node must be
 | 
								/*
 | 
				
			||||||
		 * specified
 | 
								 * At least one of CPU DAI name or CPU device name/node must be specified
 | 
				
			||||||
		 */
 | 
								 */
 | 
				
			||||||
		if (!cpu->dai_name &&
 | 
								if (snd_soc_dlc_dai_is_empty(dlc))
 | 
				
			||||||
		    !(cpu->name || cpu->of_node)) {
 | 
									goto component_dai_empty;
 | 
				
			||||||
			dev_err(card->dev,
 | 
							} else {
 | 
				
			||||||
				"ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
 | 
								/*
 | 
				
			||||||
				link->name);
 | 
								 * Defer card registration if Component is not added
 | 
				
			||||||
			return -EINVAL;
 | 
								 */
 | 
				
			||||||
 | 
								if (!soc_find_component(dlc))
 | 
				
			||||||
 | 
									goto component_not_find;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue