Skip to contentSkip to conversation

ASoC: SDCA: Use Function Extension info for FDL

PATCH Superseded Maciej Strozek 2 participants 4 messages Nov 17 – Nov 20

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Maciej Strozek

author maintainer
#0 lore raw

PATCH 1/1 ASoC: SDCA: Use Function Extension info for FDL

Add additional way of selecting files for FDL using Function Extension ID and Function Extension Version, following Windows' SDCA driver usage of those controls for FDL.
Make sure the introduced FEID/FEV search path is separate from the 'legacy' SSID-only search path in case some vendors choose to re-use SSIDs for different SKUs and identify them by Function Extension controls instead.

Change-Id I6ac1a5e5c85b67c2e9e0eaff930bfefd5e89afaf
---
 sound/soc/sdca/sdca_fdl.c | 130 ++++++++++++++++++++++++--------------
 1 file changed, 82 insertions(+), 48 deletions(-)
sound/soc/sdca/sdca_fdl.c +82 -48
index 7fc809707944d..a6f58c7e6a64c 100644
@@ -147,47 +147,77 @@ int sdca_fdl_sync(struct device *dev, struct sdca_function_data *function,
 }
 EXPORT_SYMBOL_NS_GPL(sdca_fdl_sync, "SND_SOC_SDCA");
 
