[SRU][R][PATCH 3/3] ASoC: sdw_utils: add rt1320 and rt1321 dmic dai in codec_info_list

Aaron Ma aaron.ma at canonical.com
Mon Apr 27 06:19:34 UTC 2026


From: Derek Fang <derek.fang at realtek.com>

BugLink: https://bugs.launchpad.net/bugs/2150196

Add 'rt1320-aif2' dai infos for rt1320 and rt1321 dmic function.

Signed-off-by: Derek Fang <derek.fang at realtek.com>
Signed-off-by: Bard Liao <yung-chuan.liao at linux.intel.com>
Link: https://patch.msgid.link/20260326075303.1083567-4-yung-chuan.liao@linux.intel.com
Signed-off-by: Mark Brown <broonie at kernel.org>
(cherry picked from commit ae2cb3384337a556ce02e557fecd39db78c36e7d)
Signed-off-by: Aaron Ma <aaron.ma at canonical.com>
---
 sound/soc/sdw_utils/soc_sdw_rt_dmic.c | 46 +++++++++++++++++++++++++--
 sound/soc/sdw_utils/soc_sdw_utils.c   | 26 +++++++++++++--
 2 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/sound/soc/sdw_utils/soc_sdw_rt_dmic.c b/sound/soc/sdw_utils/soc_sdw_rt_dmic.c
index 97be110a59b63..fed85bad9e88c 100644
--- a/sound/soc/sdw_utils/soc_sdw_rt_dmic.c
+++ b/sound/soc/sdw_utils/soc_sdw_rt_dmic.c
@@ -9,15 +9,20 @@
 
 #include <linux/device.h>
 #include <linux/errno.h>
+#include <linux/soundwire/sdw.h>
+#include <linux/soundwire/sdw_type.h>
 #include <sound/soc.h>
 #include <sound/soc-acpi.h>
 #include <sound/soc_sdw_utils.h>
+#include <sound/sdca_function.h>
 
 int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
 {
 	struct snd_soc_card *card = rtd->card;
 	struct snd_soc_component *component;
+	struct sdw_slave *sdw_peripheral = NULL;
 	char *mic_name;
+	int rt1320_dmic_num = 0, part_id, i;
 
 	component = dai->component;
 
@@ -32,9 +37,44 @@ int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_da
 	if (!mic_name)
 		return -ENOMEM;
 
-	card->components = devm_kasprintf(card->dev, GFP_KERNEL,
-					  "%s mic:%s", card->components,
-					  mic_name);
+	/*
+	 * If there is any rt1320/rt1321 DMIC belonging to this card, try to count the `cfg-mics`
+	 * to be used in card->components.
+	 * Note: The rt1320 drivers register the peripheral dev to component->dev, so get the
+	 * sdw_peripheral from component->dev.
+	 */
+	if (is_sdw_slave(component->dev))
+		sdw_peripheral = dev_to_sdw_dev(component->dev);
+	if (sdw_peripheral &&
+	    (sdw_peripheral->id.part_id == 0x1320 || sdw_peripheral->id.part_id == 0x1321)) {
+		part_id = sdw_peripheral->id.part_id;
+		/*
+		 * This rtd init callback is called once, so count the rt1320/rt1321 with SDCA
+		 * function SmartMic type in this card.
+		 */
+		for_each_card_components(card, component) {
+			if (!is_sdw_slave(component->dev))
+				continue;
+			sdw_peripheral = dev_to_sdw_dev(component->dev);
+			if (sdw_peripheral->id.part_id != part_id)
+				continue;
+			for (i = 0; i < sdw_peripheral->sdca_data.num_functions; i++) {
+				if (sdw_peripheral->sdca_data.function[i].type ==
+				    SDCA_FUNCTION_TYPE_SMART_MIC) {
+					rt1320_dmic_num++;
+					break;
+				}
+			}
+		}
+		card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+						  "%s mic:%s cfg-mics:%d", card->components,
+						  mic_name, rt1320_dmic_num);
+	} else {
+		card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+						  "%s mic:%s", card->components,
+						  mic_name);
+	}
+
 	if (!card->components)
 		return -ENOMEM;
 
diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c
index 8f35fb0dfacff..52bfef9124275 100644
--- a/sound/soc/sdw_utils/soc_sdw_utils.c
+++ b/sound/soc/sdw_utils/soc_sdw_utils.c
@@ -319,6 +319,7 @@ struct asoc_sdw_codec_info codec_info_list[] = {
 	{
 		.part_id = 0x1320,
 		.name_prefix = "rt1320",
+		.is_amp = true,
 		.dais = {
 			{
 				.direction = {true, false},
@@ -334,12 +335,23 @@ struct asoc_sdw_codec_info codec_info_list[] = {
 				.widgets = generic_spk_widgets,
 				.num_widgets = ARRAY_SIZE(generic_spk_widgets),
 			},
+			{
+				.direction = {false, true},
+				.dai_name = "rt1320-aif2",
+				.component_name = "rt1320",
+				.dai_type = SOC_SDW_DAI_TYPE_MIC,
+				.dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+				.rtd_init = asoc_sdw_rt_dmic_rtd_init,
+				.widgets = generic_dmic_widgets,
+				.num_widgets = ARRAY_SIZE(generic_dmic_widgets),
+			},
 		},
-		.dai_num = 1,
+		.dai_num = 2,
 	},
 	{
 		.part_id = 0x1321,
 		.name_prefix = "rt1320",
+		.is_amp = true,
 		.dais = {
 			{
 				.direction = {true, false},
@@ -355,8 +367,18 @@ struct asoc_sdw_codec_info codec_info_list[] = {
 				.widgets = generic_spk_widgets,
 				.num_widgets = ARRAY_SIZE(generic_spk_widgets),
 			},
+			{
+				.direction = {false, true},
+				.dai_name = "rt1320-aif2",
+				.component_name = "rt1320",
+				.dai_type = SOC_SDW_DAI_TYPE_MIC,
+				.dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+				.rtd_init = asoc_sdw_rt_dmic_rtd_init,
+				.widgets = generic_dmic_widgets,
+				.num_widgets = ARRAY_SIZE(generic_dmic_widgets),
+			},
 		},
-		.dai_num = 1,
+		.dai_num = 2,
 	},
 	{
 		.part_id = 0x714,
-- 
2.43.0




More information about the kernel-team mailing list