ALSA: hda - Improve auto-cfg mixer name for ALC880
[pandora-kernel.git] / sound / pci / hda / patch_realtek.c
index ac3207e..07fbf7d 100644 (file)
@@ -4311,8 +4311,6 @@ static int add_control(struct alc_spec *spec, int type, const char *name,
 #define alc880_fixed_pin_idx(nid)      ((nid) - 0x14)
 #define alc880_is_multi_pin(nid)       ((nid) >= 0x18)
 #define alc880_multi_pin_idx(nid)      ((nid) - 0x18)
-#define alc880_is_input_pin(nid)       ((nid) >= 0x18)
-#define alc880_input_pin_idx(nid)      ((nid) - 0x18)
 #define alc880_idx_to_dac(nid)         ((nid) + 0x02)
 #define alc880_dac_to_idx(nid)         ((nid) - 0x02)
 #define alc880_idx_to_mixer(nid)       ((nid) + 0x0c)
@@ -4400,13 +4398,19 @@ static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
                        if (err < 0)
                                return err;
                } else {
-                       sprintf(name, "%s Playback Volume", chname[i]);
+                       const char *pfx;
+                       if (cfg->line_outs == 1 &&
+                           cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
+                               pfx = "Speaker";
+                       else
+                               pfx = chname[i];
+                       sprintf(name, "%s Playback Volume", pfx);
                        err = add_control(spec, ALC_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]);
+                       sprintf(name, "%s Playback Switch", pfx);
                        err = add_control(spec, ALC_CTL_BIND_MUTE, name,
                                          HDA_COMPOSE_AMP_VAL(nid, 3, 2,
                                                              HDA_INPUT));
@@ -4480,31 +4484,61 @@ static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
        return 0;
 }
 
+static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
+{
+       unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
+       return (pincap & AC_PINCAP_IN) != 0;
+}
+
 /* create playback/capture controls for input pins */
