[PATCH v2 1/2] ASoC: SOF: control: Report the volume range as ASoC does

From: HyeongJun An

Date: Wed Nov 18 2026 - 04:38:59 EST


SOF controls with more than two channels use snd_sof_volume_info()
instead of snd_soc_info_volsw(). The snd_sof_volume_info() reports
platform_max - min as the maximum, while snd_soc_info_volsw() reports
max - min, limited by platform_max. With min 10, max 100 and
platform_max 80, a control reports 70 with more than two channels and
80 with up to two.

To fix this, compute the maximum the way snd_soc_info_volsw() does. The
helper is reused by the next patch to check the values written to the
controls. It also no longer stores max in platform_max as a side
effect.

No SOF topology sets min or platform_max today, so the reported ranges
do not change.

Suggested-by: Peter Ujfalusi <peter.ujfalusi@xxxxxxxxxxxxxxx>
Signed-off-by: HyeongJun An <sammiee5311@xxxxxxxxx>
---
sound/soc/sof/control.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index 74d997a4f620..136e2ce15201 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -15,6 +15,17 @@
#include "sof-priv.h"
#include "sof-audio.h"

+/* the maximum value as snd_soc_info_volsw() reports it */
+static int sof_mixer_max(const struct soc_mixer_control *sm)
+{
+ int max = sm->max - sm->min;
+
+ if (sm->platform_max && sm->platform_max < max)
+ max = sm->platform_max;
+
+ return max;
+}
+
int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
@@ -50,20 +61,16 @@ int snd_sof_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info
struct soc_mixer_control *sm = (struct soc_mixer_control *)kcontrol->private_value;
struct snd_sof_control *scontrol = sm->dobj.private;
unsigned int channels = scontrol->num_channels;
- int platform_max;
-
- if (!sm->platform_max)
- sm->platform_max = sm->max;
- platform_max = sm->platform_max;
+ int max = sof_mixer_max(sm);

- if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
+ if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
else
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;

uinfo->count = channels;
uinfo->value.integer.min = 0;
- uinfo->value.integer.max = platform_max - sm->min;
+ uinfo->value.integer.max = max;
return 0;
}

--
2.43.0