Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Martin Povišer and committed by
Mark Brown
783db685 74e0fcbd

+28 -1
+28 -1
sound/soc/soc-ops.c
··· 639 639 } 640 640 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); 641 641 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 + 642 669 /** 643 670 * snd_soc_limit_volume - Set new limit to an existing volume control. 644 671 * ··· 690 663 struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; 691 664 if (max <= mc->max - mc->min) { 692 665 mc->platform_max = max; 693 - ret = 0; 666 + ret = snd_soc_clip_to_platform_max(kctl); 694 667 } 695 668 } 696 669 return ret;