Commit 70d470f0 authored by Bard Liao's avatar Bard Liao Committed by Mark Brown

ASoC: Intel: sof_sdw: add controls and dapm widgets in codec_info

Currently, we add card controls and dapm widgets one by one in the
codec_info->dais->rtd_init callback. Duplicated controls and dapm
widgets will be added if there are more than one types of amps in the
dai link. Moving it to sof_sdw_rtd_init() and only add the
controls/widgets of the first codec dai can avoid the duplications.
Reviewed-by: default avatarPéter Ujfalusi <peter.ujfalusi@linux.intel.com>
Signed-off-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20240509163418.67746-16-pierre-louis.bossart@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 01c266af
......@@ -1248,6 +1248,7 @@ static const char *get_codec_name(struct device *dev,
static int sof_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
struct sof_sdw_codec_info *codec_info;
struct snd_soc_dai *dai;
int dai_index;
......@@ -1267,6 +1268,36 @@ static int sof_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
*/
if (codec_info->dais[dai_index].rtd_init_done)
continue;
/*
* Add card controls and dapm widgets for the first codec dai.
* The controls and widgets will be used for all codec dais.
*/
if (i > 0)
goto skip_add_controls_widgets;
if (codec_info->dais[dai_index].controls) {
ret = snd_soc_add_card_controls(card, codec_info->dais[dai_index].controls,
codec_info->dais[dai_index].num_controls);
if (ret) {
dev_err(card->dev, "%#x controls addition failed: %d\n",
codec_info->part_id, ret);
return ret;
}
}
if (codec_info->dais[dai_index].widgets) {
ret = snd_soc_dapm_new_controls(&card->dapm,
codec_info->dais[dai_index].widgets,
codec_info->dais[dai_index].num_widgets);
if (ret) {
dev_err(card->dev, "%#x widgets addition failed: %d\n",
codec_info->part_id, ret);
return ret;
}
}
skip_add_controls_widgets:
if (codec_info->dais[dai_index].rtd_init) {
ret = codec_info->dais[dai_index].rtd_init(rtd);
if (ret)
......
......@@ -86,6 +86,10 @@ struct sof_sdw_dai_info {
const char *dai_name;
const int dai_type;
const int dailink[2]; /* dailink id for each direction */
const struct snd_kcontrol_new *controls;
const int num_controls;
const struct snd_soc_dapm_widget *widgets;
const int num_widgets;
int (*init)(struct snd_soc_card *card,
struct snd_soc_dai_link *dai_links,
struct sof_sdw_codec_info *info,
......
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