2024-05-18 14:17:53

by Shenghao Ding

[permalink] [raw]
Subject: [PATCH v6] 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: ef3bcde75d06 ("ASoc: tas2781: Add tas2781 driver")
Signed-off-by: Shenghao Ding <[email protected]>

---
v6:
- Merge into one patch
v5:
- correct changelog has no much relationship with the patch
v4:
- Use the the culprit of the bug itself as the fixes tag
- Better variant for tasdev_load_calibrated_data in order to much easier
to read and understand and maintain, as it makes harder to squeeze the
code.
- Fix the indentation and move operator to the previous line.
v3:
- No changes.
- Remove redundant return in tasdev_load_calibrated_data
- Put the second function parameter into the previous line for
tasdev_load_calibrated_data
v2:
- In the Subject, fixed --> Fix
- Add Fixes tag
- dsp --> DSP
- Changed the copyright year to 2024 in the related files
- In tas2781-dsp.h, __TASDEVICE_DSP_H__ --> __TAS2781_DSP_H__
v1:
- Download calibrated data after loading the new DSP config params
- Remove tasdevice_prmg_calibdata_load, because it is unnecessary to load
calibrated data after loading DSP program.
- call tasdevice_prmg_load instead of tasdevice_prmg_calibdata_load, it
is unnecessary to load calibrated data after loading DSP program. Load
it after loading DSP config params each time.
---
include/sound/tas2781-dsp.h | 7 +-
sound/soc/codecs/tas2781-fmwlib.c | 103 ++++++++----------------------
sound/soc/codecs/tas2781-i2c.c | 4 +-
3 files changed, 32 insertions(+), 82 deletions(-)

diff --git a/include/sound/tas2781-dsp.h b/include/sound/tas2781-dsp.h
index ea9af2726a53..7fba7ea26a4b 100644
--- a/include/sound/tas2781-dsp.h
+++ b/include/sound/tas2781-dsp.h
@@ -2,7 +2,7 @@
//
// ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier
//
-// Copyright (C) 2022 - 2023 Texas Instruments Incorporated
+// Copyright (C) 2022 - 2024 Texas Instruments Incorporated
// https://www.ti.com
//
// The TAS2781 driver implements a flexible and configurable
@@ -13,8 +13,8 @@
// Author: Kevin Lu <[email protected]>
//

-#ifndef __TASDEVICE_DSP_H__
-#define __TASDEVICE_DSP_H__
+#ifndef __TAS2781_DSP_H__
+#define __TAS2781_DSP_H__

#define MAIN_ALL_DEVICES 0x0d
#define MAIN_DEVICE_A 0x01
@@ -180,7 +180,6 @@ void tasdevice_calbin_remove(void *context);
int tasdevice_select_tuningprm_cfg(void *context, int prm,
int cfg_no, int rca_conf_no);
int tasdevice_prmg_load(void *context, int prm_no);
-int tasdevice_prmg_calibdata_load(void *context, int prm_no);
void tasdevice_tuning_switch(void *context, int state);
int tas2781_load_calibration(void *context, char *file_name,
unsigned short i);
diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-fmwlib.c
index a6be81adcb83..265a8ca25cbb 100644
--- a/sound/soc/codecs/tas2781-fmwlib.c
+++ b/sound/soc/codecs/tas2781-fmwlib.c
@@ -2151,6 +2151,24 @@ static int tasdevice_load_data(struct tasdevice_priv *tas_priv,
return ret;
}