-static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
-                                               const struct auto_pin_cfg *cfg)
+static int alc_auto_create_input_ctls(struct hda_codec *codec,
+                                     const struct auto_pin_cfg *cfg,
+                                     hda_nid_t mixer,
+                                     hda_nid_t cap1, hda_nid_t cap2)
 {
+       struct alc_spec *spec = codec->spec;
        struct hda_input_mux *imux = &spec->private_imux[0];
        int i, err, idx;
 
        for (i = 0; i < AUTO_PIN_LAST; i++) {
-               if (alc880_is_input_pin(cfg->input_pins[i])) {
-                       idx = alc880_input_pin_idx(cfg->input_pins[i]);
-                       err = new_analog_input(spec, cfg->input_pins[i],
-                                              auto_pin_cfg_labels[i],
-                                              idx, 0x0b);
-                       if (err < 0)
-                               return err;
+               hda_nid_t pin;
+
+               pin = cfg->input_pins[i];
+               if (!alc_is_input_pin(codec, pin))
+                       continue;
+
+               if (mixer) {
+                       idx = get_connection_index(codec, mixer, pin);
+                       if (idx >= 0) {
+                               err = new_analog_input(spec, pin,
+                                                      auto_pin_cfg_labels[i],
+                                                      idx, mixer);
+                               if (err < 0)
+                                       return err;
+                       }
+               }
+
+               if (!cap1)
+                       continue;
+               idx = get_connection_index(codec, cap1, pin);
+               if (idx < 0 && cap2)
+                       idx = get_connection_index(codec, cap2, pin);
+               if (idx >= 0) {
                        imux->items[imux->num_items].label =
                                auto_pin_cfg_labels[i];
-                       imux->items[imux->num_items].index =
-                               alc880_input_pin_idx(cfg->input_pins[i]);
+                       imux->items[imux->num_items].index = idx;
                        imux->num_items++;
                }
        }
        return 0;
 }
 
+static int alc880_auto_create_input_ctls(struct hda_codec *codec,
+                                               const struct auto_pin_cfg *cfg)
+{
+       return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
+}
+
 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
                               unsigned int pin_type)
 {
@@ -4570,7 +4604,7 @@ static void alc880_auto_init_analog_input(struct hda_codec *codec)
 
        for (i = 0; i < AUTO_PIN_LAST; i++) {
                hda_nid_t nid = spec->autocfg.input_pins[i];
-               if (alc880_is_input_pin(nid)) {
+               if (alc_is_input_pin(codec, nid)) {
                        alc_set_input_pin(codec, nid, i);
                        if (nid != ALC880_PIN_CD_NID &&
                            (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -4613,7 +4647,7 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
                                           "Headphone");
        if (err < 0)
                return err;
-       err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
+       err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
 
@@ -6006,39 +6040,10 @@ static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
 }
 
 /* create playback/capture controls for input pins */
-static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
+static int alc260_auto_create_input_ctls(struct hda_codec *codec,
                                                const struct auto_pin_cfg *cfg)
 {
-       struct hda_input_mux *imux = &spec->private_imux[0];
-       int i, err, idx;
-
-       for (i = 0; i < AUTO_PIN_LAST; i++) {
-               if (cfg->input_pins[i] >= 0x12) {
-                       idx = cfg->input_pins[i] - 0x12;
-                       err = new_analog_input(spec, cfg->input_pins[i],
-                                              auto_pin_cfg_labels[i], idx,
-                                              0x07);
-                       if (err < 0)
-                               return err;
-                       imux->items[imux->num_items].label =
-                               auto_pin_cfg_labels[i];
-                       imux->items[imux->num_items].index = idx;
-                       imux->num_items++;
-               }
-               if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
-                       idx = cfg->input_pins[i] - 0x09;
-                       err = new_analog_input(spec, cfg->input_pins[i],
-                                              auto_pin_cfg_labels[i], idx,
-                                              0x07);
-                       if (err < 0)
-                               return err;
-                       imux->items[imux->num_items].label =
-                               auto_pin_cfg_labels[i];
-                       imux->items[imux->num_items].index = idx;
-                       imux->num_items++;
-               }
-       }
-       return 0;
+       return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
 }
 
 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
@@ -6152,7 +6157,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
                return err;
        if (!spec->kctls.list)
                return 0; /* can't find valid BIOS pin config */
-       err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
+       err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
 
@@ -9464,6 +9469,12 @@ static struct snd_pci_quirk alc882_pinfix_tbl[] = {
 /*
  * BIOS auto configuration
  */
+static int alc882_auto_create_input_ctls(struct hda_codec *codec,
+                                               const struct auto_pin_cfg *cfg)
+{
+       return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
+}
+
 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
                                              hda_nid_t nid, int pin_type,
                                              int dac_idx)
@@ -9604,44 +9615,73 @@ static int alc_auto_add_mic_boost(struct hda_codec *codec)
 static int alc882_parse_auto_config(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
-       struct auto_pin_cfg *autocfg = &spec->autocfg;
-       unsigned int wcap;
-       int i;
-       int err = alc880_parse_auto_config(codec);
+       static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
+       int i, err;
 
+       err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
+                                          alc882_ignore);
        if (err < 0)
                return err;
-       else if (!err)
-               return 0; /* no config found */
+       if (!spec->autocfg.line_outs)
+               return 0; /* can't find valid BIOS pin config */
 
-       err = alc_auto_add_mic_boost(codec);
+       err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
+       if (err < 0)
+               return err;
+       err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
+       if (err < 0)
+               return err;
+       err = alc880_auto_create_extra_out(spec,
+                                          spec->autocfg.speaker_pins[0],
+                                          "Speaker");
        if (err < 0)
                return err;
+       err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
+                                          "Headphone");
+       if (err < 0)
+               return err;
+       err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
+       if (err < 0)
+               return err;
+
+       spec->multiout.max_channels = spec->multiout.num_dacs * 2;
 
-       /* hack - override the init verbs */
-       spec->init_verbs[0] = alc883_auto_init_verbs;
+       /* check multiple SPDIF-out (for recent codecs) */
+       for (i = 0; i < spec->autocfg.dig_outs; i++) {
+               hda_nid_t dig_nid;
+               err = snd_hda_get_connections(codec,
+                                             spec->autocfg.dig_out_pins[i],
+                                             &dig_nid, 1);
+               if (err < 0)
+                       continue;
+               if (!i)
+                       spec->multiout.dig_out_nid = dig_nid;
+               else {
+                       spec->multiout.slave_dig_outs = spec->slave_dig_outs;
+                       spec->slave_dig_outs[i - 1] = dig_nid;
+                       if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
+                               break;
+               }
+       }
+       if (spec->autocfg.dig_in_pin)
+               spec->dig_in_nid = ALC880_DIGIN_NID;
+
+       if (spec->kctls.list)
+               add_mixer(spec, spec->kctls.list);
+
+       add_verb(spec, alc883_auto_init_verbs);
        /* if ADC 0x07 is available, initialize it, too */
-       wcap = get_wcaps(codec, 0x07);
-       wcap = get_wcaps_type(wcap);
-       if (wcap == AC_WID_AUD_IN)
+       if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
                add_verb(spec, alc882_adc1_init_verbs);
 
-       /* digital-mic input pin is excluded in alc880_auto_create..()
-        * because it's under 0x18
-        */
-       if (autocfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
-           autocfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
-               struct hda_input_mux *imux = &spec->private_imux[0];
-               for (i = 1; i < 3; i++)
-                       memcpy(&spec->private_imux[i],
-                              &spec->private_imux[0],
-                              sizeof(spec->private_imux[0]));
-               imux->items[imux->num_items].label = "Int DMic";
-               imux->items[imux->num_items].index = 0x0b;
-               imux->num_items++;
-               spec->num_mux_defs = 3;
-               spec->input_mux = spec->private_imux;
-       }
+       spec->num_mux_defs = 1;
+       spec->input_mux = &spec->private_imux[0];
+
+       alc_ssid_check(codec, 0x15, 0x1b, 0x14);
+
+       err = alc_auto_add_mic_boost(codec);
+       if (err < 0)
+               return err;
 
        return 1; /* config found */
 }
@@ -10820,27 +10860,8 @@ static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
        return 0;
 }
 
