[PATCH 1/2] ASoC: SOF: Intel: reuse name prefix for duplicate SoundWire devices

Amaan Lalani <[email protected]>
Newsgroups gmane.linux.sound,gmane.linux.kernel
Message-ID <BY5PR02MB6370065815A8A47F536FE4CFA0AC2@BY5PR02MB6370.namprd02.prod.outlook.com>
Some firmware describes a single physical SoundWire peripheral with
multiple _ADR entries that differ only in SDCA class ID.

These entries currently consume separate amplifier indices when the
SoundWire machine description is built. This can cause the peripheral
that actually enumerates to receive a different name prefix from the
one expected by UCM.

Detect entries which differ only in class ID and reuse the name prefix
assigned to the first entry. Do not increment the amplifier index for
the duplicate entry.

Fixes: 5226d19d4cae ("ASoC: SOF: Intel: use sof_sdw as default SDW machine driver")

Assisted-by: LLM
Signed-off-by: Amaan Lalani <[email protected]>
---
 sound/soc/sof/intel/hda.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c
index 4dbba9186b29..c785e27089ea 100644
--- a/sound/soc/sof/intel/hda.c
+++ b/sound/soc/sof/intel/hda.c
@@ -1245,6 +1245,20 @@ static struct snd_soc_acpi_adr_device *find_acpi_adr_device(struct device *dev,
 			((u64)(sdw_device->id.sdw_version & 0xF) << 44) |
 			((u64)(sdw_device->bus->link_id & 0xF) << 48);
 
+	/*
+	 * Firmware may describe the same physical peripheral with multiple
+	 * _ADR entries that differ only in SDCA class ID. Reuse the prefix
+	 * so duplicate entries do not consume another amplifier index.
+	 */
+
+	for (j = 0; j < index; j++) {
+		if ((adr_dev[j].adr & ~SDW_CLASS_ID_MASK) ==
+		    (adr_dev[index].adr & ~SDW_CLASS_ID_MASK)) {
+			adr_dev[index].name_prefix = adr_dev[j].name_prefix;
+			goto done_name_prefix;
+		}
+	}
+
 	if (!codec_info_list[i].is_amp) {
 		/* For non-amp codecs, get name_prefix from codec_info_list[] */
 		adr_dev[index].name_prefix = devm_kasprintf(dev, GFP_KERNEL, "%s", name_prefix);
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.