+static void tasdev_load_calibrated_data(struct tasdevice_priv *priv, int i)
+{
+ struct tasdevice_calibration *cal;
+ struct tasdevice_fw *cal_fmw;
+
+ cal_fmw = priv->tasdevice[i].cali_data_fmw;
+
+ /* No calibrated data for current devices, playback will go ahead. */
+ if (!cal_fmw)
+ return;
+
+ cal = cal_fmw->calibrations;
+ if (cal)
+ return;
+
+ load_calib_data(priv, &cal->dev_data);
+}
+
int tasdevice_select_tuningprm_cfg(void *context, int prm_no,
int cfg_no, int rca_conf_no)
{
@@ -2210,21 +2228,9 @@ int tasdevice_select_tuningprm_cfg(void *context, int prm_no,
for (i = 0; i < tas_priv->ndev; i++) {
if (tas_priv->tasdevice[i].is_loaderr == true)
continue;
- else if (tas_priv->tasdevice[i].is_loaderr == false
- && tas_priv->tasdevice[i].is_loading == true) {
- struct tasdevice_fw *cal_fmw =
- tas_priv->tasdevice[i].cali_data_fmw;
-
- if (cal_fmw) {
- struct tasdevice_calibration
- *cal = cal_fmw->calibrations;
-
- if (cal)
- load_calib_data(tas_priv,
- &(cal->dev_data));
- }
+ if (tas_priv->tasdevice[i].is_loaderr == false &&
+ tas_priv->tasdevice[i].is_loading == true)
tas_priv->tasdevice[i].cur_prog = prm_no;
- }
}
}

@@ -2245,11 +2251,15 @@ int tasdevice_select_tuningprm_cfg(void *context, int prm_no,
tasdevice_load_data(tas_priv, &(conf->dev_data));
for (i = 0; i < tas_priv->ndev; i++) {
if (tas_priv->tasdevice[i].is_loaderr == true) {
- status |= 1 << (i + 4);
+ status |= BIT(i + 4);
continue;
- } else if (tas_priv->tasdevice[i].is_loaderr == false
- && tas_priv->tasdevice[i].is_loading == true)
+ }
+
+ if (tas_priv->tasdevice[i].is_loaderr == false &&
+ tas_priv->tasdevice[i].is_loading == true) {
+ tasdev_load_calibrated_data(tas_priv, i);
tas_priv->tasdevice[i].cur_conf = cfg_no;
+ }
}
} else
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)
}
EXPORT_SYMBOL_NS_GPL(tasdevice_prmg_load, SND_SOC_TAS2781_FMWLIB);

-int tasdevice_prmg_calibdata_load(void *context, int prm_no)
-{
- struct tasdevice_priv *tas_priv = (struct tasdevice_priv *) context;
- struct tasdevice_fw *tas_fmw = tas_priv->fmw;
- struct tasdevice_prog *program;
- int prog_status = 0;
- int i;
-
- if (!tas_fmw) {
- dev_err(tas_priv->dev, "%s: Firmware is NULL\n", __func__);
- goto out;
- }
-
- if (prm_no >= tas_fmw->nr_programs) {
- dev_err(tas_priv->dev,
- "%s: prm(%d) is not in range of Programs %u\n",
- __func__, prm_no, tas_fmw->nr_programs);
- goto out;
- }
-
- for (i = 0, prog_status = 0; i < tas_priv->ndev; i++) {
- if (prm_no >= 0 && tas_priv->tasdevice[i].cur_prog != prm_no) {
- tas_priv->tasdevice[i].cur_conf = -1;
- tas_priv->tasdevice[i].is_loading = true;
- prog_status++;
- }
- tas_priv->tasdevice[i].is_loaderr = false;
- }
-
- if (prog_status) {
- program = &(tas_fmw->programs[prm_no]);
- tasdevice_load_data(tas_priv, &(program->dev_data));
- for (i = 0; i < tas_priv->ndev; i++) {
- if (tas_priv->tasdevice[i].is_loaderr == true)
- continue;
- else if (tas_priv->tasdevice[i].is_loaderr == false
- && tas_priv->tasdevice[i].is_loading == true) {
- struct tasdevice_fw *cal_fmw =
- tas_priv->tasdevice[i].cali_data_fmw;
-
- if (cal_fmw) {
- struct tasdevice_calibration *cal =
- cal_fmw->calibrations;
-
- if (cal)
- load_calib_data(tas_priv,
- &(cal->dev_data));
- }
- tas_priv->tasdevice[i].cur_prog = prm_no;
- }
- }
- }
-
-out:
- return prog_status;
-}
-EXPORT_SYMBOL_NS_GPL(tasdevice_prmg_calibdata_load,
- SND_SOC_TAS2781_FMWLIB);
-
void tasdevice_tuning_switch(void *context, int state)
{
struct tasdevice_priv *tas_priv = (struct tasdevice_priv *) context;
diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c
index b5abff230e43..9350972dfefe 100644
--- a/sound/soc/codecs/tas2781-i2c.c
+++ b/sound/soc/codecs/tas2781-i2c.c
@@ -2,7 +2,7 @@
//
// ALSA SoC Texas Instruments TAS2563/TAS2781 Audio Smart Amplifier
//
-// Copyright (C) 2022 - 2023 Texas Instruments Incorporated
+// Copyright (C) 2022 - 2024 Texas Instruments Incorporated
// https://www.ti.com
//
// The TAS2563/TAS2781 driver implements a flexible and configurable
@@ -414,7 +414,7 @@ static void tasdevice_fw_ready(const struct firmware *fmw,
__func__, tas_priv->cal_binaryname[i]);
}

