diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c index 10305a44c7409b..e11d8f4685c336 100644 --- a/sound/soc/sdw_utils/soc_sdw_utils.c +++ b/sound/soc/sdw_utils/soc_sdw_utils.c @@ -10,6 +10,7 @@ #include #include #include +#include #include static const struct snd_soc_dapm_widget generic_dmic_widgets[] = { @@ -1062,8 +1063,10 @@ int asoc_sdw_parse_sdw_endpoints(struct snd_soc_card *card, struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; const struct snd_soc_acpi_link_adr *adr_link; struct asoc_sdw_endpoint *soc_end = soc_ends; + struct snd_soc_dai_link_component dlc; + struct snd_soc_dai *codec_dai; int num_dais = 0; - int i, j; + int i, j, k; int ret; for (adr_link = mach_params->links; adr_link->num_adr; adr_link++) { @@ -1096,6 +1099,7 @@ int asoc_sdw_parse_sdw_endpoints(struct snd_soc_card *card, if (!codec_name) return -ENOMEM; + dlc.name = codec_name; dev_dbg(dev, "Adding prefix %s for %s\n", adr_dev->name_prefix, codec_name); @@ -1113,7 +1117,9 @@ int asoc_sdw_parse_sdw_endpoints(struct snd_soc_card *card, const struct snd_soc_acpi_endpoint *adr_end; const struct asoc_sdw_dai_info *dai_info; struct asoc_sdw_dailink *soc_dai; + struct sdw_slave *slave; int stream; + char *key; adr_end = &adr_dev->endpoints[j]; dai_info = &codec_info->dais[adr_end->num]; @@ -1122,6 +1128,47 @@ int asoc_sdw_parse_sdw_endpoints(struct snd_soc_card *card, if (dai_info->quirk && !(dai_info->quirk & ctx->mc_quirk)) continue; + dlc.dai_name = dai_info->dai_name; + codec_dai = snd_soc_find_dai_with_mutex(&dlc); + if (!codec_dai) { + dev_err(dev, "codec dai %s not registered yet\n", + dlc.dai_name); + return -EAGAIN; + } + + slave = dev_to_sdw_dev(codec_dai->dev); + if (!slave) + return -EINVAL; + + switch (dai_info->dai_type) { + case SOC_SDW_DAI_TYPE_JACK: + key = "J"; /* UAJ, RJ, SimpleJack*/ + break; + case SOC_SDW_DAI_TYPE_AMP: + key = "Amp"; /* SmartAmp, SimpleAmp*/ + break; + case SOC_SDW_DAI_TYPE_MIC: + key = "Mic"; /* SmartMic, SimpleMic, SpeakerMic*/ + break; + default: + dev_err(dev, "Invalid dai type %d\n", + dai_info->dai_type); + return -EINVAL; + } + for (k = 0; k < slave->sdca_data.num_functions; k++) { + dev_dbg(&slave->dev, "function: %s key %s\n", slave->sdca_data.sdca_func[k].name, key); + if (strstr(slave->sdca_data.sdca_func[k].name, key)) { + dev_dbg(&slave->dev, "Function %s found\n", + slave->sdca_data.sdca_func[k].name); + break; + } + } + if (k == slave->sdca_data.num_functions) { + dev_dbg(&slave->dev, "DAI type %d not found, skip endpoint\n", + dai_info->dai_type); + continue; + } + dev_dbg(dev, "Add dev: %d, 0x%llx end: %d, dai: %d, %c/%c to %s: %d\n", ffs(adr_link->mask) - 1, adr_dev->adr,