-static char *fdl_get_sku_filename(struct device *dev,
-				  struct sdca_fdl_file *fdl_file)
+static int fdl_get_sku_filename(struct sdca_interrupt *interrupt,
+				struct sdca_fdl_file *fdl_file,
+				char **disk_filename,
+				char **fallback_filename)
 {
-	struct device *parent = dev;
+	unsigned int adr = interrupt->function->desc->adr;
+	char extension[sizeof("fe0000v00/")] = "";
+	struct device *parent = interrupt->dev;
 	const char *product_vendor;
 	const char *product_sku;
+	unsigned int id = 0, version = 0;
+
+	regmap_read(interrupt->function_regmap,
+		    SDW_SDCA_CTL(adr, SDCA_ENTITY_TYPE_ENTITY_0,
+				 SDCA_CTL_ENTITY_0_FUNCTION_EXTENSION_ID, 0),
+		    &id);
+	regmap_read(interrupt->function_regmap,
+		    SDW_SDCA_CTL(adr, SDCA_ENTITY_TYPE_ENTITY_0,
+				 SDCA_CTL_ENTITY_0_FUNCTION_EXTENSION_VERSION, 0),
+		    &version);
+
+	if (id || version)
+		snprintf(extension, sizeof(extension), "fe%xv%x/", id, version);
 
 	/*
 	 * Try to find pci_dev manually because the card may not be ready to be
 	 * used for snd_soc_card_get_pci_ssid yet
 	 */
-	while (parent) {
-		if (dev_is_pci(parent)) {
-			struct pci_dev *pci_dev = to_pci_dev(parent);
-
-			return kasprintf(GFP_KERNEL, "sdca/%x/%x/%x/%x.bin",
-					 fdl_file->vendor_id,
-					 pci_dev->subsystem_vendor,
-					 pci_dev->subsystem_device,
-					 fdl_file->file_id);
-		} else {
-			parent = parent->parent;
-		}
+	while (parent && !dev_is_pci(parent))
+		parent = parent->parent;
+
+	if (parent) {
+		struct pci_dev *pci_dev = to_pci_dev(parent);
+
+		*disk_filename = kasprintf(GFP_KERNEL, "sdca/%x/%x/%x/%s%x.bin",
+					   fdl_file->vendor_id,
+					   pci_dev->subsystem_vendor,
+					   pci_dev->subsystem_device,
+					   extension, fdl_file->file_id);
+	} else {
+		product_vendor = dmi_get_system_info(DMI_SYS_VENDOR);
+		if (!product_vendor || !strcmp(product_vendor, "Default string"))
+			product_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
+		if (!product_vendor || !strcmp(product_vendor, "Default string"))
+			product_vendor = dmi_get_system_info(DMI_CHASSIS_VENDOR);
+		if (!product_vendor)
+			product_vendor = "unknown";
+
+		product_sku = dmi_get_system_info(DMI_PRODUCT_SKU);
+		if (!product_sku || !strcmp(product_sku, "Default string"))
+			product_sku = dmi_get_system_info(DMI_PRODUCT_NAME);
+		if (!product_sku)
+			product_sku = "unknown";
+
+		*disk_filename = kasprintf(GFP_KERNEL, "sdca/%x/%s/%s/%s%x.bin",
+					   fdl_file->vendor_id, product_vendor,
+					   product_sku, extension,
+					   fdl_file->file_id);
+	}
+
+	*fallback_filename = kasprintf(GFP_KERNEL, "sdca/%x/%s%x.bin",
+				       fdl_file->vendor_id, extension,
+				       fdl_file->file_id);
+
+	if (!*disk_filename || !*fallback_filename) {
+		kfree(*disk_filename);
+		kfree(*fallback_filename);
+		return -ENOMEM;
 	}
 
-	product_vendor = dmi_get_system_info(DMI_SYS_VENDOR);
-	if (!product_vendor || !strcmp(product_vendor, "Default string"))
-		product_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
-	if (!product_vendor || !strcmp(product_vendor, "Default string"))
-		product_vendor = dmi_get_system_info(DMI_CHASSIS_VENDOR);
-	if (!product_vendor)
-		product_vendor = "unknown";
-
-	product_sku = dmi_get_system_info(DMI_PRODUCT_SKU);
-	if (!product_sku || !strcmp(product_sku, "Default string"))
-		product_sku = dmi_get_system_info(DMI_PRODUCT_NAME);
-	if (!product_sku)
-		product_sku = "unknown";
-
-	return kasprintf(GFP_KERNEL, "sdca/%x/%s/%s/%x.bin", fdl_file->vendor_id,
-			 product_vendor, product_sku, fdl_file->file_id);
+	return 0;
 }
 
 static int fdl_load_file(struct sdca_interrupt *interrupt,
@@ -197,7 +227,9 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
 	struct sdca_fdl_data *fdl_data = &interrupt->function->fdl_data;
 	struct acpi_sw_file *swf = NULL, *tmp;
 	struct sdca_fdl_file *fdl_file;
-	char *disk_filename;
+	const char *source = "ACPI SWFT";
+	const char *disk_source;
+	char *disk_filename, *fallback_filename;
 	int ret;
 
 	if (!set) {
@@ -231,25 +263,21 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
 		}
 	}
 
-	disk_filename = fdl_get_sku_filename(dev, fdl_file);
-	if (!disk_filename)
-		return -ENOMEM;
+	ret = fdl_get_sku_filename(interrupt, fdl_file,
+				   &disk_filename, &fallback_filename);
+	if (ret)
+		return ret;
 
 	dev_dbg(dev, "FDL disk filename: %s\n", disk_filename);
 
 	const struct firmware *firmware __free(firmware) = NULL;
+	disk_source = disk_filename;
 	ret = firmware_request_nowarn(&firmware, disk_filename, dev);
-	kfree(disk_filename);
 	if (ret) {
-		disk_filename = kasprintf(GFP_KERNEL, "sdca/%x/%x.bin",
-					  fdl_file->vendor_id, fdl_file->file_id);
-		if (!disk_filename)
-			return -ENOMEM;
+		dev_dbg(dev, "FDL disk filename: %s\n", fallback_filename);
 
-		dev_dbg(dev, "FDL disk filename: %s\n", disk_filename);
-
-		ret = firmware_request_nowarn(&firmware, disk_filename, dev);
-		kfree(disk_filename);
+		disk_source = fallback_filename;
+		ret = firmware_request_nowarn(&firmware, fallback_filename, dev);
 	}
 
 	if (!ret) {
@@ -259,18 +287,19 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
 		    tmp->file_length != firmware->size) {
 			dev_err(dev, "bad disk SWF size\n");
 		} else if (!swf || swf->file_version <= tmp->file_version) {
-			dev_dbg(dev, "using SWF from disk\n");
 			swf = tmp;
+			source = disk_source;
 		}
 	}
 
 	if (!swf) {
 		dev_err(dev, "failed to locate SWF\n");
-		return -ENOENT;
+		ret = -ENOENT;
+		goto out_free;
 	}
 
-	dev_info(dev, "loading SWF: %x-%x-%x\n",
-		 swf->vendor_id, swf->file_id, swf->file_version);
+	dev_info(dev, "loading SWF: %x-%x-%x from %s\n",
+		 swf->vendor_id, swf->file_id, swf->file_version, source);
 
 	ret = sdca_ump_write_message(dev, interrupt->device_regmap,
 				     interrupt->function_regmap,
@@ -278,6 +307,11 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
 				     SDCA_CTL_XU_FDL_MESSAGEOFFSET, fdl_file->fdl_offset,
 				     SDCA_CTL_XU_FDL_MESSAGELENGTH, swf->data,
 				     swf->file_length - offsetof(struct acpi_sw_file, data));
+
+out_free:
+	kfree(disk_filename);
+	kfree(fallback_filename);
+
 	return ret;
 }
 
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 14 lines · Maciej Strozek

Add additional way of selecting files for FDL using Function Extension ID and Function Extension Version, following Windows' SDCA driver usage of those controls for FDL.
Make sure the introduced FEID/FEV search path is separate from the 'legacy' SSID-only search path in case some vendors choose to re-use SSIDs for different SKUs and identify them by Function Extension controls instead.

Change-Id I6ac1a5e5c85b67c2e9e0eaff930bfefd5e89afaf

