Skip to contentSkip to conversation

ASoc: tas2781: Playback can work when only RCA binary loading without dsp firmware loading

PATCH In review Shenghao Ding 2 participants 4 messages May 25, 2024 – May 29, 2024

Subsystems (3)
lore
Share & tools
lore

Shenghao Ding

author maintainer
#0 lore raw

PATCH v2 1/1 ASoc: tas2781: Playback can work when only RCA binary loading without dsp firmware loading

In only RCA binary loading case, only default dsp program inside the chip will be work.

Fixes ef3bcde75d06 ("ASoC: tas2781: Add tas2781 driver")

---
v2:
- correct comment.
- Add Fixes.
- Move header file to the first.
v1:
- Split out the different logical changes into different patches.
- rename tasdevice_dsp_fw_state -> tasdevice_fw_state, the fw are not only dsp fw, but also RCA(Reconfigurable data, such as acoustic data and register setting, etc).
- Add TASDEVICE_RCA_FW_OK in tasdevice_fw_state to identify the state that only RCA binary file has been download successfully, but dsp fw is not loaded or loading failure.
- Add the this strategy into tasdevice_tuning_switch.
- If one side of the if/else has a braces both should in tasdevice_tuning_switch.
- Identify whehter both RCA and DSP have been loaded or only RCA has been loaded in tasdevice_fw_ready.
- Add check fw load status in tasdevice_startup.
- remove ret in tasdevice_startup to make th code neater.

---
 include/sound/tas2781-dsp.h       |  3 ++-
 sound/soc/codecs/tas2781-fmwlib.c | 14 ++++++++++----
 sound/soc/codecs/tas2781-i2c.c    | 30 ++++++++++++++++++------------
 3 files changed, 30 insertions(+), 17 deletions(-)
include/sound/tas2781-dsp.h +2 -1
index 7fba7ea26a4b..92d68ca5eafb 100644
@@ -117,10 +117,11 @@ struct tasdevice_fw {
 	struct device *dev;
 };
 
