Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: broonie@kernel.org
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: [PATCH 5/6] ASoC: cs-amp-lib: Add HP-specific EFI variable for calibration data
Date: Mon,  8 Sep 2025 16:58:41 +0100	[thread overview]
Message-ID: <20250908155842.599459-6-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20250908155842.599459-1-rf@opensource.cirrus.com>

Search for an HP-specific EFI variable for calibration before falling
back to the normal Cirrus Logic EFI variable.

Future HP models will use an HP-defined EFI variable for storage of
amp calibration data. The content is the same as the normal Cirrus
Logic EFI variable.

The first step in cs_amp_get_cal_efi_buffer() is to get the size of
the EFI variable, so this has been made a loop that walks through an
array of possible variables.

A small change is needed to the KUnit test, which is included in this
patch. Originally the cs_amp_lib_test_get_efi_variable() hook function
asserted that the passed name and GUID matched the Cirrus Logic EFI
variable. Obviously this will fail because the code now tries the HP
definition first. The function has been changed to return EFI_NOT_FOUND
instead, which emulates the normal behaviour of trying to get the HP
variable on a system that has the Cirrus variable.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 sound/soc/codecs/cs-amp-lib-test.c |  5 ++--
 sound/soc/codecs/cs-amp-lib.c      | 37 ++++++++++++++++++++++++------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/sound/soc/codecs/cs-amp-lib-test.c b/sound/soc/codecs/cs-amp-lib-test.c
index e7492afa041e..c090498cbf78 100644
--- a/sound/soc/codecs/cs-amp-lib-test.c
+++ b/sound/soc/codecs/cs-amp-lib-test.c
@@ -204,8 +204,9 @@ static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,
 	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, guid);
 	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, size);
 
-	KUNIT_EXPECT_MEMEQ(test, name, expected_name, sizeof(expected_name));
-	KUNIT_EXPECT_MEMEQ(test, guid, &expected_guid, sizeof(expected_guid));
+	if (memcmp(name, expected_name, sizeof(expected_name)) ||
+	    efi_guidcmp(*guid, expected_guid))
+		return -EFI_NOT_FOUND;
 
 	if (!buf) {
 		*size = priv->cal_blob->size;
diff --git a/sound/soc/codecs/cs-amp-lib.c b/sound/soc/codecs/cs-amp-lib.c
index 9b51d056d863..8434d5196107 100644
--- a/sound/soc/codecs/cs-amp-lib.c
+++ b/sound/soc/codecs/cs-amp-lib.c
@@ -28,6 +28,24 @@
 #define HP_SPEAKER_ID_EFI_GUID \
 	EFI_GUID(0xc49593a4, 0xd099, 0x419b, 0xa2, 0xc3, 0x67, 0xe9, 0x80, 0xe6, 0x1d, 0x1e)
 
+#define HP_CALIBRATION_EFI_NAME L"SmartAmpCalibrationData"
+#define HP_CALIBRATION_EFI_GUID \
+	EFI_GUID(0x53559579, 0x8753, 0x4f5c, 0x91, 0x30, 0xe8, 0x2a, 0xcf, 0xb8, 0xd8, 0x93)
+
+static const struct cs_amp_lib_cal_efivar {
+	efi_char16_t *name;
+	efi_guid_t *guid;
+} cs_amp_lib_cal_efivars[] = {
+	{
+		.name = HP_CALIBRATION_EFI_NAME,
+		.guid = &HP_CALIBRATION_EFI_GUID,
+	},
+	{
+		.name = CIRRUS_LOGIC_CALIBRATION_EFI_NAME,
+		.guid = &CIRRUS_LOGIC_CALIBRATION_EFI_GUID,
+	},
+};
+
 static int cs_amp_write_cal_coeff(struct cs_dsp *dsp,
 				  const struct cirrus_amp_cal_controls *controls,
 				  const char *ctl_name, u32 val)
@@ -146,12 +164,17 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
 	unsigned long data_size = 0;
 	u8 *data;
 	efi_status_t status;
-	int ret;
+	int i, ret;
+
+	/* Find EFI variable and get size */
+	for (i = 0; i < ARRAY_SIZE(cs_amp_lib_cal_efivars); i++) {
+		status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
+						 cs_amp_lib_cal_efivars[i].guid,
+						 &data_size, NULL);
+		if (status == EFI_BUFFER_TOO_SMALL)
+			break;
+	}
 
-	/* Get real size of UEFI variable */
-	status = cs_amp_get_efi_variable(CIRRUS_LOGIC_CALIBRATION_EFI_NAME,
-					 &CIRRUS_LOGIC_CALIBRATION_EFI_GUID,
-					 &data_size, NULL);
 	if (status != EFI_BUFFER_TOO_SMALL)
 		return ERR_PTR(-ENOENT);
 
@@ -165,8 +188,8 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
 	if (!data)
 		return ERR_PTR(-ENOMEM);
 
-	status = cs_amp_get_efi_variable(CIRRUS_LOGIC_CALIBRATION_EFI_NAME,
-					 &CIRRUS_LOGIC_CALIBRATION_EFI_GUID,
+	status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
+					 cs_amp_lib_cal_efivars[i].guid,
 					 &data_size, data);
 	if (status != EFI_SUCCESS) {
 		ret = -EINVAL;
-- 
2.39.5


  parent reply	other threads:[~2025-09-08 15:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 15:58 [PATCH 0/6] ASoC: cs35l56: Handle vendor-specific UEFI variables Richard Fitzgerald
2025-09-08 15:58 ` [PATCH 1/6] ASoC: cs-amp-lib: Rename defines for Cirrus Logic EFI Richard Fitzgerald
2025-09-08 15:58 ` [PATCH 2/6] ASoC: cs-amp-lib: Add handling for Lenovo and HP UEFI speaker ID Richard Fitzgerald
2025-09-08 15:58 ` [PATCH 3/6] ASoC: cs35l56: Check for vendor-specific speaker ID value Richard Fitzgerald
2025-09-08 15:58 ` [PATCH 4/6] ASoC: cs-amp-lib-test: Add tests for cs_amp_get_vendor_spkid() Richard Fitzgerald
2025-09-08 15:58 ` Richard Fitzgerald [this message]
2025-09-08 15:58 ` [PATCH 6/6] ASoC: cs-amp-lib-test: Add test for getting cal data from HP EFI Richard Fitzgerald

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=20250908155842.599459-6-rf@opensource.cirrus.com \
    --to=rf@opensource.cirrus.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.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