diff mbox series

[3/5] ASoC: codecs: ES8326: Adding new volume kcontrols

Message ID 20240119112858.2982-4-zhuning0077@gmail.com (mailing list archive)
State Superseded
Headers show
Series ASoC: codecs: fix ES8326 performance and pop noise | expand

Commit Message

Zhu Ning Jan. 19, 2024, 11:28 a.m. UTC
ES8326 features a headphone volume control register and four DAC
    volume control registers.
    We add new volume Kcontrols for these registers to enhance the
    configurability of the volume settings, providing users with
    greater flexibility.

Signed-off-by: Zhu Ning <zhuning0077@gmail.com>
---
 sound/soc/codecs/es8326.c | 30 ++++++++++++++++++++++++++++++
 sound/soc/codecs/es8326.h |  5 ++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

Comments

Mark Brown Jan. 19, 2024, 1:53 p.m. UTC | #1
On Fri, Jan 19, 2024 at 07:28:56PM +0800, Zhu Ning wrote:

> +static const char *const hpvol[] = {
> +	"0 dB",
> +	"-6 dB",
> +	"-24 dB",
> +	"+3.5 dB",
> +	"-3.5 dB",
> +	"-18 dB",
> +};
> +static const unsigned int hp_vol_values[] = { 0, 1, 2, 4, 5, 6 };

Volumes should be standard volume controls with TLV information rather
than enumerations.  I see that you can't just use a standard volume
control here since there's an invalid value that needs to be skipped
over, and it doesn't help that there's no ordering to the values either.
I think the best thing would probably be to open code a custom volume
control - this feels weird enough that it's probably not worrying about
trying for reuse.  Just have put and get functions that map 0..6 into
the register values for the volumes in ascending order, then you can
have a control that looks normal to userspace.
kernel test robot Jan. 20, 2024, 3:03 a.m. UTC | #2
Hi Zhu,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on tiwai-sound/for-next tiwai-sound/for-linus linus/master next-20240119]
[cannot apply to v6.7]
[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/Zhu-Ning/ASoC-codecs-ES8326-improving-crosstalk-performance/20240119-193247
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20240119112858.2982-4-zhuning0077%40gmail.com
patch subject: [PATCH 3/5] ASoC: codecs: ES8326: Adding new volume kcontrols
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20240120/202401201033.SJS8Mtlr-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240120/202401201033.SJS8Mtlr-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401201033.SJS8Mtlr-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from sound/soc/codecs/es8326.c:16:
>> sound/soc/codecs/es8326.c:184:47: error: 'ES8326_DAC_VOL' undeclared here (not in a function); did you mean 'ES8326_DACR_VOL'?
     184 |         SOC_SINGLE_TLV("DAC Playback Volume", ES8326_DAC_VOL, 0, 0xbf, 0, dac_vol_tlv),
         |                                               ^~~~~~~~~~~~~~
   include/sound/soc.h:34:17: note: in definition of macro 'SOC_DOUBLE_VALUE'
      34 |         {.reg = xreg, .rreg = xreg, .shift = shift_left, \
         |                 ^~~~
   include/sound/soc.h:80:26: note: in expansion of macro 'SOC_SINGLE_VALUE'
      80 |         .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) }
         |                          ^~~~~~~~~~~~~~~~
   sound/soc/codecs/es8326.c:184:9: note: in expansion of macro 'SOC_SINGLE_TLV'
     184 |         SOC_SINGLE_TLV("DAC Playback Volume", ES8326_DAC_VOL, 0, 0xbf, 0, dac_vol_tlv),
         |         ^~~~~~~~~~~~~~


vim +184 sound/soc/codecs/es8326.c

