ALSA: oxygen: Xonar DG(X): modify input select functions

First of all, we should not touch the GPIOs. They are not
for selecting the capture source, but they seems just enable
the whole audio input curcuit. The 'put' function calls the
'apply' functions to change register values. Change the order
of capture sources.

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 70e0d82d cf218b2e

+30 -25
+2 -1
sound/pci/oxygen/xonar_dg.h
··· 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 }; 36
··· 30 unsigned char output_sel; 31 /* volumes for all capture sources */ 32 char input_vol[4][2]; 33 + /* input select: mic/fp mic/line/aux */ 34 + unsigned char input_sel; 35 u8 hp_vol_att; 36 }; 37
+28 -24
sound/pci/oxygen/xonar_dg_mixer.c
··· 260 return changed; 261 } 262 263 static int input_sel_info(struct snd_kcontrol *ctl, 264 struct snd_ctl_elem_info *info) 265 { 266 static const char *const names[4] = { 267 - "Mic", "Aux", "Front Mic", "Line" 268 }; 269 270 return snd_ctl_enum_info(info, 1, 4, names); ··· 301 static int input_sel_put(struct snd_kcontrol *ctl, 302 struct snd_ctl_elem_value *value) 303 { 304 - static const u8 sel_values[4] = { 305 - CS4245_SEL_MIC, 306 - CS4245_SEL_INPUT_1, 307 - CS4245_SEL_INPUT_2, 308 - CS4245_SEL_INPUT_4 309 - }; 310 struct oxygen *chip = ctl->private_data; 311 struct dg *data = chip->model_data; 312 int changed; 313 314 if (value->value.enumerated.item[0] > 3) 315 return -EINVAL; ··· 314 if (changed) { 315 data->input_sel = value->value.enumerated.item[0]; 316 317 - cs4245_write(chip, CS4245_ANALOG_IN, 318 - (data->cs4245_shadow[CS4245_ANALOG_IN] & 319 - ~CS4245_SEL_MASK) | 320 - sel_values[data->input_sel]); 321 - 322 - cs4245_write_cached(chip, CS4245_PGA_A_CTRL, 323 - data->input_vol[data->input_sel][0]); 324 - cs4245_write_cached(chip, CS4245_PGA_B_CTRL, 325 - data->input_vol[data->input_sel][1]); 326 - 327 - oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 328 - data->input_sel ? 0 : GPIO_INPUT_ROUTE, 329 - GPIO_INPUT_ROUTE); 330 } 331 mutex_unlock(&chip->mutex); 332 return changed; ··· 399 .get = hp_mute_get, 400 .put = hp_mute_put, 401 }, 402 - INPUT_VOLUME("Mic Capture Volume", 0), 403 - INPUT_VOLUME("Aux Capture Volume", 1), 404 - INPUT_VOLUME("Front Mic Capture Volume", 2), 405 - INPUT_VOLUME("Line Capture Volume", 3), 406 { 407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 408 .name = "Capture Source",
··· 260 return changed; 261 } 262 263 + /* Capture Source */ 264 + 265 + static int input_source_apply(struct oxygen *chip) 266 + { 267 + struct dg *data = chip->model_data; 268 + 269 + data->cs4245_shadow[CS4245_ANALOG_IN] &= ~CS4245_SEL_MASK; 270 + if (data->input_sel == CAPTURE_SRC_FP_MIC) 271 + data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_2; 272 + else if (data->input_sel == CAPTURE_SRC_LINE) 273 + data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_4; 274 + else if (data->input_sel != CAPTURE_SRC_MIC) 275 + data->cs4245_shadow[CS4245_ANALOG_IN] |= CS4245_SEL_INPUT_1; 276 + return cs4245_write_spi(chip, CS4245_ANALOG_IN); 277 + } 278 + 279 static int input_sel_info(struct snd_kcontrol *ctl, 280 struct snd_ctl_elem_info *info) 281 { 282 static const char *const names[4] = { 283 + "Mic", "Front Mic", "Line", "Aux" 284 }; 285 286 return snd_ctl_enum_info(info, 1, 4, names); ··· 285 static int input_sel_put(struct snd_kcontrol *ctl, 286 struct snd_ctl_elem_value *value) 287 { 288 struct oxygen *chip = ctl->private_data; 289 struct dg *data = chip->model_data; 290 int changed; 291 + int ret; 292 293 if (value->value.enumerated.item[0] > 3) 294 return -EINVAL; ··· 303 if (changed) { 304 data->input_sel = value->value.enumerated.item[0]; 305 306 + ret = input_source_apply(chip); 307 + if (ret >= 0) 308 + ret = input_volume_apply(chip, 309 + data->input_vol[data->input_sel][0], 310 + data->input_vol[data->input_sel][1]); 311 + changed = ret >= 0 ? 1 : ret; 312 } 313 mutex_unlock(&chip->mutex); 314 return changed; ··· 395 .get = hp_mute_get, 396 .put = hp_mute_put, 397 }, 398 + INPUT_VOLUME("Mic Capture Volume", CAPTURE_SRC_MIC), 399 + INPUT_VOLUME("Front Mic Capture Volume", CAPTURE_SRC_FP_MIC), 400 + INPUT_VOLUME("Line Capture Volume", CAPTURE_SRC_LINE), 401 + INPUT_VOLUME("Aux Capture Volume", CAPTURE_SRC_AUX), 402 { 403 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 404 .name = "Capture Source",