[ALSA] hda-intel - Fix PCM device number assignment
[cascardo/linux.git] / sound / pci / hda / patch_sigmatel.c
index a074155..f693011 100644 (file)
@@ -24,7 +24,6 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-#include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include "hda_local.h"
 
 #define NUM_CONTROL_ALLOC      32
-#define STAC_HP_EVENT          0x37
+#define STAC_PWR_EVENT         0x20
+#define STAC_HP_EVENT          0x30
 
 enum {
        STAC_REF,
+       STAC_9200_OQO,
        STAC_9200_DELL_D21,
        STAC_9200_DELL_D22,
        STAC_9200_DELL_D23,
@@ -121,13 +122,24 @@ struct sigmatel_spec {
        unsigned int mic_switch: 1;
        unsigned int alt_switch: 1;
        unsigned int hp_detect: 1;
-       unsigned int gpio_mute: 1;
 
-       unsigned int gpio_mask, gpio_data;
+       /* gpio lines */
+       unsigned int gpio_mask;
+       unsigned int gpio_dir;
+       unsigned int gpio_data;
+       unsigned int gpio_mute;
+
+       /* analog loopback */
        unsigned char aloopback_mask;
        unsigned char aloopback_shift;
 
+       /* power management */
+       unsigned int num_pwrs;
+       hda_nid_t *pwr_nids;
+
        /* playback */
+       struct hda_input_mux *mono_mux;
+       unsigned int cur_mmux;
        struct hda_multi_out multiout;
        hda_nid_t dac_nids[5];
 
@@ -141,6 +153,7 @@ struct sigmatel_spec {
        hda_nid_t *dmux_nids;
        unsigned int num_dmuxes;
        hda_nid_t dig_in_nid;
+       hda_nid_t mono_nid;
 
        /* pin widgets */
        hda_nid_t *pin_nids;
@@ -171,6 +184,10 @@ 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_mono_mux;
+
+       /* virtual master */
+       unsigned int vmaster_tlv[4];
 };
 
 static hda_nid_t stac9200_adc_nids[1] = {
@@ -185,6 +202,11 @@ static hda_nid_t stac9200_dac_nids[1] = {
         0x02,
 };
 
+static hda_nid_t stac92hd73xx_pwr_nids[8] = {
+       0x0a, 0x0b, 0x0c, 0xd, 0x0e,
+       0x0f, 0x10, 0x11
+};
+
 static hda_nid_t stac92hd73xx_adc_nids[2] = {
        0x1a, 0x1b
 };
@@ -207,6 +229,10 @@ static hda_nid_t stac92hd73xx_dmux_nids[2] = {
        0x20, 0x21,
 };
 
+static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
+       0x0a, 0x0d, 0x0f
+};
+
 static hda_nid_t stac92hd71bxx_adc_nids[2] = {
        0x12, 0x13,
 };
@@ -386,6 +412,34 @@ static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
                                     spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
 }
 
+static int stac92xx_mono_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->mono_mux, uinfo);
+}
+
+static int stac92xx_mono_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_mmux;
+       return 0;
+}
+
+static int stac92xx_mono_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;
+
+       return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
+                                    spec->mono_nid, &spec->cur_mmux);
+}
+
 #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
 
 static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
