From 24088a58d694ca5acc31ba67f966f60385789235 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 16:59:21 +0200 Subject: [PATCH 01/39] ALSA: hda - Add control to suppress the dynamic pin-power for VIA Currently VIA driver controls the power-state of each pin per jack detection. But, it means that the power-state mismatch may occur when the machine doesn't give the proper jack-detection. For avoiding this problem, a new control element "Dynamic Power-Control" is provided so that user can turn on/off the pin-power control. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 60 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 995974d0b120..8a9791ab43c0 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -153,6 +153,7 @@ struct via_spec { unsigned int hp_independent_mode_index; unsigned int smart51_enabled; unsigned int dmic_enabled; + unsigned int no_pin_power_ctl; enum VIA_HDA_CODEC codec_type; /* work to check hp jack state */ @@ -605,8 +606,12 @@ static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, unsigned no_presence = (def_conf & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ - unsigned present = snd_hda_jack_detect(codec, nid); struct via_spec *spec = codec->spec; + unsigned present = 0; + + no_presence |= spec->no_pin_power_ctl; + if (!no_presence) + present = snd_hda_jack_detect(codec, nid); if ((spec->smart51_enabled && is_smart51_pins(spec, nid)) || ((no_presence || present) && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { @@ -618,6 +623,55 @@ static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); } +static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + static const char * const texts[] = { + "Disabled", "Enabled" + }; + + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; + uinfo->count = 1; + uinfo->value.enumerated.items = 2; + if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) + uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; + strcpy(uinfo->value.enumerated.name, + texts[uinfo->value.enumerated.item]); + return 0; +} + +static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct hda_codec *codec = snd_kcontrol_chip(kcontrol); + struct via_spec *spec = codec->spec; + ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; + return 0; +} + +static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct hda_codec *codec = snd_kcontrol_chip(kcontrol); + struct via_spec *spec = codec->spec; + unsigned int val = !ucontrol->value.enumerated.item[0]; + + if (val == spec->no_pin_power_ctl) + return 0; + spec->no_pin_power_ctl = val; + set_widgets_power_state(codec); + return 1; +} + +static const struct snd_kcontrol_new via_pin_power_ctl_enum = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Dynamic Power-Control", + .info = via_pin_power_ctl_info, + .get = via_pin_power_ctl_get, + .put = via_pin_power_ctl_put, +}; + + /* * input MUX handling */ @@ -1480,6 +1534,10 @@ static int via_build_controls(struct hda_codec *codec) const struct snd_kcontrol_new *knew; int err, i; + if (spec->set_widgets_power_state) + if (!via_clone_control(spec, &via_pin_power_ctl_enum)) + return -ENOMEM; + for (i = 0; i < spec->num_mixers; i++) { err = snd_hda_add_new_ctls(codec, spec->mixers[i]); if (err < 0) From a766d0d763bf9d64ff622db2c9c620d45a4ead96 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 09:01:29 +0200 Subject: [PATCH 02/39] ALSA: hda - Fill ADCs dynamically for VIA codecs Instead of giving the fixed ADC list, parse the widgets and fill in ADCs dynamically. Also, probe the stereo-mixer input more dynamically, too. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 244 +++++++++++++------------------------- 1 file changed, 80 insertions(+), 164 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 8a9791ab43c0..3a3df946661c 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -129,7 +129,7 @@ struct via_spec { /* capture */ unsigned int num_adc_nids; - const hda_nid_t *adc_nids; + hda_nid_t adc_nids[3]; hda_nid_t mux_nids[3]; hda_nid_t dig_in_nid; hda_nid_t dig_in_pin; @@ -418,51 +418,6 @@ static const struct snd_kcontrol_new via_control_templates[] = { BIND_PIN_MUTE, }; -static const hda_nid_t vt1708_adc_nids[2] = { - /* ADC1-2 */ - 0x15, 0x27 -}; - -static const hda_nid_t vt1709_adc_nids[3] = { - /* ADC1-2 */ - 0x14, 0x15, 0x16 -}; - -static const hda_nid_t vt1708B_adc_nids[2] = { - /* ADC1-2 */ - 0x13, 0x14 -}; - -static const hda_nid_t vt1708S_adc_nids[2] = { - /* ADC1-2 */ - 0x13, 0x14 -}; - -static const hda_nid_t vt1702_adc_nids[3] = { - /* ADC1-2 */ - 0x12, 0x20, 0x1F -}; - -static const hda_nid_t vt1718S_adc_nids[2] = { - /* ADC1-2 */ - 0x10, 0x11 -}; - -static const hda_nid_t vt1716S_adc_nids[2] = { - /* ADC1-2 */ - 0x13, 0x14 -}; - -static const hda_nid_t vt2002P_adc_nids[2] = { - /* ADC1-2 */ - 0x10, 0x11 -}; - -static const hda_nid_t vt1812_adc_nids[2] = { - /* ADC1-2 */ - 0x10, 0x11 -}; - /* add dynamic controls */ static int __via_add_control(struct via_spec *spec, int type, const char *name, @@ -2050,20 +2005,71 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } +static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, + hda_nid_t nid) +{ + hda_nid_t conn[HDA_MAX_NUM_INPUTS]; + int i, nums; + + nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); + for (i = 0; i < nums; i++) + if (conn[i] == nid) + return i; + return -1; +} + +/* look for ADCs */ +static int via_fill_adcs(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + hda_nid_t nid = codec->start_nid; + int i; + + for (i = 0; i < codec->num_nodes; i++, nid++) { + unsigned int wcaps = get_wcaps(codec, nid); + if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) + continue; + if (wcaps & AC_WCAP_DIGITAL) + continue; + if (!(wcaps & AC_WCAP_CONN_LIST)) + continue; + if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) + return -ENOMEM; + spec->adc_nids[spec->num_adc_nids++] = nid; + } + return 0; +} + +static int get_mux_nids(struct hda_codec *codec); + /* create playback/capture controls for input pins */ static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg, - hda_nid_t cap_nid, - const hda_nid_t pin_idxs[], - int num_idxs) + hda_nid_t mix_nid) { struct via_spec *spec = codec->spec; struct hda_input_mux *imux = &spec->private_imux[0]; - int i, err, idx, type, type_idx = 0; + int i, err, idx, idx2, type, type_idx = 0; + hda_nid_t cap_nid; + hda_nid_t pin_idxs[8]; + int num_idxs; + + err = via_fill_adcs(codec); + if (err < 0) + return err; + err = get_mux_nids(codec); + if (err < 0) + return err; + cap_nid = spec->mux_nids[0]; + + num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, + ARRAY_SIZE(pin_idxs)); + if (num_idxs <= 0) + return 0; /* for internal loopback recording select */ for (idx = 0; idx < num_idxs; idx++) { - if (pin_idxs[idx] == 0xff) { + if (pin_idxs[idx] == mix_nid) { snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); break; } @@ -2082,14 +2088,10 @@ static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, else type_idx = 0; label = hda_get_autocfg_input_label(codec, cfg, i); - if (spec->codec_type == VT1708S || - spec->codec_type == VT1702 || - spec->codec_type == VT1716S) + idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]); + if (idx2 >= 0) err = via_new_analog_input(spec, label, type_idx, - idx+1, cap_nid); - else - err = via_new_analog_input(spec, label, type_idx, - idx, cap_nid); + idx2, mix_nid); if (err < 0) return err; snd_hda_add_imux_item(imux, label, idx, NULL); @@ -2101,9 +2103,7 @@ static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - static const hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 }; - return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs, - ARRAY_SIZE(pin_idxs)); + return vt_auto_create_analog_input_ctls(codec, cfg, 0x17); } #ifdef CONFIG_SND_HDA_POWER_SAVE @@ -2326,11 +2326,7 @@ static int patch_vt1708(struct hda_codec *codec) spec->stream_digital_playback = &vt1708_pcm_digital_playback; spec->stream_digital_capture = &vt1708_pcm_digital_capture; - - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1708_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1708_capture_mixer; spec->num_mixers++; } @@ -2675,9 +2671,7 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - static const hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 }; - return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs, - ARRAY_SIZE(pin_idxs)); + return vt_auto_create_analog_input_ctls(codec, cfg, 0x18); } static int vt1709_parse_auto_config(struct hda_codec *codec) @@ -2764,11 +2758,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec) spec->stream_digital_playback = &vt1709_pcm_digital_playback; spec->stream_digital_capture = &vt1709_pcm_digital_capture; - - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1709_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1709_capture_mixer; spec->num_mixers++; } @@ -2856,11 +2846,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec) spec->stream_digital_playback = &vt1709_pcm_digital_playback; spec->stream_digital_capture = &vt1709_pcm_digital_capture; - - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1709_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1709_capture_mixer; spec->num_mixers++; } @@ -3207,9 +3193,7 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - static const hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e }; - return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs, - ARRAY_SIZE(pin_idxs)); + return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); } static int vt1708B_parse_auto_config(struct hda_codec *codec) @@ -3380,10 +3364,7 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) spec->stream_digital_playback = &vt1708B_pcm_digital_playback; spec->stream_digital_capture = &vt1708B_pcm_digital_capture; - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1708B_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; spec->num_mixers++; } @@ -3432,10 +3413,7 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) spec->stream_digital_playback = &vt1708B_pcm_digital_playback; spec->stream_digital_capture = &vt1708B_pcm_digital_capture; - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1708B_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; spec->num_mixers++; } @@ -3771,9 +3749,7 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff }; - return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs, - ARRAY_SIZE(pin_idxs)); + return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); } /* fill out digital output widgets; one for master and one for slave outputs */ @@ -3909,10 +3885,7 @@ static int patch_vt1708S(struct hda_codec *codec) spec->stream_name_digital = "VT1708S Digital"; spec->stream_digital_playback = &vt1708S_pcm_digital_playback; - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1708S_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x1a, 0, 3, 40); override_mic_boost(codec, 0x1e, 0, 3, 40); spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; @@ -4148,9 +4121,7 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - static const hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff }; - return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs, - ARRAY_SIZE(pin_idxs)); + return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a); } static int vt1702_parse_auto_config(struct hda_codec *codec) @@ -4269,10 +4240,7 @@ static int patch_vt1702(struct hda_codec *codec) spec->stream_name_digital = "VT1702 Digital"; spec->stream_digital_playback = &vt1702_pcm_digital_playback; - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1702_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1702_capture_mixer; spec->num_mixers++; } @@ -4568,9 +4536,7 @@ static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - static const hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff }; - return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs, - ARRAY_SIZE(pin_idxs)); + return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); } static int vt1718S_parse_auto_config(struct hda_codec *codec) @@ -4736,10 +4702,7 @@ static int patch_vt1718S(struct hda_codec *codec) if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) spec->stream_digital_capture = &vt1718S_pcm_digital_capture; - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1718S_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x2b, 0, 3, 40); override_mic_boost(codec, 0x29, 0, 3, 40); spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; @@ -5099,9 +5062,7 @@ static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff }; - return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs, - ARRAY_SIZE(pin_idxs)); + return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); } static int vt1716S_parse_auto_config(struct hda_codec *codec) @@ -5278,10 +5239,7 @@ static int patch_vt1716S(struct hda_codec *codec) spec->stream_name_digital = "VT1716S Digital"; spec->stream_digital_playback = &vt1716S_pcm_digital_playback; - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1716S_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x1a, 0, 3, 40); override_mic_boost(codec, 0x1e, 0, 3, 40); spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; @@ -5572,24 +5530,7 @@ static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - struct via_spec *spec = codec->spec; - struct hda_input_mux *imux = &spec->private_imux[0]; - static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff }; - int err; - - err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs, - ARRAY_SIZE(pin_idxs)); - if (err < 0) - return err; - /* build volume/mute control of loopback */ - err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21); - if (err < 0) - return err; - - /* for digital mic select */ - snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL); - - return 0; + return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); } static int vt2002P_parse_auto_config(struct hda_codec *codec) @@ -5802,10 +5743,7 @@ static int patch_vt2002P(struct hda_codec *codec) spec->stream_name_digital = "VT2002P Digital"; spec->stream_digital_playback = &vt2002P_pcm_digital_playback; - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt2002P_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x2b, 0, 3, 40); override_mic_boost(codec, 0x29, 0, 3, 40); spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; @@ -6021,25 +5959,7 @@ static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) { - struct via_spec *spec = codec->spec; - struct hda_input_mux *imux = &spec->private_imux[0]; - static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff }; - int err; - - err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs, - ARRAY_SIZE(pin_idxs)); - if (err < 0) - return err; - - /* build volume/mute control of loopback */ - err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21); - if (err < 0) - return err; - - /* for digital mic select */ - snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL); - - return 0; + return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); } static int vt1812_parse_auto_config(struct hda_codec *codec) @@ -6217,11 +6137,7 @@ static int patch_vt1812(struct hda_codec *codec) spec->stream_name_digital = "VT1812 Digital"; spec->stream_digital_playback = &vt1812_pcm_digital_playback; - - if (!spec->adc_nids && spec->input_mux) { - spec->adc_nids = vt1812_adc_nids; - spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids); - get_mux_nids(codec); + if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x2b, 0, 3, 40); override_mic_boost(codec, 0x29, 0, 3, 40); spec->mixers[spec->num_mixers] = vt1812_capture_mixer; From e06e5a297474c8027beffe10541981845ca0c98b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 15:46:13 +0200 Subject: [PATCH 03/39] ALSA: hda - Defer mixer element creation to the right time in patch_via.c The jack-detect control should be created at the time of build_controls callback instead of calling snd_hda_add_ctls() at the tree-parsing time. For that, copy the control to the temporary array like other cases. Also, fixed typos of vt1708_jack_detect in all places. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 42 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 3a3df946661c..30d1273f3c3a 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -159,7 +159,7 @@ struct via_spec { /* work to check hp jack state */ struct hda_codec *codec; struct delayed_work vt1708_hp_work; - int vt1708_jack_detectect; + int vt1708_jack_detect; int vt1708_hp_present; void (*set_widgets_power_state)(struct hda_codec *codec); @@ -264,7 +264,7 @@ static void vt1708_start_hp_work(struct via_spec *spec) if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) return; snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, - !spec->vt1708_jack_detectect); + !spec->vt1708_jack_detect); if (!delayed_work_pending(&spec->vt1708_hp_work)) schedule_delayed_work(&spec->vt1708_hp_work, msecs_to_jiffies(100)); @@ -278,7 +278,7 @@ static void vt1708_stop_hp_work(struct via_spec *spec) && !is_aa_path_mute(spec->codec)) return; snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, - !spec->vt1708_jack_detectect); + !spec->vt1708_jack_detect); cancel_delayed_work_sync(&spec->vt1708_hp_work); } @@ -2133,7 +2133,7 @@ static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) return; } -static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol, +static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); @@ -2141,13 +2141,13 @@ static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol, if (spec->codec_type != VT1708) return 0; - spec->vt1708_jack_detectect = + spec->vt1708_jack_detect = !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); - ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect; + ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; return 0; } -static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol, +static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); @@ -2156,26 +2156,23 @@ static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol, if (spec->codec_type != VT1708) return 0; - spec->vt1708_jack_detectect = ucontrol->value.integer.value[0]; + spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) - == !spec->vt1708_jack_detectect; - if (spec->vt1708_jack_detectect) { + == !spec->vt1708_jack_detect; + if (spec->vt1708_jack_detect) { mute_aa_path(codec, 1); notify_aa_path_ctls(codec); } return change; } -static const struct snd_kcontrol_new vt1708_jack_detectect[] = { - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "Jack Detect", - .count = 1, - .info = snd_ctl_boolean_mono_info, - .get = vt1708_jack_detectect_get, - .put = vt1708_jack_detectect_put, - }, - {} /* end */ +static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Jack Detect", + .count = 1, + .info = snd_ctl_boolean_mono_info, + .get = vt1708_jack_detect_get, + .put = vt1708_jack_detect_put, }; static int vt1708_parse_auto_config(struct hda_codec *codec) @@ -2206,9 +2203,8 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; /* add jack detect on/off control */ - err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect); - if (err < 0) - return err; + if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) + return -ENOMEM; spec->multiout.max_channels = spec->multiout.num_dacs * 2; From 291c9e33bf3f8ac201b24b8f9e481756d43d7df7 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 16:15:26 +0200 Subject: [PATCH 04/39] ALSA: hda - Refactor ctl array handling in patch_via.c No functional change. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 30d1273f3c3a..41398b07ba8b 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -420,18 +420,34 @@ static const struct snd_kcontrol_new via_control_templates[] = { /* add dynamic controls */ -static int __via_add_control(struct via_spec *spec, int type, const char *name, - int idx, unsigned long val) +static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, + const struct snd_kcontrol_new *tmpl, + const char *name) { struct snd_kcontrol_new *knew; snd_array_init(&spec->kctls, sizeof(*knew), 32); knew = snd_array_new(&spec->kctls); if (!knew) - return -ENOMEM; - *knew = via_control_templates[type]; - knew->name = kstrdup(name, GFP_KERNEL); - if (!knew->name) + return NULL; + *knew = *tmpl; + if (!name) + name = tmpl->name; + if (name) { + knew->name = kstrdup(name, GFP_KERNEL); + if (!knew->name) + return NULL; + } + return knew; +} + +static int __via_add_control(struct via_spec *spec, int type, const char *name, + int idx, unsigned long val) +{ + struct snd_kcontrol_new *knew; + + knew = __via_clone_ctl(spec, &via_control_templates[type], name); + if (!knew) return -ENOMEM; if (get_amp_nid_(val)) knew->subdevice = HDA_SUBDEV_AMP_FLAG; @@ -442,21 +458,7 @@ static int __via_add_control(struct via_spec *spec, int type, const char *name, #define via_add_control(spec, type, name, val) \ __via_add_control(spec, type, name, 0, val) -static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec, - const struct snd_kcontrol_new *tmpl) -{ - struct snd_kcontrol_new *knew; - - snd_array_init(&spec->kctls, sizeof(*knew), 32); - knew = snd_array_new(&spec->kctls); - if (!knew) - return NULL; - *knew = *tmpl; - knew->name = kstrdup(tmpl->name, GFP_KERNEL); - if (!knew->name) - return NULL; - return knew; -} +#define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) static void via_free_kctls(struct hda_codec *codec) { From 82673bc8950b869f01f9fd517f1c2286e0e49f44 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 16:24:21 +0200 Subject: [PATCH 05/39] ALSA: hda - Generate PCM names dynamically in patch_via.c This reduces lots of static strings. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 64 +++++---------------------------------- 1 file changed, 7 insertions(+), 57 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 41398b07ba8b..c66ff69eccf2 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -115,11 +115,11 @@ struct via_spec { const struct hda_verb *init_verbs[5]; unsigned int num_iverbs; - char *stream_name_analog; + char stream_name_analog[32]; const struct hda_pcm_stream *stream_analog_playback; const struct hda_pcm_stream *stream_analog_capture; - char *stream_name_digital; + char stream_name_digital[32]; const struct hda_pcm_stream *stream_digital_playback; const struct hda_pcm_stream *stream_digital_capture; @@ -1556,6 +1556,8 @@ static int via_build_pcms(struct hda_codec *codec) codec->num_pcms = 1; codec->pcm_info = info; + snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), + "%s Analog", codec->chip_name); info->name = spec->stream_name_analog; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); @@ -1570,6 +1572,9 @@ static int via_build_pcms(struct hda_codec *codec) if (spec->multiout.dig_out_nid || spec->dig_in_nid) { codec->num_pcms++; info++; + snprintf(spec->stream_name_digital, + sizeof(spec->stream_name_digital), + "%s Digital", codec->chip_name); info->name = spec->stream_name_digital; info->pcm_type = HDA_PCM_TYPE_SPDIF; if (spec->multiout.dig_out_nid) { @@ -2313,14 +2318,12 @@ static int patch_vt1708(struct hda_codec *codec) } - spec->stream_name_analog = "VT1708 Analog"; spec->stream_analog_playback = &vt1708_pcm_analog_playback; /* disable 32bit format on VT1708 */ if (codec->vendor_id == 0x11061708) spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; spec->stream_analog_capture = &vt1708_pcm_analog_capture; - spec->stream_name_digital = "VT1708 Digital"; spec->stream_digital_playback = &vt1708_pcm_digital_playback; spec->stream_digital_capture = &vt1708_pcm_digital_capture; @@ -2748,11 +2751,9 @@ static int patch_vt1709_10ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - spec->stream_name_analog = "VT1709 Analog"; spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; spec->stream_analog_capture = &vt1709_pcm_analog_capture; - spec->stream_name_digital = "VT1709 Digital"; spec->stream_digital_playback = &vt1709_pcm_digital_playback; spec->stream_digital_capture = &vt1709_pcm_digital_capture; @@ -2836,11 +2837,9 @@ static int patch_vt1709_6ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - spec->stream_name_analog = "VT1709 Analog"; spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; spec->stream_analog_capture = &vt1709_pcm_analog_capture; - spec->stream_name_digital = "VT1709 Digital"; spec->stream_digital_playback = &vt1709_pcm_digital_playback; spec->stream_digital_capture = &vt1709_pcm_digital_capture; @@ -3354,11 +3353,9 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - spec->stream_name_analog = "VT1708B Analog"; spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; spec->stream_analog_capture = &vt1708B_pcm_analog_capture; - spec->stream_name_digital = "VT1708B Digital"; spec->stream_digital_playback = &vt1708B_pcm_digital_playback; spec->stream_digital_capture = &vt1708B_pcm_digital_capture; @@ -3403,11 +3400,9 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - spec->stream_name_analog = "VT1708B Analog"; spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; spec->stream_analog_capture = &vt1708B_pcm_analog_capture; - spec->stream_name_digital = "VT1708B Digital"; spec->stream_digital_playback = &vt1708B_pcm_digital_playback; spec->stream_digital_capture = &vt1708B_pcm_digital_capture; @@ -3863,24 +3858,12 @@ static int patch_vt1708S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; - if (codec->vendor_id == 0x11060440) - spec->stream_name_analog = "VT1818S Analog"; - else if (codec->vendor_id == 0x11064397) - spec->stream_name_analog = "VT1705 Analog"; - else - spec->stream_name_analog = "VT1708S Analog"; if (codec->vendor_id == 0x11064397) spec->stream_analog_playback = &vt1705_pcm_analog_playback; else spec->stream_analog_playback = &vt1708S_pcm_analog_playback; spec->stream_analog_capture = &vt1708S_pcm_analog_capture; - if (codec->vendor_id == 0x11060440) - spec->stream_name_digital = "VT1818S Digital"; - else if (codec->vendor_id == 0x11064397) - spec->stream_name_digital = "VT1705 Digital"; - else - spec->stream_name_digital = "VT1708S Digital"; spec->stream_digital_playback = &vt1708S_pcm_digital_playback; if (spec->adc_nids && spec->input_mux) { @@ -3905,13 +3888,6 @@ static int patch_vt1708S(struct hda_codec *codec) snprintf(codec->bus->card->mixername, sizeof(codec->bus->card->mixername), "%s %s", codec->vendor_name, codec->chip_name); - spec->stream_name_analog = "VT1708BCE Analog"; - spec->stream_name_digital = "VT1708BCE Digital"; - } - /* correct names for VT1818S */ - if (codec->vendor_id == 0x11060440) { - spec->stream_name_analog = "VT1818S Analog"; - spec->stream_name_digital = "VT1818S Digital"; } /* correct names for VT1705 */ if (codec->vendor_id == 0x11064397) { @@ -4231,11 +4207,9 @@ static int patch_vt1702(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; - spec->stream_name_analog = "VT1702 Analog"; spec->stream_analog_playback = &vt1702_pcm_analog_playback; spec->stream_analog_capture = &vt1702_pcm_analog_capture; - spec->stream_name_digital = "VT1702 Digital"; spec->stream_digital_playback = &vt1702_pcm_digital_playback; if (spec->adc_nids && spec->input_mux) { @@ -4681,21 +4655,9 @@ static int patch_vt1718S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; - if (codec->vendor_id == 0x11060441) - spec->stream_name_analog = "VT2020 Analog"; - else if (codec->vendor_id == 0x11064441) - spec->stream_name_analog = "VT1828S Analog"; - else - spec->stream_name_analog = "VT1718S Analog"; spec->stream_analog_playback = &vt1718S_pcm_analog_playback; spec->stream_analog_capture = &vt1718S_pcm_analog_capture; - if (codec->vendor_id == 0x11060441) - spec->stream_name_digital = "VT2020 Digital"; - else if (codec->vendor_id == 0x11064441) - spec->stream_name_digital = "VT1828S Digital"; - else - spec->stream_name_digital = "VT1718S Digital"; spec->stream_digital_playback = &vt1718S_pcm_digital_playback; if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) spec->stream_digital_capture = &vt1718S_pcm_digital_capture; @@ -5230,11 +5192,9 @@ static int patch_vt1716S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; - spec->stream_name_analog = "VT1716S Analog"; spec->stream_analog_playback = &vt1716S_pcm_analog_playback; spec->stream_analog_capture = &vt1716S_pcm_analog_capture; - spec->stream_name_digital = "VT1716S Digital"; spec->stream_digital_playback = &vt1716S_pcm_digital_playback; if (spec->adc_nids && spec->input_mux) { @@ -5728,17 +5688,9 @@ static int patch_vt2002P(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs; - if (spec->codec_type == VT1802) - spec->stream_name_analog = "VT1802 Analog"; - else - spec->stream_name_analog = "VT2002P Analog"; spec->stream_analog_playback = &vt2002P_pcm_analog_playback; spec->stream_analog_capture = &vt2002P_pcm_analog_capture; - if (spec->codec_type == VT1802) - spec->stream_name_digital = "VT1802 Digital"; - else - spec->stream_name_digital = "VT2002P Digital"; spec->stream_digital_playback = &vt2002P_pcm_digital_playback; if (spec->adc_nids && spec->input_mux) { @@ -6128,11 +6080,9 @@ static int patch_vt1812(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; - spec->stream_name_analog = "VT1812 Analog"; spec->stream_analog_playback = &vt1812_pcm_analog_playback; spec->stream_analog_capture = &vt1812_pcm_analog_capture; - spec->stream_name_digital = "VT1812 Digital"; spec->stream_digital_playback = &vt1812_pcm_digital_playback; if (spec->adc_nids && spec->input_mux) { From 3e0693e278ae2000cff0c9250074591696caedbf Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 16:37:45 +0200 Subject: [PATCH 06/39] ALSA: hda - Change pin-ctl for auto-muting in patch_via.c Mute the outputs via pin-controls instead of amps for the auto-mute handling. This makes our life easier as it avoids conflict of the states between the mixer elements and the auto-mute toggles. With this change, we can use vmaster for the master control easily now. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 64 +++++++++++++++------------------------ 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index c66ff69eccf2..d374e8cfdcc8 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1615,17 +1615,10 @@ static void via_hp_automute(struct hda_codec *codec) present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); if (!spec->hp_independent_mode) { - struct snd_ctl_elem_id id; /* auto mute */ - snd_hda_codec_amp_stereo( - codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0, - HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); - /* notify change */ - memset(&id, 0, sizeof(id)); - id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - strcpy(id.name, "Front Playback Switch"); - snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, - &id); + snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + present ? 0 : PIN_OUT); } } @@ -1643,17 +1636,18 @@ static void via_mono_automute(struct hda_codec *codec) /* Mute Mono Out if Line Out is plugged */ if (lineout_present) { - snd_hda_codec_amp_stereo( - codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE); + snd_hda_codec_write(codec, 0x2A, 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + lineout_present ? 0 : PIN_OUT); return; } hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); if (!spec->hp_independent_mode) - snd_hda_codec_amp_stereo( - codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, - hp_present ? HDA_AMP_MUTE : 0); + snd_hda_codec_write(codec, 0x2A, 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + hp_present ? 0 : PIN_OUT); } static void via_gpio_control(struct hda_codec *codec) @@ -1678,9 +1672,9 @@ static void via_gpio_control(struct hda_codec *codec) if (gpio_data == 0x02) { /* unmute line out */ - snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], - HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); - + snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + PIN_OUT); if (vol_counter & 0x20) { /* decrease volume */ if (vol > master_vol) @@ -1697,10 +1691,9 @@ static void via_gpio_control(struct hda_codec *codec) } } else if (!(gpio_data & 0x02)) { /* mute line out */ - snd_hda_codec_amp_stereo(codec, - spec->autocfg.line_out_pins[0], - HDA_OUTPUT, 0, HDA_AMP_MUTE, - HDA_AMP_MUTE); + snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + 0); } } @@ -1716,16 +1709,9 @@ static void via_speaker_automute(struct hda_codec *codec) hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); if (!spec->hp_independent_mode) { - struct snd_ctl_elem_id id; - snd_hda_codec_amp_stereo( - codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0, - HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); - /* notify change */ - memset(&id, 0, sizeof(id)); - id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - strcpy(id.name, "Speaker Playback Switch"); - snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, - &id); + snd_hda_codec_write(codec, spec->autocfg.speaker_pins[0], 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + hp_present ? 0 : PIN_OUT); } } @@ -1749,18 +1735,18 @@ static void via_hp_bind_automute(struct hda_codec *codec) if (!spec->hp_independent_mode) { /* Mute Line-Outs */ for (i = 0; i < spec->autocfg.line_outs; i++) - snd_hda_codec_amp_stereo( - codec, spec->autocfg.line_out_pins[i], - HDA_OUTPUT, 0, - HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); + snd_hda_codec_write(codec, + spec->autocfg.line_out_pins[i], 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + hp_present ? 0 : PIN_OUT); if (hp_present) present = hp_present; } /* Speakers */ for (i = 0; i < spec->autocfg.speaker_outs; i++) - snd_hda_codec_amp_stereo( - codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0, - HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); + snd_hda_codec_write(codec, spec->autocfg.speaker_pins[i], 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + present ? 0 : PIN_OUT); } From 64be285b669e5eed65fb3630f1b2b549447b9f1e Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 16:51:39 +0200 Subject: [PATCH 07/39] ALSA: hda - Auto-mute all LO and speakers in patch_via.c Muting all line-outs and/or speakers is more common in other drivers, so we should follow it, too. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 63 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index d374e8cfdcc8..b9bd4d1cc860 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1606,6 +1606,17 @@ static void via_free(struct hda_codec *codec) kfree(codec->spec); } +/* mute/unmute outputs */ +static void toggle_output_mutes(struct hda_codec *codec, int num_pins, + hda_nid_t *pins, bool mute) +{ + int i; + for (i = 0; i < num_pins; i++) + snd_hda_codec_write(codec, pins[i], 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, + mute ? 0 : PIN_OUT); +} + /* mute internal speaker if HP is plugged */ static void via_hp_automute(struct hda_codec *codec) { @@ -1614,12 +1625,10 @@ static void via_hp_automute(struct hda_codec *codec) present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); - if (!spec->hp_independent_mode) { - /* auto mute */ - snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, - present ? 0 : PIN_OUT); - } + if (!spec->hp_independent_mode) + toggle_output_mutes(codec, spec->autocfg.line_outs, + spec->autocfg.line_out_pins, + present); } /* mute mono out if HP or Line out is plugged */ @@ -1708,45 +1717,35 @@ static void via_speaker_automute(struct hda_codec *codec) hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); - if (!spec->hp_independent_mode) { - snd_hda_codec_write(codec, spec->autocfg.speaker_pins[0], 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, - hp_present ? 0 : PIN_OUT); - } + if (!spec->hp_independent_mode) + toggle_output_mutes(codec, spec->autocfg.speaker_outs, + spec->autocfg.speaker_pins, + hp_present); } /* mute line-out and internal speaker if HP is plugged */ static void via_hp_bind_automute(struct hda_codec *codec) { - /* use long instead of int below just to avoid an internal compiler - * error with gcc 4.0.x - */ - unsigned long hp_present, present = 0; + int present; struct via_spec *spec = codec->spec; - int i; if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) return; - hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); + present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); + if (!spec->hp_independent_mode) + toggle_output_mutes(codec, spec->autocfg.line_outs, + spec->autocfg.line_out_pins, + present); - present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]); + if (!present) + present = snd_hda_jack_detect(codec, + spec->autocfg.line_out_pins[0]); - if (!spec->hp_independent_mode) { - /* Mute Line-Outs */ - for (i = 0; i < spec->autocfg.line_outs; i++) - snd_hda_codec_write(codec, - spec->autocfg.line_out_pins[i], 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, - hp_present ? 0 : PIN_OUT); - if (hp_present) - present = hp_present; - } /* Speakers */ - for (i = 0; i < spec->autocfg.speaker_outs; i++) - snd_hda_codec_write(codec, spec->autocfg.speaker_pins[i], 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, - present ? 0 : PIN_OUT); + toggle_output_mutes(codec, spec->autocfg.speaker_outs, + spec->autocfg.speaker_pins, + present); } From 620e2b28b7840f54da243ab3c771bcce5324bd80 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 17:19:19 +0200 Subject: [PATCH 08/39] ALSA: hda - Unify input-volume creations in patch_via.c Now storing the analog-mixer widget in spec, we can simplify the rest parts. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 132 ++++++++++++-------------------------- 1 file changed, 40 insertions(+), 92 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index b9bd4d1cc860..3704f2b024ec 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -131,6 +131,7 @@ struct via_spec { unsigned int num_adc_nids; hda_nid_t adc_nids[3]; hda_nid_t mux_nids[3]; + hda_nid_t aa_mix_nid; hda_nid_t dig_in_nid; hda_nid_t dig_in_pin; @@ -873,20 +874,17 @@ static void notify_aa_path_ctls(struct hda_codec *codec) static void mute_aa_path(struct hda_codec *codec, int mute) { struct via_spec *spec = codec->spec; - hda_nid_t nid_mixer; int start_idx; int end_idx; int i; /* get nid of MW0 and start & end index */ switch (spec->codec_type) { case VT1708: - nid_mixer = 0x17; start_idx = 2; end_idx = 4; break; case VT1709_10CH: case VT1709_6CH: - nid_mixer = 0x18; start_idx = 2; end_idx = 4; break; @@ -894,12 +892,10 @@ static void mute_aa_path(struct hda_codec *codec, int mute) case VT1708B_4CH: case VT1708S: case VT1716S: - nid_mixer = 0x16; start_idx = 2; end_idx = 4; break; case VT1718S: - nid_mixer = 0x21; start_idx = 1; end_idx = 3; break; @@ -909,7 +905,7 @@ static void mute_aa_path(struct hda_codec *codec, int mute) /* check AA path's mute status */ for (i = start_idx; i <= end_idx; i++) { int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; - snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i, + snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i, HDA_AMP_MUTE, val); } } @@ -1075,7 +1071,6 @@ static const struct snd_kcontrol_new vt1708_capture_mixer[] = { static int is_aa_path_mute(struct hda_codec *codec) { int mute = 1; - hda_nid_t nid_mixer; int start_idx; int end_idx; int i; @@ -1086,24 +1081,20 @@ static int is_aa_path_mute(struct hda_codec *codec) case VT1708B_4CH: case VT1708S: case VT1716S: - nid_mixer = 0x16; start_idx = 2; end_idx = 4; break; case VT1702: - nid_mixer = 0x1a; start_idx = 1; end_idx = 3; break; case VT1718S: - nid_mixer = 0x21; start_idx = 1; end_idx = 3; break; case VT2002P: case VT1812: case VT1802: - nid_mixer = 0x21; start_idx = 0; end_idx = 2; break; @@ -1113,15 +1104,15 @@ static int is_aa_path_mute(struct hda_codec *codec) /* check AA path's mute status */ for (i = start_idx; i <= end_idx; i++) { unsigned int con_list = snd_hda_codec_read( - codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); + codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); int shift = 8 * (i % 4); hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { /* check mute status while the pin is connected */ - int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0, + int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0, HDA_INPUT, i) >> 7; - int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1, + int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1, HDA_INPUT, i) >> 7; if (!mute_l || !mute_r) { mute = 0; @@ -2035,9 +2026,8 @@ static int via_fill_adcs(struct hda_codec *codec) static int get_mux_nids(struct hda_codec *codec); /* create playback/capture controls for input pins */ -static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg, - hda_nid_t mix_nid) +static int via_auto_create_analog_input_ctls(struct hda_codec *codec, + const struct auto_pin_cfg *cfg) { struct via_spec *spec = codec->spec; struct hda_input_mux *imux = &spec->private_imux[0]; @@ -2061,7 +2051,7 @@ static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, /* for internal loopback recording select */ for (idx = 0; idx < num_idxs; idx++) { - if (pin_idxs[idx] == mix_nid) { + if (pin_idxs[idx] == spec->aa_mix_nid) { snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); break; } @@ -2080,10 +2070,11 @@ static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, else type_idx = 0; label = hda_get_autocfg_input_label(codec, cfg, i); - idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]); + idx2 = get_connection_index(codec, spec->aa_mix_nid, + pin_idxs[idx]); if (idx2 >= 0) err = via_new_analog_input(spec, label, type_idx, - idx2, mix_nid); + idx2, spec->aa_mix_nid); if (err < 0) return err; snd_hda_add_imux_item(imux, label, idx, NULL); @@ -2091,13 +2082,6 @@ static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, return 0; } -/* create playback/capture controls for input pins */ -static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x17); -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1708_loopbacks[] = { { 0x17, HDA_INPUT, 1 }, @@ -2191,7 +2175,7 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; /* add jack detect on/off control */ @@ -2292,6 +2276,8 @@ static int patch_vt1708(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x17; + /* automatic parse from the BIOS config */ err = vt1708_parse_auto_config(codec); if (err < 0) { @@ -2653,13 +2639,6 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x18); -} - static int vt1709_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -2680,7 +2659,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec) err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -2724,6 +2703,8 @@ static int patch_vt1709_10ch(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x18; + err = vt1709_parse_auto_config(codec); if (err < 0) { via_free(codec); @@ -2810,6 +2791,8 @@ static int patch_vt1709_6ch(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x18; + err = vt1709_parse_auto_config(codec); if (err < 0) { via_free(codec); @@ -3171,13 +3154,6 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); -} - static int vt1708B_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3198,7 +3174,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec) err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -3325,6 +3301,8 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x16; + /* automatic parse from the BIOS config */ err = vt1708B_parse_auto_config(codec); if (err < 0) { @@ -3723,13 +3701,6 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); -} - /* fill out digital output widgets; one for master and one for slave outputs */ static void fill_dig_outs(struct hda_codec *codec) { @@ -3775,7 +3746,7 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec) err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -3825,6 +3796,8 @@ static int patch_vt1708S(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x16; + /* automatic parse from the BIOS config */ err = vt1708S_parse_auto_config(codec); if (err < 0) { @@ -4076,13 +4049,6 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a); -} - static int vt1702_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -4109,7 +4075,7 @@ static int vt1702_parse_auto_config(struct hda_codec *codec) (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | (1 << AC_AMPCAP_MUTE_SHIFT)); - err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -4179,6 +4145,8 @@ static int patch_vt1702(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x1a; + /* automatic parse from the BIOS config */ err = vt1702_parse_auto_config(codec); if (err < 0) { @@ -4489,13 +4457,6 @@ static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); -} - static int vt1718S_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -4517,7 +4478,7 @@ static int vt1718S_parse_auto_config(struct hda_codec *codec) err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -4627,6 +4588,8 @@ static int patch_vt1718S(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x21; + /* automatic parse from the BIOS config */ err = vt1718S_parse_auto_config(codec); if (err < 0) { @@ -5003,13 +4966,6 @@ static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); -} - static int vt1716S_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -5030,7 +4986,7 @@ static int vt1716S_parse_auto_config(struct hda_codec *codec) err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -5164,6 +5120,8 @@ static int patch_vt1716S(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x16; + /* automatic parse from the BIOS config */ err = vt1716S_parse_auto_config(codec); if (err < 0) { @@ -5469,13 +5427,6 @@ static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); -} - static int vt2002P_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -5499,7 +5450,7 @@ static int vt2002P_parse_auto_config(struct hda_codec *codec) err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -5649,6 +5600,8 @@ static int patch_vt2002P(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x21; + /* automatic parse from the BIOS config */ err = vt2002P_parse_auto_config(codec); if (err < 0) { @@ -5890,13 +5843,6 @@ static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) return 0; } -/* create playback/capture controls for input pins */ -static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); -} - static int vt1812_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -5920,7 +5866,7 @@ static int vt1812_parse_auto_config(struct hda_codec *codec) err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); if (err < 0) return err; - err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; @@ -6051,6 +5997,8 @@ static int patch_vt1812(struct hda_codec *codec) if (spec == NULL) return -ENOMEM; + spec->aa_mix_nid = 0x21; + /* automatic parse from the BIOS config */ err = vt1812_parse_auto_config(codec); if (err < 0) { From 4a79616d079f833714c9ef63a9b825caacafe675 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 17:53:38 +0200 Subject: [PATCH 09/39] ALSA: hda - Unify output-control parsing in patch_via.c Parse the output-paths more dynamically, i.e. traverse the paths from each output pin instead of fixed assignment for each codec. Now all codecs are using the same output parser code. The smart51 setup doesn't work with this change, and will be fixed in the next commits. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 1370 +++++-------------------------------- 1 file changed, 182 insertions(+), 1188 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 3704f2b024ec..1a3618599dec 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -107,6 +107,12 @@ enum VIA_HDA_CODEC { (spec)->codec_type == VT1812 ||\ (spec)->codec_type == VT1802) +struct nid_path { + int depth; + hda_nid_t path[5]; + short idx[5]; +}; + struct via_spec { /* codec parameterization */ const struct snd_kcontrol_new *mixers[6]; @@ -127,6 +133,10 @@ struct via_spec { struct hda_multi_out multiout; hda_nid_t slave_dig_outs[2]; + struct nid_path out_path[4]; + struct nid_path hp_path; + struct nid_path hp_dep_path; + /* capture */ unsigned int num_adc_nids; hda_nid_t adc_nids[3]; @@ -1822,130 +1832,165 @@ static const struct hda_codec_ops via_patch_ops = { #endif }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt1708_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) +static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac) { + struct via_spec *spec = codec->spec; + int i; + + for (i = 0; i < spec->multiout.num_dacs; i++) { + if (spec->multiout.dac_nids[i] == dac) + return false; + } + if (spec->multiout.hp_nid == dac) + return false; + return true; +} + +static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, + hda_nid_t target_dac, struct nid_path *path, + int depth, int wid_type) +{ + hda_nid_t conn[8]; + int i, nums; + + nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); + for (i = 0; i < nums; i++) { + if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) + continue; + if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { + path->path[depth] = conn[i]; + path->idx[depth] = i; + path->depth = ++depth; + return true; + } + } + if (depth > 4) + return false; + for (i = 0; i < nums; i++) { + unsigned int type; + type = get_wcaps_type(get_wcaps(codec, conn[i])); + if (type == AC_WID_AUD_OUT || + (wid_type != -1 && type != wid_type)) + continue; + if (parse_output_path(codec, conn[i], target_dac, + path, depth + 1, AC_WID_AUD_SEL)) { + path->path[depth] = conn[i]; + path->idx[depth] = i; + return true; + } + } + return false; +} + +static int via_auto_fill_dac_nids(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + const struct auto_pin_cfg *cfg = &spec->autocfg; int i; hda_nid_t nid; - spec->multiout.num_dacs = cfg->line_outs; - spec->multiout.dac_nids = spec->private_dac_nids; - - for (i = 0; i < 4; i++) { + spec->multiout.num_dacs = cfg->line_outs; + for (i = 0; i < cfg->line_outs; i++) { nid = cfg->line_out_pins[i]; - if (nid) { - /* config dac list */ - switch (i) { - case AUTO_SEQ_FRONT: - spec->private_dac_nids[i] = 0x10; - break; - case AUTO_SEQ_CENLFE: - spec->private_dac_nids[i] = 0x12; - break; - case AUTO_SEQ_SURROUND: - spec->private_dac_nids[i] = 0x11; - break; - case AUTO_SEQ_SIDE: - spec->private_dac_nids[i] = 0x13; - break; - } - } + if (!nid) + continue; + if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1)) + spec->private_dac_nids[i] = + spec->out_path[i].path[spec->out_path[i].depth - 1]; } - return 0; } -/* add playback controls from the parsed DAC table */ -static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) +static int create_ch_ctls(struct hda_codec *codec, const char *pfx, + hda_nid_t pin, hda_nid_t dac, int chs) { + struct via_spec *spec = codec->spec; char name[32]; + hda_nid_t nid; + int err; + + if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) + nid = dac; + else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) + nid = pin; + else + nid = 0; + if (nid) { + sprintf(name, "%s Playback Volume", pfx); + err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, + HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT)); + if (err < 0) + return err; + } + + if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE) + nid = dac; + else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE) + nid = pin; + else + nid = 0; + if (nid) { + sprintf(name, "%s Playback Switch", pfx); + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, + HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); + if (err < 0) + return err; + } + return 0; +} + +static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, + hda_nid_t nid); + +/* add playback controls from the parsed DAC table */ +static int via_auto_create_multi_out_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + const struct auto_pin_cfg *cfg = &spec->autocfg; static const char * const chname[4] = { "Front", "Surround", "C/LFE", "Side" }; - hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b}; - int i, err; + int i, idx, err; - for (i = 0; i <= AUTO_SEQ_SIDE; i++) { - nid = cfg->line_out_pins[i]; - - if (!nid) + for (i = 0; i < cfg->line_outs; i++) { + hda_nid_t pin, dac; + pin = cfg->line_out_pins[i]; + dac = spec->multiout.dac_nids[i]; + if (!pin || !dac) continue; - - nid_vol = nid_vols[i]; - if (i == AUTO_SEQ_CENLFE) { - /* Center/LFE */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Center Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); + err = create_ch_ctls(codec, "Center", pin, dac, 1); if (err < 0) return err; - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "LFE Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Center Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "LFE Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_FRONT) { - /* add control to mixer index 0 */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Master Front Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Master Front Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - - /* add control to PW3 */ - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid, 3, 0, - HDA_OUTPUT)); + err = create_ch_ctls(codec, "LFE", pin, dac, 2); if (err < 0) return err; } else { - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); + err = create_ch_ctls(codec, chname[i], pin, dac, 3); if (err < 0) return err; } } + idx = get_connection_index(codec, spec->aa_mix_nid, + spec->multiout.dac_nids[0]); + if (idx >= 0) { + /* add control to mixer */ + err = via_add_control(spec, VIA_CTL_WIDGET_VOL, + "PCM Playback Volume", + HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, + idx, HDA_INPUT)); + if (err < 0) + return err; + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, + "PCM Playback Switch", + HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, + idx, HDA_INPUT)); + if (err < 0) + return err; + } + return 0; } @@ -1962,28 +2007,29 @@ static void create_hp_imux(struct via_spec *spec) spec->hp_mux = &spec->private_imux[1]; } -static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) +static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) { + struct via_spec *spec = codec->spec; + hda_nid_t dac = 0; int err; if (!pin) return 0; - spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ - spec->hp_independent_mode_index = 1; + if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], + &spec->hp_dep_path, 0, -1)) + return 0; + if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) { + dac = spec->hp_path.path[spec->hp_path.depth - 1]; + spec->multiout.hp_nid = dac; + spec->hp_independent_mode_index = + spec->hp_path.idx[spec->hp_path.depth - 1]; + create_hp_imux(spec); + } - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); + err = create_ch_ctls(codec, "Headphone", pin, dac, 3); if (err < 0) return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - create_hp_imux(spec); return 0; } @@ -2163,16 +2209,16 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; - err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -2437,208 +2483,6 @@ static const struct hda_pcm_stream vt1709_pcm_digital_capture = { .channels_max = 2, }; -static int vt1709_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - int i; - hda_nid_t nid; - - if (cfg->line_outs == 4) /* 10 channels */ - spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */ - else if (cfg->line_outs == 3) /* 6 channels */ - spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */ - - spec->multiout.dac_nids = spec->private_dac_nids; - - if (cfg->line_outs == 4) { /* 10 channels */ - for (i = 0; i < cfg->line_outs; i++) { - nid = cfg->line_out_pins[i]; - if (nid) { - /* config dac list */ - switch (i) { - case AUTO_SEQ_FRONT: - /* AOW0 */ - spec->private_dac_nids[i] = 0x10; - break; - case AUTO_SEQ_CENLFE: - /* AOW2 */ - spec->private_dac_nids[i] = 0x12; - break; - case AUTO_SEQ_SURROUND: - /* AOW3 */ - spec->private_dac_nids[i] = 0x11; - break; - case AUTO_SEQ_SIDE: - /* AOW1 */ - spec->private_dac_nids[i] = 0x27; - break; - default: - break; - } - } - } - spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ - - } else if (cfg->line_outs == 3) { /* 6 channels */ - for (i = 0; i < cfg->line_outs; i++) { - nid = cfg->line_out_pins[i]; - if (nid) { - /* config dac list */ - switch (i) { - case AUTO_SEQ_FRONT: - /* AOW0 */ - spec->private_dac_nids[i] = 0x10; - break; - case AUTO_SEQ_CENLFE: - /* AOW2 */ - spec->private_dac_nids[i] = 0x12; - break; - case AUTO_SEQ_SURROUND: - /* AOW1 */ - spec->private_dac_nids[i] = 0x11; - break; - default: - break; - } - } - } - } - - return 0; -} - -/* add playback controls from the parsed DAC table */ -static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - char name[32]; - static const char * const chname[4] = { - "Front", "Surround", "C/LFE", "Side" - }; - hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29}; - int i, err; - - for (i = 0; i <= AUTO_SEQ_SIDE; i++) { - nid = cfg->line_out_pins[i]; - - if (!nid) - continue; - - nid_vol = nid_vols[i]; - - if (i == AUTO_SEQ_CENLFE) { - /* Center/LFE */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Center Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "LFE Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Center Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "LFE Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_FRONT) { - /* ADD control to mixer index 0 */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Master Front Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Master Front Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - - /* add control to PW3 */ - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_SURROUND) { - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_SIDE) { - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } - } - - return 0; -} - -static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err; - - if (!pin) - return 0; - - if (spec->multiout.num_dacs == 5) /* 10 channels */ - spec->multiout.hp_nid = VT1709_HP_DAC_NID; - else if (spec->multiout.num_dacs == 3) /* 6 channels */ - spec->multiout.hp_nid = 0; - spec->hp_independent_mode_index = 1; - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - return 0; -} - static int vt1709_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -2647,16 +2491,16 @@ static int vt1709_parse_auto_config(struct hda_codec *codec) err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; - err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -3000,160 +2844,6 @@ static const struct hda_pcm_stream vt1708B_pcm_digital_capture = { .channels_max = 2, }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt1708B_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - int i; - hda_nid_t nid; - - spec->multiout.num_dacs = cfg->line_outs; - - spec->multiout.dac_nids = spec->private_dac_nids; - - for (i = 0; i < 4; i++) { - nid = cfg->line_out_pins[i]; - if (nid) { - /* config dac list */ - switch (i) { - case AUTO_SEQ_FRONT: - spec->private_dac_nids[i] = 0x10; - break; - case AUTO_SEQ_CENLFE: - spec->private_dac_nids[i] = 0x24; - break; - case AUTO_SEQ_SURROUND: - spec->private_dac_nids[i] = 0x11; - break; - case AUTO_SEQ_SIDE: - spec->private_dac_nids[i] = 0x25; - break; - } - } - } - - return 0; -} - -/* add playback controls from the parsed DAC table */ -static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - char name[32]; - static const char * const chname[4] = { - "Front", "Surround", "C/LFE", "Side" - }; - hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27}; - hda_nid_t nid, nid_vol = 0; - int i, err; - - for (i = 0; i <= AUTO_SEQ_SIDE; i++) { - nid = cfg->line_out_pins[i]; - - if (!nid) - continue; - - nid_vol = nid_vols[i]; - - if (i == AUTO_SEQ_CENLFE) { - /* Center/LFE */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Center Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "LFE Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Center Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "LFE Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_FRONT) { - /* add control to mixer index 0 */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Master Front Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Master Front Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - - /* add control to PW3 */ - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else { - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } - } - - return 0; -} - -static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err; - - if (!pin) - return 0; - - spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ - spec->hp_independent_mode_index = 1; - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - create_hp_imux(spec); - - return 0; -} - static int vt1708B_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3162,16 +2852,16 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec) err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; - err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -3516,191 +3206,6 @@ static const struct hda_pcm_stream vt1708S_pcm_digital_playback = { }, }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt1708S_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - int i; - hda_nid_t nid; - - spec->multiout.num_dacs = cfg->line_outs; - - spec->multiout.dac_nids = spec->private_dac_nids; - - for (i = 0; i < 4; i++) { - nid = cfg->line_out_pins[i]; - if (nid) { - /* config dac list */ - switch (i) { - case AUTO_SEQ_FRONT: - spec->private_dac_nids[i] = 0x10; - break; - case AUTO_SEQ_CENLFE: - if (spec->codec->vendor_id == 0x11064397) - spec->private_dac_nids[i] = 0x25; - else - spec->private_dac_nids[i] = 0x24; - break; - case AUTO_SEQ_SURROUND: - spec->private_dac_nids[i] = 0x11; - break; - case AUTO_SEQ_SIDE: - spec->private_dac_nids[i] = 0x25; - break; - } - } - } - - /* for Smart 5.1, line/mic inputs double as output pins */ - if (cfg->line_outs == 1) { - spec->multiout.num_dacs = 3; - spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11; - if (spec->codec->vendor_id == 0x11064397) - spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25; - else - spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24; - } - - return 0; -} - -/* add playback controls from the parsed DAC table */ -static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) -{ - struct via_spec *spec = codec->spec; - char name[32]; - static const char * const chname[4] = { - "Front", "Surround", "C/LFE", "Side" - }; - hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25}, - {0x10, 0x11, 0x25, 0} }; - hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27}, - {0x1C, 0x18, 0x27, 0} }; - hda_nid_t nid, nid_vol, nid_mute; - int i, err; - - for (i = 0; i <= AUTO_SEQ_SIDE; i++) { - nid = cfg->line_out_pins[i]; - - /* for Smart 5.1, there are always at least six channels */ - if (!nid && i > AUTO_SEQ_CENLFE) - continue; - - if (codec->vendor_id == 0x11064397) { - nid_vol = nid_vols[1][i]; - nid_mute = nid_mutes[1][i]; - } else { - nid_vol = nid_vols[0][i]; - nid_mute = nid_mutes[0][i]; - } - if (!nid_vol && !nid_mute) - continue; - - if (i == AUTO_SEQ_CENLFE) { - /* Center/LFE */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Center Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "LFE Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Center Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_mute, - 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "LFE Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_mute, - 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_FRONT) { - /* add control to mixer index 0 */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Master Front Playback Volume", - HDA_COMPOSE_AMP_VAL(0x16, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Master Front Playback Switch", - HDA_COMPOSE_AMP_VAL(0x16, 3, 0, - HDA_INPUT)); - if (err < 0) - return err; - - /* Front */ - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_mute, - 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else { - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_mute, - 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } - } - - return 0; -} - -static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err; - - if (!pin) - return 0; - - spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ - spec->hp_independent_mode_index = 1; - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - create_hp_imux(spec); - - return 0; -} - /* fill out digital output widgets; one for master and one for slave outputs */ static void fill_dig_outs(struct hda_codec *codec) { @@ -3734,16 +3239,16 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec) err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; - err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -3966,89 +3471,6 @@ static const struct hda_pcm_stream vt1702_pcm_digital_playback = { }, }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt1702_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - spec->multiout.num_dacs = 1; - spec->multiout.dac_nids = spec->private_dac_nids; - - if (cfg->line_out_pins[0]) { - /* config dac list */ - spec->private_dac_nids[0] = 0x10; - } - - return 0; -} - -/* add playback controls from the parsed DAC table */ -static int vt1702_auto_create_line_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - int err; - - if (!cfg->line_out_pins[0]) - return -1; - - /* add control to mixer index 0 */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Master Front Playback Volume", - HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Master Front Playback Switch", - HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); - if (err < 0) - return err; - - /* Front */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Front Playback Volume", - HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Front Playback Switch", - HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - return 0; -} - -static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err, i; - struct hda_input_mux *imux; - static const char * const texts[] = { "ON", "OFF", NULL}; - if (!pin) - return 0; - spec->multiout.hp_nid = 0x1D; - spec->hp_independent_mode_index = 0; - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - imux = &spec->private_imux[1]; - - /* for hp mode select */ - for (i = 0; texts[i]; i++) - snd_hda_add_imux_item(imux, texts[i], i, NULL); - - spec->hp_mux = &spec->private_imux[1]; - return 0; -} - static int vt1702_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -4057,16 +3479,16 @@ static int vt1702_parse_auto_config(struct hda_codec *codec) err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; - err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; /* limit AA path volume to 0 dB */ @@ -4313,150 +3735,6 @@ static const struct hda_pcm_stream vt1718S_pcm_digital_capture = { .channels_max = 2, }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt1718S_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - int i; - hda_nid_t nid; - - spec->multiout.num_dacs = cfg->line_outs; - - spec->multiout.dac_nids = spec->private_dac_nids; - - for (i = 0; i < 4; i++) { - nid = cfg->line_out_pins[i]; - if (nid) { - /* config dac list */ - switch (i) { - case AUTO_SEQ_FRONT: - spec->private_dac_nids[i] = 0x8; - break; - case AUTO_SEQ_CENLFE: - spec->private_dac_nids[i] = 0xa; - break; - case AUTO_SEQ_SURROUND: - spec->private_dac_nids[i] = 0x9; - break; - case AUTO_SEQ_SIDE: - spec->private_dac_nids[i] = 0xb; - break; - } - } - } - - return 0; -} - -/* add playback controls from the parsed DAC table */ -static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - char name[32]; - static const char * const chname[4] = { - "Front", "Surround", "C/LFE", "Side" - }; - hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb}; - hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27}; - hda_nid_t nid, nid_vol, nid_mute = 0; - int i, err; - - for (i = 0; i <= AUTO_SEQ_SIDE; i++) { - nid = cfg->line_out_pins[i]; - - if (!nid) - continue; - nid_vol = nid_vols[i]; - nid_mute = nid_mutes[i]; - - if (i == AUTO_SEQ_CENLFE) { - /* Center/LFE */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Center Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "LFE Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, - "Center Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, - "LFE Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_FRONT) { - /* Front */ - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else { - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } - } - return 0; -} - -static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err; - - if (!pin) - return 0; - - spec->multiout.hp_nid = 0xc; /* AOW4 */ - spec->hp_independent_mode_index = 1; - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - create_hp_imux(spec); - return 0; -} - static int vt1718S_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -4466,16 +3744,16 @@ static int vt1718S_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; - err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -4813,159 +4091,6 @@ static const struct hda_pcm_stream vt1716S_pcm_digital_playback = { }, }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt1716S_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ int i; - hda_nid_t nid; - - spec->multiout.num_dacs = cfg->line_outs; - - spec->multiout.dac_nids = spec->private_dac_nids; - - for (i = 0; i < 3; i++) { - nid = cfg->line_out_pins[i]; - if (nid) { - /* config dac list */ - switch (i) { - case AUTO_SEQ_FRONT: - spec->private_dac_nids[i] = 0x10; - break; - case AUTO_SEQ_CENLFE: - spec->private_dac_nids[i] = 0x25; - break; - case AUTO_SEQ_SURROUND: - spec->private_dac_nids[i] = 0x11; - break; - } - } - } - - return 0; -} - -/* add playback controls from the parsed DAC table */ -static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - char name[32]; - static const char * const chname[3] = { - "Front", "Surround", "C/LFE" - }; - hda_nid_t nid_vols[] = {0x10, 0x11, 0x25}; - hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27}; - hda_nid_t nid, nid_vol, nid_mute; - int i, err; - - for (i = 0; i <= AUTO_SEQ_CENLFE; i++) { - nid = cfg->line_out_pins[i]; - - if (!nid) - continue; - - nid_vol = nid_vols[i]; - nid_mute = nid_mutes[i]; - - if (i == AUTO_SEQ_CENLFE) { - err = via_add_control( - spec, VIA_CTL_WIDGET_VOL, - "Center Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control( - spec, VIA_CTL_WIDGET_VOL, - "LFE Playback Volume", - HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, - "Center Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, - "LFE Playback Switch", - HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else if (i == AUTO_SEQ_FRONT) { - - err = via_add_control( - spec, VIA_CTL_WIDGET_VOL, - "Master Front Playback Volume", - HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); - if (err < 0) - return err; - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, - "Master Front Playback Switch", - HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); - if (err < 0) - return err; - - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } else { - sprintf(name, "%s Playback Volume", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - sprintf(name, "%s Playback Switch", chname[i]); - err = via_add_control( - spec, VIA_CTL_WIDGET_MUTE, name, - HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, - HDA_OUTPUT)); - if (err < 0) - return err; - } - } - return 0; -} - -static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err; - - if (!pin) - return 0; - - spec->multiout.hp_nid = 0x25; /* AOW3 */ - spec->hp_independent_mode_index = 1; - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - create_hp_imux(spec); - return 0; -} - static int vt1716S_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -4974,16 +4099,16 @@ static int vt1716S_parse_auto_config(struct hda_codec *codec) err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; - err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -5359,74 +4484,6 @@ static const struct hda_pcm_stream vt2002P_pcm_digital_playback = { }, }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt2002P_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - spec->multiout.num_dacs = 1; - spec->multiout.dac_nids = spec->private_dac_nids; - if (cfg->line_out_pins[0]) - spec->private_dac_nids[0] = 0x8; - return 0; -} - -/* add playback controls from the parsed DAC table */ -static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - int err; - hda_nid_t sw_nid; - - if (!cfg->line_out_pins[0]) - return -1; - - if (spec->codec_type == VT1802) - sw_nid = 0x28; - else - sw_nid = 0x26; - - /* Line-Out: PortE */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Master Front Playback Volume", - HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, - "Master Front Playback Switch", - HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - return 0; -} - -static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err; - - if (!pin) - return 0; - - spec->multiout.hp_nid = 0x9; - spec->hp_independent_mode_index = 1; - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL( - spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - create_hp_imux(spec); - return 0; -} - static int vt2002P_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -5437,17 +4494,17 @@ static int vt2002P_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; - err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) return 0; /* can't find valid BIOS pin config */ - err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -5779,69 +4836,6 @@ static const struct hda_pcm_stream vt1812_pcm_digital_playback = { .cleanup = via_dig_playback_pcm_cleanup }, }; -/* fill in the dac_nids table from the parsed pin configuration */ -static int vt1812_auto_fill_dac_nids(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - spec->multiout.num_dacs = 1; - spec->multiout.dac_nids = spec->private_dac_nids; - if (cfg->line_out_pins[0]) - spec->private_dac_nids[0] = 0x8; - return 0; -} - - -/* add playback controls from the parsed DAC table */ -static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec, - const struct auto_pin_cfg *cfg) -{ - int err; - - if (!cfg->line_out_pins[0]) - return -1; - - /* Line-Out: PortE */ - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Front Playback Volume", - HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, - "Front Playback Switch", - HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - return 0; -} - -static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) -{ - int err; - - if (!pin) - return 0; - - spec->multiout.hp_nid = 0x9; - spec->hp_independent_mode_index = 1; - - - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, - "Headphone Playback Volume", - HDA_COMPOSE_AMP_VAL( - spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, - "Headphone Playback Switch", - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); - if (err < 0) - return err; - - create_hp_imux(spec); - return 0; -} static int vt1812_parse_auto_config(struct hda_codec *codec) { @@ -5853,17 +4847,17 @@ static int vt1812_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; fill_dig_outs(codec); - err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg); + err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) return 0; /* can't find valid BIOS pin config */ - err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg); + err = via_auto_create_multi_out_ctls(codec); if (err < 0) return err; - err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); + err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); From f4a7828bc1e85b8de03b628da1cef4e862e0623b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 17 Jun 2011 18:46:48 +0200 Subject: [PATCH 10/39] ALSA: hda - Re-implement smart51 detection for VIA codecs Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 117 ++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 42 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 1a3618599dec..77ecc778d313 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -162,6 +162,7 @@ struct via_spec { const struct hda_input_mux *hp_mux; unsigned int hp_independent_mode; unsigned int hp_independent_mode_index; + unsigned int can_smart51; unsigned int smart51_enabled; unsigned int dmic_enabled; unsigned int no_pin_power_ctl; @@ -544,7 +545,7 @@ static void via_auto_init_hp_out(struct hda_codec *codec) } } -static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin); +static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); static void via_auto_init_analog_input(struct hda_codec *codec) { @@ -555,7 +556,7 @@ static void via_auto_init_analog_input(struct hda_codec *codec) for (i = 0; i < cfg->num_inputs; i++) { hda_nid_t nid = cfg->inputs[i].pin; - if (spec->smart51_enabled && is_smart51_pins(spec, nid)) + if (spec->smart51_enabled && is_smart51_pins(codec, nid)) ctl = PIN_OUT; else if (cfg->inputs[i].type == AUTO_PIN_MIC) ctl = PIN_VREF50; @@ -580,7 +581,7 @@ static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, no_presence |= spec->no_pin_power_ctl; if (!no_presence) present = snd_hda_jack_detect(codec, nid); - if ((spec->smart51_enabled && is_smart51_pins(spec, nid)) + if ((spec->smart51_enabled && is_smart51_pins(codec, nid)) || ((no_presence || present) && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { *affected_parm = AC_PWRST_D0; /* if it's connected */ @@ -919,16 +920,25 @@ static void mute_aa_path(struct hda_codec *codec, int mute) HDA_AMP_MUTE, val); } } -static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin) + +static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) { + struct via_spec *spec = codec->spec; const struct auto_pin_cfg *cfg = &spec->autocfg; int i; for (i = 0; i < cfg->num_inputs; i++) { - if (pin == cfg->inputs[i].pin) - return cfg->inputs[i].type <= AUTO_PIN_LINE_IN; + unsigned int defcfg; + if (pin != cfg->inputs[i].pin) + continue; + if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) + return false; + defcfg = snd_hda_codec_get_pincfg(codec, pin); + if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL) + return false; + return true; } - return 0; + return false; } static int via_smart51_info(struct snd_kcontrol *kcontrol, @@ -952,13 +962,14 @@ static int via_smart51_get(struct snd_kcontrol *kcontrol, for (i = 0; i < cfg->num_inputs; i++) { hda_nid_t nid = cfg->inputs[i].pin; - int ctl = snd_hda_codec_read(codec, nid, 0, - AC_VERB_GET_PIN_WIDGET_CONTROL, 0); - if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) - continue; + unsigned int ctl; if (cfg->inputs[i].type == AUTO_PIN_MIC && spec->hp_independent_mode && spec->codec_type != VT1718S) continue; /* ignore FMic for independent HP */ + if (!is_smart51_pins(codec, nid)) + continue; + ctl = snd_hda_codec_read(codec, nid, 0, + AC_VERB_GET_PIN_WIDGET_CONTROL, 0); if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) on = 0; } @@ -980,11 +991,11 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol, hda_nid_t nid = cfg->inputs[i].pin; unsigned int parm; - if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) - continue; if (cfg->inputs[i].type == AUTO_PIN_MIC && spec->hp_independent_mode && spec->codec_type != VT1718S) continue; /* don't retask FMic for independent HP */ + if (!is_smart51_pins(codec, nid)) + continue; parm = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); @@ -997,23 +1008,6 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol, mute_aa_path(codec, 1); notify_aa_path_ctls(codec); } - if (spec->codec_type == VT1718S) { - snd_hda_codec_amp_stereo( - codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE, - HDA_AMP_UNMUTE); - } - if (cfg->inputs[i].type == AUTO_PIN_MIC) { - if (spec->codec_type == VT1708S - || spec->codec_type == VT1716S) { - /* input = index 1 (AOW3) */ - snd_hda_codec_write( - codec, nid, 0, - AC_VERB_SET_CONNECT_SEL, 1); - snd_hda_codec_amp_stereo( - codec, nid, HDA_OUTPUT, - 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE); - } - } } spec->smart51_enabled = *ucontrol->value.integer.value; set_widgets_power_state(codec); @@ -1029,16 +1023,15 @@ static const struct snd_kcontrol_new via_smart51_mixer = { .put = via_smart51_put, }; -static int via_smart51_build(struct via_spec *spec) +static int via_smart51_build(struct hda_codec *codec) { + struct via_spec *spec = codec->spec; struct snd_kcontrol_new *knew; const struct auto_pin_cfg *cfg = &spec->autocfg; hda_nid_t nid; int i; - if (!cfg) - return 0; - if (cfg->line_outs > 2) + if (!spec->can_smart51) return 0; knew = via_clone_control(spec, &via_smart51_mixer); @@ -1047,7 +1040,7 @@ static int via_smart51_build(struct via_spec *spec) for (i = 0; i < cfg->num_inputs; i++) { nid = cfg->inputs[i].pin; - if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) { + if (is_smart51_pins(codec, nid)) { knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; break; } @@ -1943,15 +1936,37 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, hda_nid_t nid); +static void mangle_smart51(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + struct auto_pin_cfg *cfg = &spec->autocfg; + int i; + + for (i = 0; i < cfg->num_inputs; i++) { + if (!is_smart51_pins(codec, cfg->inputs[i].pin)) + continue; + spec->can_smart51 = 1; + cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin; + if (cfg->line_outs == 3) + break; + } +} + /* add playback controls from the parsed DAC table */ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) { struct via_spec *spec = codec->spec; - const struct auto_pin_cfg *cfg = &spec->autocfg; + struct auto_pin_cfg *cfg = &spec->autocfg; static const char * const chname[4] = { "Front", "Surround", "C/LFE", "Side" }; int i, idx, err; + int old_line_outs; + + /* check smart51 */ + old_line_outs = cfg->line_outs; + if (cfg->line_outs == 1) + mangle_smart51(codec); for (i = 0; i < cfg->line_outs; i++) { hda_nid_t pin, dac; @@ -1991,6 +2006,8 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) return err; } + cfg->line_outs = old_line_outs; + return 0; } @@ -2246,7 +2263,10 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) if (spec->hp_mux) via_hp_build(codec); - via_smart51_build(spec); + err = via_smart51_build(codec); + if (err < 0) + return err; + return 1; } @@ -2523,7 +2543,10 @@ static int vt1709_parse_auto_config(struct hda_codec *codec) if (spec->hp_mux) via_hp_build(codec); - via_smart51_build(spec); + err = via_smart51_build(codec); + if (err < 0) + return err; + return 1; } @@ -2884,7 +2907,10 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec) if (spec->hp_mux) via_hp_build(codec); - via_smart51_build(spec); + err = via_smart51_build(codec); + if (err < 0) + return err; + return 1; } @@ -3267,7 +3293,10 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec) if (spec->hp_mux) via_hp_build(codec); - via_smart51_build(spec); + err = via_smart51_build(codec); + if (err < 0) + return err; + return 1; } @@ -3775,7 +3804,9 @@ static int vt1718S_parse_auto_config(struct hda_codec *codec) if (spec->hp_mux) via_hp_build(codec); - via_smart51_build(spec); + err = via_smart51_build(codec); + if (err < 0) + return err; return 1; } @@ -4127,7 +4158,9 @@ static int vt1716S_parse_auto_config(struct hda_codec *codec) if (spec->hp_mux) via_hp_build(codec); - via_smart51_build(spec); + err = via_smart51_build(codec); + if (err < 0) + return err; return 1; } From 57307bf24ac78d135c066520234c01bda36ec39a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 18 Jun 2011 10:58:49 +0200 Subject: [PATCH 11/39] ALSA: hda - Don't create secondary substream when no independent-hp is used For VIA codecs, we shouldn't create a substream for independent HP mode, when no individual HP DAC is found. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 77ecc778d313..78e679e76ca8 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1557,6 +1557,8 @@ static int via_build_pcms(struct hda_codec *codec) *(spec->stream_analog_playback); info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; + if (!spec->multiout.hp_nid) + info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1; info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; From 9af7421091fd37a2f8c35ca8b3a5f78a6f20fa89 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 18 Jun 2011 16:17:45 +0200 Subject: [PATCH 12/39] ALSA: hda - Unify PCM assignments in patch_via.c Unify PCM streams for all codecs by assigning the NID dynamically. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 502 ++++---------------------------------- 1 file changed, 47 insertions(+), 455 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 78e679e76ca8..18f2a135c026 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1222,6 +1222,17 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, hinfo); } +static int via_playback_pcm_close(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + struct snd_pcm_substream *substream) +{ + int idle = substream->pstr->substream_opened == 1 + && substream->ref_count == 0; + + analog_low_current_mode(codec, idle); + return 0; +} + static void playback_multi_pcm_prep_0(struct hda_codec *codec, unsigned int stream_tag, unsigned int format, @@ -1419,23 +1430,24 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, return 0; } -static const struct hda_pcm_stream vt1708_pcm_analog_playback = { - .substreams = 2, +static const struct hda_pcm_stream via_pcm_analog_playback = { + .substreams = 2, /* will be changed in via_build_pcms() */ .channels_min = 2, .channels_max = 8, - .nid = 0x10, /* NID to query formats and rates */ + /* NID is set in via_build_pcms */ .ops = { .open = via_playback_pcm_open, + .close = via_playback_pcm_close, .prepare = via_playback_multi_pcm_prepare, .cleanup = via_playback_multi_pcm_cleanup }, }; static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { - .substreams = 2, + .substreams = 2, /* will be changed in via_build_pcms() */ .channels_min = 2, .channels_max = 8, - .nid = 0x10, /* NID to query formats and rates */ + /* NID is set in via_build_pcms */ /* We got noisy outputs on the right channel on VT1708 when * 24bit samples are used. Until any workaround is found, * disable the 24bit format, so far. @@ -1443,23 +1455,26 @@ static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { .formats = SNDRV_PCM_FMTBIT_S16_LE, .ops = { .open = via_playback_pcm_open, + .close = via_playback_pcm_close, .prepare = via_playback_multi_pcm_prepare, .cleanup = via_playback_multi_pcm_cleanup }, }; -static const struct hda_pcm_stream vt1708_pcm_analog_capture = { - .substreams = 2, +static const struct hda_pcm_stream via_pcm_analog_capture = { + .substreams = 2, /* will be changed in via_build_pcms() */ .channels_min = 2, .channels_max = 2, - .nid = 0x15, /* NID to query formats and rates */ + /* NID is set in via_build_pcms */ .ops = { + .open = via_playback_pcm_open, + .close = via_playback_pcm_close, .prepare = via_capture_pcm_prepare, .cleanup = via_capture_pcm_cleanup }, }; -static const struct hda_pcm_stream vt1708_pcm_digital_playback = { +static const struct hda_pcm_stream via_pcm_digital_playback = { .substreams = 1, .channels_min = 2, .channels_max = 2, @@ -1472,7 +1487,7 @@ static const struct hda_pcm_stream vt1708_pcm_digital_playback = { }, }; -static const struct hda_pcm_stream vt1708_pcm_digital_capture = { +static const struct hda_pcm_stream via_pcm_digital_capture = { .substreams = 1, .channels_min = 2, .channels_max = 2, @@ -1553,17 +1568,25 @@ static int via_build_pcms(struct hda_codec *codec) snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), "%s Analog", codec->chip_name); info->name = spec->stream_name_analog; + + if (!spec->stream_analog_playback) + spec->stream_analog_playback = &via_pcm_analog_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = - *(spec->stream_analog_playback); + *spec->stream_analog_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; - if (!spec->multiout.hp_nid) - info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1; - info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); - info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; - info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; + if (!spec->multiout.hp_nid) + info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1; + + if (!spec->stream_analog_capture) + spec->stream_analog_capture = &via_pcm_analog_capture; + info->stream[SNDRV_PCM_STREAM_CAPTURE] = + *spec->stream_analog_capture; + info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; + info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = + spec->num_adc_nids; if (spec->multiout.dig_out_nid || spec->dig_in_nid) { codec->num_pcms++; @@ -1574,14 +1597,20 @@ static int via_build_pcms(struct hda_codec *codec) info->name = spec->stream_name_digital; info->pcm_type = HDA_PCM_TYPE_SPDIF; if (spec->multiout.dig_out_nid) { + if (!spec->stream_digital_playback) + spec->stream_digital_playback = + &via_pcm_digital_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = - *(spec->stream_digital_playback); + *spec->stream_digital_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; } if (spec->dig_in_nid) { + if (!spec->stream_digital_capture) + spec->stream_digital_capture = + &via_pcm_digital_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE] = - *(spec->stream_digital_capture); + *spec->stream_digital_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; } @@ -2357,14 +2386,9 @@ static int patch_vt1708(struct hda_codec *codec) } - spec->stream_analog_playback = &vt1708_pcm_analog_playback; /* disable 32bit format on VT1708 */ if (codec->vendor_id == 0x11061708) spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; - spec->stream_analog_capture = &vt1708_pcm_analog_capture; - - spec->stream_digital_playback = &vt1708_pcm_digital_playback; - spec->stream_digital_capture = &vt1708_pcm_digital_capture; if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1708_capture_mixer; @@ -2453,58 +2477,6 @@ static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { { } }; -static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 10, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - }, -}; - -static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 6, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - }, -}; - -static const struct hda_pcm_stream vt1709_pcm_analog_capture = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x14, /* NID to query formats and rates */ - .ops = { - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup - }, -}; - -static const struct hda_pcm_stream vt1709_pcm_digital_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close - }, -}; - -static const struct hda_pcm_stream vt1709_pcm_digital_capture = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, -}; - static int vt1709_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -2586,12 +2558,6 @@ static int patch_vt1709_10ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; - spec->stream_analog_capture = &vt1709_pcm_analog_capture; - - spec->stream_digital_playback = &vt1709_pcm_digital_playback; - spec->stream_digital_capture = &vt1709_pcm_digital_capture; - if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1709_capture_mixer; spec->num_mixers++; @@ -2674,12 +2640,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; - spec->stream_analog_capture = &vt1709_pcm_analog_capture; - - spec->stream_digital_playback = &vt1709_pcm_digital_playback; - spec->stream_digital_capture = &vt1709_pcm_digital_capture; - if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1709_capture_mixer; spec->num_mixers++; @@ -2801,74 +2761,6 @@ static const struct hda_verb vt1708B_uniwill_init_verbs[] = { { } }; -static int via_pcm_open_close(struct hda_pcm_stream *hinfo, - struct hda_codec *codec, - struct snd_pcm_substream *substream) -{ - int idle = substream->pstr->substream_opened == 1 - && substream->ref_count == 0; - - analog_low_current_mode(codec, idle); - return 0; -} - -static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 8, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close - }, -}; - -static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 4, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup - }, -}; - -static const struct hda_pcm_stream vt1708B_pcm_analog_capture = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x13, /* NID to query formats and rates */ - .ops = { - .open = via_pcm_open_close, - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup, - .close = via_pcm_open_close - }, -}; - -static const struct hda_pcm_stream vt1708B_pcm_digital_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close, - .prepare = via_dig_playback_pcm_prepare, - .cleanup = via_dig_playback_pcm_cleanup - }, -}; - -static const struct hda_pcm_stream vt1708B_pcm_digital_capture = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, -}; - static int vt1708B_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3034,12 +2926,6 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; - spec->stream_analog_capture = &vt1708B_pcm_analog_capture; - - spec->stream_digital_playback = &vt1708B_pcm_digital_playback; - spec->stream_digital_capture = &vt1708B_pcm_digital_capture; - if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; spec->num_mixers++; @@ -3081,12 +2967,6 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; - spec->stream_analog_capture = &vt1708B_pcm_analog_capture; - - spec->stream_digital_playback = &vt1708B_pcm_digital_playback; - spec->stream_digital_capture = &vt1708B_pcm_digital_capture; - if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; spec->num_mixers++; @@ -3182,58 +3062,6 @@ static const struct hda_verb vt1705_uniwill_init_verbs[] = { { } }; -static const struct hda_pcm_stream vt1708S_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 8, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close - }, -}; - -static const struct hda_pcm_stream vt1705_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 6, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close - }, -}; - -static const struct hda_pcm_stream vt1708S_pcm_analog_capture = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x13, /* NID to query formats and rates */ - .ops = { - .open = via_pcm_open_close, - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup, - .close = via_pcm_open_close - }, -}; - -static const struct hda_pcm_stream vt1708S_pcm_digital_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close, - .prepare = via_dig_playback_pcm_prepare, - .cleanup = via_dig_playback_pcm_cleanup - }, -}; - /* fill out digital output widgets; one for master and one for slave outputs */ static void fill_dig_outs(struct hda_codec *codec) { @@ -3352,14 +3180,6 @@ static int patch_vt1708S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; - if (codec->vendor_id == 0x11064397) - spec->stream_analog_playback = &vt1705_pcm_analog_playback; - else - spec->stream_analog_playback = &vt1708S_pcm_analog_playback; - spec->stream_analog_capture = &vt1708S_pcm_analog_capture; - - spec->stream_digital_playback = &vt1708S_pcm_digital_playback; - if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x1a, 0, 3, 40); override_mic_boost(codec, 0x1e, 0, 3, 40); @@ -3463,45 +3283,6 @@ static const struct hda_verb vt1702_uniwill_init_verbs[] = { { } }; -static const struct hda_pcm_stream vt1702_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close - }, -}; - -static const struct hda_pcm_stream vt1702_pcm_analog_capture = { - .substreams = 3, - .channels_min = 2, - .channels_max = 2, - .nid = 0x12, /* NID to query formats and rates */ - .ops = { - .open = via_pcm_open_close, - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup, - .close = via_pcm_open_close - }, -}; - -static const struct hda_pcm_stream vt1702_pcm_digital_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close, - .prepare = via_dig_playback_pcm_prepare, - .cleanup = via_dig_playback_pcm_cleanup - }, -}; - static int vt1702_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3613,11 +3394,6 @@ static int patch_vt1702(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; - spec->stream_analog_playback = &vt1702_pcm_analog_playback; - spec->stream_analog_capture = &vt1702_pcm_analog_capture; - - spec->stream_digital_playback = &vt1702_pcm_digital_playback; - if (spec->adc_nids && spec->input_mux) { spec->mixers[spec->num_mixers] = vt1702_capture_mixer; spec->num_mixers++; @@ -3721,51 +3497,6 @@ static const struct hda_verb vt1718S_uniwill_init_verbs[] = { { } }; -static const struct hda_pcm_stream vt1718S_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 10, - .nid = 0x8, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt1718S_pcm_analog_capture = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_pcm_open_close, - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt1718S_pcm_digital_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close, - .prepare = via_dig_playback_pcm_prepare, - .cleanup = via_dig_playback_pcm_cleanup - }, -}; - -static const struct hda_pcm_stream vt1718S_pcm_digital_capture = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, -}; - static int vt1718S_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3914,13 +3645,6 @@ static int patch_vt1718S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; - spec->stream_analog_playback = &vt1718S_pcm_analog_playback; - spec->stream_analog_capture = &vt1718S_pcm_analog_capture; - - spec->stream_digital_playback = &vt1718S_pcm_digital_playback; - if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) - spec->stream_digital_capture = &vt1718S_pcm_digital_capture; - if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x2b, 0, 3, 40); override_mic_boost(codec, 0x29, 0, 3, 40); @@ -4085,45 +3809,6 @@ static const struct hda_verb vt1716S_uniwill_init_verbs[] = { { } }; -static const struct hda_pcm_stream vt1716S_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 6, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt1716S_pcm_analog_capture = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x13, /* NID to query formats and rates */ - .ops = { - .open = via_pcm_open_close, - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt1716S_pcm_digital_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close, - .prepare = via_dig_playback_pcm_prepare, - .cleanup = via_dig_playback_pcm_cleanup - }, -}; - static int vt1716S_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -4295,11 +3980,6 @@ static int patch_vt1716S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; - spec->stream_analog_playback = &vt1716S_pcm_analog_playback; - spec->stream_analog_capture = &vt1716S_pcm_analog_capture; - - spec->stream_digital_playback = &vt1716S_pcm_digital_playback; - if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x1a, 0, 3, 40); override_mic_boost(codec, 0x1e, 0, 3, 40); @@ -4480,45 +4160,6 @@ static const struct hda_verb vt1802_uniwill_init_verbs[] = { { } }; -static const struct hda_pcm_stream vt2002P_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x8, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt2002P_pcm_analog_capture = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_pcm_open_close, - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt2002P_pcm_digital_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close, - .prepare = via_dig_playback_pcm_prepare, - .cleanup = via_dig_playback_pcm_cleanup - }, -}; - static int vt2002P_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -4718,11 +4359,6 @@ static int patch_vt2002P(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs; - spec->stream_analog_playback = &vt2002P_pcm_analog_playback; - spec->stream_analog_capture = &vt2002P_pcm_analog_capture; - - spec->stream_digital_playback = &vt2002P_pcm_digital_playback; - if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x2b, 0, 3, 40); override_mic_boost(codec, 0x29, 0, 3, 40); @@ -4833,45 +4469,6 @@ static const struct hda_verb vt1812_uniwill_init_verbs[] = { { } }; -static const struct hda_pcm_stream vt1812_pcm_analog_playback = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x8, /* NID to query formats and rates */ - .ops = { - .open = via_playback_pcm_open, - .prepare = via_playback_multi_pcm_prepare, - .cleanup = via_playback_multi_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt1812_pcm_analog_capture = { - .substreams = 2, - .channels_min = 2, - .channels_max = 2, - .nid = 0x10, /* NID to query formats and rates */ - .ops = { - .open = via_pcm_open_close, - .prepare = via_capture_pcm_prepare, - .cleanup = via_capture_pcm_cleanup, - .close = via_pcm_open_close, - }, -}; - -static const struct hda_pcm_stream vt1812_pcm_digital_playback = { - .substreams = 1, - .channels_min = 2, - .channels_max = 2, - /* NID is set in via_build_pcms */ - .ops = { - .open = via_dig_playback_pcm_open, - .close = via_dig_playback_pcm_close, - .prepare = via_dig_playback_pcm_prepare, - .cleanup = via_dig_playback_pcm_cleanup - }, -}; - static int vt1812_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -5042,11 +4639,6 @@ static int patch_vt1812(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; - spec->stream_analog_playback = &vt1812_pcm_analog_playback; - spec->stream_analog_capture = &vt1812_pcm_analog_capture; - - spec->stream_digital_playback = &vt1812_pcm_digital_playback; - if (spec->adc_nids && spec->input_mux) { override_mic_boost(codec, 0x2b, 0, 3, 40); override_mic_boost(codec, 0x29, 0, 3, 40); From 7eb56e84e6c4deaa552db96834ea0b233ba92f50 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 18 Jun 2011 16:40:14 +0200 Subject: [PATCH 13/39] ALSA: hda - Assign HP-independent PCM to individual stream Instead of using the secondary substream, create an individual PCM stream for HP-independent PCM. Otherwise it's difficult to handle different channel numbers with multi-channel stream in the sam PCM stream structure. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 146 ++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 54 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 18f2a135c026..264889c9c177 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -122,6 +122,7 @@ struct via_spec { unsigned int num_iverbs; char stream_name_analog[32]; + char stream_name_hp[32]; const struct hda_pcm_stream *stream_analog_playback; const struct hda_pcm_stream *stream_analog_capture; @@ -1210,14 +1211,20 @@ static const struct hda_verb vt1708_volume_init_verbs[] = { { } }; +static void substream_set_idle(struct hda_codec *codec, + struct snd_pcm_substream *substream) +{ + int idle = substream->pstr->substream_opened == 1 + && substream->ref_count == 0; + analog_low_current_mode(codec, idle); +} + static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; - int idle = substream->pstr->substream_opened == 1 - && substream->ref_count == 0; - analog_low_current_mode(codec, idle); + substream_set_idle(codec, substream); return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, hinfo); } @@ -1226,17 +1233,29 @@ static int via_playback_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { - int idle = substream->pstr->substream_opened == 1 - && substream->ref_count == 0; - - analog_low_current_mode(codec, idle); + substream_set_idle(codec, substream); return 0; } -static void playback_multi_pcm_prep_0(struct hda_codec *codec, - unsigned int stream_tag, - unsigned int format, - struct snd_pcm_substream *substream) +static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + struct snd_pcm_substream *substream) +{ + struct via_spec *spec = codec->spec; + struct hda_multi_out *mout = &spec->multiout; + + if (!mout->hp_nid || mout->hp_nid == mout->dac_nids[HDA_FRONT] || + !spec->hp_independent_mode) + return -EINVAL; + substream_set_idle(codec, substream); + return 0; +} + +static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + unsigned int stream_tag, + unsigned int format, + struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; struct hda_multi_out *mout = &spec->multiout; @@ -1301,27 +1320,20 @@ static void playback_multi_pcm_prep_0(struct hda_codec *codec, snd_hda_codec_setup_stream(codec, nids[i], stream_tag, 0, format); } + vt1708_start_hp_work(spec); + return 0; } -static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, - struct hda_codec *codec, - unsigned int stream_tag, - unsigned int format, - struct snd_pcm_substream *substream) +static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + unsigned int stream_tag, + unsigned int format, + struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; struct hda_multi_out *mout = &spec->multiout; - const hda_nid_t *nids = mout->dac_nids; - if (substream->number == 0) - playback_multi_pcm_prep_0(codec, stream_tag, format, - substream); - else { - if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && - spec->hp_independent_mode) - snd_hda_codec_setup_stream(codec, mout->hp_nid, - stream_tag, 0, format); - } + snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format); vt1708_start_hp_work(spec); return 0; } @@ -1335,33 +1347,38 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, const hda_nid_t *nids = mout->dac_nids; int i; - if (substream->number == 0) { - for (i = 0; i < mout->num_dacs; i++) - snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); + for (i = 0; i < mout->num_dacs; i++) + snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); - if (mout->hp_nid && !spec->hp_independent_mode) - snd_hda_codec_setup_stream(codec, mout->hp_nid, - 0, 0, 0); + if (mout->hp_nid && !spec->hp_independent_mode) + snd_hda_codec_setup_stream(codec, mout->hp_nid, + 0, 0, 0); - for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) - if (mout->extra_out_nid[i]) - snd_hda_codec_setup_stream(codec, - mout->extra_out_nid[i], - 0, 0, 0); - mutex_lock(&codec->spdif_mutex); - if (mout->dig_out_nid && - mout->dig_out_used == HDA_DIG_ANALOG_DUP) { - snd_hda_codec_setup_stream(codec, mout->dig_out_nid, - 0, 0, 0); - mout->dig_out_used = 0; - } - mutex_unlock(&codec->spdif_mutex); - } else { - if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && - spec->hp_independent_mode) - snd_hda_codec_setup_stream(codec, mout->hp_nid, + for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) + if (mout->extra_out_nid[i]) + snd_hda_codec_setup_stream(codec, + mout->extra_out_nid[i], 0, 0, 0); + mutex_lock(&codec->spdif_mutex); + if (mout->dig_out_nid && + mout->dig_out_used == HDA_DIG_ANALOG_DUP) { + snd_hda_codec_setup_stream(codec, mout->dig_out_nid, + 0, 0, 0); + mout->dig_out_used = 0; } + mutex_unlock(&codec->spdif_mutex); + vt1708_stop_hp_work(spec); + return 0; +} + +static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + struct snd_pcm_substream *substream) +{ + struct via_spec *spec = codec->spec; + struct hda_multi_out *mout = &spec->multiout; + + snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0); vt1708_stop_hp_work(spec); return 0; } @@ -1431,7 +1448,7 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, } static const struct hda_pcm_stream via_pcm_analog_playback = { - .substreams = 2, /* will be changed in via_build_pcms() */ + .substreams = 1, .channels_min = 2, .channels_max = 8, /* NID is set in via_build_pcms */ @@ -1443,8 +1460,21 @@ static const struct hda_pcm_stream via_pcm_analog_playback = { }, }; +static const struct hda_pcm_stream via_pcm_hp_playback = { + .substreams = 1, + .channels_min = 2, + .channels_max = 2, + /* NID is set in via_build_pcms */ + .ops = { + .open = via_playback_hp_pcm_open, + .close = via_playback_pcm_close, + .prepare = via_playback_hp_pcm_prepare, + .cleanup = via_playback_hp_pcm_cleanup + }, +}; + static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { - .substreams = 2, /* will be changed in via_build_pcms() */ + .substreams = 1, .channels_min = 2, .channels_max = 8, /* NID is set in via_build_pcms */ @@ -1462,7 +1492,7 @@ static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { }; static const struct hda_pcm_stream via_pcm_analog_capture = { - .substreams = 2, /* will be changed in via_build_pcms() */ + .substreams = 1, /* will be changed in via_build_pcms() */ .channels_min = 2, .channels_max = 2, /* NID is set in via_build_pcms */ @@ -1577,8 +1607,6 @@ static int via_build_pcms(struct hda_codec *codec) spec->multiout.dac_nids[0]; info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; - if (!spec->multiout.hp_nid) - info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1; if (!spec->stream_analog_capture) spec->stream_analog_capture = &via_pcm_analog_capture; @@ -1616,6 +1644,16 @@ static int via_build_pcms(struct hda_codec *codec) } } + if (spec->multiout.hp_nid) { + codec->num_pcms++; + info++; + snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp), + "%s HP", codec->chip_name); + info->name = spec->stream_name_hp; + info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback; + info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = + spec->multiout.hp_nid; + } return 0; } From d7a99cce558f84477adacce9324ab22f52c951ba Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 18 Jun 2011 17:24:46 +0200 Subject: [PATCH 14/39] ALSA: hda - Unify capture-mixer creations in patch_via.c Create capture-related mixer elements dynamically from the parsed ADCs and input-pins instead of fixed values for each codec. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 341 ++++++++------------------------------ 1 file changed, 73 insertions(+), 268 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 264889c9c177..d64560f63a75 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -462,6 +462,7 @@ static int __via_add_control(struct via_spec *spec, int type, const char *name, knew = __via_clone_ctl(spec, &via_control_templates[type], name); if (!knew) return -ENOMEM; + knew->index = idx; if (get_amp_nid_(val)) knew->subdevice = HDA_SUBDEV_AMP_FLAG; knew->private_value = val; @@ -1050,27 +1051,6 @@ static int via_smart51_build(struct hda_codec *codec) return 0; } -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1708_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - /* .name = "Capture Source", */ - .name = "Input Source", - .count = 1, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - /* check AA path's mute statue */ static int is_aa_path_mute(struct hda_codec *codec) { @@ -2157,6 +2137,18 @@ static int via_fill_adcs(struct hda_codec *codec) static int get_mux_nids(struct hda_codec *codec); +static const struct snd_kcontrol_new via_input_src_ctl = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + /* The multiple "Capture Source" controls confuse alsamixer + * So call somewhat different.. + */ + /* .name = "Capture Source", */ + .name = "Input Source", + .info = via_mux_enum_info, + .get = via_mux_enum_get, + .put = via_mux_enum_put, +}; + /* create playback/capture controls for input pins */ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) @@ -2211,6 +2203,56 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, return err; snd_hda_add_imux_item(imux, label, idx, NULL); } + + /* create capture mixer elements */ + for (i = 0; i < spec->num_adc_nids; i++) { + hda_nid_t adc = spec->adc_nids[i]; + err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, + "Capture Volume", i, + HDA_COMPOSE_AMP_VAL(adc, 3, 0, + HDA_INPUT)); + if (err < 0) + return err; + err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE, + "Capture Switch", i, + HDA_COMPOSE_AMP_VAL(adc, 3, 0, + HDA_INPUT)); + if (err < 0) + return err; + } + + /* input-source control */ + for (i = 0; i < spec->num_adc_nids; i++) + if (!spec->mux_nids[i]) + break; + if (i) { + struct snd_kcontrol_new *knew; + knew = via_clone_control(spec, &via_input_src_ctl); + if (!knew) + return -ENOMEM; + knew->count = i; + } + + /* mic-boosts */ + for (i = 0; i < cfg->num_inputs; i++) { + hda_nid_t pin = cfg->inputs[i].pin; + unsigned int caps; + const char *label; + char name[32]; + + if (cfg->inputs[i].type != AUTO_PIN_MIC) + continue; + caps = query_amp_caps(codec, pin, HDA_INPUT); + if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) + continue; + label = hda_get_autocfg_input_label(codec, cfg, i); + snprintf(name, sizeof(name), "%s Boost Capture Volume", label); + err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, + HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); + if (err < 0) + return err; + } + return 0; } @@ -2428,11 +2470,6 @@ static int patch_vt1708(struct hda_codec *codec) if (codec->vendor_id == 0x11061708) spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; - if (spec->adc_nids && spec->input_mux) { - spec->mixers[spec->num_mixers] = vt1708_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -2443,29 +2480,6 @@ static int patch_vt1708(struct hda_codec *codec) return 0; } -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1709_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - /* .name = "Capture Source", */ - .name = "Input Source", - .count = 1, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - static const struct hda_verb vt1709_uniwill_init_verbs[] = { {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, @@ -2596,11 +2610,6 @@ static int patch_vt1709_10ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - spec->mixers[spec->num_mixers] = vt1709_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -2678,11 +2687,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - spec->mixers[spec->num_mixers] = vt1709_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -2693,26 +2697,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) return 0; } -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1708B_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - /* .name = "Capture Source", */ - .name = "Input Source", - .count = 1, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; /* * generic initialization of ADC, input mixers and output mixers */ @@ -2964,11 +2948,6 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -3005,11 +2984,6 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -3025,30 +2999,6 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) /* Patch for VT1708S */ -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1708S_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, - HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - /* .name = "Capture Source", */ - .name = "Input Source", - .count = 1, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - static const struct hda_verb vt1708S_volume_init_verbs[] = { /* Unmute ADC0-1 and set the default input to mic-in */ {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, @@ -3199,6 +3149,8 @@ static int patch_vt1708S(struct hda_codec *codec) return -ENOMEM; spec->aa_mix_nid = 0x16; + override_mic_boost(codec, 0x1a, 0, 3, 40); + override_mic_boost(codec, 0x1e, 0, 3, 40); /* automatic parse from the BIOS config */ err = vt1708S_parse_auto_config(codec); @@ -3218,13 +3170,6 @@ static int patch_vt1708S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - override_mic_boost(codec, 0x1a, 0, 3, 40); - override_mic_boost(codec, 0x1e, 0, 3, 40); - spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -3255,31 +3200,6 @@ static int patch_vt1708S(struct hda_codec *codec) /* Patch for VT1702 */ -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1702_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0, - HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - /* .name = "Capture Source", */ - .name = "Input Source", - .count = 1, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - static const struct hda_verb vt1702_volume_init_verbs[] = { /* * Unmute ADC0-1 and set the default input to mic-in @@ -3432,11 +3352,6 @@ static int patch_vt1702(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - spec->mixers[spec->num_mixers] = vt1702_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -3451,29 +3366,6 @@ static int patch_vt1702(struct hda_codec *codec) /* Patch for VT1718S */ -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1718S_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, - HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - .name = "Input Source", - .count = 2, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - static const struct hda_verb vt1718S_volume_init_verbs[] = { /* * Unmute ADC0-1 and set the default input to mic-in @@ -3669,6 +3561,8 @@ static int patch_vt1718S(struct hda_codec *codec) return -ENOMEM; spec->aa_mix_nid = 0x21; + override_mic_boost(codec, 0x2b, 0, 3, 40); + override_mic_boost(codec, 0x29, 0, 3, 40); /* automatic parse from the BIOS config */ err = vt1718S_parse_auto_config(codec); @@ -3683,13 +3577,6 @@ static int patch_vt1718S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - override_mic_boost(codec, 0x2b, 0, 3, 40); - override_mic_boost(codec, 0x29, 0, 3, 40); - spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -3744,26 +3631,6 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, return 1; } -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1716S_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, - HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "Input Source", - .count = 1, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), { @@ -4004,6 +3871,8 @@ static int patch_vt1716S(struct hda_codec *codec) return -ENOMEM; spec->aa_mix_nid = 0x16; + override_mic_boost(codec, 0x1a, 0, 3, 40); + override_mic_boost(codec, 0x1e, 0, 3, 40); /* automatic parse from the BIOS config */ err = vt1716S_parse_auto_config(codec); @@ -4018,13 +3887,6 @@ static int patch_vt1716S(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - override_mic_boost(codec, 0x1a, 0, 3, 40); - override_mic_boost(codec, 0x1e, 0, 3, 40); - spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; - spec->num_mixers++; - } - spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; spec->num_mixers++; @@ -4045,30 +3907,6 @@ static int patch_vt1716S(struct hda_codec *codec) /* for vt2002P */ -/* capture mixer elements */ -static const struct snd_kcontrol_new vt2002P_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, - HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - /* .name = "Capture Source", */ - .name = "Input Source", - .count = 2, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - static const struct hda_verb vt2002P_volume_init_verbs[] = { /* Class-D speaker related verbs */ {0x1, 0xfe0, 0x4}, @@ -4372,6 +4210,8 @@ static int patch_vt2002P(struct hda_codec *codec) return -ENOMEM; spec->aa_mix_nid = 0x21; + override_mic_boost(codec, 0x2b, 0, 3, 40); + override_mic_boost(codec, 0x29, 0, 3, 40); /* automatic parse from the BIOS config */ err = vt2002P_parse_auto_config(codec); @@ -4397,13 +4237,6 @@ static int patch_vt2002P(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - override_mic_boost(codec, 0x2b, 0, 3, 40); - override_mic_boost(codec, 0x29, 0, 3, 40); - spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; @@ -4419,29 +4252,6 @@ static int patch_vt2002P(struct hda_codec *codec) /* for vt1812 */ -/* capture mixer elements */ -static const struct snd_kcontrol_new vt1812_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), - HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), - HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0, - HDA_INPUT), - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - /* The multiple "Capture Source" controls confuse alsamixer - * So call somewhat different.. - */ - .name = "Input Source", - .count = 2, - .info = via_mux_enum_info, - .get = via_mux_enum_get, - .put = via_mux_enum_put, - }, - { } /* end */ -}; - static const struct hda_verb vt1812_volume_init_verbs[] = { /* * Unmute ADC0-1 and set the default input to mic-in @@ -4662,6 +4472,8 @@ static int patch_vt1812(struct hda_codec *codec) return -ENOMEM; spec->aa_mix_nid = 0x21; + override_mic_boost(codec, 0x2b, 0, 3, 40); + override_mic_boost(codec, 0x29, 0, 3, 40); /* automatic parse from the BIOS config */ err = vt1812_parse_auto_config(codec); @@ -4677,13 +4489,6 @@ static int patch_vt1812(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; - if (spec->adc_nids && spec->input_mux) { - override_mic_boost(codec, 0x2b, 0, 3, 40); - override_mic_boost(codec, 0x29, 0, 3, 40); - spec->mixers[spec->num_mixers] = vt1812_capture_mixer; - spec->num_mixers++; - } - codec->patch_ops = via_patch_ops; codec->patch_ops.init = via_auto_init; From 7f0df88ce0ad846b68156b73b3acc9f3901989d3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 18 Jun 2011 17:33:34 +0200 Subject: [PATCH 15/39] ALSA: hda - Return error for invalid setup for VIA Instead of ignoring the invalid pin configuration, return the error. This will avoid unexpected crash, anyway. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 53 +++++++-------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index d64560f63a75..f91c4db038e4 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -2341,7 +2341,7 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -2460,12 +2460,8 @@ static int patch_vt1708(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } - /* disable 32bit format on VT1708 */ if (codec->vendor_id == 0x11061708) spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; @@ -2541,7 +2537,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -2602,9 +2598,6 @@ static int patch_vt1709_10ch(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration. " - "Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; @@ -2679,9 +2672,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration. " - "Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; @@ -2795,7 +2785,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -2940,9 +2930,6 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; @@ -2976,9 +2963,6 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; @@ -3087,7 +3071,7 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -3157,9 +3141,6 @@ static int patch_vt1708S(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; @@ -3253,7 +3234,7 @@ static int vt1702_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -3344,9 +3325,6 @@ static int patch_vt1702(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; @@ -3440,7 +3418,7 @@ static int vt1718S_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -3569,9 +3547,6 @@ static int patch_vt1718S(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; @@ -3726,7 +3701,7 @@ static int vt1716S_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -3879,9 +3854,6 @@ static int patch_vt1716S(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; @@ -4051,7 +4023,7 @@ static int vt2002P_parse_auto_config(struct hda_codec *codec) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -4218,9 +4190,6 @@ static int patch_vt2002P(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } if (spec->codec_type == VT1802) @@ -4332,7 +4301,7 @@ static int vt1812_parse_auto_config(struct hda_codec *codec) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) - return 0; /* can't find valid BIOS pin config */ + return -EINVAL; err = via_auto_create_multi_out_ctls(codec); if (err < 0) @@ -4480,12 +4449,8 @@ static int patch_vt1812(struct hda_codec *codec) if (err < 0) { via_free(codec); return err; - } else if (!err) { - printk(KERN_INFO "hda_codec: Cannot set up configuration " - "from BIOS. Using genenic mode...\n"); } - spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; From 12daef65fd868cf30be5afe3e6be6689c44c7940 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 18 Jun 2011 17:45:49 +0200 Subject: [PATCH 16/39] ALSA: hda - Unify auto-parser in patch_via.c Now all codecs use the same parser-path, so we can reduce into a single auto-parser function. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 427 +++++--------------------------------- 1 file changed, 53 insertions(+), 374 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index f91c4db038e4..14fccdc21c33 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -2325,15 +2325,14 @@ static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { .put = vt1708_jack_detect_put, }; -static int vt1708_parse_auto_config(struct hda_codec *codec) +static void fill_dig_outs(struct hda_codec *codec); +static void fill_dig_in(struct hda_codec *codec); + +static int via_parse_auto_config(struct hda_codec *codec) { struct via_spec *spec = codec->spec; int err; - /* Add HP and CD pin config connect bit re-config action */ - vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); - vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); if (err < 0) return err; @@ -2352,17 +2351,11 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); if (err < 0) return err; - /* add jack detect on/off control */ - if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) - return -ENOMEM; spec->multiout.max_channels = spec->multiout.num_dacs * 2; - if (spec->autocfg.dig_outs) - spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; - spec->dig_in_pin = VT1708_DIGIN_PIN; - if (spec->autocfg.dig_in_pin) - spec->dig_in_nid = VT1708_DIGIN_NID; + fill_dig_outs(codec); + fill_dig_in(codec); if (spec->kctls.list) spec->mixers[spec->num_mixers++] = spec->kctls.list; @@ -2455,13 +2448,21 @@ static int patch_vt1708(struct hda_codec *codec) spec->aa_mix_nid = 0x17; + /* Add HP and CD pin config connect bit re-config action */ + vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); + vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); + /* automatic parse from the BIOS config */ - err = vt1708_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; } + /* add jack detect on/off control */ + if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) + return -ENOMEM; + /* disable 32bit format on VT1708 */ if (codec->vendor_id == 0x11061708) spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; @@ -2525,53 +2526,6 @@ static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { { } }; -static int vt1709_parse_auto_config(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int err; - - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return -EINVAL; - - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - if (spec->autocfg.dig_outs) - spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; - spec->dig_in_pin = VT1709_DIGIN_PIN; - if (spec->autocfg.dig_in_pin) - spec->dig_in_nid = VT1709_DIGIN_NID; - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - err = via_smart51_build(codec); - if (err < 0) - return err; - - return 1; -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1709_loopbacks[] = { { 0x18, HDA_INPUT, 1 }, @@ -2594,7 +2548,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec) spec->aa_mix_nid = 0x18; - err = vt1709_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -2668,7 +2622,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec) spec->aa_mix_nid = 0x18; - err = vt1709_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -2773,53 +2727,6 @@ static const struct hda_verb vt1708B_uniwill_init_verbs[] = { { } }; -static int vt1708B_parse_auto_config(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int err; - - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return -EINVAL; - - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - if (spec->autocfg.dig_outs) - spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; - spec->dig_in_pin = VT1708B_DIGIN_PIN; - if (spec->autocfg.dig_in_pin) - spec->dig_in_nid = VT1708B_DIGIN_NID; - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - err = via_smart51_build(codec); - if (err < 0) - return err; - - return 1; -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1708B_loopbacks[] = { { 0x16, HDA_INPUT, 1 }, @@ -2926,7 +2833,7 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) spec->aa_mix_nid = 0x16; /* automatic parse from the BIOS config */ - err = vt1708B_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -2959,7 +2866,7 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) return -ENOMEM; /* automatic parse from the BIOS config */ - err = vt1708B_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -3059,47 +2966,31 @@ static void fill_dig_outs(struct hda_codec *codec) } } -static int vt1708S_parse_auto_config(struct hda_codec *codec) +static void fill_dig_in(struct hda_codec *codec) { struct via_spec *spec = codec->spec; - int err; + hda_nid_t dig_nid; + int i, err; - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return -EINVAL; + if (!spec->autocfg.dig_in_pin) + return; - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - fill_dig_outs(codec); - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - err = via_smart51_build(codec); - if (err < 0) - return err; - - return 1; + dig_nid = codec->start_nid; + for (i = 0; i < codec->num_nodes; i++, dig_nid++) { + unsigned int wcaps = get_wcaps(codec, dig_nid); + if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) + continue; + if (!(wcaps & AC_WCAP_DIGITAL)) + continue; + if (!(wcaps & AC_WCAP_CONN_LIST)) + continue; + err = get_connection_index(codec, dig_nid, + spec->autocfg.dig_in_pin); + if (err >= 0) { + spec->dig_in_nid = dig_nid; + break; + } + } } #ifdef CONFIG_SND_HDA_POWER_SAVE @@ -3137,7 +3028,7 @@ static int patch_vt1708S(struct hda_codec *codec) override_mic_boost(codec, 0x1e, 0, 3, 40); /* automatic parse from the BIOS config */ - err = vt1708S_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -3222,51 +3113,6 @@ static const struct hda_verb vt1702_uniwill_init_verbs[] = { { } }; -static int vt1702_parse_auto_config(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int err; - - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return -EINVAL; - - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - /* limit AA path volume to 0 dB */ - snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, - (0x17 << AC_AMPCAP_OFFSET_SHIFT) | - (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | - (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | - (1 << AC_AMPCAP_MUTE_SHIFT)); - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - fill_dig_outs(codec); - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - return 1; -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1702_loopbacks[] = { { 0x1A, HDA_INPUT, 1 }, @@ -3320,8 +3166,15 @@ static int patch_vt1702(struct hda_codec *codec) spec->aa_mix_nid = 0x1a; + /* limit AA path volume to 0 dB */ + snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, + (0x17 << AC_AMPCAP_OFFSET_SHIFT) | + (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | + (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | + (1 << AC_AMPCAP_MUTE_SHIFT)); + /* automatic parse from the BIOS config */ - err = vt1702_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -3405,53 +3258,6 @@ static const struct hda_verb vt1718S_uniwill_init_verbs[] = { { } }; -static int vt1718S_parse_auto_config(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int err; - - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - - if (err < 0) - return err; - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return -EINVAL; - - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - fill_dig_outs(codec); - - if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) - spec->dig_in_nid = 0x13; - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - err = via_smart51_build(codec); - if (err < 0) - return err; - - return 1; -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1718S_loopbacks[] = { { 0x21, HDA_INPUT, 1 }, @@ -3543,7 +3349,7 @@ static int patch_vt1718S(struct hda_codec *codec) override_mic_boost(codec, 0x29, 0, 3, 40); /* automatic parse from the BIOS config */ - err = vt1718S_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -3689,49 +3495,6 @@ static const struct hda_verb vt1716S_uniwill_init_verbs[] = { { } }; -static int vt1716S_parse_auto_config(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int err; - - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return -EINVAL; - - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - fill_dig_outs(codec); - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - err = via_smart51_build(codec); - if (err < 0) - return err; - - return 1; -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1716S_loopbacks[] = { { 0x16, HDA_INPUT, 1 }, @@ -3850,7 +3613,7 @@ static int patch_vt1716S(struct hda_codec *codec) override_mic_boost(codec, 0x1e, 0, 3, 40); /* automatic parse from the BIOS config */ - err = vt1716S_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -4008,48 +3771,6 @@ static const struct hda_verb vt1802_uniwill_init_verbs[] = { { } }; -static int vt2002P_parse_auto_config(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int err; - - - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - - if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) - return -EINVAL; - - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - fill_dig_outs(codec); - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - return 1; -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt2002P_loopbacks[] = { { 0x21, HDA_INPUT, 0 }, @@ -4186,7 +3907,7 @@ static int patch_vt2002P(struct hda_codec *codec) override_mic_boost(codec, 0x29, 0, 3, 40); /* automatic parse from the BIOS config */ - err = vt2002P_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; @@ -4286,48 +4007,6 @@ static const struct hda_verb vt1812_uniwill_init_verbs[] = { { } }; -static int vt1812_parse_auto_config(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int err; - - - err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - fill_dig_outs(codec); - err = via_auto_fill_dac_nids(codec); - if (err < 0) - return err; - - if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) - return -EINVAL; - - err = via_auto_create_multi_out_ctls(codec); - if (err < 0) - return err; - err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); - if (err < 0) - return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); - if (err < 0) - return err; - - spec->multiout.max_channels = spec->multiout.num_dacs * 2; - - fill_dig_outs(codec); - - if (spec->kctls.list) - spec->mixers[spec->num_mixers++] = spec->kctls.list; - - spec->input_mux = &spec->private_imux[0]; - - if (spec->hp_mux) - via_hp_build(codec); - - return 1; -} - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1812_loopbacks[] = { { 0x21, HDA_INPUT, 0 }, @@ -4445,7 +4124,7 @@ static int patch_vt1812(struct hda_codec *codec) override_mic_boost(codec, 0x29, 0, 3, 40); /* automatic parse from the BIOS config */ - err = vt1812_parse_auto_config(codec); + err = via_parse_auto_config(codec); if (err < 0) { via_free(codec); return err; From ece8d0431fde78ea2c0a5be2884bcbc4940ae7c5 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sun, 19 Jun 2011 16:24:21 +0200 Subject: [PATCH 17/39] ALSA: hda - Fix independent-HP handling in patch_via.c Fix races in handling of HP DAC and independent streams for VIA codecs. Also, allow the HP output path without front-DAC, and removed unnecessary activation of HP mixer elements. This also removes the handling of shared side/HP stream; it's anyway implemented in a broken way, so we need to re-implement the feature later... Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 294 ++++++++------------------------------ 1 file changed, 57 insertions(+), 237 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 14fccdc21c33..fa5ed36d69e5 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -133,6 +133,7 @@ struct via_spec { /* playback */ struct hda_multi_out multiout; hda_nid_t slave_dig_outs[2]; + hda_nid_t hp_dac_nid; struct nid_path out_path[4]; struct nid_path hp_path; @@ -702,64 +703,9 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - hda_nid_t nid = kcontrol->private_value; - unsigned int pinsel; - - /* use !! to translate conn sel 2 for VT1718S */ - pinsel = !!snd_hda_codec_read(codec, nid, 0, - AC_VERB_GET_CONNECT_SEL, - 0x00); - ucontrol->value.enumerated.item[0] = pinsel; - - return 0; -} - -static void activate_ctl(struct hda_codec *codec, const char *name, int active) -{ - struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name); - if (ctl) { - ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; - ctl->vd[0].access |= active - ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE; - snd_ctl_notify(codec->bus->card, - SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id); - } -} - -static hda_nid_t side_mute_channel(struct via_spec *spec) -{ - switch (spec->codec_type) { - case VT1708: return 0x1b; - case VT1709_10CH: return 0x29; - case VT1708B_8CH: /* fall thru */ - case VT1708S: return 0x27; - case VT2002P: return 0x19; - case VT1802: return 0x15; - case VT1812: return 0x15; - default: return 0; - } -} - -static int update_side_mute_status(struct hda_codec *codec) -{ - /* mute side channel */ struct via_spec *spec = codec->spec; - unsigned int parm; - hda_nid_t sw3 = side_mute_channel(spec); - if (sw3) { - if (VT2002P_COMPATIBLE(spec)) - parm = spec->hp_independent_mode ? - AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1); - else - parm = spec->hp_independent_mode ? - AMP_OUT_MUTE : AMP_OUT_UNMUTE; - snd_hda_codec_write(codec, sw3, 0, - AC_VERB_SET_AMP_GAIN_MUTE, parm); - if (spec->codec_type == VT1812) - snd_hda_codec_write(codec, 0x1d, 0, - AC_VERB_SET_AMP_GAIN_MUTE, parm); - } + ucontrol->value.enumerated.item[0] = spec->hp_independent_mode; return 0; } @@ -773,50 +719,19 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol, /* Get Independent Mode index of headphone pin widget */ spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel ? 1 : 0; - if (spec->codec_type == VT1718S) - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0); - else - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_CONNECT_SEL, pinsel); + snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel); - if (spec->codec_type == VT1812) - snd_hda_codec_write(codec, 0x35, 0, - AC_VERB_SET_CONNECT_SEL, pinsel); - if (spec->multiout.hp_nid && spec->multiout.hp_nid - != spec->multiout.dac_nids[HDA_FRONT]) - snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid, - 0, 0, 0); - - update_side_mute_status(codec); - /* update HP volume/swtich active state */ - if (spec->codec_type == VT1708S - || spec->codec_type == VT1702 - || spec->codec_type == VT1718S - || spec->codec_type == VT1716S - || VT2002P_COMPATIBLE(spec)) { - activate_ctl(codec, "Headphone Playback Volume", - spec->hp_independent_mode); - activate_ctl(codec, "Headphone Playback Switch", - spec->hp_independent_mode); - } /* update jack power state */ set_widgets_power_state(codec); return 0; } -static const struct snd_kcontrol_new via_hp_mixer[2] = { - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "Independent HP", - .info = via_independent_hp_info, - .get = via_independent_hp_get, - .put = via_independent_hp_put, - }, - { - .iface = NID_MAPPING, - .name = "Independent HP", - }, +static const struct snd_kcontrol_new via_hp_mixer = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Independent HP", + .info = via_independent_hp_info, + .get = via_independent_hp_get, + .put = via_independent_hp_put, }; static int via_hp_build(struct hda_codec *codec) @@ -824,44 +739,15 @@ static int via_hp_build(struct hda_codec *codec) struct via_spec *spec = codec->spec; struct snd_kcontrol_new *knew; hda_nid_t nid; - int nums; - hda_nid_t conn[HDA_MAX_CONNECTIONS]; - switch (spec->codec_type) { - case VT1718S: - nid = 0x34; - break; - case VT2002P: - case VT1802: - nid = 0x35; - break; - case VT1812: - nid = 0x3d; - break; - default: - nid = spec->autocfg.hp_pins[0]; - break; - } - - if (spec->codec_type != VT1708) { - nums = snd_hda_get_connections(codec, nid, - conn, HDA_MAX_CONNECTIONS); - if (nums <= 1) - return 0; - } - - knew = via_clone_control(spec, &via_hp_mixer[0]); + nid = spec->autocfg.hp_pins[0]; + knew = via_clone_control(spec, &via_hp_mixer); if (knew == NULL) return -ENOMEM; knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; knew->private_value = nid; - knew = via_clone_control(spec, &via_hp_mixer[1]); - if (knew == NULL) - return -ENOMEM; - knew->subdevice = side_mute_channel(spec); - return 0; } @@ -1199,20 +1085,26 @@ static void substream_set_idle(struct hda_codec *codec, analog_low_current_mode(codec, idle); } -static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, +static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; + + if (!spec->hp_independent_mode) + spec->multiout.hp_nid = spec->hp_dac_nid; substream_set_idle(codec, substream); return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, hinfo); } -static int via_playback_pcm_close(struct hda_pcm_stream *hinfo, +static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { + struct via_spec *spec = codec->spec; + + spec->multiout.hp_nid = 0; substream_set_idle(codec, substream); return 0; } @@ -1222,11 +1114,19 @@ static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; - struct hda_multi_out *mout = &spec->multiout; - if (!mout->hp_nid || mout->hp_nid == mout->dac_nids[HDA_FRONT] || - !spec->hp_independent_mode) + if (snd_BUG_ON(!spec->hp_dac_nid)) return -EINVAL; + if (!spec->hp_independent_mode || spec->multiout.hp_nid) + return -EBUSY; + substream_set_idle(codec, substream); + return 0; +} + +static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + struct snd_pcm_substream *substream) +{ substream_set_idle(codec, substream); return 0; } @@ -1238,68 +1138,9 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; - struct hda_multi_out *mout = &spec->multiout; - const hda_nid_t *nids = mout->dac_nids; - int chs = substream->runtime->channels; - int i; - struct hda_spdif_out *spdif = - snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid); - mutex_lock(&codec->spdif_mutex); - if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { - if (chs == 2 && - snd_hda_is_supported_format(codec, mout->dig_out_nid, - format) && - !(spdif->status & IEC958_AES0_NONAUDIO)) { - mout->dig_out_used = HDA_DIG_ANALOG_DUP; - /* turn off SPDIF once; otherwise the IEC958 bits won't - * be updated */ - if (spdif->ctls & AC_DIG1_ENABLE) - snd_hda_codec_write(codec, mout->dig_out_nid, 0, - AC_VERB_SET_DIGI_CONVERT_1, - spdif->ctls & - ~AC_DIG1_ENABLE & 0xff); - snd_hda_codec_setup_stream(codec, mout->dig_out_nid, - stream_tag, 0, format); - /* turn on again (if needed) */ - if (spdif->ctls & AC_DIG1_ENABLE) - snd_hda_codec_write(codec, mout->dig_out_nid, 0, - AC_VERB_SET_DIGI_CONVERT_1, - spdif->ctls & 0xff); - } else { - mout->dig_out_used = 0; - snd_hda_codec_setup_stream(codec, mout->dig_out_nid, - 0, 0, 0); - } - } - mutex_unlock(&codec->spdif_mutex); - - /* front */ - snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, - 0, format); - - if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] - && !spec->hp_independent_mode) - /* headphone out will just decode front left/right (stereo) */ - snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, - 0, format); - - /* extra outputs copied from front */ - for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) - if (mout->extra_out_nid[i]) - snd_hda_codec_setup_stream(codec, - mout->extra_out_nid[i], - stream_tag, 0, format); - - /* surrounds */ - for (i = 1; i < mout->num_dacs; i++) { - if (chs >= (i + 1) * 2) /* independent out */ - snd_hda_codec_setup_stream(codec, nids[i], stream_tag, - i * 2, format); - else /* copy front */ - snd_hda_codec_setup_stream(codec, nids[i], stream_tag, - 0, format); - } + snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, + format, substream); vt1708_start_hp_work(spec); return 0; } @@ -1311,9 +1152,9 @@ static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; - struct hda_multi_out *mout = &spec->multiout; - snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format); + snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, + stream_tag, 0, format); vt1708_start_hp_work(spec); return 0; } @@ -1323,30 +1164,8 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; - struct hda_multi_out *mout = &spec->multiout; - const hda_nid_t *nids = mout->dac_nids; - int i; - for (i = 0; i < mout->num_dacs; i++) - snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); - - if (mout->hp_nid && !spec->hp_independent_mode) - snd_hda_codec_setup_stream(codec, mout->hp_nid, - 0, 0, 0); - - for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) - if (mout->extra_out_nid[i]) - snd_hda_codec_setup_stream(codec, - mout->extra_out_nid[i], - 0, 0, 0); - mutex_lock(&codec->spdif_mutex); - if (mout->dig_out_nid && - mout->dig_out_used == HDA_DIG_ANALOG_DUP) { - snd_hda_codec_setup_stream(codec, mout->dig_out_nid, - 0, 0, 0); - mout->dig_out_used = 0; - } - mutex_unlock(&codec->spdif_mutex); + snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); vt1708_stop_hp_work(spec); return 0; } @@ -1356,9 +1175,8 @@ static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; - struct hda_multi_out *mout = &spec->multiout; - snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0); + snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0); vt1708_stop_hp_work(spec); return 0; } @@ -1433,8 +1251,8 @@ static const struct hda_pcm_stream via_pcm_analog_playback = { .channels_max = 8, /* NID is set in via_build_pcms */ .ops = { - .open = via_playback_pcm_open, - .close = via_playback_pcm_close, + .open = via_playback_multi_pcm_open, + .close = via_playback_multi_pcm_close, .prepare = via_playback_multi_pcm_prepare, .cleanup = via_playback_multi_pcm_cleanup }, @@ -1447,7 +1265,7 @@ static const struct hda_pcm_stream via_pcm_hp_playback = { /* NID is set in via_build_pcms */ .ops = { .open = via_playback_hp_pcm_open, - .close = via_playback_pcm_close, + .close = via_playback_hp_pcm_close, .prepare = via_playback_hp_pcm_prepare, .cleanup = via_playback_hp_pcm_cleanup }, @@ -1464,8 +1282,8 @@ static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { */ .formats = SNDRV_PCM_FMTBIT_S16_LE, .ops = { - .open = via_playback_pcm_open, - .close = via_playback_pcm_close, + .open = via_playback_multi_pcm_open, + .close = via_playback_multi_pcm_close, .prepare = via_playback_multi_pcm_prepare, .cleanup = via_playback_multi_pcm_cleanup }, @@ -1477,8 +1295,6 @@ static const struct hda_pcm_stream via_pcm_analog_capture = { .channels_max = 2, /* NID is set in via_build_pcms */ .ops = { - .open = via_playback_pcm_open, - .close = via_playback_pcm_close, .prepare = via_capture_pcm_prepare, .cleanup = via_capture_pcm_cleanup }, @@ -1624,7 +1440,7 @@ static int via_build_pcms(struct hda_codec *codec) } } - if (spec->multiout.hp_nid) { + if (spec->hp_dac_nid) { codec->num_pcms++; info++; snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp), @@ -1632,7 +1448,7 @@ static int via_build_pcms(struct hda_codec *codec) info->name = spec->stream_name_hp; info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback; info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = - spec->multiout.hp_nid; + spec->hp_dac_nid; } return 0; } @@ -1883,7 +1699,7 @@ static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac) if (spec->multiout.dac_nids[i] == dac) return false; } - if (spec->multiout.hp_nid == dac) + if (spec->hp_dac_nid == dac) return false; return true; } @@ -2076,24 +1892,25 @@ static void create_hp_imux(struct via_spec *spec) static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) { struct via_spec *spec = codec->spec; - hda_nid_t dac = 0; int err; if (!pin) return 0; - if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], - &spec->hp_dep_path, 0, -1)) - return 0; if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) { - dac = spec->hp_path.path[spec->hp_path.depth - 1]; - spec->multiout.hp_nid = dac; + spec->hp_dac_nid = spec->hp_path.path[spec->hp_path.depth - 1]; spec->hp_independent_mode_index = spec->hp_path.idx[spec->hp_path.depth - 1]; create_hp_imux(spec); } - err = create_ch_ctls(codec, "Headphone", pin, dac, 3); + if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], + &spec->hp_dep_path, 0, -1) && + !spec->hp_dac_nid) + return 0; + + + err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3); if (err < 0) return err; @@ -2364,8 +2181,11 @@ static int via_parse_auto_config(struct hda_codec *codec) spec->input_mux = &spec->private_imux[0]; - if (spec->hp_mux) - via_hp_build(codec); + if (spec->hp_mux) { + err = via_hp_build(codec); + if (err < 0) + return err; + } err = via_smart51_build(codec); if (err < 0) From 0fe0adf82f95ed5ce5a75512b281f6cbc89cefa1 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sun, 19 Jun 2011 16:27:53 +0200 Subject: [PATCH 18/39] ALSA: hda - Replace with standard consts in patch_via.c Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index fa5ed36d69e5..ae90b95eab3a 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -263,13 +263,6 @@ enum { VIA_CTL_WIDGET_BIND_PIN_MUTE, }; -enum { - AUTO_SEQ_FRONT = 0, - AUTO_SEQ_SURROUND, - AUTO_SEQ_CENLFE, - AUTO_SEQ_SIDE -}; - static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); static int is_aa_path_mute(struct hda_codec *codec); @@ -528,7 +521,7 @@ static void via_auto_init_multi_out(struct hda_codec *codec) struct via_spec *spec = codec->spec; int i; - for (i = 0; i <= AUTO_SEQ_SIDE; i++) { + for (i = 0; i <= HDA_SIDE; i++) { hda_nid_t nid = spec->autocfg.line_out_pins[i]; if (nid) via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); @@ -1839,7 +1832,7 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) dac = spec->multiout.dac_nids[i]; if (!pin || !dac) continue; - if (i == AUTO_SEQ_CENLFE) { + if (i == HDA_CLFE) { err = create_ch_ctls(codec, "Center", pin, dac, 1); if (err < 0) return err; From 5d41762a210851943f59f0a08656ca582f76d9d3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 11:32:27 +0200 Subject: [PATCH 19/39] ALSA: hda - Initialize output path dynamically in patch_via.c Instead of fixed array for each codec type, initialize the output path dynamically from the parsed results. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 351 +++++++++++++++----------------------- 1 file changed, 136 insertions(+), 215 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index ae90b95eab3a..4f6e7bebdb45 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -501,44 +501,126 @@ static int via_new_analog_input(struct via_spec *spec, const char *ctlname, return 0; } -static void via_auto_set_output_and_unmute(struct hda_codec *codec, - hda_nid_t nid, int pin_type, - int dac_idx) +/* return the index of the given widget nid as the source of mux; + * return -1 if not found; + * if num_conns is non-NULL, set the total number of connections + */ +static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux, + hda_nid_t nid, int *num_conns) { - /* set as output */ - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, - pin_type); - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, - AMP_OUT_UNMUTE); - if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) + hda_nid_t conn[HDA_MAX_NUM_INPUTS]; + int i, nums; + + nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); + if (num_conns) + *num_conns = nums; + for (i = 0; i < nums; i++) + if (conn[i] == nid) + return i; + return -1; +} + +#define get_connection_index(codec, mux, nid) \ + __get_connection_index(codec, mux, nid, NULL) + +/* unmute input amp and select the specificed source */ +static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid, + hda_nid_t src, hda_nid_t mix) +{ + int idx, num_conns; + + idx = __get_connection_index(codec, nid, src, &num_conns); + if (idx < 0) + return; + + /* select the route explicitly when multiple connections exist */ + if (num_conns > 1) snd_hda_codec_write(codec, nid, 0, + AC_VERB_SET_CONNECT_SEL, idx); + /* unmute if the input amp is present */ + if (!(query_amp_caps(codec, nid, HDA_INPUT) & + (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))) + return; + snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, + AMP_IN_UNMUTE(idx)); + + /* unmute AA-path if present */ + if (!mix) + return; + idx = __get_connection_index(codec, nid, mix, NULL); + if (idx >= 0) + snd_hda_codec_write(codec, nid, 0, + AC_VERB_SET_AMP_GAIN_MUTE, + AMP_IN_UNMUTE(idx)); +} + +/* set the given pin as output */ +static void init_output_pin(struct hda_codec *codec, hda_nid_t pin, + int pin_type) +{ + if (!pin) + return; + snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, + pin_type); + if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) + snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x02); } +static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin, + int pin_type, struct nid_path *path) +{ + struct via_spec *spec = codec->spec; + unsigned int caps; + hda_nid_t nid; + int i; + + if (!pin) + return; + + init_output_pin(codec, pin, pin_type); + caps = query_amp_caps(codec, pin, HDA_OUTPUT); + if (caps & AC_AMPCAP_MUTE) { + unsigned int val; + val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; + snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, + AMP_OUT_MUTE | val); + } + + /* initialize the output path */ + nid = pin; + for (i = 0; i < path->depth; i++) { + unmute_and_select(codec, nid, path->idx[i], spec->aa_mix_nid); + nid = path->path[i]; + if (query_amp_caps(codec, nid, HDA_OUTPUT) & + (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)) + snd_hda_codec_write(codec, nid, 0, + AC_VERB_SET_AMP_GAIN_MUTE, + AMP_OUT_UNMUTE); + } +} + static void via_auto_init_multi_out(struct hda_codec *codec) { struct via_spec *spec = codec->spec; int i; - for (i = 0; i <= HDA_SIDE; i++) { - hda_nid_t nid = spec->autocfg.line_out_pins[i]; - if (nid) - via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); - } + for (i = 0; i < spec->autocfg.line_outs; i++) + via_auto_init_output(codec, spec->autocfg.line_out_pins[i], + PIN_OUT, &spec->out_path[i]); } static void via_auto_init_hp_out(struct hda_codec *codec) { struct via_spec *spec = codec->spec; - hda_nid_t pin; - int i; - for (i = 0; i < spec->autocfg.hp_outs; i++) { - pin = spec->autocfg.hp_pins[i]; - if (pin) /* connect to front */ - via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); - } + if (spec->hp_dac_nid) + via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP, + &spec->hp_path); + else + via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP, + &spec->hp_dep_path); } static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); @@ -1053,18 +1135,6 @@ static const struct hda_verb vt1708_volume_init_verbs[] = { {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - /* - * Set up output mixers (0x19 - 0x1b) - */ - /* set vol=0 to output mixers */ - {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - - /* Setup default input MW0 to PW4 */ - {0x20, AC_VERB_SET_CONNECT_SEL, 0}, - /* PW9 Output enable */ - {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, /* power down jack detect function */ {0x1, 0xf81, 0x1}, { } @@ -1624,33 +1694,6 @@ static void via_unsol_event(struct hda_codec *codec, via_hp_bind_automute(codec); } -static int via_init(struct hda_codec *codec) -{ - struct via_spec *spec = codec->spec; - int i; - for (i = 0; i < spec->num_iverbs; i++) - snd_hda_sequence_write(codec, spec->init_verbs[i]); - - /* Lydia Add for EAPD enable */ - if (!spec->dig_in_nid) { /* No Digital In connection */ - if (spec->dig_in_pin) { - snd_hda_codec_write(codec, spec->dig_in_pin, 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, - PIN_OUT); - snd_hda_codec_write(codec, spec->dig_in_pin, 0, - AC_VERB_SET_EAPD_BTLENABLE, 0x02); - } - } else /* enable SPDIF-input pin */ - snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); - - /* assign slave outs */ - if (spec->slave_dig_outs[0]) - codec->slave_dig_outs = spec->slave_dig_outs; - - return 0; -} - #ifdef SND_HDA_NEEDS_RESUME static int via_suspend(struct hda_codec *codec, pm_message_t state) { @@ -1670,6 +1713,9 @@ static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) /* */ + +static int via_init(struct hda_codec *codec); + static const struct hda_codec_ops via_patch_ops = { .build_controls = via_build_controls, .build_pcms = via_build_pcms, @@ -1791,9 +1837,6 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, return 0; } -static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, - hda_nid_t nid); - static void mangle_smart51(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -1910,19 +1953,6 @@ static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) return 0; } -static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, - hda_nid_t nid) -{ - hda_nid_t conn[HDA_MAX_NUM_INPUTS]; - int i, nums; - - nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); - for (i = 0; i < nums; i++) - if (conn[i] == nid) - return i; - return -1; -} - /* look for ADCs */ static int via_fill_adcs(struct hda_codec *codec) { @@ -2184,18 +2214,44 @@ static int via_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; + /* assign slave outs */ + if (spec->slave_dig_outs[0]) + codec->slave_dig_outs = spec->slave_dig_outs; + return 1; } -/* init callback for auto-configuration model -- overriding the default init */ -static int via_auto_init(struct hda_codec *codec) +static void via_auto_init_dig_outs(struct hda_codec *codec) { struct via_spec *spec = codec->spec; + if (spec->multiout.dig_out_nid) + init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT); + if (spec->slave_dig_outs[0]) + init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT); +} + +static void via_auto_init_dig_in(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + if (!spec->dig_in_nid) + return; + snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, + AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); +} + +static int via_init(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + int i; + + for (i = 0; i < spec->num_iverbs; i++) + snd_hda_sequence_write(codec, spec->init_verbs[i]); - via_init(codec); via_auto_init_multi_out(codec); via_auto_init_hp_out(codec); via_auto_init_analog_input(codec); + via_auto_init_dig_outs(codec); + via_auto_init_dig_in(codec); if (VT2002P_COMPATIBLE(spec)) { via_hp_bind_automute(codec); @@ -2282,7 +2338,6 @@ static int patch_vt1708(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1708_loopbacks; #endif @@ -2318,24 +2373,8 @@ static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - /* - * Set up output selector (0x1a, 0x1b, 0x29) - */ - /* set vol=0 to output mixers */ - {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - - /* - * Unmute PW3 and PW4 - */ - {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - /* Set input of PW4 as MW0 */ {0x20, AC_VERB_SET_CONNECT_SEL, 0}, - /* PW9 Output enable */ - {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, { } }; @@ -2372,7 +2411,6 @@ static int patch_vt1709_10ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1709_loopbacks; @@ -2446,7 +2484,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1709_loopbacks; @@ -2483,8 +2520,6 @@ static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = { {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - /* Setup default input to PW4 */ - {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, /* PW9 Output enable */ {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, /* PW10 Input enable */ @@ -2510,18 +2545,6 @@ static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = { {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - /* - * Set up output mixers - */ - /* set vol=0 to output mixers */ - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - - /* Setup default input of PW4 to MW0 */ - {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, - /* PW9 Output enable */ - {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, /* PW10 Input enable */ {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, { } @@ -2657,7 +2680,6 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1708B_loopbacks; @@ -2690,7 +2712,6 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1708B_loopbacks; @@ -2717,11 +2738,6 @@ static const struct hda_verb vt1708S_volume_init_verbs[] = { {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - /* Setup default input of PW4 to MW0 */ - {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, - /* PW9, PW10 Output enable */ - {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, - {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, /* Enable Mic Boost Volume backdoor */ {0x1, 0xf98, 0x1}, /* don't bybass mixer */ @@ -2857,7 +2873,6 @@ static int patch_vt1708S(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1708S_loopbacks; @@ -2904,11 +2919,6 @@ static const struct hda_verb vt1702_volume_init_verbs[] = { {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, - /* Setup default input of PW4 to MW0 */ - {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, - /* PW6 PW7 Output enable */ - {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, - {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, /* mixer enable */ {0x1, 0xF88, 0x3}, /* GPIO 0~2 */ @@ -2998,7 +3008,6 @@ static int patch_vt1702(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1702_loopbacks; @@ -3029,31 +3038,9 @@ static const struct hda_verb vt1718S_volume_init_verbs[] = { {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)}, - /* Setup default input of Front HP to MW9 */ - {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, - /* PW9 PW10 Output enable */ - {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, - {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, - /* PW11 Input enable */ - {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, /* Enable Boost Volume backdoor */ {0x1, 0xf88, 0x8}, - /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ - {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, - {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, - /* Unmute MW4's index 0 */ - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, + { } }; @@ -3173,7 +3160,6 @@ static int patch_vt1718S(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE @@ -3267,24 +3253,6 @@ static const struct hda_verb vt1716S_volume_init_verbs[] = { /* MUX Indices: Stereo Mixer = 5 */ {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, - /* Setup default input of PW4 to MW0 */ - {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, - - /* Setup default input of SW1 as MW0 */ - {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, - - /* Setup default input of SW4 as AOW0 */ - {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, - - /* PW9 PW10 Output enable */ - {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, - {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, - - /* Unmute SW1, PW12 */ - {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, - /* PW12 Output enable */ - {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, /* Enable Boost Volume backdoor */ {0x1, 0xf8a, 0x80}, /* don't bybass mixer */ @@ -3442,7 +3410,6 @@ static int patch_vt1716S(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE @@ -3481,31 +3448,9 @@ static const struct hda_verb vt2002P_volume_init_verbs[] = { {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, - /* PW9 Output enable */ - {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, - /* Enable Boost Volume backdoor */ {0x1, 0xfb9, 0x24}, - /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - - /* set MUX0/1/4/8 = 0 (AOW0) */ - {0x34, AC_VERB_SET_CONNECT_SEL, 0}, - {0x35, AC_VERB_SET_CONNECT_SEL, 0}, - {0x37, AC_VERB_SET_CONNECT_SEL, 0}, - {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, - - /* set PW0 index=0 (MW0) */ - {0x24, AC_VERB_SET_CONNECT_SEL, 0}, - /* Enable AOW0 to MW9 */ {0x1, 0xfb8, 0x88}, { } @@ -3742,7 +3687,6 @@ static int patch_vt2002P(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE @@ -3777,31 +3721,9 @@ static const struct hda_verb vt1812_volume_init_verbs[] = { {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, - /* PW9 Output enable */ - {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, - /* Enable Boost Volume backdoor */ {0x1, 0xfb9, 0x24}, - /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - - /* set MUX0/1/4/13/15 = 0 (AOW0) */ - {0x34, AC_VERB_SET_CONNECT_SEL, 0}, - {0x35, AC_VERB_SET_CONNECT_SEL, 0}, - {0x38, AC_VERB_SET_CONNECT_SEL, 0}, - {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, - {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, - /* Enable AOW0 to MW9 */ {0x1, 0xfb8, 0xa8}, { } @@ -3948,7 +3870,6 @@ static int patch_vt1812(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.init = via_auto_init; codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE From 096a885494f6b89a9962c6faf18e1c6092e7919c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 12:09:02 +0200 Subject: [PATCH 20/39] ALSA: hda - Initialize input-path dynamically in patch_via.c Similarly like the previous commit, initialize the input-paths dynamically from the parsed results instead of the fixed array for VIA codecs. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 363 +++++--------------------------------- 1 file changed, 49 insertions(+), 314 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 4f6e7bebdb45..68f435dbbfd4 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -629,9 +629,18 @@ static void via_auto_init_analog_input(struct hda_codec *codec) { struct via_spec *spec = codec->spec; const struct auto_pin_cfg *cfg = &spec->autocfg; + hda_nid_t conn[HDA_MAX_CONNECTIONS]; unsigned int ctl; - int i; + int i, num_conns; + /* init ADCs */ + for (i = 0; i < spec->num_adc_nids; i++) { + snd_hda_codec_write(codec, spec->adc_nids[i], 0, + AC_VERB_SET_AMP_GAIN_MUTE, + AMP_IN_UNMUTE(0)); + } + + /* init pins */ for (i = 0; i < cfg->num_inputs; i++) { hda_nid_t nid = cfg->inputs[i].pin; if (spec->smart51_enabled && is_smart51_pins(codec, nid)) @@ -643,6 +652,29 @@ static void via_auto_init_analog_input(struct hda_codec *codec) snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); } + + /* init input-src */ + for (i = 0; i < spec->num_adc_nids; i++) { + const struct hda_input_mux *imux = spec->input_mux; + if (!imux || !spec->mux_nids[i]) + continue; + snd_hda_codec_write(codec, spec->mux_nids[i], 0, + AC_VERB_SET_CONNECT_SEL, + imux->items[spec->cur_mux[i]].index); + } + + /* init aa-mixer */ + if (!spec->aa_mix_nid) + return; + num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn, + ARRAY_SIZE(conn)); + for (i = 0; i < num_conns; i++) { + unsigned int caps = get_wcaps(codec, conn[i]); + if (get_wcaps_type(caps) == AC_WID_PIN) + snd_hda_codec_write(codec, spec->aa_mix_nid, 0, + AC_VERB_SET_AMP_GAIN_MUTE, + AMP_IN_MUTE(i)); + } } static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, @@ -1117,24 +1149,7 @@ static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) /* * generic initialization of ADC, input mixers and output mixers */ -static const struct hda_verb vt1708_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, - {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, - {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - +static const struct hda_verb vt1708_init_verbs[] = { /* power down jack detect function */ {0x1, 0xf81, 0x1}, { } @@ -2200,7 +2215,7 @@ static int via_parse_auto_config(struct hda_codec *codec) if (spec->kctls.list) spec->mixers[spec->num_mixers++] = spec->kctls.list; - spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; spec->input_mux = &spec->private_imux[0]; @@ -2354,30 +2369,6 @@ static const struct hda_verb vt1709_uniwill_init_verbs[] = { /* * generic initialization of ADC, input mixers and output mixers */ -static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { - /* - * Unmute ADC0-2 and set the default input to mic-in - */ - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - - /* Set input of PW4 as MW0 */ - {0x20, AC_VERB_SET_CONNECT_SEL, 0}, - { } -}; - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1709_loopbacks[] = { { 0x18, HDA_INPUT, 1 }, @@ -2406,7 +2397,6 @@ static int patch_vt1709_10ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; codec->patch_ops = via_patch_ops; @@ -2421,46 +2411,6 @@ static int patch_vt1709_10ch(struct hda_codec *codec) /* * generic initialization of ADC, input mixers and output mixers */ -static const struct hda_verb vt1709_6ch_volume_init_verbs[] = { - /* - * Unmute ADC0-2 and set the default input to mic-in - */ - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - - /* - * Set up output selector (0x1a, 0x1b, 0x29) - */ - /* set vol=0 to output mixers */ - {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - - /* - * Unmute PW3 and PW4 - */ - {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - - /* Set input of PW4 as MW0 */ - {0x20, AC_VERB_SET_CONNECT_SEL, 0}, - /* PW9 Output enable */ - {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, - { } -}; - static int patch_vt1709_6ch(struct hda_codec *codec) { struct via_spec *spec; @@ -2479,7 +2429,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; codec->patch_ops = via_patch_ops; @@ -2494,62 +2443,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) /* * generic initialization of ADC, input mixers and output mixers */ -static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - - /* - * Set up output mixers - */ - /* set vol=0 to output mixers */ - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, - - /* PW9 Output enable */ - {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, - /* PW10 Input enable */ - {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, - { } -}; - -static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - - /* PW10 Input enable */ - {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, - { } -}; - static const struct hda_verb vt1708B_uniwill_init_verbs[] = { {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, @@ -2675,7 +2568,6 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; codec->patch_ops = via_patch_ops; @@ -2707,7 +2599,6 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; codec->patch_ops = via_patch_ops; @@ -2723,21 +2614,7 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) } /* Patch for VT1708S */ - -static const struct hda_verb vt1708S_volume_init_verbs[] = { - /* Unmute ADC0-1 and set the default input to mic-in */ - {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the - * analog-loopback mixer widget */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, - +static const struct hda_verb vt1708S_init_verbs[] = { /* Enable Mic Boost Volume backdoor */ {0x1, 0xf98, 0x1}, /* don't bybass mixer */ @@ -2863,7 +2740,7 @@ static int patch_vt1708S(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; if (codec->vendor_id == 0x11064397) spec->init_verbs[spec->num_iverbs++] = vt1705_uniwill_init_verbs; @@ -2900,25 +2777,7 @@ static int patch_vt1708S(struct hda_codec *codec) /* Patch for VT1702 */ -static const struct hda_verb vt1702_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ - {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, - {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, - {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, - +static const struct hda_verb vt1702_init_verbs[] = { /* mixer enable */ {0x1, 0xF88, 0x3}, /* GPIO 0~2 */ @@ -3003,7 +2862,7 @@ static int patch_vt1702(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; codec->patch_ops = via_patch_ops; @@ -3019,25 +2878,9 @@ static int patch_vt1702(struct hda_codec *codec) /* Patch for VT1718S */ -static const struct hda_verb vt1718S_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - +static const struct hda_verb vt1718S_init_verbs[] = { /* Enable MW0 adjust Gain 5 */ {0x1, 0xfb2, 0x10}, - /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)}, - /* Enable Boost Volume backdoor */ {0x1, 0xf88, 0x8}, @@ -3155,7 +2998,7 @@ static int patch_vt1718S(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; codec->patch_ops = via_patch_ops; @@ -3232,27 +3075,7 @@ static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { { } /* end */ }; -static const struct hda_verb vt1716S_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, - {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, - - /* MUX Indices: Stereo Mixer = 5 */ - {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, - +static const struct hda_verb vt1716S_init_verbs[] = { /* Enable Boost Volume backdoor */ {0x1, 0xf8a, 0x80}, /* don't bybass mixer */ @@ -3400,7 +3223,7 @@ static int patch_vt1716S(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; @@ -3422,86 +3245,20 @@ static int patch_vt1716S(struct hda_codec *codec) /* for vt2002P */ -static const struct hda_verb vt2002P_volume_init_verbs[] = { +static const struct hda_verb vt2002P_init_verbs[] = { /* Class-D speaker related verbs */ {0x1, 0xfe0, 0x4}, {0x1, 0xfe9, 0x80}, {0x1, 0xfe2, 0x22}, - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, - - /* MUX Indices: Mic = 0 */ - {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, - {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, - /* Enable Boost Volume backdoor */ {0x1, 0xfb9, 0x24}, - /* Enable AOW0 to MW9 */ {0x1, 0xfb8, 0x88}, { } }; -static const struct hda_verb vt1802_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, - - /* MUX Indices: Mic = 0 */ - {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, - {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, - - /* PW9 Output enable */ - {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, - +static const struct hda_verb vt1802_init_verbs[] = { /* Enable Boost Volume backdoor */ {0x1, 0xfb9, 0x24}, - - /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, - - /* set MUX0/1/4/8 = 0 (AOW0) */ - {0x34, AC_VERB_SET_CONNECT_SEL, 0}, - {0x35, AC_VERB_SET_CONNECT_SEL, 0}, - {0x38, AC_VERB_SET_CONNECT_SEL, 0}, - {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, - - /* set PW0 index=0 (MW0) */ - {0x24, AC_VERB_SET_CONNECT_SEL, 0}, - /* Enable AOW0 to MW9 */ {0x1, 0xfb8, 0x88}, { } @@ -3673,10 +3430,10 @@ static int patch_vt2002P(struct hda_codec *codec) if (spec->codec_type == VT1802) spec->init_verbs[spec->num_iverbs++] = - vt1802_volume_init_verbs; + vt1802_init_verbs; else spec->init_verbs[spec->num_iverbs++] = - vt2002P_volume_init_verbs; + vt2002P_init_verbs; if (spec->codec_type == VT1802) spec->init_verbs[spec->num_iverbs++] = @@ -3699,31 +3456,9 @@ static int patch_vt2002P(struct hda_codec *codec) /* for vt1812 */ -static const struct hda_verb vt1812_volume_init_verbs[] = { - /* - * Unmute ADC0-1 and set the default input to mic-in - */ - {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, - - - /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback - * mixer widget - */ - /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, - {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, - - /* MUX Indices: Mic = 0 */ - {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, - {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, - +static const struct hda_verb vt1812_init_verbs[] = { /* Enable Boost Volume backdoor */ {0x1, 0xfb9, 0x24}, - /* Enable AOW0 to MW9 */ {0x1, 0xfb8, 0xa8}, { } @@ -3865,7 +3600,7 @@ static int patch_vt1812(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; codec->patch_ops = via_patch_ops; From 4a918ffeaadd6a2269b9c6575478c102382c7702 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 12:39:26 +0200 Subject: [PATCH 21/39] ALSA: hda - Initialize unsol events dynamically in patch_via.c Issue the init verbs of unsolicited events dynamically from the parsed results for VIA codecs. Also, consolidate the unsol handlers for HP and line-out mutes. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 444 +++++++++----------------------------- 1 file changed, 98 insertions(+), 346 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 68f435dbbfd4..1edcd3221c98 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -138,6 +138,7 @@ struct via_spec { struct nid_path out_path[4]; struct nid_path hp_path; struct nid_path hp_dep_path; + struct nid_path speaker_path; /* capture */ unsigned int num_adc_nids; @@ -252,15 +253,12 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) #define VIA_JACK_EVENT 0x20 #define VIA_HP_EVENT 0x01 #define VIA_GPIO_EVENT 0x02 -#define VIA_MONO_EVENT 0x03 -#define VIA_SPEAKER_EVENT 0x04 -#define VIA_BIND_HP_EVENT 0x05 +#define VIA_LINE_EVENT 0x03 enum { VIA_CTL_WIDGET_VOL, VIA_CTL_WIDGET_MUTE, VIA_CTL_WIDGET_ANALOG_MUTE, - VIA_CTL_WIDGET_BIND_PIN_MUTE, }; static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); @@ -323,106 +321,10 @@ static int analog_input_switch_put(struct snd_kcontrol *kcontrol, .put = analog_input_switch_put, \ .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } -static void via_hp_bind_automute(struct hda_codec *codec); - -static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - struct via_spec *spec = codec->spec; - int i; - int change = 0; - - long *valp = ucontrol->value.integer.value; - int lmute, rmute; - if (strstr(kcontrol->id.name, "Switch") == NULL) { - snd_printd("Invalid control!\n"); - return change; - } - change = snd_hda_mixer_amp_switch_put(kcontrol, - ucontrol); - /* Get mute value */ - lmute = *valp ? 0 : HDA_AMP_MUTE; - valp++; - rmute = *valp ? 0 : HDA_AMP_MUTE; - - /* Set hp pins */ - if (!spec->hp_independent_mode) { - for (i = 0; i < spec->autocfg.hp_outs; i++) { - snd_hda_codec_amp_update( - codec, spec->autocfg.hp_pins[i], - 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, - lmute); - snd_hda_codec_amp_update( - codec, spec->autocfg.hp_pins[i], - 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, - rmute); - } - } - - if (!lmute && !rmute) { - /* Line Outs */ - for (i = 0; i < spec->autocfg.line_outs; i++) - snd_hda_codec_amp_stereo( - codec, spec->autocfg.line_out_pins[i], - HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); - /* Speakers */ - for (i = 0; i < spec->autocfg.speaker_outs; i++) - snd_hda_codec_amp_stereo( - codec, spec->autocfg.speaker_pins[i], - HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); - /* unmute */ - via_hp_bind_automute(codec); - - } else { - if (lmute) { - /* Mute all left channels */ - for (i = 1; i < spec->autocfg.line_outs; i++) - snd_hda_codec_amp_update( - codec, - spec->autocfg.line_out_pins[i], - 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, - lmute); - for (i = 0; i < spec->autocfg.speaker_outs; i++) - snd_hda_codec_amp_update( - codec, - spec->autocfg.speaker_pins[i], - 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, - lmute); - } - if (rmute) { - /* mute all right channels */ - for (i = 1; i < spec->autocfg.line_outs; i++) - snd_hda_codec_amp_update( - codec, - spec->autocfg.line_out_pins[i], - 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, - rmute); - for (i = 0; i < spec->autocfg.speaker_outs; i++) - snd_hda_codec_amp_update( - codec, - spec->autocfg.speaker_pins[i], - 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, - rmute); - } - } - return change; -} - -#define BIND_PIN_MUTE \ - { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ - .name = NULL, \ - .index = 0, \ - .info = snd_hda_mixer_amp_switch_info, \ - .get = snd_hda_mixer_amp_switch_get, \ - .put = bind_pin_switch_put, \ - .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } - static const struct snd_kcontrol_new via_control_templates[] = { HDA_CODEC_VOLUME(NULL, 0, 0, 0), HDA_CODEC_MUTE(NULL, 0, 0, 0), ANALOG_INPUT_MUTE, - BIND_PIN_MUTE, }; @@ -623,6 +525,15 @@ static void via_auto_init_hp_out(struct hda_codec *codec) &spec->hp_dep_path); } +static void via_auto_init_speaker_out(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + + if (spec->autocfg.speaker_outs) + via_auto_init_output(codec, spec->autocfg.speaker_pins[0], + PIN_OUT, &spec->speaker_path); +} + static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); static void via_auto_init_analog_input(struct hda_codec *codec) @@ -1554,46 +1465,34 @@ static void toggle_output_mutes(struct hda_codec *codec, int num_pins, mute ? 0 : PIN_OUT); } +/* mute internal speaker if line-out is plugged */ +static void via_line_automute(struct hda_codec *codec, int present) +{ + struct via_spec *spec = codec->spec; + + if (!spec->autocfg.speaker_outs) + return; + if (!present) + present = snd_hda_jack_detect(codec, + spec->autocfg.line_out_pins[0]); + toggle_output_mutes(codec, spec->autocfg.speaker_outs, + spec->autocfg.speaker_pins, + present); +} + /* mute internal speaker if HP is plugged */ static void via_hp_automute(struct hda_codec *codec) { - unsigned int present = 0; + int present = 0; struct via_spec *spec = codec->spec; - present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); - - if (!spec->hp_independent_mode) + if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) { + present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); toggle_output_mutes(codec, spec->autocfg.line_outs, spec->autocfg.line_out_pins, present); -} - -/* mute mono out if HP or Line out is plugged */ -static void via_mono_automute(struct hda_codec *codec) -{ - unsigned int hp_present, lineout_present; - struct via_spec *spec = codec->spec; - - if (spec->codec_type != VT1716S) - return; - - lineout_present = snd_hda_jack_detect(codec, - spec->autocfg.line_out_pins[0]); - - /* Mute Mono Out if Line Out is plugged */ - if (lineout_present) { - snd_hda_codec_write(codec, 0x2A, 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, - lineout_present ? 0 : PIN_OUT); - return; } - - hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); - - if (!spec->hp_independent_mode) - snd_hda_codec_write(codec, 0x2A, 0, - AC_VERB_SET_PIN_WIDGET_CONTROL, - hp_present ? 0 : PIN_OUT); + via_line_automute(codec, present); } static void via_gpio_control(struct hda_codec *codec) @@ -1643,49 +1542,6 @@ static void via_gpio_control(struct hda_codec *codec) } } -/* mute Internal-Speaker if HP is plugged */ -static void via_speaker_automute(struct hda_codec *codec) -{ - unsigned int hp_present; - struct via_spec *spec = codec->spec; - - if (!VT2002P_COMPATIBLE(spec)) - return; - - hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); - - if (!spec->hp_independent_mode) - toggle_output_mutes(codec, spec->autocfg.speaker_outs, - spec->autocfg.speaker_pins, - hp_present); -} - -/* mute line-out and internal speaker if HP is plugged */ -static void via_hp_bind_automute(struct hda_codec *codec) -{ - int present; - struct via_spec *spec = codec->spec; - - if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) - return; - - present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); - if (!spec->hp_independent_mode) - toggle_output_mutes(codec, spec->autocfg.line_outs, - spec->autocfg.line_out_pins, - present); - - if (!present) - present = snd_hda_jack_detect(codec, - spec->autocfg.line_out_pins[0]); - - /* Speakers */ - toggle_output_mutes(codec, spec->autocfg.speaker_outs, - spec->autocfg.speaker_pins, - present); -} - - /* unsolicited event for jack sensing */ static void via_unsol_event(struct hda_codec *codec, unsigned int res) @@ -1701,12 +1557,8 @@ static void via_unsol_event(struct hda_codec *codec, via_hp_automute(codec); else if (res == VIA_GPIO_EVENT) via_gpio_control(codec); - else if (res == VIA_MONO_EVENT) - via_mono_automute(codec); - else if (res == VIA_SPEAKER_EVENT) - via_speaker_automute(codec); - else if (res == VIA_BIND_HP_EVENT) - via_hp_bind_automute(codec); + else if (res == VIA_LINE_EVENT) + via_line_automute(codec, false); } #ifdef SND_HDA_NEEDS_RESUME @@ -1736,6 +1588,7 @@ static const struct hda_codec_ops via_patch_ops = { .build_pcms = via_build_pcms, .init = via_init, .free = via_free, + .unsol_event = via_unsol_event, #ifdef SND_HDA_NEEDS_RESUME .suspend = via_suspend, #endif @@ -1968,6 +1821,27 @@ static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) return 0; } +static int via_auto_create_speaker_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + hda_nid_t pin, dac; + + pin = spec->autocfg.speaker_pins[0]; + if (!spec->autocfg.speaker_outs || !pin) + return 0; + + if (parse_output_path(codec, pin, 0, &spec->speaker_path, 0, -1)) { + dac = spec->speaker_path.path[spec->speaker_path.depth - 1]; + spec->multiout.extra_out_nid[0] = dac; + return create_ch_ctls(codec, "Speaker", pin, dac, 3); + } + if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], + &spec->speaker_path, 0, -1)) + return create_ch_ctls(codec, "Headphone", pin, 0, 3); + + return 0; +} + /* look for ADCs */ static int via_fill_adcs(struct hda_codec *codec) { @@ -2201,6 +2075,9 @@ static int via_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); + if (err < 0) + return err; + err = via_auto_create_speaker_ctls(codec); if (err < 0) return err; err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); @@ -2254,6 +2131,39 @@ static void via_auto_init_dig_in(struct hda_codec *codec) AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); } +/* initialize the unsolicited events */ +static void via_auto_init_unsol_event(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + struct auto_pin_cfg *cfg = &spec->autocfg; + unsigned int ev; + int i; + + if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0])) + snd_hda_codec_write(codec, cfg->hp_pins[0], 0, + AC_VERB_SET_UNSOLICITED_ENABLE, + AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT); + + if (cfg->speaker_pins[0]) + ev = VIA_LINE_EVENT; + else + ev = 0; + for (i = 0; i < cfg->line_outs; i++) { + if (cfg->line_out_pins[i] && + is_jack_detectable(codec, cfg->line_out_pins[i])) + snd_hda_codec_write(codec, cfg->line_out_pins[0], 0, + AC_VERB_SET_UNSOLICITED_ENABLE, + AC_USRSP_EN | ev | VIA_JACK_EVENT); + } + + for (i = 0; i < cfg->num_inputs; i++) { + if (is_jack_detectable(codec, cfg->inputs[i].pin)) + snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, + AC_VERB_SET_UNSOLICITED_ENABLE, + AC_USRSP_EN | VIA_JACK_EVENT); + } +} + static int via_init(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -2264,16 +2174,15 @@ static int via_init(struct hda_codec *codec) via_auto_init_multi_out(codec); via_auto_init_hp_out(codec); + via_auto_init_speaker_out(codec); via_auto_init_analog_input(codec); via_auto_init_dig_outs(codec); via_auto_init_dig_in(codec); - if (VT2002P_COMPATIBLE(spec)) { - via_hp_bind_automute(codec); - } else { - via_hp_automute(codec); - via_speaker_automute(codec); - } + via_auto_init_unsol_event(codec); + + via_hp_automute(codec); + via_line_automute(codec, false); return 0; } @@ -2360,12 +2269,6 @@ static int patch_vt1708(struct hda_codec *codec) return 0; } -static const struct hda_verb vt1709_uniwill_init_verbs[] = { - {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, - { } -}; - /* * generic initialization of ADC, input mixers and output mixers */ @@ -2397,11 +2300,8 @@ static int patch_vt1709_10ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1709_loopbacks; #endif @@ -2429,11 +2329,8 @@ static int patch_vt1709_6ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; - codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1709_loopbacks; #endif @@ -2443,19 +2340,6 @@ static int patch_vt1709_6ch(struct hda_codec *codec) /* * generic initialization of ADC, input mixers and output mixers */ -static const struct hda_verb vt1708B_uniwill_init_verbs[] = { - {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, - {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1708B_loopbacks[] = { { 0x16, HDA_INPUT, 1 }, @@ -2568,11 +2452,8 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1708B_loopbacks; #endif @@ -2599,11 +2480,8 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) return err; } - spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; - codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1708B_loopbacks; #endif @@ -2622,31 +2500,6 @@ static const struct hda_verb vt1708S_init_verbs[] = { { } }; -static const struct hda_verb vt1708S_uniwill_init_verbs[] = { - {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, - {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - -static const struct hda_verb vt1705_uniwill_init_verbs[] = { - {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, - {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - /* fill out digital output widgets; one for master and one for slave outputs */ static void fill_dig_outs(struct hda_codec *codec) { @@ -2741,16 +2594,9 @@ static int patch_vt1708S(struct hda_codec *codec) } spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; - if (codec->vendor_id == 0x11064397) - spec->init_verbs[spec->num_iverbs++] = - vt1705_uniwill_init_verbs; - else - spec->init_verbs[spec->num_iverbs++] = - vt1708S_uniwill_init_verbs; codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1708S_loopbacks; #endif @@ -2785,16 +2631,6 @@ static const struct hda_verb vt1702_init_verbs[] = { { } }; -static const struct hda_verb vt1702_uniwill_init_verbs[] = { - {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, - {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1702_loopbacks[] = { { 0x1A, HDA_INPUT, 1 }, @@ -2863,11 +2699,9 @@ static int patch_vt1702(struct hda_codec *codec) } spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; - spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1702_loopbacks; #endif @@ -2887,20 +2721,6 @@ static const struct hda_verb vt1718S_init_verbs[] = { { } }; - -static const struct hda_verb vt1718S_uniwill_init_verbs[] = { - {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, - {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1718S_loopbacks[] = { { 0x21, HDA_INPUT, 1 }, @@ -2999,12 +2819,9 @@ static int patch_vt1718S(struct hda_codec *codec) } spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; - spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; - #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1718S_loopbacks; #endif @@ -3085,20 +2902,6 @@ static const struct hda_verb vt1716S_init_verbs[] = { { } }; - -static const struct hda_verb vt1716S_uniwill_init_verbs[] = { - {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, - {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, - {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1716S_loopbacks[] = { { 0x16, HDA_INPUT, 1 }, @@ -3224,7 +3027,6 @@ static int patch_vt1716S(struct hda_codec *codec) } spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs; - spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; spec->num_mixers++; @@ -3233,8 +3035,6 @@ static int patch_vt1716S(struct hda_codec *codec) codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; - #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1716S_loopbacks; #endif @@ -3256,6 +3056,7 @@ static const struct hda_verb vt2002P_init_verbs[] = { {0x1, 0xfb8, 0x88}, { } }; + static const struct hda_verb vt1802_init_verbs[] = { /* Enable Boost Volume backdoor */ {0x1, 0xfb9, 0x24}, @@ -3264,28 +3065,6 @@ static const struct hda_verb vt1802_init_verbs[] = { { } }; - -static const struct hda_verb vt2002P_uniwill_init_verbs[] = { - {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, - {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, - {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; -static const struct hda_verb vt1802_uniwill_init_verbs[] = { - {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, - {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, - {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt2002P_loopbacks[] = { { 0x21, HDA_INPUT, 0 }, @@ -3429,23 +3208,12 @@ static int patch_vt2002P(struct hda_codec *codec) } if (spec->codec_type == VT1802) - spec->init_verbs[spec->num_iverbs++] = - vt1802_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs; else - spec->init_verbs[spec->num_iverbs++] = - vt2002P_init_verbs; - - if (spec->codec_type == VT1802) - spec->init_verbs[spec->num_iverbs++] = - vt1802_uniwill_init_verbs; - else - spec->init_verbs[spec->num_iverbs++] = - vt2002P_uniwill_init_verbs; + spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; - #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt2002P_loopbacks; #endif @@ -3464,19 +3232,6 @@ static const struct hda_verb vt1812_init_verbs[] = { { } }; - -static const struct hda_verb vt1812_uniwill_init_verbs[] = { - {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, - {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, - {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, - AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, - {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, - { } -}; - #ifdef CONFIG_SND_HDA_POWER_SAVE static const struct hda_amp_list vt1812_loopbacks[] = { { 0x21, HDA_INPUT, 0 }, @@ -3601,12 +3356,9 @@ static int patch_vt1812(struct hda_codec *codec) } spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; - spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; codec->patch_ops = via_patch_ops; - codec->patch_ops.unsol_event = via_unsol_event; - #ifdef CONFIG_SND_HDA_POWER_SAVE spec->loopback.amplist = vt1812_loopbacks; #endif From 370bafbdae3d78c9081ebe3028a3ff5f0e91357b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 12:47:45 +0200 Subject: [PATCH 22/39] ALSA: hda - Create virtual-master control for VIA codecs Now let's add the missing Master control to VIA codecs. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 1edcd3221c98..deb33ae109c8 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1308,6 +1308,31 @@ static const struct hda_pcm_stream via_pcm_digital_capture = { .channels_max = 2, }; +/* + * slave controls for virtual master + */ +static const char * const via_slave_vols[] = { + "Front Playback Volume", + "Surround Playback Volume", + "Center Playback Volume", + "LFE Playback Volume", + "Side Playback Volume", + "Headphone Playback Volume", + "Speaker Playback Volume", + NULL, +}; + +static const char * const via_slave_sws[] = { + "Front Playback Switch", + "Surround Playback Switch", + "Center Playback Switch", + "LFE Playback Switch", + "Side Playback Switch", + "Headphone Playback Switch", + "Speaker Playback Switch", + NULL, +}; + static int via_build_controls(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -1343,6 +1368,23 @@ static int via_build_controls(struct hda_codec *codec) return err; } + /* if we have no master control, let's create it */ + if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { + unsigned int vmaster_tlv[4]; + snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], + HDA_OUTPUT, vmaster_tlv); + err = snd_hda_add_vmaster(codec, "Master Playback Volume", + vmaster_tlv, via_slave_vols); + if (err < 0) + return err; + } + if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { + err = snd_hda_add_vmaster(codec, "Master Playback Switch", + NULL, via_slave_sws); + if (err < 0) + return err; + } + /* assign Capture Source enums to NID */ kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); for (i = 0; kctl && i < kctl->count; i++) { From e3d7a1431f1d8851d11b2262dda5bb67158450eb Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 13:52:33 +0200 Subject: [PATCH 23/39] ALSA: hda - Fix smart51 handling again Fix the broken detection of smart51 and its handling. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 145 +++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 82 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index deb33ae109c8..c3be9f124b68 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -165,12 +165,17 @@ struct via_spec { const struct hda_input_mux *hp_mux; unsigned int hp_independent_mode; unsigned int hp_independent_mode_index; - unsigned int can_smart51; - unsigned int smart51_enabled; unsigned int dmic_enabled; unsigned int no_pin_power_ctl; enum VIA_HDA_CODEC codec_type; + /* smart51 setup */ + unsigned int smart51_nums; + hda_nid_t smart51_pins[2]; + int smart51_idxs[2]; + const char *smart51_labels[2]; + unsigned int smart51_enabled; + /* work to check hp jack state */ struct hda_codec *codec; struct delayed_work vt1708_hp_work; @@ -508,7 +513,7 @@ static void via_auto_init_multi_out(struct hda_codec *codec) struct via_spec *spec = codec->spec; int i; - for (i = 0; i < spec->autocfg.line_outs; i++) + for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) via_auto_init_output(codec, spec->autocfg.line_out_pins[i], PIN_OUT, &spec->out_path[i]); } @@ -771,15 +776,15 @@ static int via_hp_build(struct hda_codec *codec) static void notify_aa_path_ctls(struct hda_codec *codec) { + struct via_spec *spec = codec->spec; int i; - struct snd_ctl_elem_id id; - const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"}; - struct snd_kcontrol *ctl; - memset(&id, 0, sizeof(id)); - id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - for (i = 0; i < ARRAY_SIZE(labels); i++) { - sprintf(id.name, "%s Playback Volume", labels[i]); + for (i = 0; i < spec->smart51_nums; i++) { + struct snd_kcontrol *ctl; + struct snd_ctl_elem_id id; + memset(&id, 0, sizeof(id)); + id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]); ctl = snd_hda_find_mixer_ctl(codec, id.name); if (ctl) snd_ctl_notify(codec->bus->card, @@ -791,43 +796,20 @@ static void notify_aa_path_ctls(struct hda_codec *codec) static void mute_aa_path(struct hda_codec *codec, int mute) { struct via_spec *spec = codec->spec; - int start_idx; - int end_idx; + int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; int i; - /* get nid of MW0 and start & end index */ - switch (spec->codec_type) { - case VT1708: - start_idx = 2; - end_idx = 4; - break; - case VT1709_10CH: - case VT1709_6CH: - start_idx = 2; - end_idx = 4; - break; - case VT1708B_8CH: - case VT1708B_4CH: - case VT1708S: - case VT1716S: - start_idx = 2; - end_idx = 4; - break; - case VT1718S: - start_idx = 1; - end_idx = 3; - break; - default: - return; - } + /* check AA path's mute status */ - for (i = start_idx; i <= end_idx; i++) { - int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; - snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i, + for (i = 0; i < spec->smart51_nums; i++) { + if (spec->smart51_idxs[i] < 0) + continue; + snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, + HDA_INPUT, spec->smart51_idxs[i], HDA_AMP_MUTE, val); } } -static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) +static bool is_smart51_candidate(struct hda_codec *codec, hda_nid_t pin) { struct via_spec *spec = codec->spec; const struct auto_pin_cfg *cfg = &spec->autocfg; @@ -847,6 +829,17 @@ static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) return false; } +static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) +{ + struct via_spec *spec = codec->spec; + int i; + + for (i = 0; i < spec->smart51_nums; i++) + if (spec->smart51_pins[i] == pin) + return true; + return false; +} + static int via_smart51_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { @@ -862,18 +855,12 @@ static int via_smart51_get(struct snd_kcontrol *kcontrol, { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct via_spec *spec = codec->spec; - const struct auto_pin_cfg *cfg = &spec->autocfg; int on = 1; int i; - for (i = 0; i < cfg->num_inputs; i++) { - hda_nid_t nid = cfg->inputs[i].pin; + for (i = 0; i < spec->smart51_nums; i++) { + hda_nid_t nid = spec->smart51_pins[i]; unsigned int ctl; - if (cfg->inputs[i].type == AUTO_PIN_MIC && - spec->hp_independent_mode && spec->codec_type != VT1718S) - continue; /* ignore FMic for independent HP */ - if (!is_smart51_pins(codec, nid)) - continue; ctl = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) @@ -888,21 +875,14 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol, { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct via_spec *spec = codec->spec; - const struct auto_pin_cfg *cfg = &spec->autocfg; int out_in = *ucontrol->value.integer.value ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; int i; - for (i = 0; i < cfg->num_inputs; i++) { - hda_nid_t nid = cfg->inputs[i].pin; + for (i = 0; i < spec->smart51_nums; i++) { + hda_nid_t nid = spec->smart51_pins[i]; unsigned int parm; - if (cfg->inputs[i].type == AUTO_PIN_MIC && - spec->hp_independent_mode && spec->codec_type != VT1718S) - continue; /* don't retask FMic for independent HP */ - if (!is_smart51_pins(codec, nid)) - continue; - parm = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); @@ -932,26 +912,11 @@ static const struct snd_kcontrol_new via_smart51_mixer = { static int via_smart51_build(struct hda_codec *codec) { struct via_spec *spec = codec->spec; - struct snd_kcontrol_new *knew; - const struct auto_pin_cfg *cfg = &spec->autocfg; - hda_nid_t nid; - int i; - if (!spec->can_smart51) + if (!spec->smart51_nums) return 0; - - knew = via_clone_control(spec, &via_smart51_mixer); - if (knew == NULL) + if (!via_clone_control(spec, &via_smart51_mixer)) return -ENOMEM; - - for (i = 0; i < cfg->num_inputs; i++) { - nid = cfg->inputs[i].pin; - if (is_smart51_pins(codec, nid)) { - knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; - break; - } - } - return 0; } @@ -1751,12 +1716,18 @@ static void mangle_smart51(struct hda_codec *codec) { struct via_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; - int i; + int i, nums = 0; for (i = 0; i < cfg->num_inputs; i++) { - if (!is_smart51_pins(codec, cfg->inputs[i].pin)) + if (is_smart51_candidate(codec, cfg->inputs[i].pin)) + nums++; + } + if (cfg->line_outs + nums < 3) + return; + for (i = 0; i < cfg->num_inputs; i++) { + if (!is_smart51_candidate(codec, cfg->inputs[i].pin)) continue; - spec->can_smart51 = 1; + spec->smart51_pins[spec->smart51_nums++] = cfg->inputs[i].pin; cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin; if (cfg->line_outs == 3) break; @@ -1779,6 +1750,10 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) if (cfg->line_outs == 1) mangle_smart51(codec); + err = via_auto_fill_dac_nids(codec); + if (err < 0) + return err; + for (i = 0; i < cfg->line_outs; i++) { hda_nid_t pin, dac; pin = cfg->line_out_pins[i]; @@ -1926,7 +1901,7 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, { struct via_spec *spec = codec->spec; struct hda_input_mux *imux = &spec->private_imux[0]; - int i, err, idx, idx2, type, type_idx = 0; + int i, j, err, idx, idx2, type, type_idx = 0; hda_nid_t cap_nid; hda_nid_t pin_idxs[8]; int num_idxs; @@ -1973,6 +1948,15 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, if (err < 0) return err; snd_hda_add_imux_item(imux, label, idx, NULL); + + /* remember the label for smart51 control */ + for (j = 0; j < spec->smart51_nums; j++) { + if (spec->smart51_pins[j] == cfg->inputs[i].pin) { + spec->smart51_idxs[j] = idx; + spec->smart51_labels[j] = label; + break; + } + } } /* create capture mixer elements */ @@ -2105,9 +2089,6 @@ static int via_parse_auto_config(struct hda_codec *codec) int err; err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); - if (err < 0) - return err; - err = via_auto_fill_dac_nids(codec); if (err < 0) return err; if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) From 13af8e77ea3e0dff80db9b2e0007535c21d49094 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 14:05:46 +0200 Subject: [PATCH 24/39] ALSA: hda - Create loopback-list dynamically in patch_via.c Create loopback list dynamically from the parsed input pins for VIA codecs instead of the fixed arrays. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 164 ++++++-------------------------------- 1 file changed, 25 insertions(+), 139 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index c3be9f124b68..bd6ffa602f22 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -186,6 +186,8 @@ struct via_spec { #ifdef CONFIG_SND_HDA_POWER_SAVE struct hda_loopback_check loopback; + int num_loopbacks; + struct hda_amp_list loopback_list[8]; #endif }; @@ -1895,6 +1897,24 @@ static const struct snd_kcontrol_new via_input_src_ctl = { .put = via_mux_enum_put, }; +#ifdef CONFIG_SND_HDA_POWER_SAVE +static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) +{ + struct hda_amp_list *list; + + if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1) + return; + list = spec->loopback_list + spec->num_loopbacks; + list->nid = mix; + list->dir = HDA_INPUT; + list->idx = idx; + spec->num_loopbacks++; + spec->loopback.amplist = spec->loopback_list; +} +#else +#define add_loopback_list(spec, mix, idx) /* NOP */ +#endif + /* create playback/capture controls for input pins */ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg) @@ -1942,11 +1962,13 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, label = hda_get_autocfg_input_label(codec, cfg, i); idx2 = get_connection_index(codec, spec->aa_mix_nid, pin_idxs[idx]); - if (idx2 >= 0) + if (idx2 >= 0) { err = via_new_analog_input(spec, label, type_idx, idx2, spec->aa_mix_nid); - if (err < 0) - return err; + if (err < 0) + return err; + add_loopback_list(spec, spec->aa_mix_nid, idx2); + } snd_hda_add_imux_item(imux, label, idx, NULL); /* remember the label for smart51 control */ @@ -2011,16 +2033,6 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, return 0; } -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1708_loopbacks[] = { - { 0x17, HDA_INPUT, 1 }, - { 0x17, HDA_INPUT, 2 }, - { 0x17, HDA_INPUT, 3 }, - { 0x17, HDA_INPUT, 4 }, - { } /* end */ -}; -#endif - static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) { unsigned int def_conf; @@ -2285,26 +2297,10 @@ static int patch_vt1708(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1708_loopbacks; -#endif INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); return 0; } -/* - * generic initialization of ADC, input mixers and output mixers - */ -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1709_loopbacks[] = { - { 0x18, HDA_INPUT, 1 }, - { 0x18, HDA_INPUT, 2 }, - { 0x18, HDA_INPUT, 3 }, - { 0x18, HDA_INPUT, 4 }, - { } /* end */ -}; -#endif - static int patch_vt1709_10ch(struct hda_codec *codec) { struct via_spec *spec; @@ -2325,10 +2321,6 @@ static int patch_vt1709_10ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1709_loopbacks; -#endif - return 0; } /* @@ -2354,25 +2346,9 @@ static int patch_vt1709_6ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1709_loopbacks; -#endif return 0; } -/* - * generic initialization of ADC, input mixers and output mixers - */ -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1708B_loopbacks[] = { - { 0x16, HDA_INPUT, 1 }, - { 0x16, HDA_INPUT, 2 }, - { 0x16, HDA_INPUT, 3 }, - { 0x16, HDA_INPUT, 4 }, - { } /* end */ -}; -#endif - static void set_widgets_power_state_vt1708B(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -2477,10 +2453,6 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1708B_loopbacks; -#endif - spec->set_widgets_power_state = set_widgets_power_state_vt1708B; return 0; @@ -2505,10 +2477,6 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1708B_loopbacks; -#endif - spec->set_widgets_power_state = set_widgets_power_state_vt1708B; return 0; @@ -2575,16 +2543,6 @@ static void fill_dig_in(struct hda_codec *codec) } } -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1708S_loopbacks[] = { - { 0x16, HDA_INPUT, 1 }, - { 0x16, HDA_INPUT, 2 }, - { 0x16, HDA_INPUT, 3 }, - { 0x16, HDA_INPUT, 4 }, - { } /* end */ -}; -#endif - static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, int offset, int num_steps, int step_size) { @@ -2620,10 +2578,6 @@ static int patch_vt1708S(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1708S_loopbacks; -#endif - /* correct names for VT1708BCE */ if (get_codec_type(codec) == VT1708BCE) { kfree(codec->chip_name); @@ -2654,16 +2608,6 @@ static const struct hda_verb vt1702_init_verbs[] = { { } }; -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1702_loopbacks[] = { - { 0x1A, HDA_INPUT, 1 }, - { 0x1A, HDA_INPUT, 2 }, - { 0x1A, HDA_INPUT, 3 }, - { 0x1A, HDA_INPUT, 4 }, - { } /* end */ -}; -#endif - static void set_widgets_power_state_vt1702(struct hda_codec *codec) { int imux_is_smixer = @@ -2725,10 +2669,6 @@ static int patch_vt1702(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1702_loopbacks; -#endif - spec->set_widgets_power_state = set_widgets_power_state_vt1702; return 0; } @@ -2744,16 +2684,6 @@ static const struct hda_verb vt1718S_init_verbs[] = { { } }; -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1718S_loopbacks[] = { - { 0x21, HDA_INPUT, 1 }, - { 0x21, HDA_INPUT, 2 }, - { 0x21, HDA_INPUT, 3 }, - { 0x21, HDA_INPUT, 4 }, - { } /* end */ -}; -#endif - static void set_widgets_power_state_vt1718S(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -2845,10 +2775,6 @@ static int patch_vt1718S(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1718S_loopbacks; -#endif - spec->set_widgets_power_state = set_widgets_power_state_vt1718S; return 0; @@ -2925,16 +2851,6 @@ static const struct hda_verb vt1716S_init_verbs[] = { { } }; -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1716S_loopbacks[] = { - { 0x16, HDA_INPUT, 1 }, - { 0x16, HDA_INPUT, 2 }, - { 0x16, HDA_INPUT, 3 }, - { 0x16, HDA_INPUT, 4 }, - { } /* end */ -}; -#endif - static void set_widgets_power_state_vt1716S(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3058,10 +2974,6 @@ static int patch_vt1716S(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1716S_loopbacks; -#endif - spec->set_widgets_power_state = set_widgets_power_state_vt1716S; return 0; } @@ -3088,15 +3000,6 @@ static const struct hda_verb vt1802_init_verbs[] = { { } }; -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt2002P_loopbacks[] = { - { 0x21, HDA_INPUT, 0 }, - { 0x21, HDA_INPUT, 1 }, - { 0x21, HDA_INPUT, 2 }, - { } /* end */ -}; -#endif - static void set_widgets_power_state_vt2002P(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3237,10 +3140,6 @@ static int patch_vt2002P(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt2002P_loopbacks; -#endif - spec->set_widgets_power_state = set_widgets_power_state_vt2002P; return 0; } @@ -3255,15 +3154,6 @@ static const struct hda_verb vt1812_init_verbs[] = { { } }; -#ifdef CONFIG_SND_HDA_POWER_SAVE -static const struct hda_amp_list vt1812_loopbacks[] = { - { 0x21, HDA_INPUT, 0 }, - { 0x21, HDA_INPUT, 1 }, - { 0x21, HDA_INPUT, 2 }, - { } /* end */ -}; -#endif - static void set_widgets_power_state_vt1812(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -3382,10 +3272,6 @@ static int patch_vt1812(struct hda_codec *codec) codec->patch_ops = via_patch_ops; -#ifdef CONFIG_SND_HDA_POWER_SAVE - spec->loopback.amplist = vt1812_loopbacks; -#endif - spec->set_widgets_power_state = set_widgets_power_state_vt1812; return 0; } From 6aadf41d6b9f8da68db5962929c07f816db15893 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 14:09:02 +0200 Subject: [PATCH 25/39] ALSA: hda - Name the primary out as Speaker when needed for VIA codecs When the primary output is the speaker output, rather name it as "Speaker". This will be more intuitive. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index bd6ffa602f22..6e621b7c984e 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1770,7 +1770,11 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) if (err < 0) return err; } else { - err = create_ch_ctls(codec, chname[i], pin, dac, 3); + const char *pfx = chname[i]; + if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && + cfg->line_outs == 1) + pfx = "Speaker"; + err = create_ch_ctls(codec, pfx, pin, dac, 3); if (err < 0) return err; } From c6191607871776e828b8bc47b944d0c425776951 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 14:11:59 +0200 Subject: [PATCH 26/39] ALSA: hda - Remove unused defines and struct fields in patch_via.c Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 6e621b7c984e..adb04c1c7053 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -56,34 +56,10 @@ #define NID_MAPPING (-1) -/* amp values */ -#define AMP_VAL_IDX_SHIFT 19 -#define AMP_VAL_IDX_MASK (0x0f<<19) - /* Pin Widget NID */ -#define VT1708_HP_NID 0x13 -#define VT1708_DIGOUT_NID 0x14 -#define VT1708_DIGIN_NID 0x16 -#define VT1708_DIGIN_PIN 0x26 #define VT1708_HP_PIN_NID 0x20 #define VT1708_CD_PIN_NID 0x24 -#define VT1709_HP_DAC_NID 0x28 -#define VT1709_DIGOUT_NID 0x13 -#define VT1709_DIGIN_NID 0x17 -#define VT1709_DIGIN_PIN 0x25 - -#define VT1708B_HP_NID 0x25 -#define VT1708B_DIGOUT_NID 0x12 -#define VT1708B_DIGIN_NID 0x15 -#define VT1708B_DIGIN_PIN 0x21 - -#define VT1708S_HP_NID 0x25 -#define VT1708S_DIGOUT_NID 0x12 - -#define VT1702_HP_NID 0x17 -#define VT1702_DIGOUT_NID 0x11 - enum VIA_HDA_CODEC { UNKNOWN = -1, VT1708, @@ -146,7 +122,6 @@ struct via_spec { hda_nid_t mux_nids[3]; hda_nid_t aa_mix_nid; hda_nid_t dig_in_nid; - hda_nid_t dig_in_pin; /* capture source */ const struct hda_input_mux *input_mux; From 47be05ce0a634779e1e86ec318a046f43dd6c602 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 15:10:28 +0200 Subject: [PATCH 27/39] ALSA: hda - Remove NID_MAPPING hacks in patch_via.c There is no longer virtual kmixer element for NID mapping. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index adb04c1c7053..6b4a6b7a6c7a 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -54,8 +54,6 @@ #include "hda_codec.h" #include "hda_local.h" -#define NID_MAPPING (-1) - /* Pin Widget NID */ #define VT1708_HP_PIN_NID 0x20 #define VT1708_CD_PIN_NID 0x24 @@ -1279,7 +1277,6 @@ static int via_build_controls(struct hda_codec *codec) { struct via_spec *spec = codec->spec; struct snd_kcontrol *kctl; - const struct snd_kcontrol_new *knew; int err, i; if (spec->set_widgets_power_state) @@ -1335,19 +1332,6 @@ static int via_build_controls(struct hda_codec *codec) return err; } - /* other nid->control mapping */ - for (i = 0; i < spec->num_mixers; i++) { - for (knew = spec->mixers[i]; knew->name; knew++) { - if (knew->iface != NID_MAPPING) - continue; - kctl = snd_hda_find_mixer_ctl(codec, knew->name); - if (kctl == NULL) - continue; - err = snd_hda_add_nid(codec, kctl, 0, - knew->subdevice); - } - } - /* init power states */ set_widgets_power_state(codec); analog_low_current_mode(codec, 1); From ada509ec00e4ae1bfc4e0fa8a5c14091df920dbc Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Jun 2011 15:40:19 +0200 Subject: [PATCH 28/39] ALSA: hda - Simplify analog-low-current mode check for VIA codecs Use the existing aa-loop list for simplifying the check for analog low-current mode. Also fix the stream count test for playback streams. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 125 +++++++++++++------------------------- 1 file changed, 43 insertions(+), 82 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 6b4a6b7a6c7a..819267a4e2df 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -108,6 +108,7 @@ struct via_spec { struct hda_multi_out multiout; hda_nid_t slave_dig_outs[2]; hda_nid_t hp_dac_nid; + int num_active_streams; struct nid_path out_path[4]; struct nid_path hp_path; @@ -157,11 +158,9 @@ struct via_spec { void (*set_widgets_power_state)(struct hda_codec *codec); -#ifdef CONFIG_SND_HDA_POWER_SAVE struct hda_loopback_check loopback; int num_loopbacks; struct hda_amp_list loopback_list[8]; -#endif }; static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); @@ -241,8 +240,8 @@ enum { VIA_CTL_WIDGET_ANALOG_MUTE, }; -static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); -static int is_aa_path_mute(struct hda_codec *codec); +static void analog_low_current_mode(struct hda_codec *codec); +static bool is_aa_path_mute(struct hda_codec *codec); static void vt1708_start_hp_work(struct via_spec *spec) { @@ -281,7 +280,7 @@ static int analog_input_switch_put(struct snd_kcontrol *kcontrol, struct hda_codec *codec = snd_kcontrol_chip(kcontrol); set_widgets_power_state(codec); - analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); + analog_low_current_mode(snd_kcontrol_chip(kcontrol)); if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { if (is_aa_path_mute(codec)) vt1708_start_hp_work(codec->spec); @@ -895,77 +894,33 @@ static int via_smart51_build(struct hda_codec *codec) return 0; } -/* check AA path's mute statue */ -static int is_aa_path_mute(struct hda_codec *codec) +/* check AA path's mute status */ +static bool is_aa_path_mute(struct hda_codec *codec) { - int mute = 1; - int start_idx; - int end_idx; - int i; struct via_spec *spec = codec->spec; - /* get nid of MW0 and start & end index */ - switch (spec->codec_type) { - case VT1708B_8CH: - case VT1708B_4CH: - case VT1708S: - case VT1716S: - start_idx = 2; - end_idx = 4; - break; - case VT1702: - start_idx = 1; - end_idx = 3; - break; - case VT1718S: - start_idx = 1; - end_idx = 3; - break; - case VT2002P: - case VT1812: - case VT1802: - start_idx = 0; - end_idx = 2; - break; - default: - return 0; - } - /* check AA path's mute status */ - for (i = start_idx; i <= end_idx; i++) { - unsigned int con_list = snd_hda_codec_read( - codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); - int shift = 8 * (i % 4); - hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; - unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); - if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { - /* check mute status while the pin is connected */ - int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0, - HDA_INPUT, i) >> 7; - int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1, - HDA_INPUT, i) >> 7; - if (!mute_l || !mute_r) { - mute = 0; - break; - } + const struct hda_amp_list *p; + int i, ch, v; + + for (i = 0; i < spec->num_loopbacks; i++) { + p = &spec->loopback_list[i]; + for (ch = 0; ch < 2; ch++) { + v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, + p->idx); + if (!(v & HDA_AMP_MUTE) && v > 0) + return false; } } - return mute; + return true; } /* enter/exit analog low-current mode */ -static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) +static void analog_low_current_mode(struct hda_codec *codec) { struct via_spec *spec = codec->spec; - static int saved_stream_idle = 1; /* saved stream idle status */ - int enable = is_aa_path_mute(codec); - unsigned int verb = 0; - unsigned int parm = 0; + bool enable; + unsigned int verb, parm; - if (stream_idle == -1) /* stream status did not change */ - enable = enable && saved_stream_idle; - else { - enable = enable && stream_idle; - saved_stream_idle = stream_idle; - } + enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0); /* decide low current mode's verb & parameter */ switch (spec->codec_type) { @@ -1006,12 +961,15 @@ static const struct hda_verb vt1708_init_verbs[] = { { } }; -static void substream_set_idle(struct hda_codec *codec, - struct snd_pcm_substream *substream) +static void set_stream_active(struct hda_codec *codec, bool active) { - int idle = substream->pstr->substream_opened == 1 - && substream->ref_count == 0; - analog_low_current_mode(codec, idle); + struct via_spec *spec = codec->spec; + + if (active) + spec->num_active_streams++; + else + spec->num_active_streams--; + analog_low_current_mode(codec); } static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo, @@ -1019,12 +977,19 @@ static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { struct via_spec *spec = codec->spec; + int err; if (!spec->hp_independent_mode) spec->multiout.hp_nid = spec->hp_dac_nid; - substream_set_idle(codec, substream); - return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, - hinfo); + set_stream_active(codec, true); + err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, + hinfo); + if (err < 0) { + spec->multiout.hp_nid = 0; + set_stream_active(codec, false); + return err; + } + return 0; } static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo, @@ -1034,7 +999,7 @@ static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo, struct via_spec *spec = codec->spec; spec->multiout.hp_nid = 0; - substream_set_idle(codec, substream); + set_stream_active(codec, false); return 0; } @@ -1048,7 +1013,7 @@ static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo, return -EINVAL; if (!spec->hp_independent_mode || spec->multiout.hp_nid) return -EBUSY; - substream_set_idle(codec, substream); + set_stream_active(codec, true); return 0; } @@ -1056,7 +1021,7 @@ static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) { - substream_set_idle(codec, substream); + set_stream_active(codec, false); return 0; } @@ -1334,7 +1299,7 @@ static int via_build_controls(struct hda_codec *codec) /* init power states */ set_widgets_power_state(codec); - analog_low_current_mode(codec, 1); + analog_low_current_mode(codec); via_free_kctls(codec); /* no longer needed */ return 0; @@ -1860,7 +1825,6 @@ static const struct snd_kcontrol_new via_input_src_ctl = { .put = via_mux_enum_put, }; -#ifdef CONFIG_SND_HDA_POWER_SAVE static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) { struct hda_amp_list *list; @@ -1874,9 +1838,6 @@ static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) spec->num_loopbacks++; spec->loopback.amplist = spec->loopback_list; } -#else -#define add_loopback_list(spec, mix, idx) /* NOP */ -#endif /* create playback/capture controls for input pins */ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, From 30f7c5d491ec2d515148882fa0b4080ab61d4bb0 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 08:37:41 +0200 Subject: [PATCH 29/39] ALSA: hda - Use xxx Boost Volume for VIA Drop "Capture" prefix from the mic-boost names. Otherwise some control names can overflow the max name length. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 819267a4e2df..51e7ce010543 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1947,7 +1947,7 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) continue; label = hda_get_autocfg_input_label(codec, cfg, i); - snprintf(name, sizeof(name), "%s Boost Capture Volume", label); + snprintf(name, sizeof(name), "%s Boost Volume", label); err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); if (err < 0) From 8e3679dca200a326426a92d998b63cab5a17c52d Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 09:01:36 +0200 Subject: [PATCH 30/39] ALSA: hda - Revisit output_path parsing in patch_via.c Change the order of the output-path list in a way from the DAC to the target pin. Also now the list include the target pin, too. Together with this format change, simplify the arguments of parse_output_path() function, and fix the initialization in via_auto_init_output(). Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 87 ++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 51e7ce010543..e445a4d24778 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -81,10 +81,12 @@ enum VIA_HDA_CODEC { (spec)->codec_type == VT1812 ||\ (spec)->codec_type == VT1802) +#define MAX_NID_PATH_DEPTH 5 + struct nid_path { int depth; - hda_nid_t path[5]; - short idx[5]; + hda_nid_t path[MAX_NID_PATH_DEPTH]; + short idx[MAX_NID_PATH_DEPTH]; }; struct via_spec { @@ -415,15 +417,22 @@ static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid, return; /* select the route explicitly when multiple connections exist */ - if (num_conns > 1) + if (num_conns > 1 && + get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX) snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx); + /* unmute if the input amp is present */ - if (!(query_amp_caps(codec, nid, HDA_INPUT) & - (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))) - return; - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, - AMP_IN_UNMUTE(idx)); + if (query_amp_caps(codec, nid, HDA_INPUT) & + (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)) + snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, + AMP_IN_UNMUTE(idx)); + + /* unmute the src output */ + if (query_amp_caps(codec, src, HDA_OUTPUT) & + (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)) + snd_hda_codec_write(codec, src, 0, AC_VERB_SET_AMP_GAIN_MUTE, + AMP_OUT_UNMUTE); /* unmute AA-path if present */ if (!mix) @@ -469,15 +478,9 @@ static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin, } /* initialize the output path */ - nid = pin; - for (i = 0; i < path->depth; i++) { - unmute_and_select(codec, nid, path->idx[i], spec->aa_mix_nid); - nid = path->path[i]; - if (query_amp_caps(codec, nid, HDA_OUTPUT) & - (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)) - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_AMP_GAIN_MUTE, - AMP_OUT_UNMUTE); + for (i = path->depth - 1; i > 0; i--) { + nid = path->path[i - 1]; + unmute_and_select(codec, path->path[i], nid, spec->aa_mix_nid); } } @@ -1544,7 +1547,7 @@ static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac) return true; } -static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, +static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid, hda_nid_t target_dac, struct nid_path *path, int depth, int wid_type) { @@ -1556,13 +1559,13 @@ static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) continue; if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { - path->path[depth] = conn[i]; - path->idx[depth] = i; - path->depth = ++depth; + path->path[0] = conn[i]; + path->idx[0] = i; + path->depth = 1; return true; } } - if (depth > 4) + if (depth >= MAX_NID_PATH_DEPTH) return false; for (i = 0; i < nums; i++) { unsigned int type; @@ -1570,16 +1573,28 @@ static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, if (type == AC_WID_AUD_OUT || (wid_type != -1 && type != wid_type)) continue; - if (parse_output_path(codec, conn[i], target_dac, + if (__parse_output_path(codec, conn[i], target_dac, path, depth + 1, AC_WID_AUD_SEL)) { - path->path[depth] = conn[i]; - path->idx[depth] = i; + path->path[path->depth] = conn[i]; + path->idx[path->depth] = i; + path->depth++; return true; } } return false; } +static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, + hda_nid_t target_dac, struct nid_path *path) +{ + if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) { + path->path[path->depth] = nid; + path->depth++; + return true; + } + return false; +} + static int via_auto_fill_dac_nids(struct hda_codec *codec) { struct via_spec *spec = codec->spec; @@ -1593,9 +1608,8 @@ static int via_auto_fill_dac_nids(struct hda_codec *codec) nid = cfg->line_out_pins[i]; if (!nid) continue; - if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1)) - spec->private_dac_nids[i] = - spec->out_path[i].path[spec->out_path[i].depth - 1]; + if (parse_output_path(codec, nid, 0, &spec->out_path[i])) + spec->private_dac_nids[i] = spec->out_path[i].path[0]; } return 0; } @@ -1748,15 +1762,14 @@ static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) if (!pin) return 0; - if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) { - spec->hp_dac_nid = spec->hp_path.path[spec->hp_path.depth - 1]; - spec->hp_independent_mode_index = - spec->hp_path.idx[spec->hp_path.depth - 1]; + if (parse_output_path(codec, pin, 0, &spec->hp_path)) { + spec->hp_dac_nid = spec->hp_path.path[0]; + spec->hp_independent_mode_index = spec->hp_path.idx[0]; create_hp_imux(spec); } if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], - &spec->hp_dep_path, 0, -1) && + &spec->hp_dep_path) && !spec->hp_dac_nid) return 0; @@ -1777,14 +1790,14 @@ static int via_auto_create_speaker_ctls(struct hda_codec *codec) if (!spec->autocfg.speaker_outs || !pin) return 0; - if (parse_output_path(codec, pin, 0, &spec->speaker_path, 0, -1)) { - dac = spec->speaker_path.path[spec->speaker_path.depth - 1]; + if (parse_output_path(codec, pin, 0, &spec->speaker_path)) { + dac = spec->speaker_path.path[0]; spec->multiout.extra_out_nid[0] = dac; return create_ch_ctls(codec, "Speaker", pin, dac, 3); } if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], - &spec->speaker_path, 0, -1)) - return create_ch_ctls(codec, "Headphone", pin, 0, 3); + &spec->speaker_path)) + return create_ch_ctls(codec, "Speaker", pin, 0, 3); return 0; } From a00a5fad9ddbabc7cd03d143520b9a4730edc75d Mon Sep 17 00:00:00 2001 From: Lydia Wang Date: Tue, 21 Jun 2011 16:11:11 +0800 Subject: [PATCH 31/39] ALSA: hda - Fix creations of playback volume controls in patch_via.c Fix a issue to create playback volume control if pin has amplifier capability but not DAC. Signed-off-by: Lydia Wang Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index e445a4d24778..853d24411d53 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1631,7 +1631,7 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, if (nid) { sprintf(name, "%s Playback Volume", pfx); err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT)); + HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); if (err < 0) return err; } From 8df2a3129d946dc91f9824958567a990329822b3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 11:48:29 +0200 Subject: [PATCH 32/39] ALSA: hda - Fix re-routing of HP-independent mode in patch_via.c Re-route the whole output path when HP-independent mode is changed. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 101 ++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 853d24411d53..7b353405e068 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -138,9 +138,7 @@ struct via_spec { hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; /* HP mode source */ - const struct hda_input_mux *hp_mux; unsigned int hp_independent_mode; - unsigned int hp_independent_mode_index; unsigned int dmic_enabled; unsigned int no_pin_power_ctl; enum VIA_HDA_CODEC codec_type; @@ -406,6 +404,24 @@ static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux, #define get_connection_index(codec, mux, nid) \ __get_connection_index(codec, mux, nid, NULL) +static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, + unsigned int mask) +{ + unsigned int caps = get_wcaps(codec, nid); + if (dir == HDA_INPUT) + caps &= AC_WCAP_IN_AMP; + else + caps &= AC_WCAP_OUT_AMP; + if (!caps) + return false; + if (query_amp_caps(codec, nid, dir) & mask) + return true; + return false; +} + +#define have_vol_or_mute(codec, nid, dir) \ + check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE) + /* unmute input amp and select the specificed source */ static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid, hda_nid_t src, hda_nid_t mix) @@ -423,22 +439,20 @@ static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid, AC_VERB_SET_CONNECT_SEL, idx); /* unmute if the input amp is present */ - if (query_amp_caps(codec, nid, HDA_INPUT) & - (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)) + if (have_vol_or_mute(codec, nid, HDA_INPUT)) snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(idx)); /* unmute the src output */ - if (query_amp_caps(codec, src, HDA_OUTPUT) & - (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)) + if (have_vol_or_mute(codec, src, HDA_OUTPUT)) snd_hda_codec_write(codec, src, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); /* unmute AA-path if present */ - if (!mix) + if (!mix || mix == src) return; idx = __get_connection_index(codec, nid, mix, NULL); - if (idx >= 0) + if (idx >= 0 && have_vol_or_mute(codec, nid, HDA_INPUT)) snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(idx)); @@ -694,9 +708,16 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol, static int via_independent_hp_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { - struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - struct via_spec *spec = codec->spec; - return snd_hda_input_mux_info(spec->hp_mux, uinfo); + static const char * const texts[] = { "OFF", "ON" }; + + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; + uinfo->count = 1; + uinfo->value.enumerated.items = 2; + if (uinfo->value.enumerated.item >= 2) + uinfo->value.enumerated.item = 1; + strcpy(uinfo->value.enumerated.name, + texts[uinfo->value.enumerated.item]); + return 0; } static int via_independent_hp_get(struct snd_kcontrol *kcontrol, @@ -714,12 +735,28 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol, { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct via_spec *spec = codec->spec; - hda_nid_t nid = kcontrol->private_value; - unsigned int pinsel = ucontrol->value.enumerated.item[0]; - /* Get Independent Mode index of headphone pin widget */ - spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel - ? 1 : 0; - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel); + hda_nid_t nid, src; + int i, idx, num_conns; + struct nid_path *path; + + spec->hp_independent_mode = !!ucontrol->value.enumerated.item[0]; + if (spec->hp_independent_mode) + path = &spec->hp_path; + else + path = &spec->hp_dep_path; + + /* re-route the output path */ + for (i = path->depth - 1; i > 0; i--) { + nid = path->path[i]; + src = path->path[i - 1]; + idx = __get_connection_index(codec, nid, src, &num_conns); + if (idx < 0) + continue; + if (num_conns > 1 && + get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX) + snd_hda_codec_write(codec, nid, 0, + AC_VERB_SET_CONNECT_SEL, idx); + } /* update jack power state */ set_widgets_power_state(codec); @@ -746,7 +783,6 @@ static int via_hp_build(struct hda_codec *codec) return -ENOMEM; knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; - knew->private_value = nid; return 0; } @@ -1622,9 +1658,9 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, hda_nid_t nid; int err; - if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) + if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) nid = dac; - else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) + else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) nid = pin; else nid = 0; @@ -1636,9 +1672,9 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, return err; } - if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE) + if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE)) nid = dac; - else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE) + else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE)) nid = pin; else nid = 0; @@ -1741,19 +1777,6 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) return 0; } -static void create_hp_imux(struct via_spec *spec) -{ - int i; - struct hda_input_mux *imux = &spec->private_imux[1]; - static const char * const texts[] = { "OFF", "ON", NULL}; - - /* for hp mode select */ - for (i = 0; texts[i]; i++) - snd_hda_add_imux_item(imux, texts[i], i, NULL); - - spec->hp_mux = &spec->private_imux[1]; -} - static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) { struct via_spec *spec = codec->spec; @@ -1762,18 +1785,14 @@ static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) if (!pin) return 0; - if (parse_output_path(codec, pin, 0, &spec->hp_path)) { + if (parse_output_path(codec, pin, 0, &spec->hp_path)) spec->hp_dac_nid = spec->hp_path.path[0]; - spec->hp_independent_mode_index = spec->hp_path.idx[0]; - create_hp_imux(spec); - } if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], &spec->hp_dep_path) && !spec->hp_dac_nid) return 0; - err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3); if (err < 0) return err; @@ -2068,7 +2087,7 @@ static int via_parse_auto_config(struct hda_codec *codec) spec->input_mux = &spec->private_imux[0]; - if (spec->hp_mux) { + if (spec->hp_dac_nid && spec->hp_dep_path.depth) { err = via_hp_build(codec); if (err < 0) return err; From 0f98c24b807f024d42cf743897e2c1d95ff1e8be Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 12:51:33 +0200 Subject: [PATCH 33/39] ALSA: hda - Assign smart51 only in the same stack for VIA codecs The input jacks assigned as the smart51 outputs must be in the same stack, either rear, front or other. Also, prefer line-in as the surround to mic-in. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 61 +++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 7b353405e068..785f7f5022a4 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -822,26 +822,6 @@ static void mute_aa_path(struct hda_codec *codec, int mute) } } -static bool is_smart51_candidate(struct hda_codec *codec, hda_nid_t pin) -{ - struct via_spec *spec = codec->spec; - const struct auto_pin_cfg *cfg = &spec->autocfg; - int i; - - for (i = 0; i < cfg->num_inputs; i++) { - unsigned int defcfg; - if (pin != cfg->inputs[i].pin) - continue; - if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) - return false; - defcfg = snd_hda_codec_get_pincfg(codec, pin); - if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL) - return false; - return true; - } - return false; -} - static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) { struct via_spec *spec = codec->spec; @@ -1692,21 +1672,38 @@ static void mangle_smart51(struct hda_codec *codec) { struct via_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; - int i, nums = 0; + struct auto_pin_cfg_item *ins = cfg->inputs; + int i, j, nums, attr; + int pins[AUTO_CFG_MAX_INS]; - for (i = 0; i < cfg->num_inputs; i++) { - if (is_smart51_candidate(codec, cfg->inputs[i].pin)) + for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) { + nums = 0; + for (i = 0; i < cfg->num_inputs; i++) { + unsigned int def; + if (ins[i].type > AUTO_PIN_LINE_IN) + continue; + def = snd_hda_codec_get_pincfg(codec, ins[i].pin); + if (snd_hda_get_input_pin_attr(def) != attr) + continue; + for (j = 0; j < nums; j++) + if (ins[pins[j]].type < ins[i].type) { + memmove(pins + j + 1, pins + j, + (nums - j - 1) * sizeof(int)); + break; + } + pins[j] = i; nums++; - } - if (cfg->line_outs + nums < 3) - return; - for (i = 0; i < cfg->num_inputs; i++) { - if (!is_smart51_candidate(codec, cfg->inputs[i].pin)) + } + if (cfg->line_outs + nums < 3) continue; - spec->smart51_pins[spec->smart51_nums++] = cfg->inputs[i].pin; - cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin; - if (cfg->line_outs == 3) - break; + for (i = 0; i < nums; i++) { + hda_nid_t pin = ins[pins[i]].pin; + spec->smart51_pins[spec->smart51_nums++] = pin; + cfg->line_out_pins[cfg->line_outs++] = pin; + if (cfg->line_outs == 3) + break; + } + return; } } From 1e11cae143e4c0a4fc77fe532e18c550d63ab02d Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 12:57:22 +0200 Subject: [PATCH 34/39] ALSA: hda - Fix the check of loopback-mixer element index in patch_via.c Fix the check of the multiple loopback-mixer, which gave sometimes a wrong index assigned to an element even for different names, e.g. Mic and Front Mic. Now check the label properly for avoid duplication. Reported-by: David Henningsson Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 785f7f5022a4..b67a5768a9de 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -1875,6 +1875,7 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, struct via_spec *spec = codec->spec; struct hda_input_mux *imux = &spec->private_imux[0]; int i, j, err, idx, idx2, type, type_idx = 0; + const char *prev_label = NULL; hda_nid_t cap_nid; hda_nid_t pin_idxs[8]; int num_idxs; @@ -1908,11 +1909,12 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, break; if (idx >= num_idxs) continue; - if (i > 0 && type == cfg->inputs[i - 1].type) + label = hda_get_autocfg_input_label(codec, cfg, i); + if (prev_label && !strcmp(label, prev_label)) type_idx++; else type_idx = 0; - label = hda_get_autocfg_input_label(codec, cfg, i); + prev_label = label; idx2 = get_connection_index(codec, spec->aa_mix_nid, pin_idxs[idx]); if (idx2 >= 0) { From a934d5a983528543850c90b29bedbdfd71f7097b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 14:22:14 +0200 Subject: [PATCH 35/39] ALSA: hda - Fix surround-volume parsing for VT1708B codecs The surround/CLFE/side DACs on VT1708B and co have no amp but the connected selector widgets have the amp instead. Fix the parser to check these selector widgets for the possible mixer controls as well. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index b67a5768a9de..5b907b356951 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -407,7 +407,10 @@ static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux, static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, unsigned int mask) { - unsigned int caps = get_wcaps(codec, nid); + unsigned int caps; + if (!nid) + return false; + caps = get_wcaps(codec, nid); if (dir == HDA_INPUT) caps &= AC_WCAP_IN_AMP; else @@ -1635,13 +1638,21 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, { struct via_spec *spec = codec->spec; char name[32]; - hda_nid_t nid; - int err; + hda_nid_t nid, sel, conn[8]; + int nums, err; + + /* check selector widget connected to the pin */ + sel = 0; + nums = snd_hda_get_connections(codec, pin, conn, ARRAY_SIZE(conn)); + if (nums == 1 && conn[0] != pin) + sel = conn[0]; if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) nid = dac; else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) nid = pin; + else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) + nid = sel; else nid = 0; if (nid) { @@ -1656,6 +1667,8 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, nid = dac; else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE)) nid = pin; + else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE)) + nid = sel; else nid = 0; if (nid) { From 09a9ad69a5467fbda3fd358d2be155c22aa416e4 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 15:57:44 +0200 Subject: [PATCH 36/39] ALSA: hda - VT1708 independent HP routing fix The codecs like VT1708 needs more complicated routing using the mixer widget rather than the simple selector widgets. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 222 +++++++++++++++++++++----------------- 1 file changed, 122 insertions(+), 100 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 5b907b356951..bceb6b2364fe 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -83,10 +83,20 @@ enum VIA_HDA_CODEC { #define MAX_NID_PATH_DEPTH 5 +/* output-path: DAC -> ... -> pin + * idx[] contains the source index number of the next widget; + * e.g. idx[0] is the index of the DAC selected by path[1] widget + * multi[] indicates whether it's a selector widget with multi-connectors + * (i.e. the connection selection is mandatory) + * vol_ctl and mute_ctl contains the NIDs for the assigned mixers + */ struct nid_path { int depth; hda_nid_t path[MAX_NID_PATH_DEPTH]; - short idx[MAX_NID_PATH_DEPTH]; + unsigned char idx[MAX_NID_PATH_DEPTH]; + unsigned char multi[MAX_NID_PATH_DEPTH]; + unsigned int vol_ctl; + unsigned int mute_ctl; }; struct via_spec { @@ -422,43 +432,39 @@ static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, return false; } -#define have_vol_or_mute(codec, nid, dir) \ - check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE) +#define have_mute(codec, nid, dir) \ + check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) -/* unmute input amp and select the specificed source */ -static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid, - hda_nid_t src, hda_nid_t mix) +/* enable/disable the output-route */ +static void activate_output_path(struct hda_codec *codec, struct nid_path *path, + bool enable, bool force) { - int idx, num_conns; - - idx = __get_connection_index(codec, nid, src, &num_conns); - if (idx < 0) - return; - - /* select the route explicitly when multiple connections exist */ - if (num_conns > 1 && - get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX) - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_CONNECT_SEL, idx); - - /* unmute if the input amp is present */ - if (have_vol_or_mute(codec, nid, HDA_INPUT)) - snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, - AMP_IN_UNMUTE(idx)); - - /* unmute the src output */ - if (have_vol_or_mute(codec, src, HDA_OUTPUT)) - snd_hda_codec_write(codec, src, 0, AC_VERB_SET_AMP_GAIN_MUTE, - AMP_OUT_UNMUTE); - - /* unmute AA-path if present */ - if (!mix || mix == src) - return; - idx = __get_connection_index(codec, nid, mix, NULL); - if (idx >= 0 && have_vol_or_mute(codec, nid, HDA_INPUT)) - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_AMP_GAIN_MUTE, - AMP_IN_UNMUTE(idx)); + int i; + for (i = 0; i < path->depth; i++) { + hda_nid_t src, dst; + int idx = path->idx[i]; + src = path->path[i]; + if (i < path->depth - 1) + dst = path->path[i + 1]; + else + dst = 0; + if (enable && path->multi[i]) + snd_hda_codec_write(codec, dst, 0, + AC_VERB_SET_CONNECT_SEL, idx); + if (have_mute(codec, dst, HDA_INPUT)) { + int val = enable ? AMP_IN_UNMUTE(idx) : + AMP_IN_MUTE(idx); + snd_hda_codec_write(codec, dst, 0, + AC_VERB_SET_AMP_GAIN_MUTE, val); + } + if (!force && (src == path->vol_ctl || src == path->mute_ctl)) + continue; + if (have_mute(codec, src, HDA_OUTPUT)) { + int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE; + snd_hda_codec_write(codec, src, 0, + AC_VERB_SET_AMP_GAIN_MUTE, val); + } + } } /* set the given pin as output */ @@ -474,16 +480,18 @@ static void init_output_pin(struct hda_codec *codec, hda_nid_t pin, AC_VERB_SET_EAPD_BTLENABLE, 0x02); } -static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin, - int pin_type, struct nid_path *path) +static void via_auto_init_output(struct hda_codec *codec, + struct nid_path *path, int pin_type, + bool force) { struct via_spec *spec = codec->spec; unsigned int caps; - hda_nid_t nid; - int i; + hda_nid_t pin, nid; + int i, idx; - if (!pin) + if (!path->depth) return; + pin = path->path[path->depth - 1]; init_output_pin(codec, pin, pin_type); caps = query_amp_caps(codec, pin, HDA_OUTPUT); @@ -494,34 +502,48 @@ static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin, AMP_OUT_MUTE | val); } - /* initialize the output path */ + activate_output_path(codec, path, true, force); + + /* initialize the AA-path */ + if (!spec->aa_mix_nid) + return; for (i = path->depth - 1; i > 0; i--) { - nid = path->path[i - 1]; - unmute_and_select(codec, path->path[i], nid, spec->aa_mix_nid); + nid = path->path[i]; + idx = get_connection_index(codec, nid, spec->aa_mix_nid); + if (idx >= 0) { + if (have_mute(codec, nid, HDA_INPUT)) + snd_hda_codec_write(codec, nid, 0, + AC_VERB_SET_AMP_GAIN_MUTE, + AMP_IN_UNMUTE(idx)); + break; + } } } - static void via_auto_init_multi_out(struct hda_codec *codec) { struct via_spec *spec = codec->spec; int i; for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) - via_auto_init_output(codec, spec->autocfg.line_out_pins[i], - PIN_OUT, &spec->out_path[i]); + via_auto_init_output(codec, &spec->out_path[i], PIN_OUT, true); } static void via_auto_init_hp_out(struct hda_codec *codec) { struct via_spec *spec = codec->spec; - if (spec->hp_dac_nid) - via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP, - &spec->hp_path); - else - via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP, - &spec->hp_dep_path); + if (!spec->hp_dac_nid) { + via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true); + return; + } + if (spec->hp_independent_mode) { + activate_output_path(codec, &spec->hp_dep_path, false, false); + via_auto_init_output(codec, &spec->hp_path, PIN_HP, true); + } else { + activate_output_path(codec, &spec->hp_path, false, false); + via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true); + } } static void via_auto_init_speaker_out(struct hda_codec *codec) @@ -529,8 +551,7 @@ static void via_auto_init_speaker_out(struct hda_codec *codec) struct via_spec *spec = codec->spec; if (spec->autocfg.speaker_outs) - via_auto_init_output(codec, spec->autocfg.speaker_pins[0], - PIN_OUT, &spec->speaker_path); + via_auto_init_output(codec, &spec->speaker_path, PIN_OUT, true); } static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); @@ -738,27 +759,14 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol, { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct via_spec *spec = codec->spec; - hda_nid_t nid, src; - int i, idx, num_conns; - struct nid_path *path; spec->hp_independent_mode = !!ucontrol->value.enumerated.item[0]; - if (spec->hp_independent_mode) - path = &spec->hp_path; - else - path = &spec->hp_dep_path; - - /* re-route the output path */ - for (i = path->depth - 1; i > 0; i--) { - nid = path->path[i]; - src = path->path[i - 1]; - idx = __get_connection_index(codec, nid, src, &num_conns); - if (idx < 0) - continue; - if (num_conns > 1 && - get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX) - snd_hda_codec_write(codec, nid, 0, - AC_VERB_SET_CONNECT_SEL, idx); + if (spec->hp_independent_mode) { + activate_output_path(codec, &spec->hp_dep_path, false, false); + activate_output_path(codec, &spec->hp_path, true, false); + } else { + activate_output_path(codec, &spec->hp_path, false, false); + activate_output_path(codec, &spec->hp_dep_path, true, false); } /* update jack power state */ @@ -1577,12 +1585,8 @@ static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid, for (i = 0; i < nums; i++) { if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) continue; - if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { - path->path[0] = conn[i]; - path->idx[0] = i; - path->depth = 1; - return true; - } + if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) + goto found; } if (depth >= MAX_NID_PATH_DEPTH) return false; @@ -1593,14 +1597,18 @@ static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid, (wid_type != -1 && type != wid_type)) continue; if (__parse_output_path(codec, conn[i], target_dac, - path, depth + 1, AC_WID_AUD_SEL)) { - path->path[path->depth] = conn[i]; - path->idx[path->depth] = i; - path->depth++; - return true; - } + path, depth + 1, AC_WID_AUD_SEL)) + goto found; } return false; + + found: + path->path[path->depth] = conn[i]; + path->idx[path->depth] = i; + if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX) + path->multi[path->depth] = 1; + path->depth++; + return true; } static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, @@ -1634,18 +1642,16 @@ static int via_auto_fill_dac_nids(struct hda_codec *codec) } static int create_ch_ctls(struct hda_codec *codec, const char *pfx, - hda_nid_t pin, hda_nid_t dac, int chs) + int chs, bool check_dac, struct nid_path *path) { struct via_spec *spec = codec->spec; char name[32]; - hda_nid_t nid, sel, conn[8]; - int nums, err; + hda_nid_t dac, pin, sel, nid; + int err; - /* check selector widget connected to the pin */ - sel = 0; - nums = snd_hda_get_connections(codec, pin, conn, ARRAY_SIZE(conn)); - if (nums == 1 && conn[0] != pin) - sel = conn[0]; + dac = check_dac ? path->path[0] : 0; + pin = path->path[path->depth - 1]; + sel = path->depth > 1 ? path->path[1] : 0; if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) nid = dac; @@ -1661,6 +1667,7 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); if (err < 0) return err; + path->vol_ctl = nid; } if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE)) @@ -1677,6 +1684,7 @@ static int create_ch_ctls(struct hda_codec *codec, const char *pfx, HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); if (err < 0) return err; + path->mute_ctl = nid; } return 0; } @@ -1747,10 +1755,12 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) if (!pin || !dac) continue; if (i == HDA_CLFE) { - err = create_ch_ctls(codec, "Center", pin, dac, 1); + err = create_ch_ctls(codec, "Center", 1, true, + &spec->out_path[i]); if (err < 0) return err; - err = create_ch_ctls(codec, "LFE", pin, dac, 2); + err = create_ch_ctls(codec, "LFE", 2, true, + &spec->out_path[i]); if (err < 0) return err; } else { @@ -1758,7 +1768,8 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->line_outs == 1) pfx = "Speaker"; - err = create_ch_ctls(codec, pfx, pin, dac, 3); + err = create_ch_ctls(codec, pfx, 3, true, + &spec->out_path[i]); if (err < 0) return err; } @@ -1790,6 +1801,7 @@ static int via_auto_create_multi_out_ctls(struct hda_codec *codec) static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) { struct via_spec *spec = codec->spec; + struct nid_path *path; int err; if (!pin) @@ -1803,9 +1815,17 @@ static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) !spec->hp_dac_nid) return 0; - err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3); + if (spec->hp_dac_nid) + path = &spec->hp_path; + else + path = &spec->hp_dep_path; + err = create_ch_ctls(codec, "Headphone", 3, false, path); if (err < 0) return err; + if (spec->hp_dac_nid) { + spec->hp_dep_path.vol_ctl = spec->hp_path.vol_ctl; + spec->hp_dep_path.mute_ctl = spec->hp_path.mute_ctl; + } return 0; } @@ -1822,11 +1842,13 @@ static int via_auto_create_speaker_ctls(struct hda_codec *codec) if (parse_output_path(codec, pin, 0, &spec->speaker_path)) { dac = spec->speaker_path.path[0]; spec->multiout.extra_out_nid[0] = dac; - return create_ch_ctls(codec, "Speaker", pin, dac, 3); + return create_ch_ctls(codec, "Speaker", 3, true, + &spec->speaker_path); } if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], &spec->speaker_path)) - return create_ch_ctls(codec, "Speaker", pin, 0, 3); + return create_ch_ctls(codec, "Speaker", 3, false, + &spec->speaker_path); return 0; } From ddd304d8be4ffbb3662a92da515b1c74376b2280 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 16:33:55 +0200 Subject: [PATCH 37/39] ALSA: hda - Remove redundant VT1709 and VT1708B codes Unify the VT1709 10ch and 6ch parsers, as well as VT1708B 8ch and 4ch parsers. They have no difference now. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 86 +++++++++------------------------------ 1 file changed, 19 insertions(+), 67 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index bceb6b2364fe..899b96631312 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -2291,32 +2291,7 @@ static int patch_vt1708(struct hda_codec *codec) return 0; } -static int patch_vt1709_10ch(struct hda_codec *codec) -{ - struct via_spec *spec; - int err; - - /* create a codec specific record */ - spec = via_new_spec(codec); - if (spec == NULL) - return -ENOMEM; - - spec->aa_mix_nid = 0x18; - - err = via_parse_auto_config(codec); - if (err < 0) { - via_free(codec); - return err; - } - - codec->patch_ops = via_patch_ops; - - return 0; -} -/* - * generic initialization of ADC, input mixers and output mixers - */ -static int patch_vt1709_6ch(struct hda_codec *codec) +static int patch_vt1709(struct hda_codec *codec) { struct via_spec *spec; int err; @@ -2420,13 +2395,14 @@ static void set_widgets_power_state_vt1708B(struct hda_codec *codec) } static int patch_vt1708S(struct hda_codec *codec); -static int patch_vt1708B_8ch(struct hda_codec *codec) +static int patch_vt1708B(struct hda_codec *codec) { struct via_spec *spec; int err; if (get_codec_type(codec) == VT1708BCE) return patch_vt1708S(codec); + /* create a codec specific record */ spec = via_new_spec(codec); if (spec == NULL) @@ -2448,30 +2424,6 @@ static int patch_vt1708B_8ch(struct hda_codec *codec) return 0; } -static int patch_vt1708B_4ch(struct hda_codec *codec) -{ - struct via_spec *spec; - int err; - - /* create a codec specific record */ - spec = via_new_spec(codec); - if (spec == NULL) - return -ENOMEM; - - /* automatic parse from the BIOS config */ - err = via_parse_auto_config(codec); - if (err < 0) { - via_free(codec); - return err; - } - - codec->patch_ops = via_patch_ops; - - spec->set_widgets_power_state = set_widgets_power_state_vt1708B; - - return 0; -} - /* Patch for VT1708S */ static const struct hda_verb vt1708S_init_verbs[] = { /* Enable Mic Boost Volume backdoor */ @@ -3275,37 +3227,37 @@ static const struct hda_codec_preset snd_hda_preset_via[] = { { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, { .id = 0x1106e710, .name = "VT1709 10-Ch", - .patch = patch_vt1709_10ch}, + .patch = patch_vt1709}, { .id = 0x1106e711, .name = "VT1709 10-Ch", - .patch = patch_vt1709_10ch}, + .patch = patch_vt1709}, { .id = 0x1106e712, .name = "VT1709 10-Ch", - .patch = patch_vt1709_10ch}, + .patch = patch_vt1709}, { .id = 0x1106e713, .name = "VT1709 10-Ch", - .patch = patch_vt1709_10ch}, + .patch = patch_vt1709}, { .id = 0x1106e714, .name = "VT1709 6-Ch", - .patch = patch_vt1709_6ch}, + .patch = patch_vt1709}, { .id = 0x1106e715, .name = "VT1709 6-Ch", - .patch = patch_vt1709_6ch}, + .patch = patch_vt1709}, { .id = 0x1106e716, .name = "VT1709 6-Ch", - .patch = patch_vt1709_6ch}, + .patch = patch_vt1709}, { .id = 0x1106e717, .name = "VT1709 6-Ch", - .patch = patch_vt1709_6ch}, + .patch = patch_vt1709}, { .id = 0x1106e720, .name = "VT1708B 8-Ch", - .patch = patch_vt1708B_8ch}, + .patch = patch_vt1708B}, { .id = 0x1106e721, .name = "VT1708B 8-Ch", - .patch = patch_vt1708B_8ch}, + .patch = patch_vt1708B}, { .id = 0x1106e722, .name = "VT1708B 8-Ch", - .patch = patch_vt1708B_8ch}, + .patch = patch_vt1708B}, { .id = 0x1106e723, .name = "VT1708B 8-Ch", - .patch = patch_vt1708B_8ch}, + .patch = patch_vt1708B}, { .id = 0x1106e724, .name = "VT1708B 4-Ch", - .patch = patch_vt1708B_4ch}, + .patch = patch_vt1708B}, { .id = 0x1106e725, .name = "VT1708B 4-Ch", - .patch = patch_vt1708B_4ch}, + .patch = patch_vt1708B}, { .id = 0x1106e726, .name = "VT1708B 4-Ch", - .patch = patch_vt1708B_4ch}, + .patch = patch_vt1708B}, { .id = 0x1106e727, .name = "VT1708B 4-Ch", - .patch = patch_vt1708B_4ch}, + .patch = patch_vt1708B}, { .id = 0x11060397, .name = "VT1708S", .patch = patch_vt1708S}, { .id = 0x11061397, .name = "VT1708S", From f2b1c9f031d6b7604f861223f9e7024e6597b201 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 21 Jun 2011 16:52:39 +0200 Subject: [PATCH 38/39] ALSA: hda - Auto-mute smart51 surround pins for VIA codecs When smart51 mode is enabled, auto-mute these surround outputs as well as the primary line-out. Also this patch includes minor clean-ups. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index 899b96631312..af47b9aca974 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -844,33 +844,13 @@ static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) return false; } -static int via_smart51_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - uinfo->count = 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 1; - return 0; -} - static int via_smart51_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct via_spec *spec = codec->spec; - int on = 1; - int i; - for (i = 0; i < spec->smart51_nums; i++) { - hda_nid_t nid = spec->smart51_pins[i]; - unsigned int ctl; - ctl = snd_hda_codec_read(codec, nid, 0, - AC_VERB_GET_PIN_WIDGET_CONTROL, 0); - if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) - on = 0; - } - *ucontrol->value.integer.value = on; + *ucontrol->value.integer.value = spec->smart51_enabled; return 0; } @@ -908,7 +888,7 @@ static const struct snd_kcontrol_new via_smart51_mixer = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Smart 5.1", .count = 1, - .info = via_smart51_info, + .info = snd_ctl_boolean_mono_info, .get = via_smart51_get, .put = via_smart51_put, }; @@ -1450,8 +1430,13 @@ static void via_hp_automute(struct hda_codec *codec) struct via_spec *spec = codec->spec; if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) { + int nums; present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); - toggle_output_mutes(codec, spec->autocfg.line_outs, + if (spec->smart51_enabled) + nums = spec->autocfg.line_outs + spec->smart51_nums; + else + nums = spec->autocfg.line_outs; + toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present); } From a86a88eaf6db7bcc3900d0b7d4755474cc73201f Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 22 Jun 2011 15:23:25 +0200 Subject: [PATCH 39/39] ALSA: hda - Implement dynamic-ADC switching for VIA codecs Some VIA codecs like VT1702 provide the input-route only to specific ADCs such as digital-mic inputs. These routes aren't covered by the normal primary ADC, and for now, user had to open the capture stream assigned to that special ADC manually for using such inputs. This patch implements a way to switch the current ADC dynamically per the input-source selection in such a case. When this workaround is activated, the driver provides only one capture stream and one input- source control but with the full possible inputs. The driver switches the ADC to be used (or being used) according to the input-source on the fly. Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_via.c | 516 +++++++++++++++++++++++++++++--------- 1 file changed, 391 insertions(+), 125 deletions(-) diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index af47b9aca974..fb5468b4c55a 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c @@ -99,6 +99,14 @@ struct nid_path { unsigned int mute_ctl; }; +/* input-path */ +struct via_input { + hda_nid_t pin; /* input-pin or aa-mix */ + int adc_idx; /* ADC index to be used */ + int mux_idx; /* MUX index (if any) */ + const char *label; /* input-source label */ +}; + struct via_spec { /* codec parameterization */ const struct snd_kcontrol_new *mixers[6]; @@ -135,16 +143,22 @@ struct via_spec { hda_nid_t dig_in_nid; /* capture source */ - const struct hda_input_mux *input_mux; + bool dyn_adc_switch; + int num_inputs; + struct via_input inputs[AUTO_CFG_MAX_INS + 1]; unsigned int cur_mux[3]; + /* dynamic ADC switching */ + hda_nid_t cur_adc; + unsigned int cur_adc_stream_tag; + unsigned int cur_adc_format; + /* PCM information */ struct hda_pcm pcm_rec[3]; /* dynamic controls, init_verbs and input_mux */ struct auto_pin_cfg autocfg; struct snd_array kctls; - struct hda_input_mux private_imux[2]; hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; /* HP mode source */ @@ -171,6 +185,10 @@ struct via_spec { struct hda_loopback_check loopback; int num_loopbacks; struct hda_amp_list loopback_list[8]; + + /* bind capture-volume */ + struct hda_bind_ctls *bind_cap_vol; + struct hda_bind_ctls *bind_cap_sw; }; static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); @@ -586,12 +604,15 @@ static void via_auto_init_analog_input(struct hda_codec *codec) /* init input-src */ for (i = 0; i < spec->num_adc_nids; i++) { - const struct hda_input_mux *imux = spec->input_mux; - if (!imux || !spec->mux_nids[i]) - continue; - snd_hda_codec_write(codec, spec->mux_nids[i], 0, - AC_VERB_SET_CONNECT_SEL, - imux->items[spec->cur_mux[i]].index); + int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx; + if (spec->mux_nids[adc_idx]) { + int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx; + snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, + AC_VERB_SET_CONNECT_SEL, + mux_idx); + } + if (spec->dyn_adc_switch) + break; /* only one input-src */ } /* init aa-mixer */ @@ -682,53 +703,6 @@ static const struct snd_kcontrol_new via_pin_power_ctl_enum = { }; -/* - * input MUX handling - */ -static int via_mux_enum_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - struct via_spec *spec = codec->spec; - return snd_hda_input_mux_info(spec->input_mux, uinfo); -} - -static int via_mux_enum_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - struct via_spec *spec = codec->spec; - unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); - - ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; - return 0; -} - -static int via_mux_enum_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - struct via_spec *spec = codec->spec; - unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); - int ret; - - if (!spec->mux_nids[adc_idx]) - return -EINVAL; - /* switch to D0 beofre change index */ - if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, - AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) - snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, - AC_VERB_SET_POWER_STATE, AC_PWRST_D0); - - ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, - spec->mux_nids[adc_idx], - &spec->cur_mux[adc_idx]); - /* update jack power state */ - set_widgets_power_state(codec); - - return ret; -} - static int via_independent_hp_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { @@ -1149,6 +1123,53 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, return 0; } +/* analog capture with dynamic ADC switching */ +static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + unsigned int stream_tag, + unsigned int format, + struct snd_pcm_substream *substream) +{ + struct via_spec *spec = codec->spec; + int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx; + + spec->cur_adc = spec->adc_nids[adc_idx]; + spec->cur_adc_stream_tag = stream_tag; + spec->cur_adc_format = format; + snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); + return 0; +} + +static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, + struct hda_codec *codec, + struct snd_pcm_substream *substream) +{ + struct via_spec *spec = codec->spec; + + snd_hda_codec_cleanup_stream(codec, spec->cur_adc); + spec->cur_adc = 0; + return 0; +} + +/* re-setup the stream if running; called from input-src put */ +static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) +{ + struct via_spec *spec = codec->spec; + int adc_idx = spec->inputs[cur].adc_idx; + hda_nid_t adc = spec->adc_nids[adc_idx]; + + if (spec->cur_adc && spec->cur_adc != adc) { + /* stream is running, let's swap the current ADC */ + __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); + spec->cur_adc = adc; + snd_hda_codec_setup_stream(codec, adc, + spec->cur_adc_stream_tag, 0, + spec->cur_adc_format); + return true; + } + return false; +} + static const struct hda_pcm_stream via_pcm_analog_playback = { .substreams = 1, .channels_min = 2, @@ -1204,6 +1225,17 @@ static const struct hda_pcm_stream via_pcm_analog_capture = { }, }; +static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = { + .substreams = 1, + .channels_min = 2, + .channels_max = 2, + /* NID is set in via_build_pcms */ + .ops = { + .prepare = via_dyn_adc_capture_pcm_prepare, + .cleanup = via_dyn_adc_capture_pcm_cleanup, + }, +}; + static const struct hda_pcm_stream via_pcm_digital_playback = { .substreams = 1, .channels_min = 2, @@ -1336,13 +1368,19 @@ static int via_build_pcms(struct hda_codec *codec) info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; - if (!spec->stream_analog_capture) - spec->stream_analog_capture = &via_pcm_analog_capture; + if (!spec->stream_analog_capture) { + if (spec->dyn_adc_switch) + spec->stream_analog_capture = + &via_pcm_dyn_adc_analog_capture; + else + spec->stream_analog_capture = &via_pcm_analog_capture; + } info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->stream_analog_capture; info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; - info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = - spec->num_adc_nids; + if (!spec->dyn_adc_switch) + info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = + spec->num_adc_nids; if (spec->multiout.dig_out_nid || spec->dig_in_nid) { codec->num_pcms++; @@ -1394,7 +1432,9 @@ static void via_free(struct hda_codec *codec) via_free_kctls(codec); vt1708_stop_hp_work(spec); - kfree(codec->spec); + kfree(spec->bind_cap_vol); + kfree(spec->bind_cap_sw); + kfree(spec); } /* mute/unmute outputs */ @@ -1860,7 +1900,74 @@ static int via_fill_adcs(struct hda_codec *codec) return 0; } -static int get_mux_nids(struct hda_codec *codec); +/* input-src control */ +static int via_mux_enum_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct hda_codec *codec = snd_kcontrol_chip(kcontrol); + struct via_spec *spec = codec->spec; + + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; + uinfo->count = 1; + uinfo->value.enumerated.items = spec->num_inputs; + if (uinfo->value.enumerated.item >= spec->num_inputs) + uinfo->value.enumerated.item = spec->num_inputs - 1; + strcpy(uinfo->value.enumerated.name, + spec->inputs[uinfo->value.enumerated.item].label); + return 0; +} + +static int via_mux_enum_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct hda_codec *codec = snd_kcontrol_chip(kcontrol); + struct via_spec *spec = codec->spec; + unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); + + ucontrol->value.enumerated.item[0] = spec->cur_mux[idx]; + return 0; +} + +static int via_mux_enum_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct hda_codec *codec = snd_kcontrol_chip(kcontrol); + struct via_spec *spec = codec->spec; + unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); + hda_nid_t mux; + int cur; + + cur = ucontrol->value.enumerated.item[0]; + if (cur < 0 || cur >= spec->num_inputs) + return -EINVAL; + if (spec->cur_mux[idx] == cur) + return 0; + spec->cur_mux[idx] = cur; + if (spec->dyn_adc_switch) { + int adc_idx = spec->inputs[cur].adc_idx; + mux = spec->mux_nids[adc_idx]; + via_dyn_adc_pcm_resetup(codec, cur); + } else { + mux = spec->mux_nids[idx]; + if (snd_BUG_ON(!mux)) + return -EINVAL; + } + + if (mux) { + /* switch to D0 beofre change index */ + if (snd_hda_codec_read(codec, mux, 0, + AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) + snd_hda_codec_write(codec, mux, 0, + AC_VERB_SET_POWER_STATE, AC_PWRST_D0); + snd_hda_codec_write(codec, mux, 0, + AC_VERB_SET_CONNECT_SEL, + spec->inputs[cur].mux_idx); + } + + /* update jack power state */ + set_widgets_power_state(codec); + return 0; +} static const struct snd_kcontrol_new via_input_src_ctl = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, @@ -1874,6 +1981,22 @@ static const struct snd_kcontrol_new via_input_src_ctl = { .put = via_mux_enum_put, }; +static int create_input_src_ctls(struct hda_codec *codec, int count) +{ + struct via_spec *spec = codec->spec; + struct snd_kcontrol_new *knew; + + if (spec->num_inputs <= 1 || !count) + return 0; /* no need for single src */ + + knew = via_clone_control(spec, &via_input_src_ctl); + if (!knew) + return -ENOMEM; + knew->count = count; + return 0; +} + +/* add the powersave loopback-list entry */ static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) { struct hda_amp_list *list; @@ -1888,17 +2011,65 @@ static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) spec->loopback.amplist = spec->loopback_list; } -/* create playback/capture controls for input pins */ -static int via_auto_create_analog_input_ctls(struct hda_codec *codec, - const struct auto_pin_cfg *cfg) +/* check whether the path from src to dst is reachable */ +static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src, + hda_nid_t dst, int depth) +{ + hda_nid_t conn[8]; + int i, nums; + + nums = snd_hda_get_connections(codec, src, conn, ARRAY_SIZE(conn)); + for (i = 0; i < nums; i++) + if (conn[i] == dst) + return true; + if (++depth > MAX_NID_PATH_DEPTH) + return false; + for (i = 0; i < nums; i++) + if (is_reachable_nid(codec, conn[i], dst, depth)) + return true; + return false; +} + +/* add the input-route to the given pin */ +static bool add_input_route(struct hda_codec *codec, hda_nid_t pin) { struct via_spec *spec = codec->spec; - struct hda_input_mux *imux = &spec->private_imux[0]; - int i, j, err, idx, idx2, type, type_idx = 0; - const char *prev_label = NULL; - hda_nid_t cap_nid; - hda_nid_t pin_idxs[8]; - int num_idxs; + int c, idx; + + spec->inputs[spec->num_inputs].adc_idx = -1; + spec->inputs[spec->num_inputs].pin = pin; + for (c = 0; c < spec->num_adc_nids; c++) { + if (spec->mux_nids[c]) { + idx = get_connection_index(codec, spec->mux_nids[c], + pin); + if (idx < 0) + continue; + spec->inputs[spec->num_inputs].mux_idx = idx; + } else { + if (!is_reachable_nid(codec, spec->adc_nids[c], pin, 0)) + continue; + } + spec->inputs[spec->num_inputs].adc_idx = c; + /* Can primary ADC satisfy all inputs? */ + if (!spec->dyn_adc_switch && + spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) { + snd_printd(KERN_INFO + "via: dynamic ADC switching enabled\n"); + spec->dyn_adc_switch = 1; + } + return true; + } + return false; +} + +static int get_mux_nids(struct hda_codec *codec); + +/* parse input-routes; fill ADCs, MUXs and input-src entries */ +static int parse_analog_inputs(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + const struct auto_pin_cfg *cfg = &spec->autocfg; + int i, err; err = via_fill_adcs(codec); if (err < 0) @@ -1906,55 +2077,97 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, err = get_mux_nids(codec); if (err < 0) return err; - cap_nid = spec->mux_nids[0]; - num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, - ARRAY_SIZE(pin_idxs)); - if (num_idxs <= 0) - return 0; - - /* for internal loopback recording select */ - for (idx = 0; idx < num_idxs; idx++) { - if (pin_idxs[idx] == spec->aa_mix_nid) { - snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); - break; - } + /* fill all input-routes */ + for (i = 0; i < cfg->num_inputs; i++) { + if (add_input_route(codec, cfg->inputs[i].pin)) + spec->inputs[spec->num_inputs++].label = + hda_get_autocfg_input_label(codec, cfg, i); } + /* check for internal loopback recording */ + if (spec->aa_mix_nid && + add_input_route(codec, spec->aa_mix_nid)) + spec->inputs[spec->num_inputs++].label = "Stereo Mixer"; + + return 0; +} + +/* create analog-loopback volume/switch controls */ +static int create_loopback_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + const struct auto_pin_cfg *cfg = &spec->autocfg; + const char *prev_label = NULL; + int type_idx = 0; + int i, j, err, idx; + + if (!spec->aa_mix_nid) + return 0; + for (i = 0; i < cfg->num_inputs; i++) { - const char *label; - type = cfg->inputs[i].type; - for (idx = 0; idx < num_idxs; idx++) - if (pin_idxs[idx] == cfg->inputs[i].pin) - break; - if (idx >= num_idxs) - continue; - label = hda_get_autocfg_input_label(codec, cfg, i); + hda_nid_t pin = cfg->inputs[i].pin; + const char *label = hda_get_autocfg_input_label(codec, cfg, i); + if (prev_label && !strcmp(label, prev_label)) type_idx++; else type_idx = 0; prev_label = label; - idx2 = get_connection_index(codec, spec->aa_mix_nid, - pin_idxs[idx]); - if (idx2 >= 0) { + idx = get_connection_index(codec, spec->aa_mix_nid, pin); + if (idx >= 0) { err = via_new_analog_input(spec, label, type_idx, - idx2, spec->aa_mix_nid); + idx, spec->aa_mix_nid); if (err < 0) return err; - add_loopback_list(spec, spec->aa_mix_nid, idx2); + add_loopback_list(spec, spec->aa_mix_nid, idx); } - snd_hda_add_imux_item(imux, label, idx, NULL); /* remember the label for smart51 control */ for (j = 0; j < spec->smart51_nums; j++) { - if (spec->smart51_pins[j] == cfg->inputs[i].pin) { + if (spec->smart51_pins[j] == pin) { spec->smart51_idxs[j] = idx; spec->smart51_labels[j] = label; break; } } } + return 0; +} + +/* create mic-boost controls (if present) */ +static int create_mic_boost_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + const struct auto_pin_cfg *cfg = &spec->autocfg; + int i, err; + + for (i = 0; i < cfg->num_inputs; i++) { + hda_nid_t pin = cfg->inputs[i].pin; + unsigned int caps; + const char *label; + char name[32]; + + if (cfg->inputs[i].type != AUTO_PIN_MIC) + continue; + caps = query_amp_caps(codec, pin, HDA_INPUT); + if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) + continue; + label = hda_get_autocfg_input_label(codec, cfg, i); + snprintf(name, sizeof(name), "%s Boost Volume", label); + err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, + HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); + if (err < 0) + return err; + } + return 0; +} + +/* create capture and input-src controls for multiple streams */ +static int create_multi_adc_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + int i, err; /* create capture mixer elements */ for (i = 0; i < spec->num_adc_nids; i++) { @@ -1977,34 +2190,89 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, for (i = 0; i < spec->num_adc_nids; i++) if (!spec->mux_nids[i]) break; - if (i) { - struct snd_kcontrol_new *knew; - knew = via_clone_control(spec, &via_input_src_ctl); - if (!knew) - return -ENOMEM; - knew->count = i; - } + err = create_input_src_ctls(codec, i); + if (err < 0) + return err; + return 0; +} - /* mic-boosts */ - for (i = 0; i < cfg->num_inputs; i++) { - hda_nid_t pin = cfg->inputs[i].pin; - unsigned int caps; - const char *label; - char name[32]; +/* bind capture volume/switch */ +static struct snd_kcontrol_new via_bind_cap_vol_ctl = + HDA_BIND_VOL("Capture Volume", 0); +static struct snd_kcontrol_new via_bind_cap_sw_ctl = + HDA_BIND_SW("Capture Switch", 0); - if (cfg->inputs[i].type != AUTO_PIN_MIC) - continue; - caps = query_amp_caps(codec, pin, HDA_INPUT); - if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) - continue; - label = hda_get_autocfg_input_label(codec, cfg, i); - snprintf(name, sizeof(name), "%s Boost Volume", label); - err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, - HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); - if (err < 0) - return err; - } +static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret, + struct hda_ctl_ops *ops) +{ + struct hda_bind_ctls *ctl; + int i; + ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL); + if (!ctl) + return -ENOMEM; + ctl->ops = ops; + for (i = 0; i < spec->num_adc_nids; i++) + ctl->values[i] = + HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT); + *ctl_ret = ctl; + return 0; +} + +/* create capture and input-src controls for dynamic ADC-switch case */ +static int create_dyn_adc_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + struct snd_kcontrol_new *knew; + int err; + + /* set up the bind capture ctls */ + err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol); + if (err < 0) + return err; + err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw); + if (err < 0) + return err; + + /* create capture mixer elements */ + knew = via_clone_control(spec, &via_bind_cap_vol_ctl); + if (!knew) + return -ENOMEM; + knew->private_value = (long)spec->bind_cap_vol; + + knew = via_clone_control(spec, &via_bind_cap_sw_ctl); + if (!knew) + return -ENOMEM; + knew->private_value = (long)spec->bind_cap_sw; + + /* input-source control */ + err = create_input_src_ctls(codec, 1); + if (err < 0) + return err; + return 0; +} + +/* parse and create capture-related stuff */ +static int via_auto_create_analog_input_ctls(struct hda_codec *codec) +{ + struct via_spec *spec = codec->spec; + int err; + + err = parse_analog_inputs(codec); + if (err < 0) + return err; + if (spec->dyn_adc_switch) + err = create_dyn_adc_ctls(codec); + else + err = create_multi_adc_ctls(codec); + if (err < 0) + return err; + err = create_loopback_ctls(codec); + if (err < 0) + return err; + err = create_mic_boost_ctls(codec); + if (err < 0) + return err; return 0; } @@ -2090,7 +2358,7 @@ static int via_parse_auto_config(struct hda_codec *codec) err = via_auto_create_speaker_ctls(codec); if (err < 0) return err; - err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); + err = via_auto_create_analog_input_ctls(codec); if (err < 0) return err; @@ -2104,8 +2372,6 @@ static int via_parse_auto_config(struct hda_codec *codec) spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; - spec->input_mux = &spec->private_imux[0]; - if (spec->hp_dac_nid && spec->hp_dep_path.depth) { err = via_hp_build(codec); if (err < 0)