Skip to content

Commit b195acf

Browse files
Shenghao-Dingbroonie
authored andcommitted
ASoC: tas2781: Fix wrong loading calibrated data sequence
Calibrated data will be set to default after loading DSP config params, which will cause speaker protection work abnormally. Reload calibrated data after loading DSP config params. Remove declaration of unused API which load calibrated data in wrong sequence, changed the copyright year and correct file name in license header. Fixes: ef3bcde ("ASoC: tas2781: Add tas2781 driver") Signed-off-by: Shenghao Ding <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 7078ac4 commit b195acf

File tree

3 files changed

+32
-82
lines changed

3 files changed

+32
-82
lines changed

include/sound/tas2781-dsp.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier
44
//
5-
// Copyright (C) 2022 - 2023 Texas Instruments Incorporated
5+
// Copyright (C) 2022 - 2024 Texas Instruments Incorporated
66
// https://www.ti.com
77
//
88
// The TAS2781 driver implements a flexible and configurable
@@ -13,8 +13,8 @@
1313
// Author: Kevin Lu <[email protected]>
1414
//
1515

16-
#ifndef __TASDEVICE_DSP_H__
17-
#define __TASDEVICE_DSP_H__
16+
#ifndef __TAS2781_DSP_H__
17+
#define __TAS2781_DSP_H__
1818

1919
#define MAIN_ALL_DEVICES 0x0d
2020
#define MAIN_DEVICE_A 0x01
@@ -180,7 +180,6 @@ void tasdevice_calbin_remove(void *context);
180180
int tasdevice_select_tuningprm_cfg(void *context, int prm,
181181
int cfg_no, int rca_conf_no);
182182
int tasdevice_prmg_load(void *context, int prm_no);
183-
int tasdevice_prmg_calibdata_load(void *context, int prm_no);
184183
void tasdevice_tuning_switch(void *context, int state);
185184
int tas2781_load_calibration(void *context, char *file_name,
186185
unsigned short i);

sound/soc/codecs/tas2781-fmwlib.c

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,24 @@ static int tasdevice_load_data(struct tasdevice_priv *tas_priv,
21512151
return ret;
21522152
}
21532153

2154+
static void tasdev_load_calibrated_data(struct tasdevice_priv *priv, int i)
2155+
{
2156+
struct tasdevice_calibration *cal;
2157+
struct tasdevice_fw *cal_fmw;
2158+
2159+
cal_fmw = priv->tasdevice[i].cali_data_fmw;
2160+
2161+
/* No calibrated data for current devices, playback will go ahead. */
2162+
if (!cal_fmw)
2163+
return;
2164+
2165+
cal = cal_fmw->calibrations;
2166+
if (cal)
2167+
return;
2168+
2169+
load_calib_data(priv, &cal->dev_data);
2170+
}
2171+
21542172
int tasdevice_select_tuningprm_cfg(void *context, int prm_no,
21552173
int cfg_no, int rca_conf_no)
21562174
{
@@ -2210,21 +2228,9 @@ int tasdevice_select_tuningprm_cfg(void *context, int prm_no,
22102228
for (i = 0; i < tas_priv->ndev; i++) {
22112229
if (tas_priv->tasdevice[i].is_loaderr == true)
22122230
continue;
2213-
else if (tas_priv->tasdevice[i].is_loaderr == false
2214-
&& tas_priv->tasdevice[i].is_loading == true) {
2215-
struct tasdevice_fw *cal_fmw =
2216-
tas_priv->tasdevice[i].cali_data_fmw;
2217-
2218-
if (cal_fmw) {
2219-
struct tasdevice_calibration
2220-
*cal = cal_fmw->calibrations;
2221-
2222-
if (cal)
2223-
load_calib_data(tas_priv,
2224-
&(cal->dev_data));
2225-
}
2231+
if (tas_priv->tasdevice[i].is_loaderr == false &&
2232+
tas_priv->tasdevice[i].is_loading == true)
22262233
tas_priv->tasdevice[i].cur_prog = prm_no;
2227-
}
22282234
}
22292235
}
22302236

@@ -2245,11 +2251,15 @@ int tasdevice_select_tuningprm_cfg(void *context, int prm_no,
22452251
tasdevice_load_data(tas_priv, &(conf->dev_data));
22462252
for (i = 0; i < tas_priv->ndev; i++) {
22472253
if (tas_priv->tasdevice[i].is_loaderr == true) {
2248-
status |= 1 << (i + 4);
2254+
status |= BIT(i + 4);
22492255
continue;
2250-
} else if (tas_priv->tasdevice[i].is_loaderr == false
2251-
&& tas_priv->tasdevice[i].is_loading == true)
2256+
}
2257+
2258+
if (tas_priv->tasdevice[i].is_loaderr == false &&
2259+
tas_priv->tasdevice[i].is_loading == true) {
2260+
tasdev_load_calibrated_data(tas_priv, i);
22522261
tas_priv->tasdevice[i].cur_conf = cfg_no;
2262+
}
22532263
}
22542264
} else
22552265
dev_dbg(tas_priv->dev, "%s: Unneeded loading dsp conf %d\n",
@@ -2308,65 +2318,6 @@ int tasdevice_prmg_load(void *context, int prm_no)
23082318
}
23092319
EXPORT_SYMBOL_NS_GPL(tasdevice_prmg_load, SND_SOC_TAS2781_FMWLIB);
23102320