@@ -463,9 +517,6 @@ static struct hda_verb stac92hd73xx_6ch_core_init[] = {
        /* setup adcs to point to mixer */
        { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
        { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
-       { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Front Mic */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Mic */
-       { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Line In */
        { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
@@ -490,9 +541,6 @@ static struct hda_verb stac92hd73xx_8ch_core_init[] = {
        /* setup adcs to point to mixer */
        { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
        { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
-       { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Front Mic */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Mic */
-       { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Line In */
        { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
@@ -519,9 +567,6 @@ static struct hda_verb stac92hd73xx_10ch_core_init[] = {
        /* setup adcs to point to mixer */
        { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
        { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
-       { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Front Mic */
-       { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Mic */
-       { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Line In */
        { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
@@ -543,8 +588,6 @@ static struct hda_verb stac92hd71bxx_core_init[] = {
        { 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)},
-       /* unmute mono out node */
-       { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
 };
 
 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
@@ -555,15 +598,13 @@ static struct hda_verb stac92hd71bxx_analog_core_init[] = {
        /* connect ports 0d and 0f to audio mixer */
        { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
        { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
+       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
        /* unmute dac0 input in audio mixer */
        { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
        /* 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)},
-       /* unmute mono out node */
-       { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {}
 };
 
@@ -601,6 +642,16 @@ static struct hda_verb stac9205_core_init[] = {
        {}
 };
 
+#define STAC_MONO_MUX \
+       { \
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+               .name = "Mono Mux", \
+               .count = 1, \
+               .info = stac92xx_mono_mux_enum_info, \
+               .get = stac92xx_mono_mux_enum_get, \
+               .put = stac92xx_mono_mux_enum_put, \
+       }
+
 #define STAC_INPUT_SOURCE(cnt) \
        { \
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -635,10 +686,6 @@ static struct snd_kcontrol_new stac9200_mixer[] = {
 static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
        STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
 
-       /* hardware gain controls */
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x13, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x14, 0x0, HDA_INPUT),
-
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
 
@@ -665,10 +712,6 @@ static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
 static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
        STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
 
-       /* hardware gain controls */
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x13, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x14, 0x0, HDA_INPUT),
-
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
 
@@ -695,10 +738,6 @@ static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
 static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
        STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
 
-       /* hardware gain controls */
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x13, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x14, 0x0, HDA_INPUT),
-
        HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
 
@@ -725,10 +764,6 @@ static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
 static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
        STAC_INPUT_SOURCE(2),
 
-       /* hardware gain controls */
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT),
-
        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),
@@ -746,10 +781,6 @@ static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
        STAC_INPUT_SOURCE(2),
        STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
 
-       /* hardware gain controls */
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT),
-
        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),
@@ -824,6 +855,35 @@ static struct snd_kcontrol_new stac_dmux_mixer = {
        .put = stac92xx_dmux_enum_put,
 };
 
+static const char *slave_vols[] = {
+       "Front Playback Volume",
+       "Surround Playback Volume",
+       "Center Playback Volume",
+       "LFE Playback Volume",
+       "Side Playback Volume",
+       "Headphone Playback Volume",
+       "Headphone Playback Volume",
+       "Speaker Playback Volume",
+       "External Speaker Playback Volume",
+       "Speaker2 Playback Volume",
+       NULL
+};
+
+static const char *slave_sws[] = {
+       "Front Playback Switch",
+       "Surround Playback Switch",
+       "Center Playback Switch",
+       "LFE Playback Switch",
+       "Side Playback Switch",
+       "Headphone Playback Switch",
+       "Headphone Playback Switch",
+       "Speaker Playback Switch",
+       "External Speaker Playback Switch",
+       "Speaker2 Playback Switch",
+       "IEC958 Playback Switch",
+       NULL
+};
+
 static int stac92xx_build_controls(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
@@ -857,6 +917,23 @@ static int stac92xx_build_controls(struct hda_codec *codec)
                if (err < 0)
                        return err;
        }
+
+       /* if we have no master control, let's create it */
+       if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
+               snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
+                                       HDA_OUTPUT, spec->vmaster_tlv);
+               err = snd_hda_add_vmaster(codec, "Master Playback Volume",
+                                         spec->vmaster_tlv, 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, slave_sws);
+               if (err < 0)
+                       return err;
+       }
+
        return 0;       
 }
 
@@ -976,9 +1053,15 @@ static unsigned int dell9200_m27_pin_configs[8] = {
        0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
 };
 
+static unsigned int oqo9200_pin_configs[8] = {
+       0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
+       0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
+};
+
 
 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
        [STAC_REF] = ref9200_pin_configs,
+       [STAC_9200_OQO] = oqo9200_pin_configs,
        [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
        [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
        [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
@@ -993,6 +1076,7 @@ static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
 
 static const char *stac9200_models[STAC_9200_MODELS] = {
        [STAC_REF] = "ref",
+       [STAC_9200_OQO] = "oqo",
        [STAC_9200_DELL_D21] = "dell-d21",
        [STAC_9200_DELL_D22] = "dell-d22",
        [STAC_9200_DELL_D23] = "dell-d23",
@@ -1077,12 +1161,14 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
                      STAC_9200_GATEWAY),
        SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
                      STAC_9200_GATEWAY),
+       /* OQO Mobile */
+       SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
        {} /* terminator */
 };
 
 static unsigned int ref925x_pin_configs[8] = {
        0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
-       0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
+       0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
 };
 
 static unsigned int stac925x_MA6_pin_configs[8] = {
@@ -1149,7 +1235,7 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
 
 static unsigned int ref92hd71bxx_pin_configs[10] = {
        0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
-       0x0181302e, 0x01114010, 0x01a19020, 0x90a000f0,
+       0x0181302e, 0x01114010, 0x01019020, 0x90a000f0,
        0x90a000f0, 0x01452050,
 };
 
@@ -1458,13 +1544,13 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
        SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
        /* Dell 3 stack systems */
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_3ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01ed, "Dell     ", STAC_DELL_3ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f4, "Dell     ", STAC_DELL_3ST),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_3ST),
        /* Dell 3 stack systems with verb table in BIOS */
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0227, "Dell Vostro 1400  ", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022f, "Dell     ", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x022e, "Dell     ", STAC_DELL_BIOS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0242, "Dell     ", STAC_DELL_BIOS),
@@ -1486,7 +1572,7 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
 
 static unsigned int ref9205_pin_configs[12] = {
        0x40000100, 0x40000100, 0x01016011, 0x01014010,
-       0x01813122, 0x01a19021, 0x40000100, 0x40000100,
+       0x01813122, 0x01a19021, 0x01019020, 0x40000100,
        0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
 };
 
@@ -1498,6 +1584,7 @@ static unsigned int ref9205_pin_configs[12] = {
     102801FD
     10280204
     1028021F
+    10280228 (Dell Vostro 1500)
 */
 static unsigned int dell_9205_m42_pin_configs[12] = {
        0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
@@ -1581,6 +1668,8 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
                      "unknown Dell", STAC_9205_DELL_M42),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
                      "Dell Inspiron", STAC_9205_DELL_M44),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
+                     "Dell Vostro 1500", STAC_9205_DELL_M42),
        {} /* terminator */
 };
 
@@ -1646,22 +1735,6 @@ static void stac92xx_set_config_regs(struct hda_codec *codec)
                                        spec->pin_configs[i]);
 }
 
-static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
-{
-       struct sigmatel_spec *spec = codec->spec;
-       /* Configure GPIOx as output */
-       snd_hda_codec_write_cache(codec, codec->afg, 0,
-                                 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
-       /* Configure GPIOx as CMOS */
-       snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
-       /* Assert GPIOx */
-       snd_hda_codec_write_cache(codec, codec->afg, 0,
-                                 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
-       /* Enable GPIOx */
-       snd_hda_codec_write_cache(codec, codec->afg, 0,
-                                 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
-}
-
 /*
  * Analog playback callbacks
  */
@@ -1826,6 +1899,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
                codec->num_pcms++;
                info++;
                info->name = "STAC92xx Digital";
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                if (spec->multiout.dig_out_nid) {
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -1956,6 +2030,7 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
 enum {
        STAC_CTL_WIDGET_VOL,
        STAC_CTL_WIDGET_MUTE,
+       STAC_CTL_WIDGET_MONO_MUX,
        STAC_CTL_WIDGET_IO_SWITCH,
        STAC_CTL_WIDGET_CLFE_SWITCH
 };
@@ -1963,6 +2038,7 @@ enum {
 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_CODEC_IO_SWITCH(NULL, 0),
        STAC_CODEC_CLFE_SWITCH(NULL, 0),
 };
@@ -2168,7 +2244,7 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
        int i, err;
 
        struct sigmatel_spec *spec = codec->spec;
-       unsigned int wid_caps;
+       unsigned int wid_caps, pincap;
 
 
        for (i = 0; i < cfg->line_outs; i++) {
@@ -2204,13 +2280,39 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
                }
        }
 
-       if (spec->line_switch)
-               if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
-                       return err;
+       if (spec->line_switch) {
+               nid = cfg->input_pins[AUTO_PIN_LINE];
+               pincap = snd_hda_param_read(codec, nid,
+                                               AC_PAR_PIN_CAP);
+               if (pincap & AC_PINCAP_OUT) {
+                       err = stac92xx_add_control(spec,
+                               STAC_CTL_WIDGET_IO_SWITCH,
+                               "Line In as Output Switch", nid << 8);
+                       if (err < 0)
+                               return err;
+               }
+       }
 
-       if (spec->mic_switch)
-               if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
-                       return err;
+       if (spec->mic_switch) {
+               unsigned int def_conf;
+               nid = cfg->input_pins[AUTO_PIN_MIC];
+               def_conf = snd_hda_codec_read(codec, nid, 0,
+                                               AC_VERB_GET_CONFIG_DEFAULT, 0);
+
+               /* some laptops have an internal analog microphone
+                * which can't be used as a output */
+               if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
+                       pincap = snd_hda_param_read(codec, nid,
+                                                       AC_PAR_PIN_CAP);
+                       if (pincap & AC_PINCAP_OUT) {
+                               err = stac92xx_add_control(spec,
+                                       STAC_CTL_WIDGET_IO_SWITCH,
+                                       "Mic as Output Switch", (nid << 8) | 1);
+                               if (err < 0)
+                                       return err;
+                       }
+               }
+       }
 
        return 0;
 }
@@ -2300,6 +2402,37 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
        return 0;
 }
 
+/* labels for mono mux outputs */
+static const char *stac92xx_mono_labels[3] = {
+       "DAC0", "DAC1", "Mixer"
+};
+
+/* create mono mux for mono out on capable codecs */
+static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
+{
+       struct sigmatel_spec *spec = codec->spec;
+       struct hda_input_mux *mono_mux = &spec->private_mono_mux;
+       int i, num_cons;
+       hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
+
+       num_cons = snd_hda_get_connections(codec,
+                               spec->mono_nid,
+                               con_lst,
+                               HDA_MAX_NUM_INPUTS);
+       if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
+               return -EINVAL;
+
+       for (i = 0; i < num_cons; i++) {
+               mono_mux->items[mono_mux->num_items].label =
+                                       stac92xx_mono_labels[i];
+               mono_mux->items[mono_mux->num_items].index = i;
+               mono_mux->num_items++;
+       }
+
+       return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
+                               "Mono Mux", spec->mono_nid);
+}
+
 /* labels for dmic mux inputs */
 static const char *stac92xx_dmic_labels[5] = {
        "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
@@ -2313,15 +2446,18 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
        struct sigmatel_spec *spec = codec->spec;
        struct hda_input_mux *dimux = &spec->private_dimux;
        hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
-       int i, j;
+       int err, i, j;
+       char name[32];
 
        dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
        dimux->items[dimux->num_items].index = 0;
        dimux->num_items++;
 
        for (i = 0; i < spec->num_dmics; i++) {
+               hda_nid_t nid;
                int index;
                int num_cons;
+               unsigned int wcaps;
                unsigned int def_conf;
 
                def_conf = snd_hda_codec_read(codec,
@@ -2332,17 +2468,32 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
                if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
                        continue;
 
+               nid = spec->dmic_nids[i];
                num_cons = snd_hda_get_connections(codec,
                                spec->dmux_nids[0],
                                con_lst,
                                HDA_MAX_NUM_INPUTS);
                for (j = 0; j < num_cons; j++)
-                       if (con_lst[j] == spec->dmic_nids[i]) {
+                       if (con_lst[j] == nid) {
                                index = j;
                                goto found;
                        }
                continue;
 found:
+               wcaps = get_wcaps(codec, nid);
+
+               if (wcaps & AC_WCAP_OUT_AMP) {
+                       sprintf(name, "%s Capture Volume",
+                               stac92xx_dmic_labels[dimux->num_items]);
+
+                       err = stac92xx_add_control(spec,
+                               STAC_CTL_WIDGET_VOL,
+                               name,
+                               HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
+                       if (err < 0)
+                               return err;
+               }
+
                dimux->items[dimux->num_items].label =
                        stac92xx_dmic_labels[dimux->num_items];
                dimux->items[dimux->num_items].index = index;
@@ -2461,6 +2612,50 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
                spec->autocfg.line_outs = spec->autocfg.hp_outs;
                hp_speaker_swap = 1;
        }
+       if (spec->autocfg.mono_out_pin) {
+               int dir = (get_wcaps(codec, spec->autocfg.mono_out_pin)
+                               & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
+               u32 caps = query_amp_caps(codec,
+                               spec->autocfg.mono_out_pin, dir);
+               hda_nid_t conn_list[1];
+
+               /* get the mixer node and then the mono mux if it exists */
+               if (snd_hda_get_connections(codec,
+                               spec->autocfg.mono_out_pin, conn_list, 1) &&
+                               snd_hda_get_connections(codec, conn_list[0],
+                               conn_list, 1)) {
+
+                               int wcaps = get_wcaps(codec, conn_list[0]);
+                               int wid_type = (wcaps & AC_WCAP_TYPE)
+                                       >> AC_WCAP_TYPE_SHIFT;
+                               /* LR swap check, some stac925x have a mux that
+                                * changes the DACs output path instead of the
+                                * mono-mux path.
+                                */
+                               if (wid_type == AC_WID_AUD_SEL &&
+                                               !(wcaps & AC_WCAP_LR_SWAP))
+                                       spec->mono_nid = conn_list[0];
+               }
+               /* all mono outs have a least a mute/unmute switch */
+               err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
+                       "Mono Playback Switch",
+                       HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin,
+                                       1, 0, dir));
+               if (err < 0)
+                       return err;
+               /* check to see if there is volume support for the amp */
+               if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
+                       err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
+                               "Mono Playback Volume",
+                               HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin,
+                                       1, 0, dir));
+                       if (err < 0)
+                               return err;
+               }
+
+               stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
+                                        AC_PINCTL_OUT_EN);
+       }
 
        if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
                return err;
@@ -2496,6 +2691,12 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
        if (err < 0)
                return err;
 
+       if (spec->mono_nid > 0) {
+               err = stac92xx_auto_create_mono_output_ctls(codec);
+               if (err < 0)
+                       return err;
+       }
+
        if (spec->num_dmics > 0)
                if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
                                                &spec->autocfg)) < 0)
@@ -2516,6 +2717,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
        spec->input_mux = &spec->private_imux;
        if (!spec->dinput_mux)
                spec->dinput_mux = &spec->private_dimux;
+       spec->mono_mux = &spec->private_mono_mux;
 
        return 1;
 }
@@ -2625,38 +2827,35 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
  * funky external mute control using GPIO pins.
  */
 
-static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
+static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
+                         unsigned int dir_mask, unsigned int data)
 {
        unsigned int gpiostate, gpiomask, gpiodir;
 
        gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
                                       AC_VERB_GET_GPIO_DATA, 0);
-
-       if (!muted)
-               gpiostate |= (1 << pin);
-       else
-               gpiostate &= ~(1 << pin);
+       gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
 
        gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
                                      AC_VERB_GET_GPIO_MASK, 0);
-       gpiomask |= (1 << pin);
+       gpiomask |= mask;
 
        gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
                                     AC_VERB_GET_GPIO_DIRECTION, 0);
-       gpiodir |= (1 << pin);
+       gpiodir |= dir_mask;
 
-       /* AppleHDA seems to do this -- WTF is this verb?? */
+       /* Configure GPIOx as CMOS */
        snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
 
        snd_hda_codec_write(codec, codec->afg, 0,
                            AC_VERB_SET_GPIO_MASK, gpiomask);
-       snd_hda_codec_write(codec, codec->afg, 0,
-                           AC_VERB_SET_GPIO_DIRECTION, gpiodir);
+       snd_hda_codec_read(codec, codec->afg, 0,
+                          AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
 
        msleep(1);
 
-       snd_hda_codec_write(codec, codec->afg, 0,
-                           AC_VERB_SET_GPIO_DATA, gpiostate);
+       snd_hda_codec_read(codec, codec->afg, 0,
+                          AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
 }
 
 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
@@ -2668,6 +2867,16 @@ static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
                                          (AC_USRSP_EN | event));
 }
 