- tasdevice_prmg_calibdata_load(tas_priv, 0);
+ tasdevice_prmg_load(tas_priv, 0);
tas_priv->cur_prog = 0;
out:
if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
--
2.34.1



2024-05-20 19:28:38

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v6] ASoC: tas2781: Fix wrong loading calibrated data sequence

On Sat, 18 May 2024 22:15:46 +0800, Shenghao Ding wrote:
> 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.
>
> [...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: tas2781: Fix wrong loading calibrated data sequence
commit: b195acf5266d2dee4067f89345c3e6b88d925311

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


2024-06-02 13:13:12

by Shenghao Ding

[permalink] [raw]
Subject: RE: [EXTERNAL] Re: [PATCH v6] ASoC: tas2781: Fix wrong loading calibrated data sequence

Hi Brown
One of my customers requested tas2781 driver in kernel 6.10 to be merged into kernel 6.1.
I wondered how I can handle this. May I resubmit the whole code into latest 6.1 branch?
Looking forward to your reply. Thanks.

BR
Shenghao Ding
> -----Original Message-----
> From: Mark Brown <[email protected]>
> Sent: Tuesday, May 21, 2024 3:27 AM
> To: Ding, Shenghao <[email protected]>
> Cc: [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; [email protected];
> [email protected]; Lu, Kevin <[email protected]>;
> [email protected]; [email protected]; Xu, Baojun
> <[email protected]>; [email protected]; [email protected]
> Subject: [EXTERNAL] Re: [PATCH v6] ASoC: tas2781: Fix wrong loading
> calibrated data sequence
>
...
> If any updates are required or you are submitting further changes they
> should be sent as incremental updates against current git, existing patches
> will not be replaced.
>
> Please add any relevant lists and maintainers to the CCs when replying to this
> mail.
>
> Thanks,
> Mark

2024-06-03 12:13:02

by Mark Brown

[permalink] [raw]
Subject: Re: [EXTERNAL] Re: [PATCH v6] ASoC: tas2781: Fix wrong loading calibrated data sequence

On Sun, Jun 02, 2024 at 01:11:39PM +0000, Ding, Shenghao wrote:

> One of my customers requested tas2781 driver in kernel 6.10 to be merged into kernel 6.1.
> I wondered how I can handle this. May I resubmit the whole code into latest 6.1 branch?
> Looking forward to your reply. Thanks.

You'd need to do something yourself - the stable kernels themselves
don't add new features, and I think v6.1 is not updated any more anyway.
The usual thing would be to do a backport and then publish it somehow,
some vendors have git trees they use (some use github), some share
patches via e-mail but there's a bunch of options there.

If this is for some OS vendor (or for use with a specific OS) you may be
able to work directly with them to add the driver, some OSs are open to
that but some aren't.


Attachments:
(No filename) (810.00 B)
signature.asc (499.00 B)
Download all attachments

2024-06-04 09:56:25

by Shenghao Ding

[permalink] [raw]
Subject: RE: [EXTERNAL] Re: [PATCH v6] ASoC: tas2781: Fix wrong loading calibrated data sequence

Thanks for your comments.

> -----Original Message-----
> From: Mark Brown <[email protected]>
> Sent: Monday, June 3, 2024 8:12 PM
> To: Ding, Shenghao <[email protected]>
> Cc: [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]; [email protected]; [email protected]; Xu,
> Baojun <[email protected]>; [email protected]; [email protected];
> [email protected]; Yue, Jaden <[email protected]>; Lo, Henry
> <[email protected]>; Navada Kanyana, Mukund <[email protected]>; Hari, Raj
> <[email protected]>; [email protected]
> Subject: Re: [EXTERNAL] Re: [PATCH v6] ASoC: tas2781: Fix wrong loading
> calibrated data sequence
>
> On Sun, Jun 02, 2024 at 01:11:39PM +0000, Ding, Shenghao wrote:
>
> > One of my customers requested tas2781 driver in kernel 6.10 to be merged
> into kernel 6.1.
> > I wondered how I can handle this. May I resubmit the whole code into
> latest 6.1 branch?
> > Looking forward to your reply. Thanks.
>
> You'd need to do something yourself - the stable kernels themselves don't
> add new features, and I think v6.1 is not updated any more anyway.
> The usual thing would be to do a backport and then publish it somehow,
> some vendors have git trees they use (some use github), some share patches
> via e-mail but there's a bunch of options there.
>
> If this is for some OS vendor (or for use with a specific OS) you may be able
> to work directly with them to add the driver, some OSs are open to that but
> some aren't.