Skip to content

Commit cac5f2a

Browse files
Shenghao-Dingtiwai
authored andcommitted
ALSA: hda/tas2781: Support L"SmartAmpCalibrationData" to save calibrated data
Some devices save the calibrated data into L"CALI_DATA", and others into L"SmartAmpCalibrationData". Driver code will support both. Signed-off-by: Shenghao Ding <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 8cbe564 commit cac5f2a

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

sound/hda/codecs/side-codecs/tas2781_hda.c

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "tas2781_hda.h"
2020

21+
#define CALIBRATION_DATA_AREA_NUM 2
22+
2123
const efi_guid_t tasdev_fct_efi_guid[] = {
2224
/* DELL */
2325
EFI_GUID(0xcc92382d, 0x6337, 0x41cb, 0xa8, 0x8b, 0x8e, 0xce, 0x74,
@@ -160,36 +162,51 @@ int tas2781_save_calibration(struct tas2781_hda *hda)
160162
* manufactory.
161163
*/
162164
efi_guid_t efi_guid = tasdev_fct_efi_guid[LENOVO];
163-
static efi_char16_t efi_name[] = TASDEVICE_CALIBRATION_DATA_NAME;
165+
/*
166+
* Some devices save the calibrated data into L"CALI_DATA",
167+
* and others into L"SmartAmpCalibrationData".
168+
*/
169+
static efi_char16_t *efi_name[CALIBRATION_DATA_AREA_NUM] = {
170+
L"CALI_DATA",
171+
L"SmartAmpCalibrationData",
172+
};
164173
struct tasdevice_priv *p = hda->priv;
165174
struct calidata *cali_data = &p->cali_data;
166175
unsigned long total_sz = 0;
167176
unsigned int attr, size;
168177
unsigned char *data;
169178
efi_status_t status;
179+
int i;
170180

171181
if (hda->catlog_id < LENOVO)
172182
efi_guid = tasdev_fct_efi_guid[hda->catlog_id];
173183

174184
cali_data->cali_dat_sz_per_dev = 20;
175185
size = p->ndev * (cali_data->cali_dat_sz_per_dev + 1);
176-
/* Get real size of UEFI variable */
177-
status = efi.get_variable(efi_name, &efi_guid, &attr, &total_sz, NULL);
178-
cali_data->total_sz = total_sz > size ? total_sz : size;
179-
if (status == EFI_BUFFER_TOO_SMALL) {
180-
/* Allocate data buffer of data_size bytes */
181-
data = p->cali_data.data = devm_kzalloc(p->dev,
182-
p->cali_data.total_sz, GFP_KERNEL);
183-
if (!data) {
184-
p->cali_data.total_sz = 0;
185-
return -ENOMEM;
186+
for (i = 0; i < CALIBRATION_DATA_AREA_NUM; i++) {
187+
/* Get real size of UEFI variable */
188+
status = efi.get_variable(efi_name[i], &efi_guid, &attr,
189+
&total_sz, NULL);
190+
cali_data->total_sz = total_sz > size ? total_sz : size;
191+
if (status == EFI_BUFFER_TOO_SMALL) {
192+
/* Allocate data buffer of data_size bytes */
193+
data = cali_data->data = devm_kzalloc(p->dev,
194+
cali_data->total_sz, GFP_KERNEL);
195+
if (!data) {
196+
status = -ENOMEM;
197+
continue;
198+
}
199+
/* Get variable contents into buffer */
200+
status = efi.get_variable(efi_name[i], &efi_guid,
201+
&attr, &cali_data->total_sz, data);
186202
}
187-
/* Get variable contents into buffer */
188-
status = efi.get_variable(efi_name, &efi_guid, &attr,
189-
&p->cali_data.total_sz, data);
203+
/* Check whether get the calibrated data */
204+
if (status == EFI_SUCCESS)
205+
break;
190206
}
207+
191208
if (status != EFI_SUCCESS) {
192-
p->cali_data.total_sz = 0;
209+
cali_data->total_sz = 0;
193210
return status;
194211
}
195212

sound/hda/codecs/side-codecs/tas2781_hda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/* Flag of calibration registers address. */
1313
#define TASDEV_UEFI_CALI_REG_ADDR_FLG BIT(7)
14-
#define TASDEVICE_CALIBRATION_DATA_NAME L"CALI_DATA"
14+
1515
#define TASDEV_CALIB_N 5
1616

1717
/*

0 commit comments

Comments
 (0)