Skip to contentSkip to conversation

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

PATCH In review [email protected] 4 participants 7 messages Apr 1 – Apr 7

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

From: Jack Yu <[email protected]>

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

---
 sound/soc/codecs/rt1320-sdw.c | 47 +++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt1320-sdw.h |  1 +
 2 files changed, 48 insertions(+)
sound/soc/codecs/rt1320-sdw.c +47 -0
index 8bb7e8497c72..40da3fea1c64 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:
@@ -2299,6 +2300,14 @@ static SOC_ENUM_SINGLE_DECL(rt1320_rx_data_ch_enum,
 	SDW_SDCA_CTL(FUNC_NUM_AMP, RT1320_SDCA_ENT_PPU21, RT1320_SDCA_CTL_POSTURE_NUMBER, 0), 0,
 	rt1320_rx_data_ch_select);
 
+static const char * const rt1320_brown_out_mode[] = {
+	"On",
+	"Off",
+};
+
+static SOC_ENUM_SINGLE_DECL(rt1320_brown_out_enum, 0, 0,
+	rt1320_brown_out_mode);
+
 static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6525, 75, 0);
 static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -1725, 75, 0);
 
@@ -2486,6 +2495,42 @@ 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);
+	struct device *dev = &rt1320->sdw_slave->dev;
+	int ret, tmp;
+
+	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 == 1)
+		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 +2590,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_ENUM_EXT("Brown Out Switch", rt1320_brown_out_enum,
+		rt1320_brown_out_get, rt1320_brown_out_put),
 };
 
 static const struct snd_kcontrol_new rt1320_spk_l_dac =
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

+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);
+       struct device *dev = &rt1320->sdw_slave->dev;
+       int ret, tmp;

+
+ 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 == 1)
+ 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 +2590,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_ENUM_EXT("Brown Out Switch", rt1320_brown_out_enum,
+ rt1320_brown_out_get, rt1320_brown_out_put),
};

static const struct snd_kcontrol_new rt1320_spk_l_dac =

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;
 

Could you set brown_out to 1 by default?
The blind write enables brown-out by default.