+static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
+{
+       int i;
+       for (i = 0; i < cfg->hp_outs; i++)
+               if (cfg->hp_pins[i] == nid)
+                       return 1; /* nid is a HP-Out */
+
+       return 0; /* nid is not a HP-Out */
+};
+
 static int stac92xx_init(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
@@ -2703,10 +2912,23 @@ static int stac92xx_init(struct hda_codec *codec)
                        stac92xx_auto_set_pinctl(codec, nid, pinctl);
                }
        }
-       if (spec->num_dmics > 0)
-               for (i = 0; i < spec->num_dmics; i++)
-                       stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
-                                                AC_PINCTL_IN_EN);
+       for (i = 0; i < spec->num_dmics; i++)
+               stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
+                                       AC_PINCTL_IN_EN);
+       for (i = 0; i < spec->num_pwrs; i++)  {
+               int event = is_nid_hp_pin(cfg, spec->pwr_nids[i])
+                                       ? STAC_HP_EVENT : STAC_PWR_EVENT;
+               int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i],
+                                       0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
+               /* outputs are only ports capable of power management
+                * any attempts on powering down a input port cause the
+                * referenced VREF to act quirky.
+                */
+               if (pinctl & AC_PINCTL_IN_EN)
+                       continue;
+               enable_pin_detect(codec, spec->pwr_nids[i], event | i);
+               codec->patch_ops.unsol_event(codec, (event | i) << 26);
+       }
 
        if (cfg->dig_out_pin)
                stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
