From 5c7c343a1159d1cb7604b6137cf547b2c1e2375d Mon Sep 17 00:00:00 2001 From: Howard Mitchell Date: Fri, 19 Sep 2014 12:50:31 +0100 Subject: [PATCH] ASoC: core: Fix volsw_range funcs so SOC_DOUBLE_R_RANGE_TLV works. This fixes a bug when using the SOC_DOUBLE_R_RANGE_TLV macro in the invert mode. In the non-invert case, e.g. SOC_DOUBLE_R_RANGE_TLV("", , , 0, 40, 255, 0, ) the range sent to the hardware is 40..255, but in the invert case: SOC_DOUBLE_R_RANGE_TLV("", , , 0, 40, 255, 1, ) the range 215..0 was being sent to the hardware. This commit corrects this to 255..40 so it is consistent with the non-invert case. Signed-off-by: Howard Mitchell Signed-off-by: Mark Brown --- sound/soc/soc-core.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 3c57f5cf2779..dde4b82ad41d 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3019,9 +3019,10 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, unsigned int val, val_mask; int ret; - val = ((ucontrol->value.integer.value[0] + min) & mask); if (invert) - val = max - val; + val = (max - ucontrol->value.integer.value[0]) & mask; + else + val = ((ucontrol->value.integer.value[0] + min) & mask); val_mask = mask << shift; val = val << shift; @@ -3030,9 +3031,10 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, return ret; if (snd_soc_volsw_is_stereo(mc)) { - val = ((ucontrol->value.integer.value[1] + min) & mask); if (invert) - val = max - val; + val = (max - ucontrol->value.integer.value[1]) & mask; + else + val = ((ucontrol->value.integer.value[1] + min) & mask); val_mask = mask << shift; val = val << shift; @@ -3077,8 +3079,9 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, if (invert) ucontrol->value.integer.value[0] = max - ucontrol->value.integer.value[0]; - ucontrol->value.integer.value[0] = - ucontrol->value.integer.value[0] - min; + else + ucontrol->value.integer.value[0] = + ucontrol->value.integer.value[0] - min; if (snd_soc_volsw_is_stereo(mc)) { ret = snd_soc_component_read(component, rreg, &val); @@ -3089,8 +3092,9 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol, if (invert) ucontrol->value.integer.value[1] = max - ucontrol->value.integer.value[1]; - ucontrol->value.integer.value[1] = - ucontrol->value.integer.value[1] - min; + else + ucontrol->value.integer.value[1] = + ucontrol->value.integer.value[1] - min; } return 0; -- 2.45.2