Skip to contentSkip to conversation

ASoC: es8316: limit headphone mixer volume

PATCH Superseded Katsuhiro Suzuki 3 participants 7 messages Aug 24, 2019 – Aug 26, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: es8316: limit headphone mixer volume

This patch limits Headphone mixer volume to 4 from 7. Because output sound suddenly becomes very loudly with many noise if set volume over 4.

---
 sound/soc/codecs/es8316.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/es8316.c +1 -1
index 8dfb5dbeebbf..bc4141e1eb7f 100644
@@ -91,7 +91,7 @@ static const struct snd_kcontrol_new es8316_snd_controls[] = {
 	SOC_DOUBLE_TLV("Headphone Playback Volume", ES8316_CPHP_ICAL_VOL,
 		       4, 0, 3, 1, hpout_vol_tlv),
 	SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL,
-		       0, 4, 7, 0, hpmixer_gain_tlv),
+		       0, 4, 4, 0, hpmixer_gain_tlv),
 
 	SOC_ENUM("Playback Polarity", dacpol),
 	SOC_DOUBLE_R_TLV("DAC Playback Volume", ES8316_DAC_VOLL,
Signature · 1 line
2.23.0.rc1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 5 lines · Katsuhiro Suzuki

This patch limits Headphone mixer volume to 4 from 7. Because output sound suddenly becomes very loudly with many noise if set volume over 4.

Higher then 4 not working matches my experience, see this comment from the UCM file: alsa-lib/src/conf/ucm/codecs/es8316/EnableSeq.conf :

# Set HP mixer vol to -6 dB (4/7) louder does not work cset "name='Headphone Mixer Volume' 4"

Limiting this to the actual working range at the kernel level seems sensible:

Regards,

Hans

Quoted 18 lines
---
  sound/soc/codecs/es8316.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/es8316.c +1 -1
index 8dfb5dbeebbf..bc4141e1eb7f 100644
@@ -91,7 +91,7 @@ static const struct snd_kcontrol_new es8316_snd_controls[] = {
  	SOC_DOUBLE_TLV("Headphone Playback Volume", ES8316_CPHP_ICAL_VOL,
  		       4, 0, 3, 1, hpout_vol_tlv),
  	SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL,
-		       0, 4, 7, 0, hpmixer_gain_tlv),
+		       0, 4, 4, 0, hpmixer_gain_tlv),
 
  	SOC_ENUM("Playback Polarity", dacpol),
  	SOC_DOUBLE_R_TLV("DAC Playback Volume", ES8316_DAC_VOLL,
#2 lore raw
Quoted 4 lines · Hans de Goede
Quoted 3 lines · Katsuhiro Suzuki

This patch limits Headphone mixer volume to 4 from 7. Because output sound suddenly becomes very loudly with many noise if set volume over 4.

That sounds like something that should be limited in UCM.

Quoted 5 lines

Higher then 4 not working matches my experience, see this comment from the UCM file: alsa-lib/src/conf/ucm/codecs/es8316/EnableSeq.conf :

# Set HP mixer vol to -6 dB (4/7) louder does not work cset "name='Headphone Mixer Volume' 4"

What does "does not work" mean more precisely?

I checked the spec, there is indeed something wrong in the kernel driver here. The db scale is not a simple scale as the kernel source suggests.

Instead it is:
0000 – -12dB
0001 – -10.5dB
0010 – -9dB
0011 – -7.5dB
0100 – -6dB
1000 – -4.5dB
1001 – -3dB
1010 – -1.5dB
1011 – 0dB

So perhaps we can fix the kernel to follow this table and then use UCM to limit the volume if its too high on a given platform?

Thanks
Daniel

#3 lore raw

Hello Daniel,

Quoted 30 lines · Daniel Drake
Quoted 4 lines · Hans de Goede
Quoted 3 lines · Katsuhiro Suzuki

This patch limits Headphone mixer volume to 4 from 7. Because output sound suddenly becomes very loudly with many noise if set volume over 4.

That sounds like something that should be limited in UCM.

Quoted 5 lines

Higher then 4 not working matches my experience, see this comment from the UCM file: alsa-lib/src/conf/ucm/codecs/es8316/EnableSeq.conf :

# Set HP mixer vol to -6 dB (4/7) louder does not work cset "name='Headphone Mixer Volume' 4"

What does "does not work" mean more precisely?

I checked the spec, there is indeed something wrong in the kernel driver here. The db scale is not a simple scale as the kernel source suggests.

Instead it is:
0000 – -12dB
0001 – -10.5dB
0010 – -9dB
0011 – -7.5dB
0100 – -6dB
1000 – -4.5dB
1001 – -3dB
1010 – -1.5dB
1011 – 0dB

Quoted 3 lines

So perhaps we can fix the kernel to follow this table and then use UCM to limit the volume if its too high on a given platform?

Thank you very important information. So you mean value 5, 6, 7 are illegal settings for ES8316. Correct codes are

static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(hpmixer_gain_tlv,

	0, 4, TLV_DB_SCALE_ITEM(-1200, 150, 0),
	8, 11, TLV_DB_SCALE_ITEM(-450, 150, 0),

);

and...

	SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL,
		       0, 4, 15, 0, hpmixer_gain_tlv),

Is my understanding correct? If so I'll test it on my board (RockPro64) and re-send patch.

BTW, do you know how to get ES8316 I2C registers spec?
I want to see it for understanding current code, but I cannot find...

Quoted 4 lines

Thanks
Daniel

Best Regards,
Katsuhiro Suzuki

#4 lore raw

Hello,

Oops... I got mistake,

Quoted 2 lines

SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL,
0, 4, 15, 0, hpmixer_gain_tlv),

is wrong,

Quoted 2 lines

SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL,
0, 4, 11, 0, hpmixer_gain_tlv),

