Skip to content

Commit 783db68

Browse files
povikbroonie
authored andcommitted
ASoC: ops: Enforce platform maximum on initial value
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> Link: https://patch.msgid.link/20250208-asoc-volume-limit-v1-1-b98fcf4cdbad@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 74e0fcb commit 783db68

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

sound/soc/soc-ops.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,33 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
639639
}
640640
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
641641

642+
static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl)
643+
{
644+
struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
645+
struct snd_ctl_elem_value uctl;
646+
int ret;
647+
648+
if (!mc->platform_max)
649+
return 0;
650+
651+
ret = kctl->get(kctl, &uctl);
652+
if (ret < 0)
653+
return ret;
654+
655+
if (uctl.value.integer.value[0] > mc->platform_max)
656+
uctl.value.integer.value[0] = mc->platform_max;
657+
658+
if (snd_soc_volsw_is_stereo(mc) &&
659+
uctl.value.integer.value[1] > mc->platform_max)
660+
uctl.value.integer.value[1] = mc->platform_max;
661+
662+
ret = kctl->put(kctl, &uctl);
663+
if (ret < 0)
664+
return ret;
665+
666+
return 0;
667+
}
668+
642669
/**
643670
* snd_soc_limit_volume - Set new limit to an existing volume control.
644671
*
@@ -663,7 +690,7 @@ int snd_soc_limit_volume(struct snd_soc_card *card,
663690
struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value;
664691
if (max <= mc->max - mc->min) {
665692
mc->platform_max = max;
666-
ret = 0;
693+
ret = snd_soc_clip_to_platform_max(kctl);
667694
}
668695
}
669696
return ret;

0 commit comments

Comments
 (0)