]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/pci/hda/patch_sigmatel.c
ALSA: hda - Fix SPDIF mute on IDT/STAC codecs
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_sigmatel.c
index fac6b3ca5fe25b680dc7ff49cc0eede7158a5b9d..df9b0bc7f8785a82b6ca6ee0649b7c26ddc0659a 100644 (file)
@@ -38,6 +38,7 @@
 #define NUM_CONTROL_ALLOC      32
 #define STAC_PWR_EVENT         0x20
 #define STAC_HP_EVENT          0x30
+#define STAC_VREF_EVENT                0x40
 
 enum {
        STAC_REF,
@@ -80,6 +81,7 @@ enum {
        STAC_92HD71BXX_REF,
        STAC_DELL_M4_1,
        STAC_DELL_M4_2,
+       STAC_HP_M4,
        STAC_92HD71BXX_MODELS
 };
 
@@ -137,6 +139,7 @@ struct sigmatel_spec {
        unsigned int mic_switch: 1;
        unsigned int alt_switch: 1;
        unsigned int hp_detect: 1;
+       unsigned int spdif_mute: 1;
 
        /* gpio lines */
        unsigned int eapd_mask;
@@ -145,6 +148,9 @@ struct sigmatel_spec {
        unsigned int gpio_data;
        unsigned int gpio_mute;
 
+       /* stream */
+       unsigned int stream_delay;
+
        /* analog loopback */
        unsigned char aloopback_mask;
        unsigned char aloopback_shift;
@@ -157,6 +163,7 @@ struct sigmatel_spec {
 
        /* playback */
        struct hda_input_mux *mono_mux;
+       struct hda_input_mux *amp_mux;
        unsigned int cur_mmux;
        struct hda_multi_out multiout;
        hda_nid_t dac_nids[5];
@@ -170,6 +177,10 @@ struct sigmatel_spec {
        unsigned int num_dmics;
        hda_nid_t *dmux_nids;
        unsigned int num_dmuxes;
+       hda_nid_t *smux_nids;
+       unsigned int num_smuxes;
+       const char **spdif_labels;
+
        hda_nid_t dig_in_nid;
        hda_nid_t mono_nid;
        hda_nid_t anabeep_nid;
@@ -190,6 +201,12 @@ struct sigmatel_spec {
        unsigned int cur_dmux[2];
        struct hda_input_mux *input_mux;
        unsigned int cur_mux[3];
+       struct hda_input_mux *sinput_mux;
+       unsigned int cur_smux[2];
+       unsigned int cur_amux;
+       hda_nid_t *amp_nids;
+       unsigned int num_amps;
+       unsigned int powerdown_adcs;
 
        /* i/o switches */
        unsigned int io_switch[2];
@@ -205,6 +222,8 @@ struct sigmatel_spec {
        struct snd_kcontrol_new *kctl_alloc;
        struct hda_input_mux private_dimux;
        struct hda_input_mux private_imux;
+       struct hda_input_mux private_smux;
+       struct hda_input_mux private_amp_mux;
        struct hda_input_mux private_mono_mux;
 };
 
@@ -225,10 +244,19 @@ static hda_nid_t stac92hd73xx_pwr_nids[8] = {
        0x0f, 0x10, 0x11
 };
 
+static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
+       0x26, 0,
+};
+
 static hda_nid_t stac92hd73xx_adc_nids[2] = {
        0x1a, 0x1b
 };
 
+#define DELL_M6_AMP 2
+static hda_nid_t stac92hd73xx_amp_nids[3] = {
+       0x0b, 0x0c, 0x0e
+};
+
 #define STAC92HD73XX_NUM_DMICS 2
 static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
        0x13, 0x14, 0
@@ -247,6 +275,10 @@ static hda_nid_t stac92hd73xx_dmux_nids[2] = {
        0x20, 0x21,
 };
 
+static hda_nid_t stac92hd73xx_smux_nids[2] = {
+       0x22, 0x23,
+};
+
 #define STAC92HD83XXX_NUM_DMICS        2
 static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
        0x11, 0x12, 0
@@ -270,6 +302,10 @@ static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
        0xa, 0xb, 0xd, 0xe,
 };
 
+static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
+       0x1e, 0,
+};
+
 static unsigned int stac92hd83xxx_pwr_mapping[4] = {
        0x03, 0x0c, 0x10, 0x40,
 };
@@ -286,8 +322,12 @@ static hda_nid_t stac92hd71bxx_mux_nids[2] = {
        0x1a, 0x1b
 };
 
-static hda_nid_t stac92hd71bxx_dmux_nids[1] = {
-       0x1c,
+static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
+       0x1c, 0x1d,
+};
+
+static hda_nid_t stac92hd71bxx_smux_nids[2] = {
+       0x24, 0x25,
 };
 
 static hda_nid_t stac92hd71bxx_dac_nids[1] = {
@@ -299,6 +339,10 @@ static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
        0x18, 0x19, 0
 };
 
+static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
+       0x22, 0
+};
+
 static hda_nid_t stac925x_adc_nids[1] = {
         0x03,
 };
@@ -336,6 +380,10 @@ static hda_nid_t stac927x_mux_nids[3] = {
         0x15, 0x16, 0x17
 };
 
+static hda_nid_t stac927x_smux_nids[1] = {
+       0x21,
+};
+
 static hda_nid_t stac927x_dac_nids[6] = {
        0x02, 0x03, 0x04, 0x05, 0x06, 0
 };
@@ -349,6 +397,11 @@ static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
        0x13, 0x14, 0
 };
 
+static const char *stac927x_spdif_labels[5] = {
+       "Digital Playback", "ADAT", "Analog Mux 1",
+       "Analog Mux 2", "Analog Mux 3"
+};
+
 static hda_nid_t stac9205_adc_nids[2] = {
         0x12, 0x13
 };
@@ -361,6 +414,10 @@ static hda_nid_t stac9205_dmux_nids[1] = {
        0x1d,
 };
 
+static hda_nid_t stac9205_smux_nids[1] = {
+       0x21,
+};
+
 #define STAC9205_NUM_DMICS     2
 static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
         0x17, 0x18, 0
@@ -384,7 +441,7 @@ static hda_nid_t stac922x_pin_nids[10] = {
 static hda_nid_t stac92hd73xx_pin_nids[13] = {
        0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
        0x0f, 0x10, 0x11, 0x12, 0x13,
-       0x14, 0x1e, 0x22
+       0x14, 0x22, 0x23
 };
 
 static hda_nid_t stac92hd83xxx_pin_nids[14] = {
@@ -392,9 +449,10 @@ static hda_nid_t stac92hd83xxx_pin_nids[14] = {
        0x0f, 0x10, 0x11, 0x12, 0x13,
        0x1d, 0x1e, 0x1f, 0x20
 };
-static hda_nid_t stac92hd71bxx_pin_nids[10] = {
+static hda_nid_t stac92hd71bxx_pin_nids[11] = {
        0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
        0x0f, 0x14, 0x18, 0x19, 0x1e,
+       0x1f,
 };
 
 static hda_nid_t stac927x_pin_nids[14] = {
@@ -409,6 +467,34 @@ static hda_nid_t stac9205_pin_nids[12] = {
        0x21, 0x22,
 };
 
+#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
+
+static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+       hda_nid_t nid = spec->amp_nids[spec->cur_amux];
+
+       kcontrol->private_value ^= get_amp_nid(kcontrol);
+       kcontrol->private_value |= nid;
+
+       return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
+}
+
+static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+       hda_nid_t nid = spec->amp_nids[spec->cur_amux];
+
+       kcontrol->private_value ^= get_amp_nid(kcontrol);
+       kcontrol->private_value |= nid;
+
+       return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
+}
+
 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
                                   struct snd_ctl_elem_info *uinfo)
 {
@@ -439,6 +525,56 @@ static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
                        spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
 }
 
+static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_info *uinfo)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+       return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
+}
+
+static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+       unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
+
+       ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
+       return 0;
+}
+
+static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+       struct hda_input_mux *smux = &spec->private_smux;
+       unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
+       int err, val;
+       hda_nid_t nid;
+
+       err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
+                       spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
+       if (err < 0)
+               return err;
+
+       if (spec->spdif_mute) {
+               if (smux_idx == 0)
+                       nid = spec->multiout.dig_out_nid;
+               else
+                       nid = codec->slave_dig_outs[smux_idx - 1];
+               if (spec->cur_smux[smux_idx] == smux->num_items - 1)
+                       val = AMP_OUT_MUTE;
+               else
+                       val = AMP_OUT_UNMUTE;
+               /* un/mute SPDIF out */
+               snd_hda_codec_write_cache(codec, nid, 0,
+                       AC_VERB_SET_AMP_GAIN_MUTE, val);
+       }
+       return 0;
+}
+
 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
