2023-12-04 12:47:49

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH 0/2] ASoC: qcom: Limit Digital gains on speaker

From: Srinivas Kandagatla <[email protected]>

Limit the speaker digital gains to 0dB so that the users will not damage them.
Currently there is a limit in UCM, but this does not stop the user form
changing the digital gains from command line. So limit this in driver
which makes the speakers more safer without active speaker protection in
place.

Apart from this there is also a range check fix in snd_soc_limit_volume
to allow setting this limit correctly.

Tested on Lenovo X13s.

Srinivas Kandagatla (2):
ASoC: ops: add correct range check for limiting volume
ASoC: qcom: sc8280xp: Limit speaker digital volumes

sound/soc/qcom/sc8280xp.c | 17 +++++++++++++++++
sound/soc/soc-ops.c | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)

--
2.25.1


2023-12-04 12:47:56

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH 2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes

From: Srinivas Kandagatla <[email protected]>

Limit the speaker digital gains to 0dB so that the users will not damage them.
Currently there is a limit in UCM, but this does not stop the user form
changing the digital gains from command line. So limit this in driver
which makes the speakers more safer without active speaker protection in
place.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
sound/soc/qcom/sc8280xp.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/sound/soc/qcom/sc8280xp.c b/sound/soc/qcom/sc8280xp.c
index 249a43e1dee3..1e8f9452cd28 100644
--- a/sound/soc/qcom/sc8280xp.c
+++ b/sound/soc/qcom/sc8280xp.c
@@ -25,6 +25,23 @@ struct sc8280xp_snd_data {
static int sc8280xp_snd_init(struct snd_soc_pcm_runtime *rtd)
{
struct sc8280xp_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
+ struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ struct snd_soc_card *card = rtd->card;
+
+ switch (cpu_dai->id) {
+ 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
+ */
+ snd_soc_limit_volume(card, "WSA_RX0 Digital Volume", 84);
+ snd_soc_limit_volume(card, "WSA_RX1 Digital Volume", 84);
+ break;
+ default:
+ break;
+ }

return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup);
}
--
2.25.1

2023-12-04 12:47:57

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH 1/2] ASoC: ops: add correct range check for limiting volume

From: Srinivas Kandagatla <[email protected]>

Volume can have ranges that start with negative values, ex: -84dB to
+40dB. Apply correct range check in snd_soc_limit_volume before setting
the platform_max. Without this patch, for example setting a 0dB limit on
a volume range of -84dB to +40dB would fail.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
sound/soc/soc-ops.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 55b009d3c681..2d25748ca706 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -661,7 +661,7 @@ int snd_soc_limit_volume(struct snd_soc_card *card,
kctl = snd_soc_card_get_kcontrol(card, name);
if (kctl) {
struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
- if (max <= mc->max) {
+ if (max <= mc->max - mc->min) {
mc->platform_max = max;
ret = 0;
}
--
2.25.1

2023-12-04 13:51:56

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 1/2] ASoC: ops: add correct range check for limiting volume

On Mon, Dec 04, 2023 at 12:47:35PM +0000, [email protected] wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> Volume can have ranges that start with negative values, ex: -84dB to
> +40dB. Apply correct range check in snd_soc_limit_volume before setting
> the platform_max. Without this patch, for example setting a 0dB limit on
> a volume range of -84dB to +40dB would fail.
>
> Signed-off-by: Srinivas Kandagatla <[email protected]>

Seems to work as intended with the following patch on the X13s:

Tested-by: Johan Hovold <[email protected]>
Reviewed-by: Johan Hovold <[email protected]>

Should you add a Fixes and CC-stable tag so we can get this backported
(at least to 6.5 for the X13s)?

Johan

2023-12-04 13:53:38

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes

On Mon, Dec 04, 2023 at 12:47:36PM +0000, [email protected] wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> Limit the speaker digital gains to 0dB so that the users will not damage them.
> Currently there is a limit in UCM, but this does not stop the user form
> changing the digital gains from command line. So limit this in driver
> which makes the speakers more safer without active speaker protection in
> place.
>
> Signed-off-by: Srinivas Kandagatla <[email protected]>

Works as intended:

Reviewed-by: Johan Hovold <[email protected]>
Tested-by: Johan Hovold <[email protected]>

Given the reason for why you are adding this, it seems you should have
added:

Cc: [email protected] # 6.5

as well.

Johan

2023-12-05 13:12:13

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 0/2] ASoC: qcom: Limit Digital gains on speaker

On Mon, 04 Dec 2023 12:47:34 +0000, [email protected] wrote:
> Limit the speaker digital gains to 0dB so that the users will not damage them.
> Currently there is a limit in UCM, but this does not stop the user form
> changing the digital gains from command line. So limit this in driver
> which makes the speakers more safer without active speaker protection in
> place.
>
> Apart from this there is also a range check fix in snd_soc_limit_volume
> to allow setting this limit correctly.
>
> [...]

Applied to

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

Thanks!

[1/2] ASoC: ops: add correct range check for limiting volume
commit: fb9ad24485087e0f00d84bee7a5914640b2b9024
[2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes
commit: 716d4e5373e9d1ae993485ab2e3b893bf7104fb1

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

2023-12-11 08:07:28

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 0/2] ASoC: qcom: Limit Digital gains on speaker

Hi Greg and Sasha,

On Mon, Dec 04, 2023 at 12:47:34PM +0000, [email protected] wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> Limit the speaker digital gains to 0dB so that the users will not damage them.
> Currently there is a limit in UCM, but this does not stop the user form
> changing the digital gains from command line. So limit this in driver
> which makes the speakers more safer without active speaker protection in
> place.
>
> Apart from this there is also a range check fix in snd_soc_limit_volume
> to allow setting this limit correctly.
>
> Tested on Lenovo X13s.
>
> Srinivas Kandagatla (2):
> ASoC: ops: add correct range check for limiting volume
> ASoC: qcom: sc8280xp: Limit speaker digital volumes

These were unfortunately not marked for stable, but could you pick them
up for 6.6?

The upstream commits are:

fb9ad2448508 ("ASoC: ops: add correct range check for limiting volume")
716d4e5373e9 ("ASoC: qcom: sc8280xp: Limit speaker digital volumes")

> sound/soc/qcom/sc8280xp.c | 17 +++++++++++++++++
> sound/soc/soc-ops.c | 2 +-
> 2 files changed, 18 insertions(+), 1 deletion(-)

Johan

2023-12-11 12:47:31

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 0/2] ASoC: qcom: Limit Digital gains on speaker