-static int alc262_auto_create_analog_input_ctls(struct alc_spec *spec,
-                                               const struct auto_pin_cfg *cfg)
-{
-       int err;
-
-       err = alc880_auto_create_analog_input_ctls(spec, cfg);
-       if (err < 0)
-               return err;
-       /* digital-mic input pin is excluded in alc880_auto_create..()
-        * because it's under 0x18
-        */
-       if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
-           cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
-               struct hda_input_mux *imux = &spec->private_imux[0];
-               imux->items[imux->num_items].label = "Int Mic";
-               imux->items[imux->num_items].index = 0x09;
-               imux->num_items++;
-       }
-       return 0;
-}
-
+#define alc262_auto_create_input_ctls \
+       alc880_auto_create_input_ctls
 
 /*
  * generic initialization of ADC, input mixers and output mixers
@@ -11158,7 +11179,7 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
        err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
        if (err < 0)
                return err;
-       err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
+       err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
 
@@ -12018,21 +12039,16 @@ static struct hda_verb alc268_volume_init_verbs[] = {
        { }
 };
 
+static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
+       HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
+       { } /* end */
+};
+
 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
        HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
-       {
-               .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 = alc_mux_enum_info,
-               .get = alc_mux_enum_get,
-               .put = alc_mux_enum_put,
-       },
+       _DEFINE_CAPSRC(1),
        { } /* end */
 };
 
@@ -12041,18 +12057,7 @@ static struct snd_kcontrol_new alc268_capture_mixer[] = {
        HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
-       {
-               .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 = alc_mux_enum_info,
-               .get = alc_mux_enum_get,
-               .put = alc_mux_enum_put,
-       },
+       _DEFINE_CAPSRC(2),
        { } /* end */
 };
 
@@ -12228,38 +12233,10 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
 }
 
 /* create playback/capture controls for input pins */
-static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
+static int alc268_auto_create_input_ctls(struct hda_codec *codec,
                                                const struct auto_pin_cfg *cfg)
 {
-       struct hda_input_mux *imux = &spec->private_imux[0];
-       int i, idx1;
-
-       for (i = 0; i < AUTO_PIN_LAST; i++) {
-               switch(cfg->input_pins[i]) {
-               case 0x18:
-                       idx1 = 0;       /* Mic 1 */
-                       break;
-               case 0x19:
-                       idx1 = 1;       /* Mic 2 */
-                       break;
-               case 0x1a:
-                       idx1 = 2;       /* Line In */
-                       break;
-               case 0x1c:
-                       idx1 = 3;       /* CD */
-                       break;
-               case 0x12:
-               case 0x13:
-                       idx1 = 6;       /* digital mics */
-                       break;
-               default:
-                       continue;
-               }
-               imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
-               imux->items[imux->num_items].index = idx1;
-               imux->num_items++;
-       }
-       return 0;
+       return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
 }
 
 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
