diff mbox series

[v4,2/4] ASoC: qcom: sc8280xp: limit speaker volumes

Message ID 20240119112420.7446-3-johan+linaro@kernel.org (mailing list archive)
State Superseded
Headers show
Series ASoC: qcom: volume fixes and codec cleanups | expand

Commit Message

Johan Hovold Jan. 19, 2024, 11:24 a.m. UTC
The UCM configuration for the Lenovo ThinkPad X13s has up until now
been setting the speaker PA volume to the minimum -3 dB when enabling
the speakers, but this does not prevent the user from increasing the
volume further.

Limit the digital gain and PA volumes to a combined -3 dB in the machine
driver to reduce the risk of speaker damage until we have active speaker
protection in place (or higher safe levels have been established).

Note that the PA volume limit cannot be set lower than 0 dB or
PulseAudio gets confused when the first 16 levels all map to -3 dB.

Also note that this will probably need to be generalised using
machine-specific limits, but a common limit should do for now.

Cc: stable@vger.kernel.org	# 6.5
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 sound/soc/qcom/sc8280xp.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Johan Hovold Jan. 19, 2024, 3:26 p.m. UTC | #1
On Fri, Jan 19, 2024 at 12:24:18PM +0100, Johan Hovold wrote:
> The UCM configuration for the Lenovo ThinkPad X13s has up until now
> been setting the speaker PA volume to the minimum -3 dB when enabling
> the speakers, but this does not prevent the user from increasing the
> volume further.
> 
> Limit the digital gain and PA volumes to a combined -3 dB in the machine
> driver to reduce the risk of speaker damage until we have active speaker
> protection in place (or higher safe levels have been established).
> 
> Note that the PA volume limit cannot be set lower than 0 dB or
> PulseAudio gets confused when the first 16 levels all map to -3 dB.

I tracked the down the root cause for this, which appears to be a bug
(feature) in pulseaudio that causes it to reject the dB range if the
maximum is negative:

	https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/447

This happened to work with v3 which limited the PA volume to the single
lowest setting, but would similarly break if anyone wants to set a -1.5
dB limit.

Johan
Mark Brown Jan. 22, 2024, 12:03 a.m. UTC | #2
On Fri, Jan 19, 2024 at 12:24:18PM +0100, Johan Hovold wrote:
> The UCM configuration for the Lenovo ThinkPad X13s has up until now
> been setting the speaker PA volume to the minimum -3 dB when enabling
> the speakers, but this does not prevent the user from increasing the
> volume further.

This doesn't apply against current code, please check and resend.
Johan Hovold Jan. 22, 2024, 7:41 a.m. UTC | #3
On Mon, Jan 22, 2024 at 12:03:55AM +0000, Mark Brown wrote:
> On Fri, Jan 19, 2024 at 12:24:18PM +0100, Johan Hovold wrote:
> > The UCM configuration for the Lenovo ThinkPad X13s has up until now
> > been setting the speaker PA volume to the minimum -3 dB when enabling
> > the speakers, but this does not prevent the user from increasing the
> > volume further.
> 
> This doesn't apply against current code, please check and resend.

These patches are based on Linus's tree after merging the sound updates
and I just verified that they apply cleanly to 6.8-rc1.

I couldn't find anything related in either linux-next or your ASoC tree
that should interfere.

Could you please try again or let me know which branch to rebase on?

Johan
Mark Brown Jan. 22, 2024, 4:05 p.m. UTC | #4
On Mon, Jan 22, 2024 at 08:41:59AM +0100, Johan Hovold wrote:
> On Mon, Jan 22, 2024 at 12:03:55AM +0000, Mark Brown wrote:

> > This doesn't apply against current code, please check and resend.

> These patches are based on Linus's tree after merging the sound updates
> and I just verified that they apply cleanly to 6.8-rc1.

> I couldn't find anything related in either linux-next or your ASoC tree
> that should interfere.

> Could you please try again or let me know which branch to rebase on?

