ALSA: oxygen: Xonar DG(X): modify capture volume functions

Modify the input_vol_* functions to use the new SPI routines,
There is a new applying function that will be called when
the capture source changed.

Signed-off-by: Roman Volkov <v1ron@mail.ru>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>

authored by Roman Volkov and committed by Clemens Ladisch cf218b2e c754639a

+26 -8
+2 -1
sound/pci/oxygen/xonar_dg.h
··· 28 unsigned char cs4245_shadow[17]; 29 /* output select: headphone/speakers */ 30 unsigned char output_sel; 31 - s8 input_vol[4][2]; 32 unsigned int input_sel; 33 u8 hp_vol_att; 34 };
··· 28 unsigned char cs4245_shadow[17]; 29 /* output select: headphone/speakers */ 30 unsigned char output_sel; 31 + /* volumes for all capture sources */ 32 + char input_vol[4][2]; 33 unsigned int input_sel; 34 u8 hp_vol_att; 35 };
+24 -7
sound/pci/oxygen/xonar_dg_mixer.c
··· 190 return changed; 191 } 192 193 static int input_vol_info(struct snd_kcontrol *ctl, 194 struct snd_ctl_elem_info *info) 195 { ··· 236 struct dg *data = chip->model_data; 237 unsigned int idx = ctl->private_value; 238 int changed = 0; 239 240 if (value->value.integer.value[0] < 2 * -12 || 241 value->value.integer.value[0] > 2 * 12 || ··· 250 data->input_vol[idx][0] = value->value.integer.value[0]; 251 data->input_vol[idx][1] = value->value.integer.value[1]; 252 if (idx == data->input_sel) { 253 - cs4245_write_cached(chip, CS4245_PGA_A_CTRL, 254 - data->input_vol[idx][0]); 255 - cs4245_write_cached(chip, CS4245_PGA_B_CTRL, 256 - data->input_vol[idx][1]); 257 } 258 } 259 mutex_unlock(&chip->mutex); 260 return changed; 261 } 262 - 263 - static DECLARE_TLV_DB_SCALE(cs4245_pga_db_scale, -1200, 50, 0); 264 265 static int input_sel_info(struct snd_kcontrol *ctl, 266 struct snd_ctl_elem_info *info) ··· 359 #define INPUT_VOLUME(xname, index) { \ 360 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 361 .name = xname, \ 362 .info = input_vol_info, \ 363 .get = input_vol_get, \ 364 .put = input_vol_put, \ 365 - .tlv = { .p = cs4245_pga_db_scale }, \ 366 .private_value = index, \ 367 } 368 static const DECLARE_TLV_DB_MINMAX(hp_db_scale, -12550, 0); 369 static const struct snd_kcontrol_new dg_controls[] = { 370 { 371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
··· 190 return changed; 191 } 192 193 + /* capture volume for all sources */ 194 + 195 + static int input_volume_apply(struct oxygen *chip, char left, char right) 196 + { 197 + struct dg *data = chip->model_data; 198 + int ret; 199 + 200 + data->cs4245_shadow[CS4245_PGA_A_CTRL] = left; 201 + data->cs4245_shadow[CS4245_PGA_B_CTRL] = right; 202 + ret = cs4245_write_spi(chip, CS4245_PGA_A_CTRL); 203 + if (ret < 0) 204 + return ret; 205 + return cs4245_write_spi(chip, CS4245_PGA_B_CTRL); 206 + } 207 + 208 static int input_vol_info(struct snd_kcontrol *ctl, 209 struct snd_ctl_elem_info *info) 210 { ··· 221 struct dg *data = chip->model_data; 222 unsigned int idx = ctl->private_value; 223 int changed = 0; 224 + int ret = 0; 225 226 if (value->value.integer.value[0] < 2 * -12 || 227 value->value.integer.value[0] > 2 * 12 || ··· 234 data->input_vol[idx][0] = value->value.integer.value[0]; 235 data->input_vol[idx][1] = value->value.integer.value[1]; 236 if (idx == data->input_sel) { 237 + ret = input_volume_apply(chip, 238 + data->input_vol[idx][0], 239 + data->input_vol[idx][1]); 240 } 241 + changed = ret >= 0 ? 1 : ret; 242 } 243 mutex_unlock(&chip->mutex); 244 return changed; 245 } 246 247 static int input_sel_info(struct snd_kcontrol *ctl, 248 struct snd_ctl_elem_info *info) ··· 345 #define INPUT_VOLUME(xname, index) { \ 346 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 347 .name = xname, \ 348 + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ 349 + SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 350 .info = input_vol_info, \ 351 .get = input_vol_get, \ 352 .put = input_vol_put, \ 353 + .tlv = { .p = pga_db_scale }, \ 354 .private_value = index, \ 355 } 356 static const DECLARE_TLV_DB_MINMAX(hp_db_scale, -12550, 0); 357 + static const DECLARE_TLV_DB_MINMAX(pga_db_scale, -1200, 1200); 358 static const struct snd_kcontrol_new dg_controls[] = { 359 { 360 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,