[SRU][R][PATCH 06/18] ASoC: cs-amp-lib: Support Dell SSIDExV2 UEFI variable
Chris Chiu
chris.chiu at canonical.com
Tue Mar 17 05:21:51 UTC 2026
From: Richard Fitzgerald <rf at opensource.cirrus.com>
BugLink: https://bugs.launchpad.net/bugs/2139391
Add a function cs_amp_devm_get_vendor_specific_variant_id() to return
a vendor-specific hardware identifier string (if there is one) and use
it to fetch an identifier from Dell SSIDExV2 UEFI variable content.
Dell use the same PCI SSID on multiple products that might have different
audio hardware and thus need different firmware for the amplifier DSP.
The SSIDExV2 string contains additional system identifiers, and the
second field is a 2-character audio hardware identifier.
There are older Dell models with Cirrus Logic amplifiers that have the
SSIDExV2 UEFI variable but do not have the 2-character audio ID in the
second field. The SSIDExV2 is ignored if the second field is not
2 characters.
Signed-off-by: Richard Fitzgerald <rf at opensource.cirrus.com>
Link: https://patch.msgid.link/20260121132243.1256019-2-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie at kernel.org>
(backported from commit 00fd40bc7acecf9f41d645aa0b35ddc7fd7679b6 linux-next)
[ChrisChiu: ignore funtions and variables not related to Dell]
Signed-off-by: Chris Chiu <chris.chiu at canonical.com>
---
include/sound/cs-amp-lib.h | 4 +-
sound/soc/codecs/cs-amp-lib.c | 129 ++++++++++++++++++++++++++++++++++
2 files changed, 132 insertions(+), 1 deletion(-)
diff --git a/include/sound/cs-amp-lib.h b/include/sound/cs-amp-lib.h
index 684c119c4d7b..356f7abec6ca 100644
--- a/include/sound/cs-amp-lib.h
+++ b/include/sound/cs-amp-lib.h
@@ -49,7 +49,9 @@ int cs_amp_write_cal_coeffs(struct cs_dsp *dsp,
const struct cirrus_amp_cal_data *data);
int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index,
struct cirrus_amp_cal_data *out_data);
-
+const char *cs_amp_devm_get_vendor_specific_variant_id(struct device *dev,
+ int ssid_vendor,
+ int ssid_device);
struct cs_amp_test_hooks {
efi_status_t (*get_efi_variable)(efi_char16_t *name,
efi_guid_t *guid,
diff --git a/sound/soc/codecs/cs-amp-lib.c b/sound/soc/codecs/cs-amp-lib.c
index d5f2025f1978..75e3ccebdc90 100644
--- a/sound/soc/codecs/cs-amp-lib.c
+++ b/sound/soc/codecs/cs-amp-lib.c
@@ -12,6 +12,7 @@
#include <linux/firmware/cirrus/cs_dsp.h>
#include <linux/module.h>
#include <linux/overflow.h>
+#include <linux/pci_ids.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <sound/cs-amp-lib.h>
@@ -21,6 +22,10 @@
#define CS_AMP_CAL_NAME L"CirrusSmartAmpCalibrationData"
+#define DELL_SSIDEXV2_EFI_NAME L"SSIDexV2Data"
+#define DELL_SSIDEXV2_EFI_GUID \
+ EFI_GUID(0x6a5f35df, 0x1432, 0x4656, 0x85, 0x97, 0x31, 0x04, 0xd5, 0xbf, 0x3a, 0xb0)
+
static int cs_amp_write_cal_coeff(struct cs_dsp *dsp,
const struct cirrus_amp_cal_controls *controls,
const char *ctl_name, u32 val)
@@ -120,6 +125,47 @@ static efi_status_t cs_amp_get_efi_variable(efi_char16_t *name,
return EFI_NOT_FOUND;
}
+static int cs_amp_convert_efi_status(efi_status_t status)
+{
+ switch (status) {
+ case EFI_SUCCESS:
+ return 0;
+ case EFI_NOT_FOUND:
+ return -ENOENT;
+ case EFI_BUFFER_TOO_SMALL:
+ return -EFBIG;
+ case EFI_UNSUPPORTED:
+ case EFI_ACCESS_DENIED:
+ case EFI_SECURITY_VIOLATION:
+ return -EACCES;
+ default:
+ return -EIO;
+ }
+}
+
+static void *cs_amp_alloc_get_efi_variable(efi_char16_t *name,
+ efi_guid_t *guid,
+ u32 *returned_attr)
+{
+ efi_status_t status;
+ unsigned long size = 0;
+
+ status = cs_amp_get_efi_variable(name, guid, NULL, &size, NULL);
+ if (status != EFI_BUFFER_TOO_SMALL)
+ return ERR_PTR(cs_amp_convert_efi_status(status));
+
+ /* Over-alloc to ensure strings are always NUL-terminated */
+ void *buf __free(kfree) = kzalloc(size + 1, GFP_KERNEL);
+ if (!buf)
+ return ERR_PTR(-ENOMEM);
+
+ status = cs_amp_get_efi_variable(name, guid, returned_attr, &size, buf);
+ if (status != EFI_SUCCESS)
+ return ERR_PTR(cs_amp_convert_efi_status(status));
+
+ return_ptr(buf);
+}
+
static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
{
struct cirrus_amp_efi_data *efi_data;
@@ -278,6 +324,89 @@ int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_
}
EXPORT_SYMBOL_NS_GPL(cs_amp_get_efi_calibration_data, "SND_SOC_CS_AMP_LIB");
+static const char *cs_amp_devm_get_dell_ssidex(struct device *dev,
+ int ssid_vendor, int ssid_device)
+{
+ unsigned int hex_prefix;
+ char audio_id[4];
+ char delim;
+ char *p;
+ int ret;
+
+ if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE) &&
+ !IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST))
+ return ERR_PTR(-ENOENT);
+
+ char *ssidex_buf __free(kfree) = cs_amp_alloc_get_efi_variable(DELL_SSIDEXV2_EFI_NAME,
+ &DELL_SSIDEXV2_EFI_GUID,
+ NULL);
+ ret = PTR_ERR_OR_ZERO(ssidex_buf);
+ if (ret == -ENOENT)
+ return ERR_PTR(-ENOENT);
+ else if (ret < 0)
+ return ssidex_buf;
+
+ /*
+ * SSIDExV2 string is a series of underscore delimited fields.
+ * First field is all or part of the SSID. Second field should be
+ * a 2-character audio hardware id, followed by other identifiers.
+ * Older models did not have the 2-character audio id, so reject
+ * the string if the second field is not 2 characters.
+ */
+ ret = sscanf(ssidex_buf, "%8x_%2s%c", &hex_prefix, audio_id, &delim);
+ if (ret < 2)
+ return ERR_PTR(-ENOENT);
+
+ if ((ret == 3) && (delim != '_'))
+ return ERR_PTR(-ENOENT);
+
+ if (strlen(audio_id) != 2)
+ return ERR_PTR(-ENOENT);
+
+ p = devm_kstrdup(dev, audio_id, GFP_KERNEL);
+ if (!p)
+ return ERR_PTR(-ENOMEM);
+
+ return p;
+}
+
+/**
+ * cs_amp_devm_get_vendor_specific_variant_id - get variant ID string
+ * @dev: pointer to struct device
+ * @ssid_vendor: PCI Subsystem Vendor (-1 if unknown)
+ * @ssid_device: PCI Subsystem Device (-1 if unknown)
+ *
+ * Known vendor-specific hardware identifiers are checked and if one is
+ * found its content is returned as a NUL-terminated string. The returned
+ * string is devm-managed.
+ *
+ * The returned string is not guaranteed to be globally unique.
+ * Generally it should be combined with some other qualifier, such as
+ * PCI SSID, to create a globally unique ID.
+ *
+ * If the caller has a PCI SSID it should pass it in @ssid_vendor and
+ * @ssid_device. If the vendor-spefic ID contains this SSID it will be
+ * stripped from the returned string to prevent duplication.
+ *
+ * If the caller does not have a PCI SSID, pass -1 for @ssid_vendor and
+ * @ssid_device.
+ *
+ * Return:
+ * * a pointer to a devm-managed string
+ * * ERR_PTR(-ENOENT) if no vendor-specific qualifier
+ * * ERR_PTR error value
+ */
+const char *cs_amp_devm_get_vendor_specific_variant_id(struct device *dev,
+ int ssid_vendor,
+ int ssid_device)
+{
+ if ((ssid_vendor == PCI_VENDOR_ID_DELL) || (ssid_vendor < 0))
+ return cs_amp_devm_get_dell_ssidex(dev, ssid_vendor, ssid_device);
+
+ return ERR_PTR(-ENOENT);
+}
+EXPORT_SYMBOL_NS_GPL(cs_amp_devm_get_vendor_specific_variant_id, "SND_SOC_CS_AMP_LIB");
+
static const struct cs_amp_test_hooks cs_amp_test_hook_ptrs = {
.get_efi_variable = cs_amp_get_efi_variable,
.write_cal_coeff = cs_amp_write_cal_coeff,
--
2.43.0
More information about the kernel-team
mailing list