Skip to content

Commit 1e3cd64

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: ops: Factor out common code from get callbacks
There are only two differences between snd_soc_get_volsw() and snd_soc_get_volsw_sx(). The maximum field is handled differently, and snd_soc_get_volsw() supports double controls with both values in the same register. Factor out the common code into a new helper and pass in the appropriate max value such that it is handled correctly for each control. Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20250319175123.3835849-2-ckeepax@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 318e879 commit 1e3cd64

File tree

1 file changed

+29
-39
lines changed

1 file changed

+29
-39
lines changed

sound/soc/soc-ops.c

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,33 @@ static int soc_put_volsw(struct snd_kcontrol *kcontrol,
243243
return ret;
244244
}
245245

246+
static int soc_get_volsw(struct snd_kcontrol *kcontrol,
247+
struct snd_ctl_elem_value *ucontrol,
248+
struct soc_mixer_control *mc, int mask, int max)
249+
{
250+
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
251+
unsigned int reg_val;
252+
int val;
253+
254+
reg_val = snd_soc_component_read(component, mc->reg);
255+
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
256+
257+
ucontrol->value.integer.value[0] = val;
258+
259+
if (snd_soc_volsw_is_stereo(mc)) {
260+
if (mc->reg == mc->rreg) {
261+
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, max);
262+
} else {
263+
reg_val = snd_soc_component_read(component, mc->rreg);
264+
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
265+
}
266+
267+
ucontrol->value.integer.value[1] = val;
268+
}
269+
270+
return 0;
271+
}
272+
246273
/**
247274
* snd_soc_info_volsw - single mixer info callback with range.
248275
* @kcontrol: mixer control
@@ -299,31 +326,11 @@ EXPORT_SYMBOL_GPL(snd_soc_info_volsw_sx);
299326
int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
300327
struct snd_ctl_elem_value *ucontrol)
301328
{
302-
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
303329
struct soc_mixer_control *mc =
304330
(struct soc_mixer_control *)kcontrol->private_value;
305-
int max = mc->max - mc->min;
306331
unsigned int mask = soc_mixer_mask(mc);
307-
unsigned int reg_val;
308-
int val;
309332

310-
reg_val = snd_soc_component_read(component, mc->reg);
311-
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
312-
313-
ucontrol->value.integer.value[0] = val;
314-
315-
if (snd_soc_volsw_is_stereo(mc)) {
316-
if (mc->reg == mc->rreg) {
317-
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, max);
318-
} else {
319-
reg_val = snd_soc_component_read(component, mc->rreg);
320-
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
321-
}
322-
323-
ucontrol->value.integer.value[1] = val;
324-
}
325-
326-
return 0;
333+
return soc_get_volsw(kcontrol, ucontrol, mc, mask, mc->max - mc->min);
327334
}
328335
EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
329336

@@ -361,28 +368,11 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
361368
int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
362369
struct snd_ctl_elem_value *ucontrol)
363370
{
364-
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
365371
struct soc_mixer_control *mc =
366372
(struct soc_mixer_control *)kcontrol->private_value;
367-
unsigned int reg = mc->reg;
368-
unsigned int reg2 = mc->rreg;
369373
unsigned int mask = soc_mixer_sx_mask(mc);
370-
unsigned int reg_val;
371-
int val;
372-
373-
reg_val = snd_soc_component_read(component, reg);
374-
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, mc->max);
375-
376-
ucontrol->value.integer.value[0] = val;
377-
378-
if (snd_soc_volsw_is_stereo(mc)) {
379-
reg_val = snd_soc_component_read(component, reg2);
380-
val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, mc->max);
381374

382-
ucontrol->value.integer.value[1] = val;
383-
}
384-
385-
return 0;
375+
return soc_get_volsw(kcontrol, ucontrol, mc, mask, mc->max);
386376
}
387377
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
388378

0 commit comments

Comments
 (0)