From: Bard Liao yung-chuan.liao@linux.intel.com
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: Péter Ujfalusi peter.ujfalusi@linux.intel.com Signed-off-by: Bard Liao yung-chuan.liao@linux.intel.com Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com --- sound/soc/intel/boards/sof_sdw.c | 31 +++++++++++++++++++++++++ sound/soc/intel/boards/sof_sdw_common.h | 4 ++++ 2 files changed, 35 insertions(+)
diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index 2b97972f85ef..3acc2db61b35 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -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) diff --git a/sound/soc/intel/boards/sof_sdw_common.h b/sound/soc/intel/boards/sof_sdw_common.h index 94657dd210f5..a8ba39bd5fd8 100644 --- a/sound/soc/intel/boards/sof_sdw_common.h +++ b/sound/soc/intel/boards/sof_sdw_common.h @@ -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,