Skip to content

Commit 9dfcafe

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: ops: Factor out common code from info callbacks
snd_soc_info_volsw() and snd_soc_info_volsw_sx() do very similar things, and have a lot of code in common. Already this is causing some issues as the detection of volume controls has been fixed in the normal callback but not the sx callback. Factor out a new helper containing the common code and leave the function specific bits behind in each callback. Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20250318171459.3203730-12-ckeepax@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 7d5df96 commit 9dfcafe

File tree

1 file changed

+26
-38
lines changed

1 file changed

+26
-38
lines changed

sound/soc/soc-ops.c

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,30 @@ static int soc_mixer_sx_mask(struct soc_mixer_control *mc)
168168
return GENMASK(fls(mc->min + mc->max) - 2, 0);
169169
}
170170

171+
static int soc_info_volsw(struct snd_kcontrol *kcontrol,
172+
struct snd_ctl_elem_info *uinfo,
173+
struct soc_mixer_control *mc, int max)
174+
{
175+
if (mc->platform_max && mc->platform_max < max)
176+
max = mc->platform_max;
177+
178+
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
179+
180+
if (max == 1) {
181+
/* Even two value controls ending in Volume should be integer */
182+
const char *vol_string = strstr(kcontrol->id.name, " Volume");
183+
184+
if (!vol_string || strcmp(vol_string, " Volume"))
185+
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
186+
}
187+
188+
uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
189+
uinfo->value.integer.min = 0;
190+
uinfo->value.integer.max = max;
191+
192+
return 0;
193+
}
194+
171195
/**
172196
* snd_soc_info_volsw - single mixer info callback with range.
173197
* @kcontrol: mixer control
@@ -183,29 +207,8 @@ int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
183207
{
184208
struct soc_mixer_control *mc =
185209
(struct soc_mixer_control *)kcontrol->private_value;
186-
const char *vol_string = NULL;
187-
int max;
188-
189-
max = uinfo->value.integer.max = mc->max - mc->min;
190-
if (mc->platform_max && mc->platform_max < max)
191-
max = mc->platform_max;
192-
193-
if (max == 1) {
194-
/* Even two value controls ending in Volume should always be integer */
195-
vol_string = strstr(kcontrol->id.name, " Volume");
196-
if (vol_string && !strcmp(vol_string, " Volume"))
197-
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
198-
else
199-
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
200-
} else {
201-
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
202-
}
203210

204-
uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
205-
uinfo->value.integer.min = 0;
206-
uinfo->value.integer.max = max;
207-
208-
return 0;
211+
return soc_info_volsw(kcontrol, uinfo, mc, mc->max - mc->min);
209212
}
210213
EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
211214

@@ -227,23 +230,8 @@ int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
227230
{
228231
struct soc_mixer_control *mc =
229232
(struct soc_mixer_control *)kcontrol->private_value;
230-
int max;
231233

232-
if (mc->platform_max)
233-
max = mc->platform_max;
234-
else
235-
max = mc->max;
236-
237-
if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
238-
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
239-
else
240-
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
241-
242-
uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
243-
uinfo->value.integer.min = 0;
244-
uinfo->value.integer.max = max;
245-
246-
return 0;
234+
return soc_info_volsw(kcontrol, uinfo, mc, mc->max);
247235
}
248236
EXPORT_SYMBOL_GPL(snd_soc_info_volsw_sx);
249237

0 commit comments

Comments
 (0)