Skip to content

Commit

Permalink
ASoC: core: Fix volsw_range funcs so SOC_DOUBLE_R_RANGE_TLV works.
Browse files Browse the repository at this point in the history
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("<name>", <reg_l>, <reg_r>,
					0, 40, 255, 0, <tlv>)

the range sent to the hardware is 40..255, but in the invert case:

SOC_DOUBLE_R_RANGE_TLV("<name>", <reg_l>, <reg_r>,
					0, 40, 255, 1, <tlv>)

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 <hm@hmbedded.co.uk>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Howard Mitchell authored and Mark Brown committed Sep 24, 2014
1 parent 8c8f2f6 commit 5c7c343
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 5c7c343

Please sign in to comment.