b7cd5a85ede3b0 Zhu Ning 2024-01-19  170  
5c439937775d77 Zhu Ning 2022-08-16  171  static const struct soc_enum dacpol =
5c439937775d77 Zhu Ning 2022-08-16  172  	SOC_ENUM_SINGLE(ES8326_DAC_DSM, 4, 4, dacpol_txt);
5c439937775d77 Zhu Ning 2022-08-16  173  static const struct soc_enum alc_winsize =
5c439937775d77 Zhu Ning 2022-08-16  174  	SOC_ENUM_SINGLE(ES8326_ADC_RAMPRATE, 4, 16, winsize);
5c439937775d77 Zhu Ning 2022-08-16  175  static const struct soc_enum drc_winsize =
5c439937775d77 Zhu Ning 2022-08-16  176  	SOC_ENUM_SINGLE(ES8326_DRC_WINSIZE, 4, 16, winsize);
b7cd5a85ede3b0 Zhu Ning 2024-01-19  177  static const struct soc_enum hp_vol =
b7cd5a85ede3b0 Zhu Ning 2024-01-19  178  	SOC_VALUE_ENUM_DOUBLE(ES8326_HP_VOL, 4, 0, 7,
b7cd5a85ede3b0 Zhu Ning 2024-01-19  179  			ARRAY_SIZE(hpvol), hpvol, hp_vol_values);
b7cd5a85ede3b0 Zhu Ning 2024-01-19  180  static const struct soc_enum hpvol_spkvol_switch =
b7cd5a85ede3b0 Zhu Ning 2024-01-19  181  	SOC_ENUM_SINGLE(ES8326_HP_MISC, 6, 4, hp_spkvol_switch);
5c439937775d77 Zhu Ning 2022-08-16  182  
5c439937775d77 Zhu Ning 2022-08-16  183  static const struct snd_kcontrol_new es8326_snd_controls[] = {
5c439937775d77 Zhu Ning 2022-08-16 @184  	SOC_SINGLE_TLV("DAC Playback Volume", ES8326_DAC_VOL, 0, 0xbf, 0, dac_vol_tlv),
5c439937775d77 Zhu Ning 2022-08-16  185  	SOC_ENUM("Playback Polarity", dacpol),
5c439937775d77 Zhu Ning 2022-08-16  186  	SOC_SINGLE_TLV("DAC Ramp Rate", ES8326_DAC_RAMPRATE, 0, 0x0f, 0, softramp_rate),
5c439937775d77 Zhu Ning 2022-08-16  187  	SOC_SINGLE_TLV("DRC Recovery Level", ES8326_DRC_RECOVERY, 0, 4, 0, drc_recovery_tlv),
5c439937775d77 Zhu Ning 2022-08-16  188  	SOC_ENUM("DRC Winsize", drc_winsize),
5c439937775d77 Zhu Ning 2022-08-16  189  	SOC_SINGLE_TLV("DRC Target Level", ES8326_DRC_WINSIZE, 0, 0x0f, 0, drc_target_tlv),
5c439937775d77 Zhu Ning 2022-08-16  190  
5c439937775d77 Zhu Ning 2022-08-16  191  	SOC_DOUBLE_R_TLV("ADC Capture Volume", ES8326_ADC1_VOL, ES8326_ADC2_VOL, 0, 0xff, 0,
5c439937775d77 Zhu Ning 2022-08-16  192  			 adc_vol_tlv),
5c439937775d77 Zhu Ning 2022-08-16  193  	SOC_DOUBLE_TLV("ADC PGA Volume", ES8326_ADC_SCALE, 4, 0, 5, 0, adc_pga_tlv),
5c439937775d77 Zhu Ning 2022-08-16  194  	SOC_SINGLE_TLV("ADC PGA Gain Volume", ES8326_PGAGAIN, 0, 10, 0, adc_analog_pga_tlv),
5c439937775d77 Zhu Ning 2022-08-16  195  	SOC_SINGLE_TLV("ADC Ramp Rate", ES8326_ADC_RAMPRATE, 0, 0x0f, 0, softramp_rate),
5c439937775d77 Zhu Ning 2022-08-16  196  	SOC_SINGLE("ALC Capture Switch", ES8326_ALC_RECOVERY, 3, 1, 0),
5c439937775d77 Zhu Ning 2022-08-16  197  	SOC_SINGLE_TLV("ALC Capture Recovery Level", ES8326_ALC_LEVEL,
5c439937775d77 Zhu Ning 2022-08-16  198  			0, 4, 0, drc_recovery_tlv),
5c439937775d77 Zhu Ning 2022-08-16  199  	SOC_ENUM("ALC Capture Winsize", alc_winsize),
5c439937775d77 Zhu Ning 2022-08-16  200  	SOC_SINGLE_TLV("ALC Capture Target Level", ES8326_ALC_LEVEL,
5c439937775d77 Zhu Ning 2022-08-16  201  			0, 0x0f, 0, drc_target_tlv),
5c439937775d77 Zhu Ning 2022-08-16  202  
e21a9e2701cda5 Zhu Ning 2024-01-19  203  	SOC_SINGLE_EXT("CROSSTALK1", SND_SOC_NOPM, 0, 31, 0,
e21a9e2701cda5 Zhu Ning 2024-01-19  204  			es8326_crosstalk1_get, es8326_crosstalk1_set),
e21a9e2701cda5 Zhu Ning 2024-01-19  205  	SOC_SINGLE_EXT("CROSSTALK2", SND_SOC_NOPM, 0, 31, 0,
e21a9e2701cda5 Zhu Ning 2024-01-19  206  			es8326_crosstalk2_get, es8326_crosstalk2_set),
b7cd5a85ede3b0 Zhu Ning 2024-01-19  207  
b7cd5a85ede3b0 Zhu Ning 2024-01-19  208  	SOC_SINGLE_TLV("HPL Playback Volume", ES8326_DACL_VOL, 0, 0xbf, 0, dac_vol_tlv),
b7cd5a85ede3b0 Zhu Ning 2024-01-19  209  	SOC_SINGLE_TLV("HPR Playback Volume", ES8326_DACR_VOL, 0, 0xbf, 0, dac_vol_tlv),
b7cd5a85ede3b0 Zhu Ning 2024-01-19  210  	SOC_SINGLE_TLV("SPKL Playback Volume", ES8326_SPKL_VOL, 0, 0xbf, 0, dac_vol_tlv),
b7cd5a85ede3b0 Zhu Ning 2024-01-19  211  	SOC_SINGLE_TLV("SPKR Playback Volume", ES8326_SPKR_VOL, 0, 0xbf, 0, dac_vol_tlv),
b7cd5a85ede3b0 Zhu Ning 2024-01-19  212  
b7cd5a85ede3b0 Zhu Ning 2024-01-19  213  	SOC_ENUM("HP Volume", hp_vol),
b7cd5a85ede3b0 Zhu Ning 2024-01-19  214  	SOC_ENUM("HPVol SPKVol switch", hpvol_spkvol_switch),
5c439937775d77 Zhu Ning 2022-08-16  215  };
5c439937775d77 Zhu Ning 2022-08-16  216
diff mbox series