@@ -12336,7 +12313,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
        err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
        if (err < 0)
                return err;
-       err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
+       err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
 
@@ -12355,7 +12332,7 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
                add_mixer(spec, alc268_beep_mixer);
 
        add_verb(spec, alc268_volume_init_verbs);
-       spec->num_mux_defs = 1;
+       spec->num_mux_defs = 2;
        spec->input_mux = &spec->private_imux[0];
 
        err = alc_auto_add_mic_boost(codec);
@@ -12415,8 +12392,6 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
                           ALC268_TOSHIBA),
        SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
        SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
-       SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
-                          ALC268_TOSHIBA),
        SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
        SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
        SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
@@ -12424,9 +12399,19 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
        {}
 };
 
+/* Toshiba laptops have no unique PCI SSID but only codec SSID */
+static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
+       SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
+       SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
+       SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
+                          ALC268_TOSHIBA),
+       {}
+};
+
 static struct alc_config_preset alc268_presets[] = {
        [ALC267_QUANTA_IL1] = {
-               .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
+               .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
+                           alc268_capture_nosrc_mixer },
                .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
                                alc267_quanta_il1_verbs },
                .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -12436,7 +12421,6 @@ static struct alc_config_preset alc268_presets[] = {
                .hp_nid = 0x03,
                .num_channel_mode = ARRAY_SIZE(alc268_modes),
                .channel_mode = alc268_modes,
-               .input_mux = &alc268_capture_source,
                .unsol_event = alc_sku_unsol_event,
                .setup = alc267_quanta_il1_setup,
                .init_hook = alc_inithook,
@@ -12475,7 +12459,7 @@ static struct alc_config_preset alc268_presets[] = {
                .init_hook = alc268_toshiba_automute,
        },
        [ALC268_ACER] = {
-               .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
+               .mixers = { alc268_acer_mixer, alc268_capture_nosrc_mixer,
                            alc268_beep_mixer },
                .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
                                alc268_acer_verbs },
@@ -12511,7 +12495,7 @@ static struct alc_config_preset alc268_presets[] = {
        [ALC268_ACER_ASPIRE_ONE] = {
                .mixers = { alc268_acer_aspire_one_mixer,
                            alc268_beep_mixer,
-                           alc268_capture_alt_mixer },
+                           alc268_capture_nosrc_mixer },
                .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
                                alc268_acer_aspire_one_verbs },
                .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -12527,11 +12511,15 @@ static struct alc_config_preset alc268_presets[] = {
                .init_hook = alc268_acer_lc_init_hook,
        },
        [ALC268_DELL] = {
-               .mixers = { alc268_dell_mixer, alc268_beep_mixer },
+               .mixers = { alc268_dell_mixer, alc268_beep_mixer,
+                           alc268_capture_nosrc_mixer },
                .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
                                alc268_dell_verbs },
                .num_dacs = ARRAY_SIZE(alc268_dac_nids),
                .dac_nids = alc268_dac_nids,
+               .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
+               .adc_nids = alc268_adc_nids_alt,
+               .capsrc_nids = alc268_capsrc_nids,
                .hp_nid = 0x02,
                .num_channel_mode = ARRAY_SIZE(alc268_modes),
                .channel_mode = alc268_modes,
@@ -12592,6 +12580,10 @@ static int patch_alc268(struct hda_codec *codec)
                                                  alc268_models,
                                                  alc268_cfg_tbl);
 
+       if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
+               board_config = snd_hda_check_board_codec_sid_config(codec,
+                       ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
+
        if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
                printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
                       codec->chip_name);
@@ -12651,10 +12643,14 @@ static int patch_alc268(struct hda_codec *codec)
 
                /* get type */
                wcap = get_wcaps_type(wcap);
-               if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
+               if (spec->auto_mic ||
+                   wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
                        spec->adc_nids = alc268_adc_nids_alt;
                        spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
-                       add_mixer(spec, alc268_capture_alt_mixer);
+                       if (spec->auto_mic || spec->input_mux->num_items == 1)
+                               add_mixer(spec, alc268_capture_nosrc_mixer);
+                       else
+                               add_mixer(spec, alc268_capture_alt_mixer);
                } else {
                        spec->adc_nids = alc268_adc_nids;
                        spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
@@ -12665,6 +12661,8 @@ static int patch_alc268(struct hda_codec *codec)
                for (i = 0; i < spec->num_adc_nids; i++)
                        snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
                                0, AC_VERB_SET_CONNECT_SEL,
+                               i < spec->num_mux_defs ?
+                               spec->input_mux[i].items[0].index :
                                spec->input_mux->items[0].index);
        }
 