#2 lore raw
Quoted 6 lines
Quoted 6 lines
sound/soc/codecs/rt1320-sdw.h +0 -0
index 5a9f496dd848..4a1d3fc4c8ee 100644
@@ -159,6 +159,7 @@ struct rt1320_sdw_priv {
          bool hw_init;
Quoted 8 lines

sound/soc/codecs/rt1320-sdw.h struct rt1320_sdw_priv { · line 163

Quoted 4 lines
sound/soc/codecs/rt1320-sdw.h +1 -0
          bool first_hw_init;
          int version_id;
+       int brown_out;
          unsigned int dev_id;

Could you set brown_out to 1 by default?
The blind write enables brown-out by default.

Sorry, I misunderstood.
LGTM.

maintainer
#3 lore raw
In reply to [email protected]

sound/soc/codecs/rt1320-sdw.c static SOC_ENUM_SINGLE_DECL(rt1320_rx_data_ch_enum, · line 2310

Quoted 12 lines · On Wed, Apr 01, 2026 at 05:31:07PM +0800, [email protected] wrote:

From: Jack Yu <[email protected]>

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

sound/soc/codecs/rt1320-sdw.c +8 -0
+static const char * const rt1320_brown_out_mode[] = {
+	"On",
+	"Off",
+};
+
+static SOC_ENUM_SINGLE_DECL(rt1320_brown_out_enum, 0, 0,
+	rt1320_brown_out_mode);
+

On/off switches should be a Switch control, not an enum.

sound/soc/codecs/rt1320-sdw.c static int rt1320_rae_update_put(struct snd_kcontrol *kcontrol, · line 2508

Quoted 11 lines
sound/soc/codecs/rt1320-sdw.c +11 -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);
+	struct device *dev = &rt1320->sdw_slave->dev;
+	int ret, tmp;
+
+	ret = pm_runtime_resume(component->dev);
+	if (ret < 0 && ret != -EACCES)
+		return ret;

Other controls in this driver ignore writes before hw_init is set, should this one?

author
#4 lore raw
Quoted 16 lines

-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Wednesday, April 1, 2026 9:23 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] ASoC: rt1320-sdw: kcontrol for brown-out feature switch

Quoted 3 lines · On Wed, Apr 01, 2026 at 05:31:07PM +0800, [email protected] wrote:

From: Jack Yu <[email protected]>

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

Quoted 10 lines

sound/soc/codecs/rt1320-sdw.c static SOC_ENUM_SINGLE_DECL(rt1320_rx_data_ch_enum, · line 2310

Quoted 8 lines
sound/soc/codecs/rt1320-sdw.c +8 -0
+static const char * const rt1320_brown_out_mode[] = {
+	"On",
+	"Off",
+};
+
+static SOC_ENUM_SINGLE_DECL(rt1320_brown_out_enum, 0, 0,
+	rt1320_brown_out_mode);
+

On/off switches should be a Switch control, not an enum.

Maybe the name of kcontrol leads to misunderstand, it's just an effect setting for amplifier. I'll update this and use another control type but not enum.

Quoted 6 lines

sound/soc/codecs/rt1320-sdw.c static int rt1320_rae_update_put(struct snd_kcontrol *kcontrol,

Quoted 5 lines
sound/soc/codecs/rt1320-sdw.c +4 -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);

Quoted 9 lines

sound/soc/codecs/rt1320-sdw.c static int rt1320_rae_update_put(struct snd_kcontrol *kcontrol, · line 2508

Quoted 6 lines
sound/soc/codecs/rt1320-sdw.c +6 -0
+	struct device *dev = &rt1320->sdw_slave->dev;
+	int ret, tmp;
+
+	ret = pm_runtime_resume(component->dev);
+	if (ret < 0 && ret != -EACCES)
+		return ret;

Other controls in this driver ignore writes before hw_init is set, should this one?

Will fix it.

maintainer
#5 lore raw
Quoted 5 lines · Jack Yu
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/rt1320-sdw.c +4 -0
+static const char * const rt1320_brown_out_mode[] = {
+	"On",
+	"Off",
+};
Quoted 7 lines
Quoted 4 lines

sound/soc/codecs/rt1320-sdw.c static SOC_ENUM_SINGLE_DECL(rt1320_rx_data_ch_enum, · line 2309

Quoted 2 lines
sound/soc/codecs/rt1320-sdw.c +2 -0
+static SOC_ENUM_SINGLE_DECL(rt1320_brown_out_enum, 0, 0,
+	rt1320_brown_out_mode);

On/off switches should be a Switch control, not an enum.

Maybe the name of kcontrol leads to misunderstand, it's just an effect setting for amplifier. I'll update this and use another control type but not enum.

Turning effects on and off are still things being turned on and off.

#6 lore raw
In reply to [email protected]
kernel test robot noticed the following build warnings:

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on linus/master v7.0-rc6 next-20260402] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/jack-yu-realtek-com/ASoC-rt1320-sdw-kcontrol-for-brown-out-feature-switch/20260403-160437
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20260401093107.632673-1-jack.yu%40realtek.com
patch subject: [PATCH] ASoC: rt1320-sdw: kcontrol for brown-out feature switch
config: arc-randconfig-001-20260403 (https://download.01.org/0day-ci/archive/20260403/[email protected]/config)
compiler: arc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260403/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

sound/soc/codecs/rt1320-sdw.c: In function 'rt1320_brown_out_put':

>> sound/soc/codecs/rt1320-sdw.c:2504:11: warning: unused variable 'tmp' [-Wunused-variable]
     int ret, tmp;
              ^~~
>> sound/soc/codecs/rt1320-sdw.c:2503:17: warning: unused variable 'dev' [-Wunused-variable]
     struct device *dev = &rt1320->sdw_slave->dev;
                    ^~~

vim +/tmp +2504 sound/soc/codecs/rt1320-sdw.c

2497
2498 static int rt1320_brown_out_put(struct snd_kcontrol *kcontrol,
2499 struct snd_ctl_elem_value *ucontrol)
2500 {
2501 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
2502 struct rt1320_sdw_priv *rt1320 = snd_soc_component_get_drvdata(component);

> 2503		struct device *dev = &rt1320->sdw_slave->dev;
> 2504		int ret, tmp;

2505
2506 ret = pm_runtime_resume(component->dev);
2507 if (ret < 0 && ret != -EACCES)
2508 return ret;
2509
2510 rt1320->brown_out = ucontrol->value.integer.value[0];
2511 regcache_cache_bypass(rt1320->regmap, true);
2512
2513 if (rt1320->brown_out == 1)
2514 regmap_write(rt1320->regmap, 0xdb03, 0x00);
2515 else
2516 regmap_write(rt1320->regmap, 0xdb03, 0xf0);
2517
2518 regcache_cache_bypass(rt1320->regmap, false);
2519
2520 return 0;
2521 }
2522

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki