Skip to content

Commit 5b027c7

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: sdw_utils: Call init callbacks on the correct codec DAI
asoc_sdw_rtd_init() needs to call the rtd_init() callbacks for each codec in a dailink. It was finding the codecs by looking for the matching DAI name in codec_info_list[] but this isn't correct, because the DAI name isn't guaranteed to be unique. Parts using the same codec driver (so the same DAI names) might require different machine driver setup. Instead, get the struct sdw_slave and extract the SoundWire part ID. Use this to lookup the entry in codec_info_list[]. This is the same identity info that was used to find the entry when the machine driver created the dailink. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Fixes: e377c94 ("ASoC: intel/sdw_utils: move soundwire codec_info_list structure") Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20260112140758.215799-3-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1ddbcb9 commit 5b027c7

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

sound/soc/sdw_utils/soc_sdw_utils.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,19 @@ struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_part(const u64 adr)
841841
}
842842
EXPORT_SYMBOL_NS(asoc_sdw_find_codec_info_part, "SND_SOC_SDW_UTILS");
843843

844+
static struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_sdw_id(const struct sdw_slave_id *id)
845+
{
846+
int i;
847+
848+
for (i = 0; i < ARRAY_SIZE(codec_info_list); i++)
849+
if (id->part_id == codec_info_list[i].part_id &&
850+
(!codec_info_list[i].version_id ||
851+
id->sdw_version == codec_info_list[i].version_id))
852+
return &codec_info_list[i];
853+
854+
return NULL;
855+
}
856+
844857
struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_acpi(const u8 *acpi_id)
845858
{
846859
int i;
@@ -873,22 +886,46 @@ struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_dai(const char *dai_name, i
873886
}
874887
EXPORT_SYMBOL_NS(asoc_sdw_find_codec_info_dai, "SND_SOC_SDW_UTILS");
875888

889+
static int asoc_sdw_find_codec_info_dai_index(const struct asoc_sdw_codec_info *codec_info,
890+
const char *dai_name)
891+
{
892+
int i;
893+
894+
for (i = 0; i < codec_info->dai_num; i++) {
895+
if (!strcmp(codec_info->dais[i].dai_name, dai_name))
896+
return i;
897+
}
898+
899+
return -ENOENT;
900+
}
901+
876902
int asoc_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
877903
{
878904
struct snd_soc_card *card = rtd->card;
879905
struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
880906
struct asoc_sdw_codec_info *codec_info;
881907
struct snd_soc_dai *dai;
908+
struct sdw_slave *sdw_peripheral;
882909
const char *spk_components="";
883910
int dai_index;
884911
int ret;
885912
int i;
886913

887914
for_each_rtd_codec_dais(rtd, i, dai) {
888-
codec_info = asoc_sdw_find_codec_info_dai(dai->name, &dai_index);
915+
if (is_sdw_slave(dai->component->dev))
916+
sdw_peripheral = dev_to_sdw_dev(dai->component->dev);
917+
else if (dai->component->dev->parent && is_sdw_slave(dai->component->dev->parent))
918+
sdw_peripheral = dev_to_sdw_dev(dai->component->dev->parent);
919+
else
920+
continue;
921+
922+
codec_info = asoc_sdw_find_codec_info_sdw_id(&sdw_peripheral->id);
889923
if (!codec_info)
890924
return -EINVAL;
891925

926+
dai_index = asoc_sdw_find_codec_info_dai_index(codec_info, dai->name);
927+
WARN_ON(dai_index < 0);
928+
892929
/*
893930
* A codec dai can be connected to different dai links for capture and playback,
894931
* but we only need to call the rtd_init function once.
@@ -898,6 +935,10 @@ int asoc_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
898935
if (codec_info->dais[dai_index].rtd_init_done)
899936
continue;
900937

938+
dev_dbg(card->dev, "%#x/%s initializing for %s/%s\n",
939+
codec_info->part_id, codec_info->dais[dai_index].dai_name,
940+
dai->component->name, dai->name);
941+
901942
/*
902943
* Add card controls and dapm widgets for the first codec dai.
903944
* The controls and widgets will be used for all codec dais.

0 commit comments

Comments
 (0)