I was applying it against v6.8-rc1.
Johan Hovold Jan. 22, 2024, 5:29 p.m. UTC | #5
On Mon, Jan 22, 2024 at 04:05:37PM +0000, Mark Brown wrote:
> On Mon, Jan 22, 2024 at 08:41:59AM +0100, Johan Hovold wrote:
> > On Mon, Jan 22, 2024 at 12:03:55AM +0000, Mark Brown wrote:
> 
> > > This doesn't apply against current code, please check and resend.
> 
> > These patches are based on Linus's tree after merging the sound updates
> > and I just verified that they apply cleanly to 6.8-rc1.
> 
> > I couldn't find anything related in either linux-next or your ASoC tree
> > that should interfere.
> 
> > Could you please try again or let me know which branch to rebase on?
> 
> I was applying it against v6.8-rc1.

That's what I assumed, but I still don't understand why it doesn't apply
on your end:

	$ git checkout -b tmp v6.8-rc1
	$ b4 am 20240119112420.7446-1-johan+linaro@kernel.org
	...
 	$ git am ./v4_20240119_johan_linaro_asoc_qcom_volume_fixes_and_codec_cleanups.mbx
	Applying: ASoC: codecs: wsa883x: fix PA volume control
	Applying: ASoC: qcom: sc8280xp: limit speaker volumes
	Applying: ASoC: codecs: lpass-wsa-macro: fix compander volume hack
	Applying: ASoC: codecs: wcd9335: drop unused gain hack remnant

And if I generate patches from this branch, the diffs are identical to
the v4 patches I sent.

Could you please try again, and tell me which patch fails to apply and
how it fails?

Johan
Mark Brown Jan. 22, 2024, 6:06 p.m. UTC | #6
On Mon, Jan 22, 2024 at 06:29:12PM +0100, Johan Hovold wrote:

> Could you please try again, and tell me which patch fails to apply and
> how it fails?

It was the specific patch I replied to, just the standard "this patch
doesn't apply" message.
Johan Hovold Jan. 22, 2024, 6:21 p.m. UTC | #7
On Mon, Jan 22, 2024 at 06:06:25PM +0000, Mark Brown wrote:
> On Mon, Jan 22, 2024 at 06:29:12PM +0100, Johan Hovold wrote:
> 
> > Could you please try again, and tell me which patch fails to apply and
> > how it fails?
> 
> It was the specific patch I replied to, just the standard "this patch
> doesn't apply" message.

Ok, thanks. No idea what goes wrong here. I just sent the regenerated
patches as a v5.

Johan
diff mbox series

Patch

diff --git a/sound/soc/qcom/sc8280xp.c b/sound/soc/qcom/sc8280xp.c
index ed4bb551bfbb..b7fd503a1666 100644
--- a/sound/soc/qcom/sc8280xp.c
+++ b/sound/soc/qcom/sc8280xp.c
@@ -32,12 +32,14 @@  static int sc8280xp_snd_init(struct snd_soc_pcm_runtime *rtd)
 	case WSA_CODEC_DMA_RX_0:
 	case WSA_CODEC_DMA_RX_1:
 		/*
-		 * set limit of 0dB on Digital Volume for Speakers,
-		 * this can prevent damage of speakers to some extent without
-		 * active speaker protection
+		 * Set limit of -3 dB on Digital Volume and 0 dB on PA Volume
+		 * to reduce the risk of speaker damage until we have active
+		 * speaker protection in place.
 		 */
-		snd_soc_limit_volume(card, "WSA_RX0 Digital Volume", 84);
-		snd_soc_limit_volume(card, "WSA_RX1 Digital Volume", 84);
+		snd_soc_limit_volume(card, "WSA_RX0 Digital Volume", 81);
+		snd_soc_limit_volume(card, "WSA_RX1 Digital Volume", 81);
+		snd_soc_limit_volume(card, "SpkrLeft PA Volume", 17);
+		snd_soc_limit_volume(card, "SpkrRight PA Volume", 17);
 		break;
 	default:
 		break;