2311-
int tasdevice_prmg_calibdata_load(void *context, int prm_no)
2312-
{
2313-
struct tasdevice_priv *tas_priv = (struct tasdevice_priv *) context;
2314-
struct tasdevice_fw *tas_fmw = tas_priv->fmw;
2315-
struct tasdevice_prog *program;
2316-
int prog_status = 0;
2317-
int i;
2318-
2319-
if (!tas_fmw) {
2320-
dev_err(tas_priv->dev, "%s: Firmware is NULL\n", __func__);
2321-
goto out;
2322-
}
2323-
2324-
if (prm_no >= tas_fmw->nr_programs) {
2325-
dev_err(tas_priv->dev,
2326-
"%s: prm(%d) is not in range of Programs %u\n",
2327-
__func__, prm_no, tas_fmw->nr_programs);
2328-
goto out;
2329-
}
2330-
2331-
for (i = 0, prog_status = 0; i < tas_priv->ndev; i++) {
2332-
if (prm_no >= 0 && tas_priv->tasdevice[i].cur_prog != prm_no) {
2333-
tas_priv->tasdevice[i].cur_conf = -1;
2334-
tas_priv->tasdevice[i].is_loading = true;
2335-
prog_status++;
2336-
}
2337-
tas_priv->tasdevice[i].is_loaderr = false;
2338-
}
2339-
2340-
if (prog_status) {
2341-
program = &(tas_fmw->programs[prm_no]);
2342-
tasdevice_load_data(tas_priv, &(program->dev_data));
2343-
for (i = 0; i < tas_priv->ndev; i++) {
2344-
if (tas_priv->tasdevice[i].is_loaderr == true)
2345-
continue;
2346-
else if (tas_priv->tasdevice[i].is_loaderr == false
2347-
&& tas_priv->tasdevice[i].is_loading == true) {
2348-
struct tasdevice_fw *cal_fmw =
2349-
tas_priv->tasdevice[i].cali_data_fmw;
2350-
2351-
if (cal_fmw) {
2352-
struct tasdevice_calibration *cal =
2353-
cal_fmw->calibrations;
2354-
2355-
if (cal)
2356-
load_calib_data(tas_priv,
2357-
&(cal->dev_data));
2358-
}
2359-
tas_priv->tasdevice[i].cur_prog = prm_no;
2360-
}
2361-
}
2362-
}
2363-
2364-
out:
2365-
return prog_status;
2366-
}
2367-
EXPORT_SYMBOL_NS_GPL(tasdevice_prmg_calibdata_load,
2368-
SND_SOC_TAS2781_FMWLIB);
2369-
23702321
void tasdevice_tuning_switch(void *context, int state)
23712322
{
23722323
struct tasdevice_priv *tas_priv = (struct tasdevice_priv *) context;

sound/soc/codecs/tas2781-i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// ALSA SoC Texas Instruments TAS2563/TAS2781 Audio Smart Amplifier
44
//
5-
// Copyright (C) 2022 - 2023 Texas Instruments Incorporated
5+
// Copyright (C) 2022 - 2024 Texas Instruments Incorporated
66
// https://www.ti.com
77
//
88
// The TAS2563/TAS2781 driver implements a flexible and configurable
@@ -414,7 +414,7 @@ static void tasdevice_fw_ready(const struct firmware *fmw,
414414
__func__, tas_priv->cal_binaryname[i]);
415415
}
416416

417-
tasdevice_prmg_calibdata_load(tas_priv, 0);
417+
tasdevice_prmg_load(tas_priv, 0);
418418
tas_priv->cur_prog = 0;
419419
out:
420420
if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {

0 commit comments

Comments
 (0)