---

sound/soc/sdca/sdca_fdl.c +0 -0
@@ -231,25 +263,21 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
 		}
 	}

sound/soc/sdca/sdca_fdl.c static int fdl_load_file(struct sdca_interrupt *interrupt, · line 271

Quoted 10 lines
sound/soc/sdca/sdca_fdl.c +4 -3
 
-	disk_filename = fdl_get_sku_filename(dev, fdl_file);
-	if (!disk_filename)
-		return -ENOMEM;
+	ret = fdl_get_sku_filename(interrupt, fdl_file,
+				   &disk_filename, &fallback_filename);
+	if (ret)
+		return ret;
 
 	dev_dbg(dev, "FDL disk filename: %s\n", disk_filename);

We should probably drop these FDL disk filename prints since the filename is now printed through source anyway.

Quoted 25 lines
sound/soc/sdca/sdca_fdl.c +4 -10
 	const struct firmware *firmware __free(firmware) = NULL;
+	disk_source = disk_filename;
 	ret = firmware_request_nowarn(&firmware, disk_filename, dev);
-	kfree(disk_filename);
 	if (ret) {
-		disk_filename = kasprintf(GFP_KERNEL, "sdca/%x/%x.bin",
-					  fdl_file->vendor_id, fdl_file->file_id);
-		if (!disk_filename)
-			return -ENOMEM;
+		dev_dbg(dev, "FDL disk filename: %s\n", fallback_filename);
 
-		dev_dbg(dev, "FDL disk filename: %s\n", disk_filename);
-
-		ret = firmware_request_nowarn(&firmware, disk_filename, dev);
-		kfree(disk_filename);
+		disk_source = fallback_filename;
+		ret = firmware_request_nowarn(&firmware, fallback_filename, dev);
 	}
 
 	if (!ret) {
@@ -259,18 +287,19 @@ static int fdl_load_file(struct sdca_interrupt *interrupt,
 		    tmp->file_length != firmware->size) {
 			dev_err(dev, "bad disk SWF size\n");
 		} else if (!swf || swf->file_version <= tmp->file_version) {
-			dev_dbg(dev, "using SWF from disk\n");

sound/soc/sdca/sdca_fdl.c static int fdl_load_file(struct sdca_interrupt *interrupt, · line 298

Quoted 10 lines
sound/soc/sdca/sdca_fdl.c +3 -1
 			swf = tmp;
+			source = disk_source;
 		}
 	}
 
 	if (!swf) {
 		dev_err(dev, "failed to locate SWF\n");
-		return -ENOENT;
+		ret = -ENOENT;
+		goto out_free;

We shouldn't mix goto clean up with the __free clean up. Probably better to use an else here for the UMP write.

Thanks,
Charles

Quoted 6 lines
sound/soc/sdca/sdca_fdl.c +2 -2
 	}
 
-	dev_info(dev, "loading SWF: %x-%x-%x\n",
-		 swf->vendor_id, swf->file_id, swf->file_version);
+	dev_info(dev, "loading SWF: %x-%x-%x from %s\n",
+		 swf->vendor_id, swf->file_id, swf->file_version, source);
author maintainer
#2 lore raw

W dniu śro, 18.11.2026 o godzinie 10∶54 +0000, użytkownik Charles

Quoted 12 lines · Keepax
Quoted 10 lines · Maciej Strozek

- disk_filename = fdl_get_sku_filename(dev, fdl_file);
- if (!disk_filename)
- return -ENOMEM;
+ ret = fdl_get_sku_filename(interrupt, fdl_file,
+    &disk_filename, &fallback_filename);
+ if (ret)
+ return ret;

  dev_dbg(dev, "FDL disk filename: %s\n", disk_filename);

Quoted 3 lines

We should probably drop these FDL disk filename prints since the filename is now printed through source anyway.

Quoted 1 line

Yes, in case it finds the file, but I think it might be useful to know what it attempted to read for debugging if it fails. Would moving those prints inside the (!swf) case be better?

Quoted 1 line
Signature · 2 lines
Regards,
Maciej
maintainer
#3 lore raw
Quoted 11 lines · Maciej Strozek

W dniu śro, 18.11.2026 o godzinie 10∶54 +0000, użytkownik Charles

Quoted 6 lines · Keepax
Quoted 1 line · Maciej Strozek

  dev_dbg(dev, "FDL disk filename: %s\n", disk_filename);

We should probably drop these FDL disk filename prints since the filename is now printed through source anyway.

Quoted 1 line

Yes, in case it finds the file, but I think it might be useful to know what it attempted to read for debugging if it fails. Would moving those prints inside the (!swf) case be better?

Yeah perhaps it would be nicer to print both the filenames in the "failed to locate SWF" message, you do probably want that info if the SWF failed to load.

Thanks,
Charles