@@ -13073,89 +13071,10 @@ static struct hda_verb alc269_init_verbs[] = {
        { }
 };
 
-/* add playback controls from the parsed DAC table */
-static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
-                                            const struct auto_pin_cfg *cfg)
-{
-       hda_nid_t nid;
-       int err;
-
-       spec->multiout.num_dacs = 1;    /* only use one dac */
-       spec->multiout.dac_nids = spec->private_dac_nids;
-       spec->multiout.dac_nids[0] = 2;
-
-       nid = cfg->line_out_pins[0];
-       if (nid) {
-               err = add_control(spec, ALC_CTL_WIDGET_VOL,
-                                 "Front Playback Volume",
-                                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
-               if (err < 0)
-                       return err;
-               err = add_control(spec, ALC_CTL_WIDGET_MUTE,
-                                 "Front Playback Switch",
-                                 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
-               if (err < 0)
-                       return err;
-       }
-
-       nid = cfg->speaker_pins[0];
-       if (nid) {
-               if (!cfg->line_out_pins[0]) {
-                       err = add_control(spec, ALC_CTL_WIDGET_VOL,
-                                         "Speaker Playback Volume",
-                                         HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
-                                                             HDA_OUTPUT));
-                       if (err < 0)
-                               return err;
-               }
-               if (nid == 0x16) {
-                       err = add_control(spec, ALC_CTL_WIDGET_MUTE,
-                                         "Speaker Playback Switch",
-                                         HDA_COMPOSE_AMP_VAL(nid, 2, 0,
-                                                             HDA_OUTPUT));
-                       if (err < 0)
-                               return err;
-               } else {
-                       err = add_control(spec, ALC_CTL_WIDGET_MUTE,
-                                         "Speaker Playback Switch",
-                                         HDA_COMPOSE_AMP_VAL(nid, 3, 0,
-                                                             HDA_OUTPUT));
-                       if (err < 0)
-                               return err;
-               }
-       }
-       nid = cfg->hp_pins[0];
-       if (nid) {
-               /* spec->multiout.hp_nid = 2; */
-               if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
-                       err = add_control(spec, ALC_CTL_WIDGET_VOL,
-                                         "Headphone Playback Volume",
-                                         HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
-                                                             HDA_OUTPUT));
-                       if (err < 0)
-                               return err;
-               }
-               if (nid == 0x16) {
-                       err = add_control(spec, ALC_CTL_WIDGET_MUTE,
-                                         "Headphone Playback Switch",
-                                         HDA_COMPOSE_AMP_VAL(nid, 2, 0,
-                                                             HDA_OUTPUT));
-                       if (err < 0)
-                               return err;
-               } else {
-                       err = add_control(spec, ALC_CTL_WIDGET_MUTE,
-                                         "Headphone Playback Switch",
-                                         HDA_COMPOSE_AMP_VAL(nid, 3, 0,
-                                                             HDA_OUTPUT));
-                       if (err < 0)
-                               return err;
-               }
-       }
-       return 0;
-}
-
-#define alc269_auto_create_analog_input_ctls \
-       alc262_auto_create_analog_input_ctls
+#define alc269_auto_create_multi_out_ctls \
+       alc268_auto_create_multi_out_ctls
+#define alc269_auto_create_input_ctls \
+       alc268_auto_create_input_ctls
 
 #ifdef CONFIG_SND_HDA_POWER_SAVE
 #define alc269_loopbacks       alc880_loopbacks
@@ -13205,7 +13124,7 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
        err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
        if (err < 0)
                return err;
-       err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
+       err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
 
@@ -14186,49 +14105,10 @@ static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
 }
 
 /* create playback/capture controls for input pins */
