Skip to contentSkip to conversation

ASoC: rt1320-sdw: kcontrol for brown-out feature update

PATCH Superseded [email protected] 2 participants 5 messages Apr 2 – Apr 7

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ASoC: rt1320-sdw: kcontrol for brown-out feature update

From: Jack Yu <[email protected]>

Create a kcontrol to enable or disable brown-out dynamically.

---
 sound/soc/codecs/rt1320-sdw.c | 45 +++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt1320-sdw.h |  1 +
 2 files changed, 46 insertions(+)
sound/soc/codecs/rt1320-sdw.c +45 -0
index 8bb7e8497c72..548454c7069e 100644
@@ -577,6 +577,7 @@ static bool rt1320_volatile_register(struct device *dev, unsigned int reg)
 	case 0xd530:
 	case 0xd540 ... 0xd541:
 	case 0xd543:
+	case 0xdb00 ... 0xdb03:
 	case 0xdb58 ... 0xdb5f:
 	case 0xdb60 ... 0xdb63:
 	case 0xdb68 ... 0xdb69:
@@ -1015,11 +1016,13 @@ static void rt1320_set_advancemode(struct rt1320_sdw_priv *rt1320)
 	unsigned short l_advancegain, r_advancegain;
 	int ret;
 
+
 	/* Get advance gain/r0 */
 	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 6, &r0_data[0], sizeof(struct rt1320_datafixpoint));
 	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 7, &r0_data[1], sizeof(struct rt1320_datafixpoint));
 	l_advancegain = r0_data[0].advancegain;
 	r_advancegain = r0_data[1].advancegain;
+
 	dev_dbg(dev, "%s, LR advanceGain=0x%x 0x%x\n", __func__, l_advancegain, r_advancegain);
 
 	/* set R0 and enable protection by SetParameter id 6, 7 */
@@ -2486,6 +2489,44 @@ static int rt1320_rae_update_put(struct snd_kcontrol *kcontrol,
 	return 0;
 }
 
+static int rt1320_brown_out_put(struct snd_kcontrol *kcontrol,
+				 struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt1320_sdw_priv *rt1320 = snd_soc_component_get_drvdata(component);
+	int ret;
+
+	if (!rt1320->hw_init)
+		return 0;
+
+	ret = pm_runtime_resume(component->dev);
+	if (ret < 0 && ret != -EACCES)
+		return ret;
+
+	rt1320->brown_out = ucontrol->value.integer.value[0];
+	regcache_cache_bypass(rt1320->regmap, true);
+
+	if (rt1320->brown_out == 0)
+		regmap_write(rt1320->regmap, 0xdb03, 0x00);
+	else
+		regmap_write(rt1320->regmap, 0xdb03, 0xf0);
+
+	regcache_cache_bypass(rt1320->regmap, false);
+
+	return 0;
+}
+
+static int rt1320_brown_out_get(struct snd_kcontrol *kcontrol,
+				     struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt1320_sdw_priv *rt1320 = snd_soc_component_get_drvdata(component);
+
+	ucontrol->value.integer.value[0] = rt1320->brown_out;
+
+	return 0;
+}
+
 static int rt1320_r0_temperature_get(struct snd_kcontrol *kcontrol,
 				     struct snd_ctl_elem_value *ucontrol)
 {
@@ -2545,6 +2586,8 @@ static const struct snd_kcontrol_new rt1320_snd_controls[] = {
 		rt1320_r0_temperature_get, rt1320_r0_temperature_put),
 	SOC_SINGLE_EXT("RAE Update", SND_SOC_NOPM, 0, 1, 0,
 		rt1320_rae_update_get, rt1320_rae_update_put),
+	SOC_SINGLE_EXT("Brown Out Update", SND_SOC_NOPM, 0, 1, 0,
+		rt1320_brown_out_get, rt1320_brown_out_put),
 };
 
 static const struct snd_kcontrol_new rt1320_spk_l_dac =
@@ -2793,6 +2836,8 @@ static int rt1320_sdw_component_probe(struct snd_soc_component *component)
 		rt1320_r0_load(rt1320);
 	}
 
+	rt1320->brown_out = 1;
+
 	return 0;
 }
 
sound/soc/codecs/rt1320-sdw.h +1 -0
index 5a9f496dd848..4a1d3fc4c8ee 100644
@@ -159,6 +159,7 @@ struct rt1320_sdw_priv {
 	bool hw_init;
 	bool first_hw_init;
 	int version_id;
+	int brown_out;
 	unsigned int dev_id;
 	bool fu_dapm_mute;
 	bool fu_mixer_mute[4];
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 ASoC: rt1320-sdw: Add an approach to get new hardware advance gain

From: Jack Yu <[email protected]>

Add an approach to get new hardware advance gain, and if there is no advance gain with this approach, we can still get advance gain with original method.

---
 sound/soc/codecs/rt1320-sdw.c | 19 +++++++++++++++++--
 sound/soc/codecs/rt1320-sdw.h | 13 +++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)
sound/soc/codecs/rt1320-sdw.c +17 -2
index 548454c7069e..6186dc4dcf47 100644
@@ -1014,15 +1014,30 @@ static void rt1320_set_advancemode(struct rt1320_sdw_priv *rt1320)
 	struct device *dev = &rt1320->sdw_slave->dev;
 	struct rt1320_datafixpoint r0_data[2];
 	unsigned short l_advancegain, r_advancegain;