@@ -2715,10 +2937,8 @@ static int stac92xx_init(struct hda_codec *codec)
                stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
                                         AC_PINCTL_IN_EN);
 
-       if (spec->gpio_mute) {
-               stac922x_gpio_mute(codec, 0, 0);
-               stac922x_gpio_mute(codec, 1, 0);
-       }
+       stac_gpio_set(codec, spec->gpio_mask,
+                                       spec->gpio_dir, spec->gpio_data);
 
        return 0;
 }
@@ -2808,10 +3028,14 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
        int i, presence;
 
        presence = 0;
+       if (spec->gpio_mute)
+               presence = !(snd_hda_codec_read(codec, codec->afg, 0,
+                       AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
+
        for (i = 0; i < cfg->hp_outs; i++) {
-               presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
                if (presence)
                        break;
+               presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
        }
 
        if (presence) {
@@ -2833,12 +3057,37 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
        }
 } 
 
+static void stac92xx_pin_sense(struct hda_codec *codec, int idx)
+{
+       struct sigmatel_spec *spec = codec->spec;
+       hda_nid_t nid = spec->pwr_nids[idx];
+       int presence, val;
+       val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0)
+                                                       & 0x000000ff;
+       presence = get_hp_pin_presence(codec, nid);
+       idx = 1 << idx;
+
+       if (presence)
+               val &= ~idx;
+       else
+               val |= idx;
+
+       /* power down unused output ports */
+       snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
+};
+
 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
 {
-       switch (res >> 26) {
+       struct sigmatel_spec *spec = codec->spec;
+       int idx = res >> 26 & 0x0f;
+
+       switch ((res >> 26) & 0x30) {
        case STAC_HP_EVENT:
                stac92xx_hp_detect(codec, res);
-               break;
+               /* fallthru */
+       case STAC_PWR_EVENT:
+               if (spec->num_pwrs > 0)
+                       stac92xx_pin_sense(codec, idx);
        }
 }
 
@@ -2849,10 +3098,8 @@ static int stac92xx_resume(struct hda_codec *codec)
 
        stac92xx_set_config_regs(codec);
        snd_hda_sequence_write(codec, spec->init);
-       if (spec->gpio_mute) {
-               stac922x_gpio_mute(codec, 0, 0);
-               stac922x_gpio_mute(codec, 1, 0);
-       }
+       stac_gpio_set(codec, spec->gpio_mask,
+               spec->gpio_dir, spec->gpio_data);
        snd_hda_codec_resume_amp(codec);
        snd_hda_codec_resume_cache(codec);
        /* invoke unsolicited event to reset the HP state */
@@ -2909,8 +3156,10 @@ static int patch_stac9200(struct hda_codec *codec)
        spec->num_muxes = 1;
        spec->num_dmics = 0;
        spec->num_adcs = 1;
+       spec->num_pwrs = 0;
 
-       if (spec->board_config == STAC_9200_GATEWAY)
+       if (spec->board_config == STAC_9200_GATEWAY ||
+           spec->board_config == STAC_9200_OQO)
                spec->init = stac9200_eapd_init;
        else
                spec->init = stac9200_core_init;
@@ -2964,6 +3213,7 @@ static int patch_stac925x(struct hda_codec *codec)
        spec->mux_nids = stac925x_mux_nids;
        spec->num_muxes = 1;
        spec->num_adcs = 1;
+       spec->num_pwrs = 0;
        switch (codec->vendor_id) {
        case 0x83847632: /* STAC9202  */
        case 0x83847633: /* STAC9202D */
@@ -3084,8 +3334,11 @@ again:
        spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
        spec->dinput_mux = &stac92hd73xx_dmux;
        /* GPIO0 High = Enable EAPD */
-       spec->gpio_mask = spec->gpio_data = 0x000001;
-       stac92xx_enable_gpio_mask(codec);
+       spec->gpio_mask = spec->gpio_dir = 0x1;
+       spec->gpio_data = 0x01;
+
+       spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
+       spec->pwr_nids = stac92hd73xx_pwr_nids;
 
        err = stac92xx_parse_auto_config(codec, 0x22, 0x24);
 
@@ -3156,8 +3409,8 @@ again:
        spec->aloopback_mask = 0x20;
        spec->aloopback_shift = 0;
 
-       spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
-       stac92xx_enable_gpio_mask(codec);
+       /* GPIO0 High = EAPD */
+       spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1;
 
        spec->mux_nids = stac92hd71bxx_mux_nids;
        spec->adc_nids = stac92hd71bxx_adc_nids;
@@ -3169,6 +3422,9 @@ again:
        spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
        spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
 
+       spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
+       spec->pwr_nids = stac92hd71bxx_pwr_nids;
+
        spec->multiout.num_dacs = 2;
        spec->multiout.hp_nid = 0x11;
        spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
@@ -3210,7 +3466,8 @@ static int patch_stac922x(struct hda_codec *codec)
                                                        stac922x_models,
                                                        stac922x_cfg_tbl);
        if (spec->board_config == STAC_INTEL_MAC_V3) {
-               spec->gpio_mute = 1;
+               spec->gpio_mask = spec->gpio_dir = 0x03;
+               spec->gpio_data = 0x03;
                /* Intel Macs have all same PCI SSID, so we need to check
                 * codec SSID to distinguish the exact models
                 */
@@ -3263,6 +3520,7 @@ static int patch_stac922x(struct hda_codec *codec)
        spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
        spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
        spec->num_dmics = 0;
+       spec->num_pwrs = 0;
 
        spec->init = stac922x_core_init;
        spec->mixer = stac922x_mixer;
@@ -3337,16 +3595,23 @@ static int patch_stac927x(struct hda_codec *codec)
        case STAC_D965_3ST:
        case STAC_D965_5ST:
                /* GPIO0 High = Enable EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000001;
+               spec->gpio_mask = spec->gpio_dir = 0x01;
+               spec->gpio_data = 0x01;
                spec->num_dmics = 0;
 
                spec->init = d965_core_init;
                spec->mixer = stac927x_mixer;
                break;
        case STAC_DELL_BIOS:
+               /* correct the front output jack as a hp out */
+               stac92xx_set_config_reg(codec, 0x0f, 0x02270110);
+               /* correct the front input jack as a mic */
+               stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
+               /* fallthru */
        case STAC_DELL_3ST:
                /* GPIO2 High = Enable EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000004;
+               spec->gpio_mask = spec->gpio_dir = 0x04;
+               spec->gpio_data = 0x04;
                spec->dmic_nids = stac927x_dmic_nids;
                spec->num_dmics = STAC927X_NUM_DMICS;
 
@@ -3357,17 +3622,18 @@ static int patch_stac927x(struct hda_codec *codec)
                break;
        default:
                /* GPIO0 High = Enable EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000001;
+               spec->gpio_mask = spec->gpio_dir = 0x1;
+               spec->gpio_data = 0x01;
                spec->num_dmics = 0;
 
                spec->init = stac927x_core_init;
                spec->mixer = stac927x_mixer;
        }
 
+       spec->num_pwrs = 0;
        spec->aloopback_mask = 0x40;
        spec->aloopback_shift = 0;
 
-       stac92xx_enable_gpio_mask(codec); 
        err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
        if (!err) {
                if (spec->board_config < 0) {
@@ -3385,6 +3651,18 @@ static int patch_stac927x(struct hda_codec *codec)
 
        codec->patch_ops = stac92xx_patch_ops;
 
+       /*
+        * !!FIXME!!
+        * The STAC927x seem to require fairly long delays for certain
+        * command sequences.  With too short delays (even if the answer
+        * is set to RIRB properly), it results in the silence output
+        * on some hardwares like Dell.
+        *
+        * The below flag enables the longer delay (see get_response
+        * in hda_intel.c).
+        */
+       codec->bus->needs_damn_long_delay = 1;
+
        return 0;
 }
 
@@ -3425,6 +3703,7 @@ static int patch_stac9205(struct hda_codec *codec)
        spec->num_dmics = STAC9205_NUM_DMICS;
        spec->dmux_nids = stac9205_dmux_nids;
        spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
+       spec->num_pwrs = 0;
 
        spec->init = stac9205_core_init;
        spec->mixer = stac9205_mixer;
@@ -3439,19 +3718,28 @@ static int patch_stac9205(struct hda_codec *codec)
                stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
                stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
 
-               spec->gpio_mask = 0x00000007; /* GPIO0-2 */
-               /* GPIO0 High = EAPD, GPIO1 Low = DRM,
-                * GPIO2 High = Headphone Mute
+               /* Enable unsol response for GPIO4/Dock HP connection */
+               snd_hda_codec_write(codec, codec->afg, 0,
+                       AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
+               snd_hda_codec_write_cache(codec, codec->afg, 0,
+                                         AC_VERB_SET_UNSOLICITED_ENABLE,
+                                         (AC_USRSP_EN | STAC_HP_EVENT));
+
+               spec->gpio_dir = 0x0b;
+               spec->gpio_mask = 0x1b;
+               spec->gpio_mute = 0x10;
+               /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
+                * GPIO3 Low = DRM
                 */
-               spec->gpio_data = 0x00000005;
+               spec->gpio_data = 0x01;
                break;
        default:
                /* GPIO0 High = EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000001;
+               spec->gpio_mask = spec->gpio_dir = 0x1;
+               spec->gpio_data = 0x01;
                break;
        }
 
-       stac92xx_enable_gpio_mask(codec);
        err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
        if (!err) {
                if (spec->board_config < 0) {
@@ -3687,6 +3975,7 @@ static int patch_stac9872(struct hda_codec *codec)
                spec->multiout.hp_nid = VAIO_HP_DAC;
                spec->num_adcs = ARRAY_SIZE(vaio_adcs);
                spec->adc_nids = vaio_adcs;
+               spec->num_pwrs = 0;
                spec->input_mux = &vaio_mux;
                spec->mux_nids = vaio_mux_nids;
                codec->patch_ops = stac9872_vaio_patch_ops;
@@ -3700,6 +3989,7 @@ static int patch_stac9872(struct hda_codec *codec)
                spec->multiout.dac_nids = vaio_dacs;
                spec->multiout.hp_nid = VAIO_HP_DAC;
                spec->num_adcs = ARRAY_SIZE(vaio_adcs);
+               spec->num_pwrs = 0;
                spec->adc_nids = vaio_adcs;
                spec->input_mux = &vaio_mux;
                spec->mux_nids = vaio_mux_nids;