Re: [PATCH v9 05/10] ASoC: soc-core: Add snd_soc_of_xlate_dai_name() generic helper

From: Srinivas Kandagatla

Date: Thu Oct 15 2026 - 05:05:57 EST


On 10/13/26 6:51 AM, Harendra Gautam wrote:
> Some ASoC CPU DAI drivers need to resolve a sound-dai phandle argument
> to a DAI name by matching the argument against the component's DAI IDs.
> lpass-cpu carries a local implementation of this lookup.
>
> Add snd_soc_of_xlate_dai_name() to soc-core.c as a generic helper
> that can be assigned directly to the .of_xlate_dai_name component
> driver callback. It iterates the component's DAI list using
> for_each_component_dais() and matches by DAI ID.
>
> Signed-off-by: Harendra Gautam <harendra.gautam@xxxxxxxxxxxxxxxx>
> ---
> include/sound/soc.h | 3 +++
> sound/soc/soc-core.c | 33 +++++++++++++++++++++++++++++++++
> 2 files changed, 36 insertions(+)
>
> diff --git a/include/sound/soc.h b/include/sound/soc.h
> index 553bb7e2be98..6f15086f7313 100644
> --- a/include/sound/soc.h
> +++ b/include/sound/soc.h
> @@ -1329,6 +1329,9 @@ int snd_soc_of_parse_tdm_slot(struct device_node *np,
> unsigned int *rx_mask,
> unsigned int *slots,
> unsigned int *slot_width);
> +int snd_soc_of_xlate_dai_name(struct snd_soc_component *component,
> + const struct of_phandle_args *args,
> + const char **dai_name);
> void snd_soc_of_parse_node_prefix(struct device_node *np,
> struct snd_soc_codec_conf *codec_conf,
> struct device_node *of_node,
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index 06167a198591..609706733bf1 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -2906,6 +2906,39 @@ int snd_soc_of_parse_tdm_slot(struct device_node *np,
> }
> EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
>
> +/**
> + * snd_soc_of_xlate_dai_name - Resolve a sound-dai phandle argument to a
> + * DAI name by searching the component DAI list.
> + * @component: ASoC component to search.
> + * @args: Phandle arguments from the sound-dai property; args[0] is the
> + * DAI ID.
> + * @dai_name: Output pointer set to the matched DAI name on success.
> + *
> + * Return: 0 on success, -EINVAL if args_count != 1 or no match is found.
> + */
> +int snd_soc_of_xlate_dai_name(struct snd_soc_component *component,
> + const struct of_phandle_args *args,
> + const char **dai_name)
> +{
> + struct snd_soc_dai *dai;
> + int id;
> +
> + if (args->args_count != 1)
This only works with sound-dai-cells == 1, the api itself does not
reflect that fact nor the kernel doc.


> + return -EINVAL;
> +
> + id = args->args[0];
> +
> + for_each_component_dais(component, dai) {
> + if (dai->driver->id == id) {
> + *dai_name = snd_soc_dai_name(dai);
> + return 0;
> + }
> + }
> +
> + return -EINVAL;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_of_xlate_dai_name);
> +
> void snd_soc_dlc_use_cpu_as_platform(struct snd_soc_dai_link_component *platforms,
> struct snd_soc_dai_link_component *cpus)
> {
>