is correct.

Best Regards,
Katsuhiro Suzuki

Quoted 65 lines · Katsuhiro Suzuki

Hello Daniel,

Quoted 30 lines · Daniel Drake
Quoted 4 lines · Hans de Goede
Quoted 3 lines · Katsuhiro Suzuki

This patch limits Headphone mixer volume to 4 from 7. Because output sound suddenly becomes very loudly with many noise if set volume over 4.

That sounds like something that should be limited in UCM.

Quoted 5 lines

Higher then 4 not working matches my experience, see this comment from the UCM file: alsa-lib/src/conf/ucm/codecs/es8316/EnableSeq.conf :

# Set HP mixer vol to -6 dB (4/7) louder does not work cset "name='Headphone Mixer Volume' 4"

What does "does not work" mean more precisely?

I checked the spec, there is indeed something wrong in the kernel driver here. The db scale is not a simple scale as the kernel source suggests.

Instead it is:
0000 – -12dB
0001 – -10.5dB
0010 – -9dB
0011 – -7.5dB
0100 – -6dB
1000 – -4.5dB
1001 – -3dB
1010 – -1.5dB
1011 – 0dB

Quoted 3 lines

So perhaps we can fix the kernel to follow this table and then use UCM to limit the volume if its too high on a given platform?

Thank you very important information. So you mean value 5, 6, 7 are illegal settings for ES8316. Correct codes are

static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(hpmixer_gain_tlv,
    0, 4, TLV_DB_SCALE_ITEM(-1200, 150, 0),
    8, 11, TLV_DB_SCALE_ITEM(-450, 150, 0),
);

and...

    SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL, 0, 4, 15, 0, hpmixer_gain_tlv),

Is my understanding correct? If so I'll test it on my board (RockPro64) and re-send patch.

BTW, do you know how to get ES8316 I2C registers spec?
I want to see it for understanding current code, but I cannot find...

Quoted 4 lines

Thanks
Daniel

Best Regards,
Katsuhiro Suzuki

#5 lore raw
In reply to Daniel Drake

Hi,

Quoted 8 lines · Daniel Drake
Quoted 4 lines · Hans de Goede
Quoted 3 lines · Katsuhiro Suzuki

This patch limits Headphone mixer volume to 4 from 7. Because output sound suddenly becomes very loudly with many noise if set volume over 4.

That sounds like something that should be limited in UCM.

Quoted 7 lines
Quoted 5 lines

Higher then 4 not working matches my experience, see this comment from the UCM file: alsa-lib/src/conf/ucm/codecs/es8316/EnableSeq.conf :

# Set HP mixer vol to -6 dB (4/7) louder does not work cset "name='Headphone Mixer Volume' 4"

What does "does not work" mean more precisely?

IIRC garbled sound.

Quoted 14 lines

I checked the spec, there is indeed something wrong in the kernel driver here. The db scale is not a simple scale as the kernel source suggests.

Instead it is:
0000 – -12dB
0001 – -10.5dB
0010 – -9dB
0011 – -7.5dB
0100 – -6dB
1000 – -4.5dB
1001 – -3dB
1010 – -1.5dB
1011 – 0dB

Quoted 2 lines

So perhaps we can fix the kernel to follow this table and then use UCM to limit the volume if its too high on a given platform?

Yes that sounds like the right thing to do. Katsuhiro can you confirm that using this table allows using the full scale ? note that the full scale now has 9 steps rather then 8.

Regards,

Hans

#6 lore raw

Hello Hans, Daniel,

Thank you for reviewing and comment.

Quoted 35 lines · Hans de Goede

Hi,

Quoted 8 lines · Daniel Drake
Quoted 4 lines · Hans de Goede
Quoted 3 lines · Katsuhiro Suzuki

This patch limits Headphone mixer volume to 4 from 7. Because output sound suddenly becomes very loudly with many noise if set volume over 4.

That sounds like something that should be limited in UCM.

Quoted 7 lines
Quoted 5 lines

Higher then 4 not working matches my experience, see this comment from the UCM file: alsa-lib/src/conf/ucm/codecs/es8316/EnableSeq.conf :

# Set HP mixer vol to -6 dB (4/7) louder does not work cset "name='Headphone Mixer Volume' 4"

What does "does not work" mean more precisely?

IIRC garbled sound.

Quoted 14 lines

I checked the spec, there is indeed something wrong in the kernel driver here. The db scale is not a simple scale as the kernel source suggests.

Instead it is:
0000 – -12dB
0001 – -10.5dB
0010 – -9dB
0011 – -7.5dB
0100 – -6dB
1000 – -4.5dB
1001 – -3dB
1010 – -1.5dB
1011 – 0dB

Quoted 7 lines
Quoted 2 lines

So perhaps we can fix the kernel to follow this table and then use UCM to limit the volume if its too high on a given platform?

Yes that sounds like the right thing to do. Katsuhiro can you confirm that using this table allows using the full scale ? note that the full scale now has 9 steps rather then 8.

I've finished testing this table on my board (RockPro64). Every values work well without garbled sound.

I checked address 0x16 register via /sys/kernel/debug/regmap too. The register values and dB (get from alsamixer) are the following if I increase headphone volume to max from min.

reg dB
0x16 scale
------------

  0x00  -12.00
  0x11  -10.50
  0x22  -9.00
  0x33  -7.50
  0x44  -6.00
  0x88  -4.50
  0x99  -3.00
  0xaa  -1.50
  0xbb  0.00

And I found other problem, current code is inverted L/R volume. It's only in Headphone "mixer" volume. It seems Headphone "master" volume works correctly.

I'll fix these problems and send V2 patch set.

Quoted 5 lines

Regards,

Hans

Best Regards,
Katsuhiro Suzuki