public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update
@ 2026-04-09  6:01 jack.yu
  2026-04-09  6:01 ` [PATCH v4 2/2] ASoC: rt1320-sdw: Add an approach to get new hardware advance gain jack.yu
  2026-04-09 19:41 ` (subset) [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: jack.yu @ 2026-04-09  6:01 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: alsa-devel, lars, flove, oder_chiou, shumingf, derek.fang,
	Jack Yu

From: Jack Yu <jack.yu@realtek.com>

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

Signed-off-by: Jack Yu <jack.yu@realtek.com>
---
 sound/soc/codecs/rt1320-sdw.c | 42 +++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt1320-sdw.h |  1 +
 2 files changed, 43 insertions(+)

diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index 8bb7e8497c72..168d2f391723 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -2486,6 +2486,45 @@ 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, changed = 0;
+
+	if (!rt1320->hw_init)
+		return 0;
+
+	ret = pm_runtime_resume(component->dev);
+	if (ret < 0 && ret != -EACCES)
+		return ret;
+
+	if (rt1320->brown_out != ucontrol->value.integer.value[0]) {
+		changed = 1;
+		rt1320->brown_out = ucontrol->value.integer.value[0];
+	}
+
+	if (rt1320->brown_out == 0)
+		regmap_write(rt1320->regmap, 0xdb03, 0x00);
+	else
+		regmap_write(rt1320->regmap, 0xdb03, 0xf0);
+
+
+	return changed;
+}
+
+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 +2584,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 Switch", SND_SOC_NOPM, 0, 1, 0,
+		rt1320_brown_out_get, rt1320_brown_out_put),
 };
 
 static const struct snd_kcontrol_new rt1320_spk_l_dac =
@@ -2904,6 +2945,7 @@ static int rt1320_sdw_init(struct device *dev, struct regmap *regmap,
 	rt1320->fu_dapm_mute = true;
 	rt1320->fu_mixer_mute[0] = rt1320->fu_mixer_mute[1] =
 		rt1320->fu_mixer_mute[2] = rt1320->fu_mixer_mute[3] = true;
+	rt1320->brown_out = 1;
 
 	INIT_WORK(&rt1320->load_dspfw_work, rt1320_load_dspfw_work);
 
diff --git a/sound/soc/codecs/rt1320-sdw.h b/sound/soc/codecs/rt1320-sdw.h
index 5a9f496dd848..4a1d3fc4c8ee 100644
--- a/sound/soc/codecs/rt1320-sdw.h
+++ b/sound/soc/codecs/rt1320-sdw.h
@@ -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];
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] ASoC: rt1320-sdw: Add an approach to get new hardware advance gain
  2026-04-09  6:01 [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update jack.yu
@ 2026-04-09  6:01 ` jack.yu
  2026-04-09 19:41   ` Mark Brown
  2026-04-09 19:41 ` (subset) [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: jack.yu @ 2026-04-09  6:01 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: alsa-devel, lars, flove, oder_chiou, shumingf, derek.fang,
	Jack Yu

From: Jack Yu <jack.yu@realtek.com>

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.

Signed-off-by: Jack Yu <jack.yu@realtek.com>
---
 sound/soc/codecs/rt1320-sdw.c | 21 +++++++++++++++++++--
 sound/soc/codecs/rt1320-sdw.h | 13 +++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index 168d2f391723..68e53f6885fb 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -1013,13 +1013,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 */
diff --git a/sound/soc/codecs/rt1320-sdw.h b/sound/soc/codecs/rt1320-sdw.h
index 4a1d3fc4c8ee..a7b573883dd0 100644
--- a/sound/soc/codecs/rt1320-sdw.h
+++ b/sound/soc/codecs/rt1320-sdw.h
@@ -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;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 2/2] ASoC: rt1320-sdw: Add an approach to get new hardware advance gain
  2026-04-09  6:01 ` [PATCH v4 2/2] ASoC: rt1320-sdw: Add an approach to get new hardware advance gain jack.yu
@ 2026-04-09 19:41   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-04-09 19:41 UTC (permalink / raw)
  To: jack.yu
  Cc: lgirdwood, alsa-devel, lars, flove, oder_chiou, shumingf,
	derek.fang

[-- Attachment #1: Type: text/plain, Size: 775 bytes --]

On Thu, Apr 09, 2026 at 02:01:02PM +0800, jack.yu@realtek.com wrote:
> From: Jack Yu <jack.yu@realtek.com>
> 
> 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.

> +	 /* Get new hardware advance gain by ID 1300 */
> +	rt1320_fw_param_protocol(rt1320, RT1320_GET_PARAM, 1300,
> +		&audDriverDataHwSwGain, sizeof(audDriverDataHwSwGain));
> +	HwAdvGain = audDriverDataHwSwGain.HwAdvGain;

If this is intended to support a fallback in case param 1300 isn't
supported shouldn't we have an error check here in case the call to the
firmware fails?  The parameters are just read onto a stack variable so
we're not relying on them being left at 0 on error...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (subset) [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update
  2026-04-09  6:01 [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update jack.yu
  2026-04-09  6:01 ` [PATCH v4 2/2] ASoC: rt1320-sdw: Add an approach to get new hardware advance gain jack.yu
@ 2026-04-09 19:41 ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-04-09 19:41 UTC (permalink / raw)
  To: lgirdwood, jack.yu
  Cc: alsa-devel, lars, flove, oder_chiou, shumingf, derek.fang

On Thu, 09 Apr 2026 14:01:01 +0800, jack.yu@realtek.com wrote:
> ASoC: rt1320-sdw: kcontrol for brown-out feature update

Applied to

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

Thanks!

[1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update
      https://git.kernel.org/broonie/sound/c/fbb1f8ba4e2d

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-09 22:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09  6:01 [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update jack.yu
2026-04-09  6:01 ` [PATCH v4 2/2] ASoC: rt1320-sdw: Add an approach to get new hardware advance gain jack.yu
2026-04-09 19:41   ` Mark Brown
2026-04-09 19:41 ` (subset) [PATCH v4 1/2] ASoC: rt1320-sdw: kcontrol for brown-out feature update Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox