Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: linux-sound@vger.kernel.org
Cc: alsa-devel@alsa-project.org, tiwai@suse.de, broonie@kernel.org,
	"Bard Liao" <yung-chuan.liao@linux.intel.com>,
	"Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>
Subject: [PATCH 15/18] ASoC: Intel: sof_sdw: add controls and dapm widgets in codec_info
Date: Thu,  9 May 2024 11:34:15 -0500	[thread overview]
Message-ID: <20240509163418.67746-16-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20240509163418.67746-1-pierre-louis.bossart@linux.intel.com>

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,
-- 
2.40.1


  parent reply	other threads:[~2024-05-09 16:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09 16:34 [PATCH 00/18] ASoC: Intel: updates for 6.10 - part7 Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 01/18] ASoC: Intel: sof_sdw_rt_sdca_jack_common: remove -sdca for new codecs Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 02/18] ASoC: Intel: sof-rt5682: remove DMI quirk for hatch Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 03/18] ASoC: Intel: sof_rt5682: board id cleanup for mtl boards Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 04/18] ASoC: Intel: realtek-common: remove 2-spk rt1015p config Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 05/18] ASoC: Intel: soc-acpi-intel-mtl-match: add cs42l43 only support Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 06/18] ASoC: Intel: soc-acpi-intel-lnl-match: " Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 07/18] ASoC: Intel: maxim-common: add max_98373_dai_link function Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 08/18] ASoC: Intel: sof_da7219: use " Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 09/18] ASoC: Intel: sof_nau8825: " Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 10/18] ASoC: Intel: sof_rt5682: " Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 11/18] ASoC: Intel: sof_sdw: add max98373 dapm routes Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 12/18] ASoC: Intel: maxim-common: change max98373 data to static Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 13/18] ASoC: Intel: sof_sdw_cs_amp: rename Speakers to Speaker Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 14/18] ASoC: Intel: sof_sdw: use generic name for controls/widgets Pierre-Louis Bossart
2024-05-09 16:34 ` Pierre-Louis Bossart [this message]
2024-05-09 16:34 ` [PATCH 16/18] ASoC: Intel: sof_sdw: use .controls/.widgets to add controls/widgets Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 17/18] ASoC: Intel: sof_sdw: add dai parameter to rtd_init callback Pierre-Louis Bossart
2024-05-09 16:34 ` [PATCH 18/18] ASoC: Intel: sof_sdw_rt_amp: use dai parameter Pierre-Louis Bossart
2024-05-10 13:18 ` [PATCH 00/18] ASoC: Intel: updates for 6.10 - part7 Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240509163418.67746-16-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=tiwai@suse.de \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox