public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH stable-6.6 0/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes
@ 2023-12-11 13:26 Johan Hovold
  2023-12-11 13:26 ` [PATCH stable-6.6 1/2] ASoC: ops: add correct range check for limiting volume Johan Hovold
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Johan Hovold @ 2023-12-11 13:26 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Sasha Levin, stable, broonie, alsa-devel, perex, tiwai,
	linux-sound, linux-kernel, johan+linaro, srinivas.kandagatla

This is a backport of the following series:

	https://lore.kernel.org/lkml/20231204124736.132185-1-srinivas.kandagatla@linaro.org/

which did not build on 6.6 due a rename of the asoc_rtd_to_cpu()
interface.

Johan


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.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH stable-6.6 1/2] ASoC: ops: add correct range check for limiting volume
  2023-12-11 13:26 [PATCH stable-6.6 0/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Johan Hovold
@ 2023-12-11 13:26 ` Johan Hovold
  2023-12-11 13:26 ` [PATCH stable-6.6 2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Johan Hovold
  2023-12-11 13:40 ` [PATCH stable-6.6 0/2] " Greg Kroah-Hartman
  2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2023-12-11 13:26 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Sasha Levin, stable, broonie, alsa-devel, perex, tiwai,
	linux-sound, linux-kernel, johan+linaro, srinivas.kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

commit fb9ad24485087e0f00d84bee7a5914640b2b9024 upstream.

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 <srinivas.kandagatla@linaro.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
Reviewed-by: Johan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20231204124736.132185-2-srinivas.kandagatla@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 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.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH stable-6.6 2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes
  2023-12-11 13:26 [PATCH stable-6.6 0/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Johan Hovold
  2023-12-11 13:26 ` [PATCH stable-6.6 1/2] ASoC: ops: add correct range check for limiting volume Johan Hovold
@ 2023-12-11 13:26 ` Johan Hovold
  2023-12-11 13:40 ` [PATCH stable-6.6 0/2] " Greg Kroah-Hartman
  2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2023-12-11 13:26 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Sasha Levin, stable, broonie, alsa-devel, perex, tiwai,
	linux-sound, linux-kernel, johan+linaro, srinivas.kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

commit 716d4e5373e9d1ae993485ab2e3b893bf7104fb1 upstream.

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 <srinivas.kandagatla@linaro.org>
Reviewed-by: Johan Hovold <johan+linaro@kernel.org>
Tested-by: Johan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20231204124736.132185-3-srinivas.kandagatla@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
[ johan: backport to 6.6; rename snd_soc_rtd_to_cpu() ]
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 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 14d9fea33d16..c61cad0180c8 100644
--- a/sound/soc/qcom/sc8280xp.c
+++ b/sound/soc/qcom/sc8280xp.c
@@ -27,6 +27,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 = asoc_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.41.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH stable-6.6 0/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes
  2023-12-11 13:26 [PATCH stable-6.6 0/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Johan Hovold
  2023-12-11 13:26 ` [PATCH stable-6.6 1/2] ASoC: ops: add correct range check for limiting volume Johan Hovold
  2023-12-11 13:26 ` [PATCH stable-6.6 2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Johan Hovold
@ 2023-12-11 13:40 ` Greg Kroah-Hartman
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2023-12-11 13:40 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Sasha Levin, stable, broonie, alsa-devel, perex, tiwai,
	linux-sound, linux-kernel, srinivas.kandagatla

On Mon, Dec 11, 2023 at 02:26:06PM +0100, Johan Hovold wrote:
> This is a backport of the following series:
> 
> 	https://lore.kernel.org/lkml/20231204124736.132185-1-srinivas.kandagatla@linaro.org/
> 
> which did not build on 6.6 due a rename of the asoc_rtd_to_cpu()
> interface.
> 
> Johan
> 
> 
> 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.41.0
> 
> 

Now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-11 13:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-11 13:26 [PATCH stable-6.6 0/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Johan Hovold
2023-12-11 13:26 ` [PATCH stable-6.6 1/2] ASoC: ops: add correct range check for limiting volume Johan Hovold
2023-12-11 13:26 ` [PATCH stable-6.6 2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Johan Hovold
2023-12-11 13:40 ` [PATCH stable-6.6 0/2] " Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox