Skip to content

Commit b78dd64

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs-amp-lib: Add HP-specific EFI variable for calibration data
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> Message-ID: <20250909113039.922065-6-rf@opensource.cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 7a4e5f4 commit b78dd64

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

sound/soc/codecs/cs-amp-lib-test.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name,
204204
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, guid);
205205
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, size);
206206

207-
KUNIT_EXPECT_MEMEQ(test, name, expected_name, sizeof(expected_name));
208-
KUNIT_EXPECT_MEMEQ(test, guid, &expected_guid, sizeof(expected_guid));
207+
if (memcmp(name, expected_name, sizeof(expected_name)) ||
208+
efi_guidcmp(*guid, expected_guid))
209+
return -EFI_NOT_FOUND;
209210

210211
if (!buf) {
211212
*size = priv->cal_blob->size;

sound/soc/codecs/cs-amp-lib.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@
2828
#define HP_SPEAKER_ID_EFI_GUID \
2929
EFI_GUID(0xc49593a4, 0xd099, 0x419b, 0xa2, 0xc3, 0x67, 0xe9, 0x80, 0xe6, 0x1d, 0x1e)
3030

31+
#define HP_CALIBRATION_EFI_NAME L"SmartAmpCalibrationData"
32+
#define HP_CALIBRATION_EFI_GUID \
33+
EFI_GUID(0x53559579, 0x8753, 0x4f5c, 0x91, 0x30, 0xe8, 0x2a, 0xcf, 0xb8, 0xd8, 0x93)
34+
35+
static const struct cs_amp_lib_cal_efivar {
36+
efi_char16_t *name;
37+
efi_guid_t *guid;
38+
} cs_amp_lib_cal_efivars[] = {
39+
{
40+
.name = HP_CALIBRATION_EFI_NAME,
41+
.guid = &HP_CALIBRATION_EFI_GUID,
42+
},
43+
{
44+
.name = CIRRUS_LOGIC_CALIBRATION_EFI_NAME,
45+
.guid = &CIRRUS_LOGIC_CALIBRATION_EFI_GUID,
46+
},
47+
};
48+
3149
static int cs_amp_write_cal_coeff(struct cs_dsp *dsp,
3250
const struct cirrus_amp_cal_controls *controls,
3351
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)
146164
unsigned long data_size = 0;
147165
u8 *data;
148166
efi_status_t status;
149-
int ret;
167+
int i, ret;
168+
169+
/* Find EFI variable and get size */
170+
for (i = 0; i < ARRAY_SIZE(cs_amp_lib_cal_efivars); i++) {
171+
status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
172+
cs_amp_lib_cal_efivars[i].guid,
173+
&data_size, NULL);
174+
if (status == EFI_BUFFER_TOO_SMALL)
175+
break;
176+
}
150177

151-
/* Get real size of UEFI variable */
152-
status = cs_amp_get_efi_variable(CIRRUS_LOGIC_CALIBRATION_EFI_NAME,
153-
&CIRRUS_LOGIC_CALIBRATION_EFI_GUID,
154-
&data_size, NULL);
155178
if (status != EFI_BUFFER_TOO_SMALL)
156179
return ERR_PTR(-ENOENT);
157180

@@ -165,8 +188,8 @@ static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev)
165188
if (!data)
166189
return ERR_PTR(-ENOMEM);
167190

168-
status = cs_amp_get_efi_variable(CIRRUS_LOGIC_CALIBRATION_EFI_NAME,
169-
&CIRRUS_LOGIC_CALIBRATION_EFI_GUID,
191+
status = cs_amp_get_efi_variable(cs_amp_lib_cal_efivars[i].name,
192+
cs_amp_lib_cal_efivars[i].guid,
170193
&data_size, data);
171194
if (status != EFI_SUCCESS) {
172195
ret = -EINVAL;

0 commit comments

Comments
 (0)