-static int alc861_auto_create_analog_input_ctls(struct hda_codec *codec,
+static int alc861_auto_create_input_ctls(struct hda_codec *codec,
                                                const struct auto_pin_cfg *cfg)
 {
-       struct alc_spec *spec = codec->spec;
-       struct hda_input_mux *imux = &spec->private_imux[0];
-       int i, err, idx, idx1;
-
-       for (i = 0; i < AUTO_PIN_LAST; i++) {
-               switch (cfg->input_pins[i]) {
-               case 0x0c:
-                       idx1 = 1;
-                       idx = 2;        /* Line In */
-                       break;
-               case 0x0f:
-                       idx1 = 2;
-                       idx = 2;        /* Line In */
-                       break;
-               case 0x0d:
-                       idx1 = 0;
-                       idx = 1;        /* Mic In */
-                       break;
-               case 0x10:
-                       idx1 = 3;
-                       idx = 1;        /* Mic In */
-                       break;
-               case 0x11:
-                       idx1 = 4;
-                       idx = 0;        /* CD */
-                       break;
-               default:
-                       continue;
-               }
-
-               err = new_analog_input(spec, cfg->input_pins[i],
-                                      auto_pin_cfg_labels[i], idx, 0x15);
-               if (err < 0)
-                       return err;
-
-               imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
-               imux->items[imux->num_items].index = idx1;
-               imux->num_items++;
-       }
-       return 0;
+       return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
 }
 
 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
@@ -14325,7 +14205,7 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
        err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
        if (err < 0)
                return err;
-       err = alc861_auto_create_analog_input_ctls(codec, &spec->autocfg);
+       err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
 
@@ -15206,6 +15086,13 @@ static struct alc_config_preset alc861vd_presets[] = {
 /*
  * BIOS auto configuration
  */
+static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
+                                               const struct auto_pin_cfg *cfg)
+{
+       return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
+}
+
+
 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
                                hda_nid_t nid, int pin_type, int dac_idx)
 {
@@ -15240,7 +15127,6 @@ static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
                alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
 }
 
-#define alc861vd_is_input_pin(nid)     alc880_is_input_pin(nid)
 #define ALC861VD_PIN_CD_NID            ALC880_PIN_CD_NID
 
 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
@@ -15250,7 +15136,7 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
 
        for (i = 0; i < AUTO_PIN_LAST; i++) {
                hda_nid_t nid = spec->autocfg.input_pins[i];
-               if (alc861vd_is_input_pin(nid)) {
+               if (alc_is_input_pin(codec, nid)) {
                        alc_set_input_pin(codec, nid, i);
                        if (nid != ALC861VD_PIN_CD_NID &&
                            (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -15413,7 +15299,7 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
                                             "Headphone");
        if (err < 0)
                return err;
-       err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
+       err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
 
@@ -17155,43 +17041,9 @@ static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
        return 0;
 }
 
-static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
-{
-       unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
-       return (pincap & AC_PINCAP_IN) != 0;
-}
-
 /* create playback/capture controls for input pins */
-static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec,
-                                               const struct auto_pin_cfg *cfg)
-{
-       struct alc_spec *spec = codec->spec;
-       struct hda_input_mux *imux = &spec->private_imux[0];
-       int i, err, idx;
-
-       for (i = 0; i < AUTO_PIN_LAST; i++) {
-               if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
-                       idx = get_connection_index(codec, 0x0b,
-                                                  cfg->input_pins[i]);
-                       if (idx >= 0) {
-                               err = new_analog_input(spec, cfg->input_pins[i],
-                                                      auto_pin_cfg_labels[i],
-                                                      idx, 0x0b);
-                               if (err < 0)
-                                       return err;
-                       }
-                       idx = get_connection_index(codec, 0x22,
-                                                  cfg->input_pins[i]);
-                       if (idx >= 0) {
-                               imux->items[imux->num_items].label =
-                                       auto_pin_cfg_labels[i];
-                               imux->items[imux->num_items].index = idx;
-                               imux->num_items++;
-                       }
-               }
-       }
-       return 0;
-}
+#define alc662_auto_create_input_ctls \
+       alc880_auto_create_input_ctls
 
 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
                                              hda_nid_t nid, int pin_type,
@@ -17245,7 +17097,7 @@ static void alc662_auto_init_analog_input(struct hda_codec *codec)
 
        for (i = 0; i < AUTO_PIN_LAST; i++) {
                hda_nid_t nid = spec->autocfg.input_pins[i];
-               if (alc662_is_input_pin(codec, nid)) {
+               if (alc_is_input_pin(codec, nid)) {
                        alc_set_input_pin(codec, nid, i);
                        if (nid != ALC662_PIN_CD_NID &&
                            (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
@@ -17286,7 +17138,7 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
                                           "Headphone");
        if (err < 0)
                return err;
-       err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg);
+       err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;