-enum tasdevice_dsp_fw_state {
+enum tasdevice_fw_state {
 	TASDEVICE_DSP_FW_NONE = 0,
 	TASDEVICE_DSP_FW_PENDING,
 	TASDEVICE_DSP_FW_FAIL,
+	TASDEVICE_RCA_FW_OK,
 	TASDEVICE_DSP_FW_ALL_OK,
 };
 
sound/soc/codecs/tas2781-fmwlib.c +10 -4
index 265a8ca25cbb..cfa022ef4a59 100644
@@ -2324,13 +2324,18 @@ void tasdevice_tuning_switch(void *context, int state)
 	struct tasdevice_fw *tas_fmw = tas_priv->fmw;
 	int profile_cfg_id = tas_priv->rcabin.profile_cfg_id;
 
-	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-		dev_err(tas_priv->dev, "DSP bin file not loaded\n");
+	/*
+	 * Only RCA file loaded can still work with default dsp program inside
+	 * the chip?
+	 */
+	if (!(tas_priv->fw_state == TASDEVICE_RCA_FW_OK ||
+		tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK)) {
+		dev_err(tas_priv->dev, "No firmware loaded\n");
 		return;
 	}
 
 	if (state == 0) {
-		if (tas_priv->cur_prog < tas_fmw->nr_programs) {
+		if (tas_fmw && tas_priv->cur_prog < tas_fmw->nr_programs) {
 			/*dsp mode or tuning mode*/
 			profile_cfg_id = tas_priv->rcabin.profile_cfg_id;
 			tasdevice_select_tuningprm_cfg(tas_priv,
@@ -2340,9 +2345,10 @@ void tasdevice_tuning_switch(void *context, int state)
 
 		tasdevice_select_cfg_blk(tas_priv, profile_cfg_id,
 			TASDEVICE_BIN_BLK_PRE_POWER_UP);
-	} else
+	} else {
 		tasdevice_select_cfg_blk(tas_priv, profile_cfg_id,
 			TASDEVICE_BIN_BLK_PRE_SHUTDOWN);
+	}
 }
 EXPORT_SYMBOL_NS_GPL(tasdevice_tuning_switch,
 	SND_SOC_TAS2781_FMWLIB);
sound/soc/codecs/tas2781-i2c.c +18 -12
index 9350972dfefe..ccb9313ada9b 100644
@@ -380,23 +380,30 @@ static void tasdevice_fw_ready(const struct firmware *fmw,
 	mutex_lock(&tas_priv->codec_lock);
 
 	ret = tasdevice_rca_parser(tas_priv, fmw);
-	if (ret)
+	if (ret) {
+		tasdevice_config_info_remove(tas_priv);
 		goto out;
+	}
 	tasdevice_create_control(tas_priv);
 
 	tasdevice_dsp_remove(tas_priv);
 	tasdevice_calbin_remove(tas_priv);
-	tas_priv->fw_state = TASDEVICE_DSP_FW_PENDING;
+	tas_priv->fw_state = TASDEVICE_RCA_FW_OK;
 	scnprintf(tas_priv->coef_binaryname, 64, "%s_coef.bin",
 		tas_priv->dev_name);
+
 	ret = tasdevice_dsp_parser(tas_priv);
 	if (ret) {
 		dev_err(tas_priv->dev, "dspfw load %s error\n",
 			tas_priv->coef_binaryname);
-		tas_priv->fw_state = TASDEVICE_DSP_FW_FAIL;
 		goto out;
 	}
-	tasdevice_dsp_create_ctrls(tas_priv);
+
+	ret = tasdevice_dsp_create_ctrls(tas_priv);
+	if (ret) {
+		dev_err(tas_priv->dev, "dsp controls error\n");
+		goto out;
+	}
 
 	tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK;
 
@@ -417,9 +424,8 @@ static void tasdevice_fw_ready(const struct firmware *fmw,
 	tasdevice_prmg_load(tas_priv, 0);
 	tas_priv->cur_prog = 0;
 out:
-	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-		/*If DSP FW fail, kcontrol won't be created */
-		tasdevice_config_info_remove(tas_priv);
+	if (tas_priv->fw_state == TASDEVICE_RCA_FW_OK) {
+		/*If DSP FW fail, DSP kcontrol won't be created */
 		tasdevice_dsp_remove(tas_priv);
 	}
 	mutex_unlock(&tas_priv->codec_lock);
@@ -466,14 +472,14 @@ static int tasdevice_startup(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_component *codec = dai->component;
 	struct tasdevice_priv *tas_priv = snd_soc_component_get_drvdata(codec);
-	int ret = 0;
 
-	if (tas_priv->fw_state != TASDEVICE_DSP_FW_ALL_OK) {
-		dev_err(tas_priv->dev, "DSP bin file not loaded\n");
-		ret = -EINVAL;
+	if (!(tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK ||
+		tas_priv->fw_state == TASDEVICE_RCA_FW_OK)) {
+		dev_err(tas_priv->dev, "Bin file not loaded\n");
+		return -EINVAL;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int tasdevice_hw_params(struct snd_pcm_substream *substream,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines · Shenghao Ding

In only RCA binary loading case, only default dsp program inside the chip will be work.

What does 'RCA' stand for?

Also clarify the commit title without double negatives, e.g.

"Enable RCA-based playback without DSP firmware download"

sound/soc/codecs/tas2781-fmwlib.c void tasdevice_tuning_switch(void *context, int state) · line 2329

Quoted 5 lines
sound/soc/codecs/tas2781-fmwlib.c +3 -2
-	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-		dev_err(tas_priv->dev, "DSP bin file not loaded\n");
+	/*
+	 * Only RCA file loaded can still work with default dsp program inside
+	 * the chip?

reword the commit and remove question mark.

sound/soc/codecs/tas2781-fmwlib.c void tasdevice_tuning_switch(void *context, int state) · line 2339

Quoted 11 lines
sound/soc/codecs/tas2781-fmwlib.c +5 -1
+	 */
+	if (!(tas_priv->fw_state == TASDEVICE_RCA_FW_OK ||
+		tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK)) {
+		dev_err(tas_priv->dev, "No firmware loaded\n");
 		return;
 	}
 
 	if (state == 0) {
-		if (tas_priv->cur_prog < tas_fmw->nr_programs) {
+		if (tas_fmw && tas_priv->cur_prog < tas_fmw->nr_programs) {
 			/*dsp mode or tuning mode*/

spaces in comments

Quoted 40 lines
sound/soc/codecs/tas2781-fmwlib.c +2 -1
 			profile_cfg_id = tas_priv->rcabin.profile_cfg_id;
 			tasdevice_select_tuningprm_cfg(tas_priv,
@@ -2340,9 +2345,10 @@ void tasdevice_tuning_switch(void *context, int state)
 
 		tasdevice_select_cfg_blk(tas_priv, profile_cfg_id,
 			TASDEVICE_BIN_BLK_PRE_POWER_UP);
-	} else
+	} else {
 		tasdevice_select_cfg_blk(tas_priv, profile_cfg_id,
 			TASDEVICE_BIN_BLK_PRE_SHUTDOWN);
+	}
 }
 EXPORT_SYMBOL_NS_GPL(tasdevice_tuning_switch,
 	SND_SOC_TAS2781_FMWLIB);
sound/soc/codecs/tas2781-i2c.c +5 -2
index 9350972dfefe..ccb9313ada9b 100644
@@ -380,23 +380,30 @@ static void tasdevice_fw_ready(const struct firmware *fmw,
 	mutex_lock(&tas_priv->codec_lock);
 
 	ret = tasdevice_rca_parser(tas_priv, fmw);
-	if (ret)
+	if (ret) {
+		tasdevice_config_info_remove(tas_priv);
 		goto out;
+	}
 	tasdevice_create_control(tas_priv);
 
 	tasdevice_dsp_remove(tas_priv);
 	tasdevice_calbin_remove(tas_priv);
-	tas_priv->fw_state = TASDEVICE_DSP_FW_PENDING;
+	tas_priv->fw_state = TASDEVICE_RCA_FW_OK;
 	scnprintf(tas_priv->coef_binaryname, 64, "%s_coef.bin",
 		tas_priv->dev_name);
+
 	ret = tasdevice_dsp_parser(tas_priv);
 	if (ret) {
 		dev_err(tas_priv->dev, "dspfw load %s error\n",
 			tas_priv->coef_binaryname);

sound/soc/codecs/tas2781-i2c.c static void tasdevice_fw_ready(const struct firmware *fmw, · line 406

Quoted 10 lines
sound/soc/codecs/tas2781-i2c.c +6 -2
-		tas_priv->fw_state = TASDEVICE_DSP_FW_FAIL;
 		goto out;
 	}
-	tasdevice_dsp_create_ctrls(tas_priv);
+
+	ret = tasdevice_dsp_create_ctrls(tas_priv);
+	if (ret) {
+		dev_err(tas_priv->dev, "dsp controls error\n");
+		goto out;
+	}

this seems unrelated to the boot process? Move to a different patch?

sound/soc/codecs/tas2781-i2c.c static void tasdevice_fw_ready(const struct firmware *fmw, · line 428

Quoted 12 lines
sound/soc/codecs/tas2781-i2c.c +2 -3
 	tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK;
 
@@ -417,9 +424,8 @@ static void tasdevice_fw_ready(const struct firmware *fmw,
 	tasdevice_prmg_load(tas_priv, 0);
 	tas_priv->cur_prog = 0;
 out:
-	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-		/*If DSP FW fail, kcontrol won't be created */
-		tasdevice_config_info_remove(tas_priv);
+	if (tas_priv->fw_state == TASDEVICE_RCA_FW_OK) {
+		/*If DSP FW fail, DSP kcontrol won't be created */

It looks like you're no longer using PENDING and FAIL states? The state machine is becoming really hard to follow.

Quoted 23 lines
sound/soc/codecs/tas2781-i2c.c +5 -5
 		tasdevice_dsp_remove(tas_priv);
 	}
 	mutex_unlock(&tas_priv->codec_lock);
@@ -466,14 +472,14 @@ static int tasdevice_startup(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_component *codec = dai->component;
 	struct tasdevice_priv *tas_priv = snd_soc_component_get_drvdata(codec);
-	int ret = 0;
 
-	if (tas_priv->fw_state != TASDEVICE_DSP_FW_ALL_OK) {
-		dev_err(tas_priv->dev, "DSP bin file not loaded\n");
-		ret = -EINVAL;
+	if (!(tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK ||
+		tas_priv->fw_state == TASDEVICE_RCA_FW_OK)) {
+		dev_err(tas_priv->dev, "Bin file not loaded\n");
+		return -EINVAL;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int tasdevice_hw_params(struct snd_pcm_substream *substream,
author maintainer
#2 lore raw

Thanks for your comments.

Quoted 19 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Monday, May 27, 2024 9:44 PM
To: Ding, Shenghao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Salazar, Ivan <[email protected]>; [email protected]; Chadha, Jasjot Singh <[email protected]>; [email protected]; Yue, Jaden <[email protected]>; [email protected]; Rao, Dipa <[email protected]>; Lu, Kevin <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; [email protected]; [email protected]; [email protected]; Navada Kanyana, Mukund <[email protected]>; [email protected]; Kutty, Aanya <[email protected]>; Mahmud, Nayeem <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v2] ASoc: tas2781: Playback can work when only RCA binary loading without dsp firmware loading

Quoted 5 lines
Quoted 2 lines · Shenghao Ding

In only RCA binary loading case, only default dsp program inside the chip will be work.

What does 'RCA' stand for?

Reconfigurable architecture binary file

Quoted 11 lines

Also clarify the commit title without double negatives, e.g.

"Enable RCA-based playback without DSP firmware download"

sound/soc/codecs/tas2781-fmwlib.c void tasdevice_tuning_switch(void *context, int state) · line 2329

Quoted 5 lines
sound/soc/codecs/tas2781-fmwlib.c +3 -2
-	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-		dev_err(tas_priv->dev, "DSP bin file not loaded\n");
+	/*
+	 * Only RCA file loaded can still work with default dsp program inside
+	 * the chip?

reword the commit and remove question mark.

accept

Quoted 8 lines
Quoted 8 lines
sound/soc/codecs/tas2781-fmwlib.c +4 -0
+	 */
+	if (!(tas_priv->fw_state == TASDEVICE_RCA_FW_OK ||
+		tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK)) {
+		dev_err(tas_priv->dev, "No firmware loaded\n");
 		return;
 	}
Quoted 7 lines

sound/soc/codecs/tas2781-fmwlib.c void tasdevice_tuning_switch(void *context, int state)

Quoted 3 lines
sound/soc/codecs/tas2781-fmwlib.c +1 -1
 	if (state == 0) {
-		if (tas_priv->cur_prog < tas_fmw->nr_programs) {
+		if (tas_fmw && tas_priv->cur_prog < tas_fmw->nr_programs)

{

Quoted 1 line

/*dsp mode or tuning mode*/

spaces in comments

accept

Quoted 48 lines

sound/soc/codecs/tas2781-i2c.c static void tasdevice_fw_ready(const struct

Quoted 22 lines
sound/soc/codecs/tas2781-fmwlib.c +2 -1
 			profile_cfg_id = tas_priv->rcabin.profile_cfg_id;
 			tasdevice_select_tuningprm_cfg(tas_priv,
@@ -2340,9 +2345,10 @@ void tasdevice_tuning_switch(void *context, int
 state)
 
 		tasdevice_select_cfg_blk(tas_priv, profile_cfg_id,
 			TASDEVICE_BIN_BLK_PRE_POWER_UP);
-	} else
+	} else {
 		tasdevice_select_cfg_blk(tas_priv, profile_cfg_id,
 			TASDEVICE_BIN_BLK_PRE_SHUTDOWN);
+	}
 }
 EXPORT_SYMBOL_NS_GPL(tasdevice_tuning_switch,
sound/soc/codecs/tas2781-fmwlib.c +0 -0
 	SND_SOC_TAS2781_FMWLIB);
(quoted diff) +0 -0

b/sound/soc/codecs/tas2781-i2c.c index 9350972dfefe..ccb9313ada9b 100644

sound/soc/codecs/tas2781-i2c.c +0 -0
@@ -380,23 +380,30 @@ static void tasdevice_fw_ready(const struct

firmware *fmw,

Quoted 25 lines
sound/soc/codecs/tas2781-i2c.c +5 -4
 	mutex_lock(&tas_priv->codec_lock);
 
 	ret = tasdevice_rca_parser(tas_priv, fmw);
-	if (ret)
+	if (ret) {
+		tasdevice_config_info_remove(tas_priv);
 		goto out;
+	}
 	tasdevice_create_control(tas_priv);
 
 	tasdevice_dsp_remove(tas_priv);
 	tasdevice_calbin_remove(tas_priv);
-	tas_priv->fw_state = TASDEVICE_DSP_FW_PENDING;
+	tas_priv->fw_state = TASDEVICE_RCA_FW_OK;
 	scnprintf(tas_priv->coef_binaryname, 64, "%s_coef.bin",
 		tas_priv->dev_name);
+
 	ret = tasdevice_dsp_parser(tas_priv);
 	if (ret) {
 		dev_err(tas_priv->dev, "dspfw load %s error\n",
 			tas_priv->coef_binaryname);
-		tas_priv->fw_state = TASDEVICE_DSP_FW_FAIL;
 		goto out;
 	}
-	tasdevice_dsp_create_ctrls(tas_priv);
Quoted 8 lines

sound/soc/codecs/tas2781-i2c.c static void tasdevice_fw_ready(const struct firmware *fmw, · line 406

Quoted 6 lines
sound/soc/codecs/tas2781-i2c.c +6 -0
+
+	ret = tasdevice_dsp_create_ctrls(tas_priv);
+	if (ret) {
+		dev_err(tas_priv->dev, "dsp controls error\n");
+		goto out;
+	}

this seems unrelated to the boot process? Move to a different patch?

It is a part of boot process, if no dsp-related kcontrol created, the dsp resource will be freed.

Quoted 6 lines

sound/soc/codecs/tas2781-i2c.c static void tasdevice_fw_ready(const struct

Quoted 5 lines
sound/soc/codecs/tas2781-i2c.c +0 -0
 	tas_priv->fw_state = TASDEVICE_DSP_FW_ALL_OK;
 
@@ -417,9 +424,8 @@ static void tasdevice_fw_ready(const struct

firmware *fmw,

Quoted 11 lines

sound/soc/codecs/tas2781-i2c.c static void tasdevice_fw_ready(const struct firmware *fmw, · line 428

Quoted 8 lines
sound/soc/codecs/tas2781-i2c.c +2 -3
 	tasdevice_prmg_load(tas_priv, 0);
 	tas_priv->cur_prog = 0;
 out:
-	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-		/*If DSP FW fail, kcontrol won't be created */
-		tasdevice_config_info_remove(tas_priv);
+	if (tas_priv->fw_state == TASDEVICE_RCA_FW_OK) {
+		/*If DSP FW fail, DSP kcontrol won't be created */

It looks like you're no longer using PENDING and FAIL states? The state machine is becoming really hard to follow.

Remove unused states.

Quoted 25 lines

sound/soc/codecs/tas2781-i2c.c static int tasdevice_startup(struct · line 474

Quoted 8 lines
sound/soc/codecs/tas2781-i2c.c +0 -0
 		tasdevice_dsp_remove(tas_priv);
 	}
 	mutex_unlock(&tas_priv->codec_lock);
@@ -466,14 +472,14 @@ static int tasdevice_startup(struct
 snd_pcm_substream *substream,  {
 	struct snd_soc_component *codec = dai->component;
 	struct tasdevice_priv *tas_priv =

snd_soc_component_get_drvdata(codec);

Quoted 16 lines
sound/soc/codecs/tas2781-i2c.c +5 -5
-	int ret = 0;
 
-	if (tas_priv->fw_state != TASDEVICE_DSP_FW_ALL_OK) {
-		dev_err(tas_priv->dev, "DSP bin file not loaded\n");
-		ret = -EINVAL;
+	if (!(tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK ||
+		tas_priv->fw_state == TASDEVICE_RCA_FW_OK)) {
+		dev_err(tas_priv->dev, "Bin file not loaded\n");
+		return -EINVAL;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int tasdevice_hw_params(struct snd_pcm_substream *substream,
author maintainer
#3 lore raw
In reply to Pierre-Louis Bossart
Quoted 36 lines

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: Monday, May 27, 2024 9:44 PM
To: Ding, Shenghao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Salazar, Ivan <[email protected]>; [email protected]; Chadha, Jasjot Singh <[email protected]>; [email protected]; Yue, Jaden <[email protected]>; [email protected]; Rao, Dipa <[email protected]>; Lu, Kevin <[email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; [email protected]; [email protected]; [email protected]; Navada Kanyana, Mukund <[email protected]>; [email protected]; Kutty, Aanya <[email protected]>; Mahmud, Nayeem <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v2] ASoc: tas2781: Playback can work when only RCA binary loading without dsp firmware loading

On 5/24/24 20: 47, Shenghao Ding wrote: > In only RCA binary loading case, only default dsp program inside the > chip will be work. What does 'RCA' stand for? Also clarify the commit title without double negatives, e. g. "Enable RCA-based ZjQcmQRYFpfptBannerStart This message was sent from outside of Texas Instruments.
Do not click links or open attachments unless you recognize the source of this email and know the content is safe. If you wish to report this message to IT Security, please forward the message as an attachment to [email protected]

ZjQcmQRYFpfptBannerEnd

Quoted 2 lines · Shenghao Ding

In only RCA binary loading case, only default dsp program inside the chip will be work.

......................................................................

Quoted 8 lines

sound/soc/codecs/tas2781-i2c.c static void tasdevice_fw_ready(const struct firmware *fmw, · line 428

Quoted 5 lines
sound/soc/codecs/tas2781-i2c.c +2 -3
-	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
-		/*If DSP FW fail, kcontrol won't be created */
-		tasdevice_config_info_remove(tas_priv);
+	if (tas_priv->fw_state == TASDEVICE_RCA_FW_OK) {
+		/*If DSP FW fail, DSP kcontrol won't be created */

It looks like you're no longer using PENDING and FAIL states? The state machine is becoming really hard to follow.

PENDING and FAIL states have been used in HDA-based tas2563/tas2781 driver

Quoted 8 lines
Quoted 8 lines
sound/soc/codecs/tas2781-i2c.c +0 -0
 		tasdevice_dsp_remove(tas_priv);
 	}
 	mutex_unlock(&tas_priv->codec_lock);
@@ -466,14 +472,14 @@ static int tasdevice_startup(struct
 snd_pcm_substream *substream,  {
 	struct snd_soc_component *codec = dai->component;
 	struct tasdevice_priv *tas_priv =

..................................................................................