+	FwPara_Get_HwSwGain audDriverDataHwSwGain;
+	unsigned int HwAdvGain;
 	int ret;
 
+	 /* Get new hardware advance gain by ID 1300 */
+	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 1300,
+		&audDriverDataHwSwGain, sizeof(audDriverDataHwSwGain));
+	HwAdvGain = audDriverDataHwSwGain.HwAdvGain;
+	dev_dbg(dev, "%s, HwAdvGain=%d\n", __func__, HwAdvGain);
+	dev_dbg(dev, "%s, HwBasGain=%d\n", __func__, audDriverDataHwSwGain.HwBasGain);
+	dev_dbg(dev, "%s, SwAdvGain=%d\n", __func__, audDriverDataHwSwGain.SwAdvGain);
+	dev_dbg(dev, "%s, SwBasGain=%d\n", __func__, audDriverDataHwSwGain.SwBasGain);
 
 	/* Get advance gain/r0 */
 	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 6, &r0_data[0], sizeof(struct rt1320_datafixpoint));
 	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 7, &r0_data[1], sizeof(struct rt1320_datafixpoint));
-	l_advancegain = r0_data[0].advancegain;
-	r_advancegain = r0_data[1].advancegain;
 
+	if (HwAdvGain != 0) {
+		l_advancegain = HwAdvGain & 0xffff;
+		r_advancegain = (HwAdvGain >> 16) & 0xffff;
+	} else {
+		l_advancegain = r0_data[0].advancegain;
+		r_advancegain = r0_data[1].advancegain;
+	}
 	dev_dbg(dev, "%s, LR advanceGain=0x%x 0x%x\n", __func__, l_advancegain, r_advancegain);
 
 	/* set R0 and enable protection by SetParameter id 6, 7 */
sound/soc/codecs/rt1320-sdw.h +13 -0
index 4a1d3fc4c8ee..a7b573883dd0 100644
@@ -121,6 +121,19 @@ struct rt1320_datafixpoint {
 	int invrs;
 };
 
+typedef struct FwPara_HwSwGain {
+	unsigned int SwAdvGain;
+	unsigned int SwBasGain;
+	unsigned int HwAdvGain;
+	unsigned int HwBasGain;
+	unsigned int reserve0;
+	unsigned int reserve1;
+	unsigned int reserve2;
+	unsigned int reserve3;
+	unsigned int reserve4;
+	unsigned int reserve5;
+} __attribute__((packed)) FwPara_Get_HwSwGain;
+
 struct rt1320_paramcmd {
 	unsigned char moudleid;
 	unsigned char commandtype;
Signature · 1 line
2.53.0
maintainer
#2 lore raw
In reply to [email protected]

sound/soc/codecs/rt1320-sdw.c static const struct snd_kcontrol_new rt1320_snd_controls[] = { · line 2590

Quoted 2 lines · On Thu, Apr 02, 2026 at 01:47:15PM +0800, [email protected] wrote:
sound/soc/codecs/rt1320-sdw.c +2 -0
+	SOC_SINGLE_EXT("Brown Out Update", SND_SOC_NOPM, 0, 1, 0,
+		rt1320_brown_out_get, rt1320_brown_out_put),

Like I say this should be a Switch - it's an on/off control, even if it's for an algorithm.

author
#3 lore raw
Quoted 11 lines

-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Thursday, April 2, 2026 7:46 PM
To: Jack Yu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Flove(HsinFu) <[email protected]>; Oder Chiou <[email protected]>; Shuming [范書銘] <[email protected]>; Derek [方德義] <[email protected]>
Subject: Re: [PATCH 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update

Quoted 7 lines

sound/soc/codecs/rt1320-sdw.c static const struct snd_kcontrol_new rt1320_snd_controls[] = { · line 2590

Quoted 2 lines · On Thu, Apr 02, 2026 at 01:47:15PM +0800, [email protected] wrote:
sound/soc/codecs/rt1320-sdw.c +2 -0
+	SOC_SINGLE_EXT("Brown Out Update", SND_SOC_NOPM, 0, 1, 0,
+		rt1320_brown_out_get, rt1320_brown_out_put),

Like I say this should be a Switch - it's an on/off control, even if it's for an algorithm.

Do you mean I should use "Brown Out Switch" instead of "Brown Out Update"? And still use SOC_SINGLE_EXT for declaration, like below
SOC_SINGLE_EXT("Brown Out Switch", SND_SOC_NOPM, 0, 1, 0,

		 rt1320_brown_out_get, rt1320_brown_out_put)
maintainer
#4 lore raw
Quoted 5 lines · Jack Yu
Quoted 5 lines

sound/soc/codecs/rt1320-sdw.c static const struct snd_kcontrol_new rt1320_snd_controls[] = { · line 2590

Quoted 2 lines
sound/soc/codecs/rt1320-sdw.c +2 -0
+	SOC_SINGLE_EXT("Brown Out Update", SND_SOC_NOPM, 0, 1, 0,
+		rt1320_brown_out_get, rt1320_brown_out_put),

Like I say this should be a Switch - it's an on/off control, even if it's for an algorithm.

i

Quoted 4 lines

Do you mean I should use "Brown Out Switch" instead of "Brown Out Update"? And still use SOC_SINGLE_EXT for declaration, like below
SOC_SINGLE_EXT("Brown Out Switch", SND_SOC_NOPM, 0, 1, 0,

		 rt1320_brown_out_get, rt1320_brown_out_put)

Yes, something like that.