Patch

diff --git a/sound/soc/codecs/es8326.c b/sound/soc/codecs/es8326.c
index 10157a4bd500..c7f89c990178 100755
--- a/sound/soc/codecs/es8326.c
+++ b/sound/soc/codecs/es8326.c
@@ -151,12 +151,34 @@  static const char *const winsize[] = {
 static const char *const dacpol_txt[] =	{
 	"Normal", "R Invert", "L Invert", "L + R Invert" };
 
+static const char *const hpvol[] = {
+	"0 dB",
+	"-6 dB",
+	"-24 dB",
+	"+3.5 dB",
+	"-3.5 dB",
+	"-18 dB",
+};
+static const unsigned int hp_vol_values[] = { 0, 1, 2, 4, 5, 6 };
+
+static const char *const hp_spkvol_switch[] = {
+	"HPVOL: HPL+HPL, SPKVOL: HPL+HPL",
+	"HPVOL: HPL+HPR, SPKVOL: HPL+HPR",
+	"HPVOL: HPL+HPL, SPKVOL: SPKL+SPKR",
+	"HPVOL: HPL+HPR, SPKVOL: SPKL+SPKR",
+};
+
 static const struct soc_enum dacpol =
 	SOC_ENUM_SINGLE(ES8326_DAC_DSM, 4, 4, dacpol_txt);
 static const struct soc_enum alc_winsize =
 	SOC_ENUM_SINGLE(ES8326_ADC_RAMPRATE, 4, 16, winsize);
 static const struct soc_enum drc_winsize =
 	SOC_ENUM_SINGLE(ES8326_DRC_WINSIZE, 4, 16, winsize);
+static const struct soc_enum hp_vol =
+	SOC_VALUE_ENUM_DOUBLE(ES8326_HP_VOL, 4, 0, 7,
+			ARRAY_SIZE(hpvol), hpvol, hp_vol_values);
+static const struct soc_enum hpvol_spkvol_switch =
+	SOC_ENUM_SINGLE(ES8326_HP_MISC, 6, 4, hp_spkvol_switch);
 
 static const struct snd_kcontrol_new es8326_snd_controls[] = {
 	SOC_SINGLE_TLV("DAC Playback Volume", ES8326_DAC_VOL, 0, 0xbf, 0, dac_vol_tlv),
@@ -182,6 +204,14 @@  static const struct snd_kcontrol_new es8326_snd_controls[] = {
 			es8326_crosstalk1_get, es8326_crosstalk1_set),
 	SOC_SINGLE_EXT("CROSSTALK2", SND_SOC_NOPM, 0, 31, 0,
 			es8326_crosstalk2_get, es8326_crosstalk2_set),
+
+	SOC_SINGLE_TLV("HPL Playback Volume", ES8326_DACL_VOL, 0, 0xbf, 0, dac_vol_tlv),
+	SOC_SINGLE_TLV("HPR Playback Volume", ES8326_DACR_VOL, 0, 0xbf, 0, dac_vol_tlv),
+	SOC_SINGLE_TLV("SPKL Playback Volume", ES8326_SPKL_VOL, 0, 0xbf, 0, dac_vol_tlv),
+	SOC_SINGLE_TLV("SPKR Playback Volume", ES8326_SPKR_VOL, 0, 0xbf, 0, dac_vol_tlv),
+
+	SOC_ENUM("HP Volume", hp_vol),
+	SOC_ENUM("HPVol SPKVol switch", hpvol_spkvol_switch),
 };
 
 static const struct snd_soc_dapm_widget es8326_dapm_widgets[] = {
diff --git a/sound/soc/codecs/es8326.h b/sound/soc/codecs/es8326.h
index 4234bbb900c4..ee12caef8105 100644
--- a/sound/soc/codecs/es8326.h
+++ b/sound/soc/codecs/es8326.h
@@ -69,7 +69,7 @@ 
 #define ES8326_DAC_DSM		0x4D
 #define ES8326_DAC_RAMPRATE	0x4E
 #define ES8326_DAC_VPPSCALE	0x4F
-#define ES8326_DAC_VOL		0x50
+#define ES8326_DACL_VOL	        0x50
 #define ES8326_DRC_RECOVERY	0x53
 #define ES8326_DRC_WINSIZE	0x54
 #define ES8326_DAC_CROSSTALK	0x55
@@ -81,6 +81,9 @@ 
 #define ES8326_SDINOUT23_IO	0x5B
 #define ES8326_JACK_PULSE	0x5C
 
+#define ES8326_DACR_VOL		0xF4
+#define ES8326_SPKL_VOL		0xF5
+#define ES8326_SPKR_VOL		0xF6
 #define ES8326_HP_MISC		0xF7
 #define ES8326_CTIA_OMTP_STA	0xF8
 #define ES8326_PULLUP_CTL	0xF9