summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorCharles Keepax <ckeepax@opensource.cirrus.com>2025-03-19 17:51:21 +0000
committerMark Brown <broonie@kernel.org>2025-03-19 17:56:34 +0000
commit1e3cd64a29baa874b89180ac0744178ecb00f3cd (patch)
treeee7e64ea5dc69e63f08bd2be882595c8e82c683a /sound
parent318e8794e05ca1879441a602e78c74f9d7e18309 (diff)
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>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/soc-ops.c68
1 files changed, 29 insertions, 39 deletions
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 0b62ffb2e222..1d7c28993a63 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -243,6 +243,33 @@ static int soc_put_volsw(struct snd_kcontrol *kcontrol,
return ret;
}
+static int soc_get_volsw(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol,
+ struct soc_mixer_control *mc, int mask, int max)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ unsigned int reg_val;
+ int val;
+
+ reg_val = snd_soc_component_read(component, mc->reg);
+ val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
+
+ ucontrol->value.integer.value[0] = val;
+
+ if (snd_soc_volsw_is_stereo(mc)) {
+ if (mc->reg == mc->rreg) {
+ val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, max);
+ } else {
+ reg_val = snd_soc_component_read(component, mc->rreg);
+ val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
+ }
+
+ ucontrol->value.integer.value[1] = val;
+ }
+
+ return 0;
+}
+
/**
* snd_soc_info_volsw - single mixer info callback with range.
* @kcontrol: mixer control
@@ -299,31 +326,11 @@ EXPORT_SYMBOL_GPL(snd_soc_info_volsw_sx);
int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value;
- int max = mc->max - mc->min;
unsigned int mask = soc_mixer_mask(mc);
- unsigned int reg_val;
- int val;
- reg_val = snd_soc_component_read(component, mc->reg);
- val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
-
- ucontrol->value.integer.value[0] = val;
-
- if (snd_soc_volsw_is_stereo(mc)) {
- if (mc->reg == mc->rreg) {
- val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, max);
- } else {
- reg_val = snd_soc_component_read(component, mc->rreg);
- val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, max);
- }
-
- ucontrol->value.integer.value[1] = val;
- }
-
- return 0;
+ return soc_get_volsw(kcontrol, ucontrol, mc, mask, mc->max - mc->min);
}
EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
@@ -361,28 +368,11 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value;
- unsigned int reg = mc->reg;
- unsigned int reg2 = mc->rreg;
unsigned int mask = soc_mixer_sx_mask(mc);
- unsigned int reg_val;
- int val;
-
- reg_val = snd_soc_component_read(component, reg);
- val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->shift, mc->max);
-
- ucontrol->value.integer.value[0] = val;
-
- if (snd_soc_volsw_is_stereo(mc)) {
- reg_val = snd_soc_component_read(component, reg2);
- val = soc_mixer_reg_to_ctl(mc, reg_val, mask, mc->rshift, mc->max);
- ucontrol->value.integer.value[1] = val;
- }
-
- return 0;
+ return soc_get_volsw(kcontrol, ucontrol, mc, mask, mc->max);
}
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);