@@ -494,6 +630,41 @@ static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
                                     spec->mono_nid, &spec->cur_mmux);
 }
 
+static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_info *uinfo)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+       return snd_hda_input_mux_info(spec->amp_mux, uinfo);
+}
+
+static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+
+       ucontrol->value.enumerated.item[0] = spec->cur_amux;
+       return 0;
+}
+
+static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct sigmatel_spec *spec = codec->spec;
+       struct snd_kcontrol *ctl =
+               snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
+       if (!ctl)
+               return -EINVAL;
+
+       snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
+               SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
+
+       return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
+                                    0, &spec->cur_amux);
+}
+
 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
 
 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
@@ -588,8 +759,8 @@ static struct hda_verb dell_eq_core_init[] = {
        { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
        /* setup audio connections */
        { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
-       { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
-       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
+       { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
+       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
        /* setup adcs to point to mixer */
        { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
        { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
@@ -688,20 +859,18 @@ static struct hda_verb stac92hd71bxx_core_init[] = {
        { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
        /* connect headphone jack to dac1 */
        { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
        /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
        { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
 };
 
-#define HD_DISABLE_PORTF 3
+#define HD_DISABLE_PORTF 2
 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
        /* start of config #1 */
 
        /* connect port 0f to audio mixer */
        { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
        /* unmute right and left channels for node 0x0f */
        { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        /* start of config #2 */
@@ -710,10 +879,6 @@ static struct hda_verb stac92hd71bxx_analog_core_init[] = {
        { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
        /* connect headphone jack to dac1 */
        { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
-       /* connect port 0d to audio mixer */
-       { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
-       /* unmute dac0 input in audio mixer */
-       { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
        /* unmute right and left channels for nodes 0x0a, 0xd */
        { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -768,6 +933,31 @@ static struct hda_verb stac9205_core_init[] = {
                .put = stac92xx_mono_mux_enum_put, \
        }
 
+#define STAC_AMP_MUX \
+       { \
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+               .name = "Amp Selector Capture Switch", \
+               .count = 1, \
+               .info = stac92xx_amp_mux_enum_info, \
+               .get = stac92xx_amp_mux_enum_get, \
+               .put = stac92xx_amp_mux_enum_put, \
+       }
+
+#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
+       { \
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+               .name = xname, \
+               .index = 0, \
+               .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
+                       SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
+                       SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
+               .info = stac92xx_amp_volume_info, \
+               .get = stac92xx_amp_volume_get, \
+               .put = stac92xx_amp_volume_put, \
+               .tlv = { .c = snd_hda_mixer_amp_tlv }, \
+               .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
+       }
+
 #define STAC_INPUT_SOURCE(cnt) \
        { \
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -795,33 +985,36 @@ static struct snd_kcontrol_new stac9200_mixer[] = {
        STAC_INPUT_SOURCE(1),
        HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
        { } /* end */
 };
 
+#define DELL_M6_MIXER 6
 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
-       STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
-
-       HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
-
-       HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
-
+       /* start of config #1 */
        HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
        HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
 
-       HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
-
        HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
        HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
 
+       HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
+       HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
+
+       /* start of config #2 */
+       HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
+       HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
+
        HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
        HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
 
-       HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
-       HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
+       STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
+
+       HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
+
+       HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
+
        { } /* end */
 };
 
@@ -906,23 +1099,30 @@ static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
 
 static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
        STAC_INPUT_SOURCE(2),
+       STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
-
        /* analog pc-beep replaced with digital beep support */
        /*
        HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
        HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
        */
 
-       HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
-       HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
+       HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
+
+       HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
+       HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
+
+       HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
+       HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
+
+       HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
+       HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
        { } /* end */
 };
 
@@ -932,11 +1132,9 @@ static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
        { } /* end */
 };
 
@@ -944,7 +1142,6 @@ static struct snd_kcontrol_new stac925x_mixer[] = {
        STAC_INPUT_SOURCE(1),
        HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
        { } /* end */
 };
 
@@ -954,12 +1151,9 @@ static struct snd_kcontrol_new stac9205_mixer[] = {
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
-
        { } /* end */
 };
 
@@ -968,11 +1162,9 @@ static struct snd_kcontrol_new stac922x_mixer[] = {
        STAC_INPUT_SOURCE(2),
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
        { } /* end */
 };
 
@@ -983,15 +1175,12 @@ static struct snd_kcontrol_new stac927x_mixer[] = {
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
 
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
        { } /* end */
 };
 
@@ -1004,6 +1193,15 @@ static struct snd_kcontrol_new stac_dmux_mixer = {
        .put = stac92xx_dmux_enum_put,
 };
 
+static struct snd_kcontrol_new stac_smux_mixer = {
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "IEC958 Playback Source",
+       /* count set later */
+       .info = stac92xx_smux_enum_info,
+       .get = stac92xx_smux_enum_get,
+       .put = stac92xx_smux_enum_put,
+};
+
 static const char *slave_vols[] = {
        "Front Playback Volume",
        "Surround Playback Volume",
@@ -1055,6 +1253,22 @@ static int stac92xx_build_controls(struct hda_codec *codec)
                if (err < 0)
                        return err;
        }
+       if (spec->num_smuxes > 0) {
+               int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
+               struct hda_input_mux *smux = &spec->private_smux;
+               /* check for mute support on SPDIF out */
+               if (wcaps & AC_WCAP_OUT_AMP) {
+                       smux->items[smux->num_items].label = "Off";
+                       smux->items[smux->num_items].index = 0;
+                       smux->num_items++;
+                       spec->spdif_mute = 1;
+               }
+               stac_smux_mixer.count = spec->num_smuxes;
+               err = snd_ctl_add(codec->bus->card,
+                                 snd_ctl_new1(&stac_smux_mixer, codec));
+               if (err < 0)
+                       return err;
+       }
 
        if (spec->multiout.dig_out_nid) {
                err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
@@ -1066,7 +1280,7 @@ static int stac92xx_build_controls(struct hda_codec *codec)
                        return err;
                spec->multiout.share_spdif = 1;
        }
-       if (spec->dig_in_nid) {
+       if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
                err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
                if (err < 0)
                        return err;
@@ -1435,40 +1649,44 @@ static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
                      "DFI LanParty", STAC_92HD71BXX_REF),
 };
 
-static unsigned int ref92hd71bxx_pin_configs[10] = {
+static unsigned int ref92hd71bxx_pin_configs[11] = {
        0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
-       0x0181302e, 0x01114010, 0x01019020, 0x90a000f0,
-       0x90a000f0, 0x01452050,
+       0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
+       0x90a000f0, 0x01452050, 0x01452050,
 };
 
-static unsigned int dell_m4_1_pin_configs[10] = {
+static unsigned int dell_m4_1_pin_configs[11] = {
        0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
        0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
-       0x40f000f0, 0x4f0000f0,
+       0x40f000f0, 0x4f0000f0, 0x4f0000f0,
 };
 
-static unsigned int dell_m4_2_pin_configs[10] = {
+static unsigned int dell_m4_2_pin_configs[11] = {
        0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
        0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
-       0x40f000f0, 0x044413b0,
+       0x40f000f0, 0x044413b0, 0x044413b0,
 };
 
 static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
        [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
        [STAC_DELL_M4_1]        = dell_m4_1_pin_configs,
        [STAC_DELL_M4_2]        = dell_m4_2_pin_configs,
+       [STAC_HP_M4]            = NULL,
 };
 
 static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
        [STAC_92HD71BXX_REF] = "ref",
        [STAC_DELL_M4_1] = "dell-m4-1",
        [STAC_DELL_M4_2] = "dell-m4-2",
+       [STAC_HP_M4] = "hp-m4",
 };
 
 static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
        /* SigmaTel reference board */
        SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
                      "DFI LanParty", STAC_92HD71BXX_REF),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
+                               "unknown HP", STAC_HP_M4),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
                                "unknown Dell", STAC_DELL_M4_1),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
@@ -2011,6 +2229,8 @@ static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
                                      struct snd_pcm_substream *substream)
 {
        struct sigmatel_spec *spec = codec->spec;
+       if (spec->stream_delay)
+               msleep(spec->stream_delay);
        return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
                                             hinfo);
 }
@@ -2074,9 +2294,14 @@ static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
                                        struct snd_pcm_substream *substream)
 {
        struct sigmatel_spec *spec = codec->spec;
+       hda_nid_t nid = spec->adc_nids[substream->number];
 
-       snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
-                                   stream_tag, 0, format);
+       if (spec->powerdown_adcs) {
+               msleep(40);
+               snd_hda_codec_write_cache(codec, nid, 0,
+                       AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
+       }
+       snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
        return 0;
 }
 
@@ -2085,8 +2310,12 @@ static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
                                        struct snd_pcm_substream *substream)
 {
        struct sigmatel_spec *spec = codec->spec;
+       hda_nid_t nid = spec->adc_nids[substream->number];
 
-       snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
+       snd_hda_codec_cleanup_stream(codec, nid);
+       if (spec->powerdown_adcs)
+               snd_hda_codec_write_cache(codec, nid, 0,
+                       AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
        return 0;
 }
 
@@ -2337,6 +2566,8 @@ enum {
        STAC_CTL_WIDGET_VOL,
        STAC_CTL_WIDGET_MUTE,
        STAC_CTL_WIDGET_MONO_MUX,
+       STAC_CTL_WIDGET_AMP_MUX,
+       STAC_CTL_WIDGET_AMP_VOL,
        STAC_CTL_WIDGET_HP_SWITCH,
        STAC_CTL_WIDGET_IO_SWITCH,
        STAC_CTL_WIDGET_CLFE_SWITCH
@@ -2346,13 +2577,16 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
        HDA_CODEC_VOLUME(NULL, 0, 0, 0),
        HDA_CODEC_MUTE(NULL, 0, 0, 0),
        STAC_MONO_MUX,
+       STAC_AMP_MUX,
+       STAC_AMP_VOL(NULL, 0, 0, 0, 0),
        STAC_CODEC_HP_SWITCH(NULL),
        STAC_CODEC_IO_SWITCH(NULL, 0),
        STAC_CODEC_CLFE_SWITCH(NULL, 0),
 };
 
 /* add dynamic controls */
-static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
+static int stac92xx_add_control_idx(struct sigmatel_spec *spec, int type,
+               int idx, const char *name, unsigned long val)
 {
        struct snd_kcontrol_new *knew;
 
@@ -2372,6 +2606,7 @@ static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char
 
        knew = &spec->kctl_alloc[spec->num_kctl_used];
        *knew = stac92xx_control_templates[type];
+       knew->index = idx;
        knew->name = kstrdup(name, GFP_KERNEL);
        if (! knew->name)
                return -ENOMEM;
@@ -2380,6 +2615,14 @@ static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char
        return 0;
 }
 
+
+/* add dynamic controls */
+static int stac92xx_add_control(struct sigmatel_spec *spec, int type,
+               const char *name, unsigned long val)
+{
+       return stac92xx_add_control_idx(spec, type, 0, name, val);
+}
+
 /* flag inputs as additional dynamic lineouts */
 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
 {
@@ -2571,7 +2814,7 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
        static const char *chname[4] = {
                "Front", "Surround", NULL /*CLFE*/, "Side"
        };
-       hda_nid_t nid;
+       hda_nid_t nid = 0;
        int i, err;
 
        struct sigmatel_spec *spec = codec->spec;
@@ -2611,6 +2854,10 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
                }
        }
 
+       if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
+                       cfg->hp_outs && !spec->multiout.hp_nid)
+               spec->multiout.hp_nid = nid;
+
        if (cfg->hp_outs > 1) {
                err = stac92xx_add_control(spec,
                        STAC_CTL_WIDGET_HP_SWITCH,
@@ -2753,6 +3000,37 @@ static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
                                "Mono Mux", spec->mono_nid);
 }
 
+/* labels for amp mux outputs */
+static const char *stac92xx_amp_labels[3] = {
+       "Front Microphone", "Microphone", "Line In",
+};
+
+/* create amp out controls mux on capable codecs */
+static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
+{
+       struct sigmatel_spec *spec = codec->spec;
+       struct hda_input_mux *amp_mux = &spec->private_amp_mux;
+       int i, err;
+
+       for (i = 0; i < spec->num_amps; i++) {
+               amp_mux->items[amp_mux->num_items].label =
+                                       stac92xx_amp_labels[i];
+               amp_mux->items[amp_mux->num_items].index = i;
+               amp_mux->num_items++;
+       }
+
+       if (spec->num_amps > 1) {
+               err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
+                       "Amp Selector Capture Switch", 0);
+               if (err < 0)
+                       return err;
+       }
+       return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
+               "Amp Capture Volume",
+               HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
+}
+
+
 /* create PC beep volume controls */
 static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
                                                hda_nid_t nid)
@@ -2781,6 +3059,57 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
        return 0;
 }
 
+static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
+{
+       struct sigmatel_spec *spec = codec->spec;
+       int wcaps, nid, i, err = 0;
+
+       for (i = 0; i < spec->num_muxes; i++) {
+               nid = spec->mux_nids[i];
+               wcaps = get_wcaps(codec, nid);
+
+               if (wcaps & AC_WCAP_OUT_AMP) {
+                       err = stac92xx_add_control_idx(spec,
+                               STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
+                               HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
+                       if (err < 0)
+                               return err;
+               }
+       }
+       return 0;
+};
+
+static const char *stac92xx_spdif_labels[3] = {
+       "Digital Playback", "Analog Mux 1", "Analog Mux 2",
+};
+
+static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
+{
+       struct sigmatel_spec *spec = codec->spec;
+       struct hda_input_mux *spdif_mux = &spec->private_smux;
+       const char **labels = spec->spdif_labels;
+       int i, num_cons;
+       hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
+
+       num_cons = snd_hda_get_connections(codec,
+                               spec->smux_nids[0],
+                               con_lst,
+                               HDA_MAX_NUM_INPUTS);
+       if (!num_cons)
+               return -EINVAL;
+
+       if (!labels)
+               labels = stac92xx_spdif_labels;
+
+       for (i = 0; i < num_cons; i++) {
+               spdif_mux->items[spdif_mux->num_items].label = labels[i];
+               spdif_mux->items[spdif_mux->num_items].index = i;
+               spdif_mux->num_items++;
+       }
+
+       return 0;
+}
+
 /* labels for dmic mux inputs */
 static const char *stac92xx_dmic_labels[5] = {
        "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
@@ -3074,11 +3403,25 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
                if (err < 0)
                        return err;
        }
-
-       if (spec->num_dmics > 0)
+       if (spec->num_amps > 0) {
+               err = stac92xx_auto_create_amp_output_ctls(codec);
+               if (err < 0)
+                       return err;
+       }
+       if (spec->num_dmics > 0 && !spec->dinput_mux)
                if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
                                                &spec->autocfg)) < 0)
                        return err;
+       if (spec->num_muxes > 0) {
+               err = stac92xx_auto_create_mux_input_ctls(codec);
+               if (err < 0)
+                       return err;
+       }
+       if (spec->num_smuxes > 0) {
+               err = stac92xx_auto_create_spdif_mux_ctls(codec);
+               if (err < 0)
+                       return err;
+       }
 
        spec->multiout.max_channels = spec->multiout.num_dacs * 2;
        if (spec->multiout.max_channels > 2)
@@ -3093,10 +3436,10 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
                spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
 
        spec->input_mux = &spec->private_imux;
-       if (!spec->dinput_mux)
-               spec->dinput_mux = &spec->private_dimux;
+       spec->dinput_mux = &spec->private_dimux;
+       spec->sinput_mux = &spec->private_smux;
        spec->mono_mux = &spec->private_mono_mux;
-
+       spec->amp_mux = &spec->private_amp_mux;
        return 1;
 }
 
@@ -3276,6 +3619,12 @@ static int stac92xx_init(struct hda_codec *codec)
 
        snd_hda_sequence_write(codec, spec->init);
 
+       /* power down adcs initially */
+       if (spec->powerdown_adcs)
+               for (i = 0; i < spec->num_adcs; i++)
+                       snd_hda_codec_write_cache(codec,
+                               spec->adc_nids[i], 0,
+                               AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
        /* set up pins */
        if (spec->hp_detect) {
                /* Enable unsolicited responses on the HP widget */
@@ -3297,7 +3646,12 @@ static int stac92xx_init(struct hda_codec *codec)
        for (i = 0; i < AUTO_PIN_LAST; i++) {
                hda_nid_t nid = cfg->input_pins[i];
                if (nid) {
-                       unsigned int pinctl = AC_PINCTL_IN_EN;
+                       unsigned int pinctl = snd_hda_codec_read(codec, nid,
+                               0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
+                       /* if PINCTL already set then skip */
+                       if (pinctl & AC_PINCAP_IN)
+                               continue;
+                       pinctl = AC_PINCTL_IN_EN;
                        if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
                                pinctl |= stac92xx_get_vref(codec, nid);
                        stac92xx_auto_set_pinctl(codec, nid, pinctl);
@@ -3503,13 +3857,22 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
        struct sigmatel_spec *spec = codec->spec;
        int idx = res >> 26 & 0x0f;
 
-       switch ((res >> 26) & 0x30) {
+       switch ((res >> 26) & 0x70) {
        case STAC_HP_EVENT:
                stac92xx_hp_detect(codec, res);
                /* fallthru */
        case STAC_PWR_EVENT:
                if (spec->num_pwrs > 0)
                        stac92xx_pin_sense(codec, idx);
+               break;
+       case STAC_VREF_EVENT: {
+               int data = snd_hda_codec_read(codec, codec->afg, 0,
+                       AC_VERB_GET_GPIO_DATA, 0);
+               /* toggle VREF state based on GPIOx status */
+               snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
+                       !!(data & (1 << idx)));
+               break;
+               }
        }
 }
 
@@ -3686,9 +4049,9 @@ static struct hda_input_mux stac92hd73xx_dmux = {
        .num_items = 4,
        .items = {
                { "Analog Inputs", 0x0b },
-               { "CD", 0x08 },
                { "Digital Mic 1", 0x09 },
                { "Digital Mic 2", 0x0a },
+               { "CD", 0x08 },
        }
 };
 
@@ -3703,6 +4066,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
                return -ENOMEM;
 
        codec->spec = spec;
+       codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
        spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
        spec->pin_nids = stac92hd73xx_pin_nids;
        spec->board_config = snd_hda_check_board_config(codec,
@@ -3735,17 +4099,14 @@ again:
 
        switch (spec->multiout.num_dacs) {
        case 0x3: /* 6 Channel */
-               spec->multiout.hp_nid = 0x17;
                spec->mixer = stac92hd73xx_6ch_mixer;
                spec->init = stac92hd73xx_6ch_core_init;
                break;
        case 0x4: /* 8 Channel */
-               spec->multiout.hp_nid = 0x18;
                spec->mixer = stac92hd73xx_8ch_mixer;
                spec->init = stac92hd73xx_8ch_core_init;
                break;
        case 0x5: /* 10 Channel */
-               spec->multiout.hp_nid = 0x19;
                spec->mixer = stac92hd73xx_10ch_mixer;
                spec->init = stac92hd73xx_10ch_core_init;
        };
@@ -3759,23 +4120,29 @@ again:
        spec->adc_nids = stac92hd73xx_adc_nids;
        spec->dmic_nids = stac92hd73xx_dmic_nids;
        spec->dmux_nids = stac92hd73xx_dmux_nids;
+       spec->smux_nids = stac92hd73xx_smux_nids;
+       spec->amp_nids = stac92hd73xx_amp_nids;
+       spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
 
        spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
        spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
        spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
-       spec->dinput_mux = &stac92hd73xx_dmux;
-       /* GPIO0 High = Enable EAPD */
-       spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
-       spec->gpio_data = 0x01;
+       memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
+                       sizeof(stac92hd73xx_dmux));
 
        switch (spec->board_config) {
        case STAC_DELL_M6:
                spec->init = dell_eq_core_init;
+               spec->num_smuxes = 0;
+               spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
+               spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
+               spec->num_amps = 1;
                switch (codec->subsystem_id) {
                case 0x1028025e: /* Analog Mics */
                case 0x1028025f:
                        stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
                        spec->num_dmics = 0;
+                       spec->private_dimux.num_items = 1;
                        break;
                case 0x10280271: /* Digital Mics */
                case 0x10280272:
@@ -3785,23 +4152,32 @@ again:
                case 0x10280255:
                        stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
                        spec->num_dmics = 1;
+                       spec->private_dimux.num_items = 2;
                        break;
                case 0x10280256: /* Both */
                case 0x10280057:
                        stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
                        stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
                        spec->num_dmics = 1;
+                       spec->private_dimux.num_items = 2;
                        break;
                }
                break;
        default:
                spec->num_dmics = STAC92HD73XX_NUM_DMICS;
+               spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
        }
+       if (spec->board_config > STAC_92HD73XX_REF) {
+               /* GPIO0 High = Enable EAPD */
+               spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
+               spec->gpio_data = 0x01;
+       }
+       spec->dinput_mux = &spec->private_dimux;
 
        spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
        spec->pwr_nids = stac92hd73xx_pwr_nids;
 
-       err = stac92xx_parse_auto_config(codec, 0x22, 0x24);
+       err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
 
        if (!err) {
                if (spec->board_config < 0) {
@@ -3842,6 +4218,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
                return -ENOMEM;
 
        codec->spec = spec;
+       codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
        spec->mono_nid = 0x19;
        spec->digbeep_nid = 0x21;
        spec->dmic_nids = stac92hd83xxx_dmic_nids;
@@ -3910,6 +4287,57 @@ again:
        return 0;
 }
 
+#ifdef SND_HDA_NEEDS_RESUME
+static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
+{
+       struct sigmatel_spec *spec = codec->spec;
+       int i;
+       snd_hda_codec_write_cache(codec, codec->afg, 0,
+               AC_VERB_SET_POWER_STATE, pwr);
+
+       msleep(1);
+       for (i = 0; i < spec->num_adcs; i++) {
+               snd_hda_codec_write_cache(codec,
+                       spec->adc_nids[i], 0,
+                       AC_VERB_SET_POWER_STATE, pwr);
+       }
+};
+
+static int stac92hd71xx_resume(struct hda_codec *codec)
+{
+       stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
+       return stac92xx_resume(codec);
+}
+
+static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
+{
+       stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
+       return 0;
+};
+
+#endif
+
+static struct hda_codec_ops stac92hd71bxx_patch_ops = {
+       .build_controls = stac92xx_build_controls,
+       .build_pcms = stac92xx_build_pcms,
+       .init = stac92xx_init,
+       .free = stac92xx_free,
+       .unsol_event = stac92xx_unsol_event,
+#ifdef SND_HDA_NEEDS_RESUME
+       .resume = stac92hd71xx_resume,
+       .suspend = stac92hd71xx_suspend,
+#endif
+};
+
+static struct hda_input_mux stac92hd71bxx_dmux = {
+       .num_items = 4,
+       .items = {
+               { "Analog Inputs", 0x00 },
+               { "Mixer", 0x01 },
+               { "Digital Mic 1", 0x02 },
+               { "Digital Mic 2", 0x03 },
+       }
+};
 
 static int patch_stac92hd71bxx(struct hda_codec *codec)
 {
@@ -3921,9 +4349,12 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
                return -ENOMEM;
 
        codec->spec = spec;
+       codec->patch_ops = stac92xx_patch_ops;
        spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
        spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
        spec->pin_nids = stac92hd71bxx_pin_nids;
+       memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
+                       sizeof(stac92hd71bxx_dmux));
        spec->board_config = snd_hda_check_board_config(codec,
                                                        STAC_92HD71BXX_MODELS,
                                                        stac92hd71bxx_models,
@@ -3950,48 +4381,101 @@ again:
        case 0x111d76b5:
                spec->mixer = stac92hd71bxx_mixer;
                spec->init = stac92hd71bxx_core_init;
+               codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
                break;
        case 0x111d7608: /* 5 Port with Analog Mixer */
+               switch (codec->subsystem_id) {
+               case 0x103c361a:
+                       /* Enable VREF power saving on GPIO1 detect */
+                       snd_hda_codec_write(codec, codec->afg, 0,
+                               AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
+                       snd_hda_codec_write_cache(codec, codec->afg, 0,
+                                       AC_VERB_SET_UNSOLICITED_ENABLE,
+                                       (AC_USRSP_EN | STAC_VREF_EVENT | 0x01));
+                       spec->gpio_mask |= 0x02;
+                       break;
+               }
+               if ((codec->revision_id & 0xf) == 0 ||
+                               (codec->revision_id & 0xf) == 1) {
+#ifdef SND_HDA_NEEDS_RESUME
+                       codec->patch_ops = stac92hd71bxx_patch_ops;
+#endif
+                       spec->stream_delay = 40; /* 40 milliseconds */
+               }
+
                /* no output amps */
                spec->num_pwrs = 0;
                spec->mixer = stac92hd71bxx_analog_mixer;
+               spec->dinput_mux = &spec->private_dimux;
 
                /* disable VSW */
                spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
                stac92xx_set_config_reg(codec, 0xf, 0x40f000f0);
                break;
        case 0x111d7603: /* 6 Port with Analog Mixer */
+               if ((codec->revision_id & 0xf) == 1) {
+#ifdef SND_HDA_NEEDS_RESUME
+                       codec->patch_ops = stac92hd71bxx_patch_ops;
+#endif
+                       spec->stream_delay = 40; /* 40 milliseconds */
+               }
+
                /* no output amps */
                spec->num_pwrs = 0;
                /* fallthru */
        default:
+               spec->dinput_mux = &spec->private_dimux;
                spec->mixer = stac92hd71bxx_analog_mixer;
                spec->init = stac92hd71bxx_analog_core_init;
+               codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
        }
 
-       spec->aloopback_mask = 0x20;
+       spec->aloopback_mask = 0x50;
        spec->aloopback_shift = 0;
 
-       /* GPIO0 High = EAPD */
-       spec->gpio_mask = 0x01;
-       spec->gpio_dir = 0x01;
-       spec->gpio_data = 0x01;
+       if (spec->board_config > STAC_92HD71BXX_REF) {
+               /* GPIO0 = EAPD */
+               spec->gpio_mask = 0x01;
+               spec->gpio_dir = 0x01;
+               spec->gpio_data = 0x01;
+       }
 
+       spec->powerdown_adcs = 1;
        spec->digbeep_nid = 0x26;
        spec->mux_nids = stac92hd71bxx_mux_nids;
        spec->adc_nids = stac92hd71bxx_adc_nids;
        spec->dmic_nids = stac92hd71bxx_dmic_nids;
        spec->dmux_nids = stac92hd71bxx_dmux_nids;
+       spec->smux_nids = stac92hd71bxx_smux_nids;
        spec->pwr_nids = stac92hd71bxx_pwr_nids;
 
        spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
        spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
-       spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
-       spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
+
+       switch (spec->board_config) {
+       case STAC_HP_M4:
+               spec->num_dmics = 0;
+               spec->num_smuxes = 0;
+               spec->num_dmuxes = 0;
+
+               /* enable internal microphone */
+               stac92xx_set_config_reg(codec, 0x0e, 0x01813040);
+               stac92xx_auto_set_pinctl(codec, 0x0e,
+                       AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
+               break;
+       default:
+               spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
+               spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
+               spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
+       };
 
        spec->multiout.num_dacs = 1;
        spec->multiout.hp_nid = 0x11;
        spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
+       if (spec->dinput_mux)
+               spec->private_dimux.num_items +=
+                       spec->num_dmics -
+                               (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
 
        err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
        if (!err) {
@@ -4009,8 +4493,6 @@ again:
                return err;
        }
 
-       codec->patch_ops = stac92xx_patch_ops;
-
        return 0;
 };
 
@@ -4157,6 +4639,9 @@ static int patch_stac927x(struct hda_codec *codec)
        spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
        spec->mux_nids = stac927x_mux_nids;
        spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
+       spec->smux_nids = stac927x_smux_nids;
+       spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
+       spec->spdif_labels = stac927x_spdif_labels;
        spec->dac_list = stac927x_dac_nids;
        spec->multiout.dac_nids = spec->dac_nids;
 
@@ -4199,9 +4684,11 @@ static int patch_stac927x(struct hda_codec *codec)
                spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
                break;
        default:
-               /* GPIO0 High = Enable EAPD */
-               spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
-               spec->gpio_data = 0x01;
+               if (spec->board_config > STAC_D965_REF) {
+                       /* GPIO0 High = Enable EAPD */
+                       spec->eapd_mask = spec->gpio_mask = 0x01;
+                       spec->gpio_dir = spec->gpio_data = 0x01;
+               }
                spec->num_dmics = 0;
 
                spec->init = stac927x_core_init;
@@ -4278,6 +4765,8 @@ static int patch_stac9205(struct hda_codec *codec)
        spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
        spec->mux_nids = stac9205_mux_nids;
        spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
+       spec->smux_nids = stac9205_smux_nids;
+       spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
        spec->dmic_nids = stac9205_dmic_nids;
        spec->num_dmics = STAC9205_NUM_DMICS;
        spec->dmux_nids = stac9205_dmux_nids;
@@ -4313,6 +4802,9 @@ static int patch_stac9205(struct hda_codec *codec)
                 */
                spec->gpio_data = 0x01;
                break;
+       case STAC_9205_REF:
+               /* SPDIF-In enabled */
+               break;
        default:
                /* GPIO0 High = EAPD */
                spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;