On Mon, Dec 11, 2023 at 09:08:03AM +0100, Johan Hovold wrote:
> Hi Greg and Sasha,
>
> On Mon, Dec 04, 2023 at 12:47:34PM +0000, [email protected] wrote:
> > From: Srinivas Kandagatla <[email protected]>
> >
> > Limit the speaker digital gains to 0dB so that the users will not damage them.
> > Currently there is a limit in UCM, but this does not stop the user form
> > changing the digital gains from command line. So limit this in driver
> > which makes the speakers more safer without active speaker protection in
> > place.
> >
> > Apart from this there is also a range check fix in snd_soc_limit_volume
> > to allow setting this limit correctly.
> >
> > Tested on Lenovo X13s.
> >
> > Srinivas Kandagatla (2):
> > ASoC: ops: add correct range check for limiting volume
> > ASoC: qcom: sc8280xp: Limit speaker digital volumes
>
> These were unfortunately not marked for stable, but could you pick them
> up for 6.6?
>
> The upstream commits are:
>
> fb9ad2448508 ("ASoC: ops: add correct range check for limiting volume")
> 716d4e5373e9 ("ASoC: qcom: sc8280xp: Limit speaker digital volumes")

Now queued up, thanks.

greg k-h

2023-12-11 12:54:56

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 0/2] ASoC: qcom: Limit Digital gains on speaker

On Mon, Dec 11, 2023 at 01:40:52PM +0100, Greg Kroah-Hartman wrote:
> On Mon, Dec 11, 2023 at 09:08:03AM +0100, Johan Hovold wrote:
> > Hi Greg and Sasha,
> >
> > On Mon, Dec 04, 2023 at 12:47:34PM +0000, [email protected] wrote:
> > > From: Srinivas Kandagatla <[email protected]>
> > >
> > > Limit the speaker digital gains to 0dB so that the users will not damage them.
> > > Currently there is a limit in UCM, but this does not stop the user form
> > > changing the digital gains from command line. So limit this in driver
> > > which makes the speakers more safer without active speaker protection in
> > > place.
> > >
> > > Apart from this there is also a range check fix in snd_soc_limit_volume
> > > to allow setting this limit correctly.
> > >
> > > Tested on Lenovo X13s.
> > >
> > > Srinivas Kandagatla (2):
> > > ASoC: ops: add correct range check for limiting volume
> > > ASoC: qcom: sc8280xp: Limit speaker digital volumes
> >
> > These were unfortunately not marked for stable, but could you pick them
> > up for 6.6?
> >
> > The upstream commits are:
> >
> > fb9ad2448508 ("ASoC: ops: add correct range check for limiting volume")
> > 716d4e5373e9 ("ASoC: qcom: sc8280xp: Limit speaker digital volumes")
>
> Now queued up, thanks.

Oops, no, this breaks the build on 6.6.y, can you send a series that is
at least built for this series successfully? :)

thanks,

greg k-h

2023-12-11 13:28:58

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 0/2] ASoC: qcom: Limit Digital gains on speaker

On Mon, Dec 11, 2023 at 01:54:39PM +0100, Greg Kroah-Hartman wrote:
> On Mon, Dec 11, 2023 at 01:40:52PM +0100, Greg Kroah-Hartman wrote:
> > On Mon, Dec 11, 2023 at 09:08:03AM +0100, Johan Hovold wrote:
> > > On Mon, Dec 04, 2023 at 12:47:34PM +0000, [email protected] wrote:

> > > These were unfortunately not marked for stable, but could you pick them
> > > up for 6.6?
> > >
> > > The upstream commits are:
> > >
> > > fb9ad2448508 ("ASoC: ops: add correct range check for limiting volume")
> > > 716d4e5373e9 ("ASoC: qcom: sc8280xp: Limit speaker digital volumes")
> >
> > Now queued up, thanks.
>
> Oops, no, this breaks the build on 6.6.y, can you send a series that is
> at least built for this series successfully? :)

Sorry about that. I was not aware of the asoc interface rename that went
into 6.7.

Just sent a backport of the series here:

https://lore.kernel.org/r/[email protected]

Johan