Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: ops: Enforce platform maximum on initial value
@ 2025-02-08  0:57 broonie
  2025-02-17 13:38 ` Mark Brown
  2025-02-18 13:52 ` Geert Uytterhoeven
  0 siblings, 2 replies; 3+ messages in thread
From: broonie @ 2025-02-08  0:57 UTC (permalink / raw)
  To: Liam Girdwood, Martin Povišer; +Cc: linux-sound, linux-kernel, Mark Brown

From: Martin Povišer <povik+lin@cutebit.org>

Lower the volume if it is violating the platform maximum at its initial
value (i.e. at the time of the 'snd_soc_limit_volume' call).

Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
[Cherry picked from the Asahi kernel with fixups -- broonie]
Signed-off-by: Mark Brown <broonie@kernel.orG>
---
 sound/soc/soc-ops.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 19928f098d8d..4d63dd0b0d0f 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -640,6 +640,33 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
 
+static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
+{
+	struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
+	struct snd_ctl_elem_value uctl;
+	int ret;
+
+	if (!mc->platform_max)
+		return 0;
+
+	ret = kctl->get(kctl, &uctl);
+	if (ret < 0)
+		return ret;
+
+	if (uctl.value.integer.value[0] > mc->platform_max)
+		uctl.value.integer.value[0] = mc->platform_max;
+
+	if (snd_soc_volsw_is_stereo(mc) &&
+	    uctl.value.integer.value[1] > mc->platform_max)
+		uctl.value.integer.value[1] = mc->platform_max;
+
+	ret = kctl->put(kctl, &uctl);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 /**
  * snd_soc_limit_volume - Set new limit to an existing volume control.
  *
@@ -664,7 +691,7 @@ int snd_soc_limit_volume(struct snd_soc_card *card,
 		struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
 		if (max <= mc->max - mc->min) {
 			mc->platform_max = max;
-			ret = 0;
+			ret = snd_soc_clip_to_platform_max(kctl);
 		}
 	}
 	return ret;

---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250207-asoc-volume-limit-80abec587f6f

Best regards,
-- 
Mark Brown <broonie@kernel.org>


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

* Re: [PATCH] ASoC: ops: Enforce platform maximum on initial value
  2025-02-08  0:57 [PATCH] ASoC: ops: Enforce platform maximum on initial value broonie
@ 2025-02-17 13:38 ` Mark Brown
  2025-02-18 13:52 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2025-02-17 13:38 UTC (permalink / raw)
  To: Liam Girdwood, Martin Povišer, broonie
  Cc: linux-sound, linux-kernel, Mark Brown

On Sat, 08 Feb 2025 00:57:22 +0000, broonie@kernel.org wrote:
> Lower the volume if it is violating the platform maximum at its initial
> value (i.e. at the time of the 'snd_soc_limit_volume' call).
> 
> 

Applied to

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

Thanks!

[1/1] ASoC: ops: Enforce platform maximum on initial value
      commit: 783db6851c1821d8b983ffb12b99c279ff64f2ee

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


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

* Re: [PATCH] ASoC: ops: Enforce platform maximum on initial value
  2025-02-08  0:57 [PATCH] ASoC: ops: Enforce platform maximum on initial value broonie
  2025-02-17 13:38 ` Mark Brown
@ 2025-02-18 13:52 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2025-02-18 13:52 UTC (permalink / raw)
  To: broonie, Martin Povišer; +Cc: Liam Girdwood, linux-sound, linux-kernel

Hi Mark, Martin,

On Sat, 8 Feb 2025 at 01:57, <broonie@kernel.org> wrote:
> From: Martin Povišer <povik+lin@cutebit.org>
>
> Lower the volume if it is violating the platform maximum at its initial
> value (i.e. at the time of the 'snd_soc_limit_volume' call).
>
> Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
> [Cherry picked from the Asahi kernel with fixups -- broonie]
> Signed-off-by: Mark Brown <broonie@kernel.orG>

Thanks for your patch, which is now commit 783db6851c1821d8 ("ASoC:
ops: Enforce platform maximum on initial value") in linux-next/master
next-20250218 sound-asoc/for-next

> --- a/sound/soc/soc-ops.c
> +++ b/sound/soc/soc-ops.c
> @@ -640,6 +640,33 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
>  }
>  EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
>
> +static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
> +{
> +       struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
> +       struct snd_ctl_elem_value uctl;

sizeof(snd_ctl_elem_value) = 1224, causing:

    sound/soc/soc-ops.c:657:1: error: the frame size of 1232 bytes is
larger than 1024 bytes [-Werror=frame-larger-than=]

> +       int ret;
> +
> +       if (!mc->platform_max)
> +               return 0;
> +
> +       ret = kctl->get(kctl, &uctl);
> +       if (ret < 0)
> +               return ret;
> +
> +       if (uctl.value.integer.value[0] > mc->platform_max)
> +               uctl.value.integer.value[0] = mc->platform_max;
> +
> +       if (snd_soc_volsw_is_stereo(mc) &&
> +           uctl.value.integer.value[1] > mc->platform_max)
> +               uctl.value.integer.value[1] = mc->platform_max;
> +
> +       ret = kctl->put(kctl, &uctl);
> +       if (ret < 0)
> +               return ret;
> +
> +       return 0;
> +}
> +
>  /**
>   * snd_soc_limit_volume - Set new limit to an existing volume control.
>   *

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2025-02-18 13:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-08  0:57 [PATCH] ASoC: ops: Enforce platform maximum on initial value broonie
2025-02-17 13:38 ` Mark Brown
2025-02-18 13:52 ` Geert Uytterhoeven

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