Skip to content

Commit c2847c2

Browse files
povikmarcan
authored andcommitted
ASoC: cs42l84: Put the volume control in shape
The previous limits of the volume control were placeholders, this reflects the current understanding of the register semantics. Signed-off-by: Martin Povišer <[email protected]>
1 parent d5e8936 commit c2847c2

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

sound/soc/codecs/cs42l84.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ static int cs42l84_put_dac_vol(struct snd_kcontrol *kctl,
7070
struct snd_ctl_elem_value *val)
7171
{
7272
struct snd_soc_component *component = snd_soc_kcontrol_component(kctl);
73-
unsigned int vola, volb;
73+
struct soc_mixer_control *mc = (struct soc_mixer_control *) kctl->private_value;
74+
int vola, volb;
7475
int ret, ret2;
7576

76-
vola = val->value.integer.value[0];
77-
volb = val->value.integer.value[1];
77+
vola = val->value.integer.value[0] + mc->min;
78+
volb = val->value.integer.value[1] + mc->min;
79+
80+
if (vola < mc->min || vola > mc->max || volb < mc->min || volb > mc->max)
81+
return -EINVAL;
7882

7983
ret = snd_soc_component_update_bits(component, CS42L84_FRZ_CTL,
8084
CS42L84_FRZ_CTL_ENGAGE,
@@ -112,7 +116,8 @@ static int cs42l84_get_dac_vol(struct snd_kcontrol *kctl,
112116
struct snd_ctl_elem_value *val)
113117
{
114118
struct snd_soc_component *component = snd_soc_kcontrol_component(kctl);
115-
unsigned int vola, volb;
119+
struct soc_mixer_control *mc = (struct soc_mixer_control *) kctl->private_value;
120+
int vola, volb;
116121
int ret;
117122

118123
ret = snd_soc_component_read(component, CS42L84_DAC_CHA_VOL_LSB);
@@ -135,18 +140,23 @@ static int cs42l84_get_dac_vol(struct snd_kcontrol *kctl,
135140
return ret;
136141
volb |= (ret & 1) << 8;
137142

138-
val->value.integer.value[0] = vola;
139-
val->value.integer.value[1] = volb;
143+
if (vola & BIT(8))
144+
vola |= ~((int)(BIT(8) - 1));
145+
if (volb & BIT(8))
146+
volb |= ~((int)(BIT(8) - 1));
147+
148+
val->value.integer.value[0] = vola - mc->min;
149+
val->value.integer.value[1] = volb - mc->min;
140150

141151
return 0;
142152
}
143153

144154
/* TODO */
145-
static const DECLARE_TLV_DB_SCALE(cs42l84_dac_tlv, -25600, 50, 1);
155+
static const DECLARE_TLV_DB_SCALE(cs42l84_dac_tlv, -12800, 50, true);
146156

147157
static const struct snd_kcontrol_new cs42l84_snd_controls[] = {
148-
SOC_DOUBLE_R_EXT_TLV("DAC Playback Volume", CS42L84_DAC_CHA_VOL_LSB,
149-
CS42L84_DAC_CHB_VOL_LSB, 0, 511, 0,
158+
SOC_DOUBLE_R_S_EXT_TLV("DAC Playback Volume", CS42L84_DAC_CHA_VOL_LSB,
159+
CS42L84_DAC_CHB_VOL_LSB, 0, -256, 24, 8, 0,
150160
cs42l84_get_dac_vol, cs42l84_put_dac_vol, cs42l84_dac_tlv),
151161
SOC_SINGLE("ADC Preamp Gain", CS42L84_ADC_CTL1,
152162
CS42L84_ADC_CTL1_PREAMP_GAIN_SHIFT, 2, 0),

0 commit comments

Comments
 (0)