[ALSA] hda-codec - Re-add quirk support for Dell XPS 1330 and Inspiron 1420
[pandora-kernel.git] / sound / pci / hda / patch_sigmatel.c
index 3918782..9fae4f1 100644 (file)
@@ -49,6 +49,7 @@ enum {
        STAC_9200_DELL_M25,
        STAC_9200_DELL_M26,
        STAC_9200_DELL_M27,
+       STAC_9200_GATEWAY,
        STAC_9200_MODELS
 };
 
@@ -57,7 +58,6 @@ enum {
        STAC_9205_DELL_M42,
        STAC_9205_DELL_M43,
        STAC_9205_DELL_M44,
-       STAC_9205_M43xx,
        STAC_9205_MODELS
 };
 
@@ -146,6 +146,8 @@ struct sigmatel_spec {
 
        /* i/o switches */
        unsigned int io_switch[2];
+       unsigned int clfe_swap;
+       unsigned int aloopback;
 
        struct hda_pcm pcm_rec[2];      /* PCM information */
 
@@ -295,12 +297,95 @@ static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
                                     spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
 }
 
+#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
+
+static int stac92xx_aloopback_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.integer.value[0] = spec->aloopback;
+       return 0;
+}
+
+static int stac92xx_aloopback_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;
+       unsigned int dac_mode;
+
+       if (spec->aloopback == ucontrol->value.integer.value[0])
+               return 0;
+
+       spec->aloopback = ucontrol->value.integer.value[0];
+
+
+       dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
+               kcontrol->private_value & 0xFFFF, 0x0);
+
+       if (spec->aloopback) {
+               snd_hda_power_up(codec);
+               dac_mode |= 0x40;
+       } else {
+               snd_hda_power_down(codec);
+               dac_mode &= ~0x40;
+       }
+
+       snd_hda_codec_write_cache(codec, codec->afg, 0,
+               kcontrol->private_value >> 16, dac_mode);
+
+       return 1;
+}
+
+static int stac92xx_volknob_info(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = 127;
+       return 0;
+}
+
+static int stac92xx_volknob_get(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       ucontrol->value.integer.value[0] = kcontrol->private_value;
+       return 0;
+}
+
+static int stac92xx_volknob_put(struct snd_kcontrol *kcontrol,
+               struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+
+       if (kcontrol->private_value == ucontrol->value.integer.value[0])
+               return 0;
+
+       kcontrol->private_value = ucontrol->value.integer.value[0];
+
+       snd_hda_codec_write_cache(codec, 0x24, 0,
+               AC_VERB_SET_VOLUME_KNOB_CONTROL,
+                       kcontrol->private_value | 0x80);
+       return 1;
+}
+
+
 static struct hda_verb stac9200_core_init[] = {
        /* set dac0mux for dac converter */
        { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
        {}
 };
 
+static struct hda_verb stac9200_eapd_init[] = {
+       /* set dac0mux for dac converter */
+       {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
+       {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
+       {}
+};
+
 static struct hda_verb stac925x_core_init[] = {
        /* set dac0mux for dac converter */
        { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -335,21 +420,43 @@ static struct hda_verb stac9205_core_init[] = {
        {}
 };
 
-#define STAC_INPUT_SOURCE \
+#define STAC_INPUT_SOURCE(cnt) \
        { \
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
                .name = "Input Source", \
-               .count = 1, \
+               .count = cnt, \
                .info = stac92xx_mux_enum_info, \
                .get = stac92xx_mux_enum_get, \
                .put = stac92xx_mux_enum_put, \
        }
 
+#define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
+       { \
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+               .name  = "Analog Loopback", \
+               .count = 1, \
+               .info  = stac92xx_aloopback_info, \
+               .get   = stac92xx_aloopback_get, \
+               .put   = stac92xx_aloopback_put, \
+               .private_value = verb_read | (verb_write << 16), \
+       }
+
+#define STAC_VOLKNOB \
+       { \
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+               .name  = "Master Playback Volume", \
+               .count = 1, \
+               .info  = stac92xx_volknob_info, \
+               .get   = stac92xx_volknob_get, \
+               .put   = stac92xx_volknob_put, \
+               .private_value = 127, \
+       }
+
 
 static struct snd_kcontrol_new stac9200_mixer[] = {
        HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
-       STAC_INPUT_SOURCE,
+       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),
@@ -357,38 +464,13 @@ static struct snd_kcontrol_new stac9200_mixer[] = {
 };
 
 static struct snd_kcontrol_new stac925x_mixer[] = {
-       STAC_INPUT_SOURCE,
+       STAC_INPUT_SOURCE(1),
        HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
        { } /* end */
 };
 
-/* This needs to be generated dynamically based on sequence */
-static struct snd_kcontrol_new stac922x_mixer[] = {
-       STAC_INPUT_SOURCE,
-       HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
-       HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-/* This needs to be generated dynamically based on sequence */
-static struct snd_kcontrol_new stac9227_mixer[] = {
-       STAC_INPUT_SOURCE,
-       HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
-static struct snd_kcontrol_new stac927x_mixer[] = {
-       STAC_INPUT_SOURCE,
-       HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
-       { } /* end */
-};
-
 static struct snd_kcontrol_new stac9205_mixer[] = {
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -398,10 +480,52 @@ static struct snd_kcontrol_new stac9205_mixer[] = {
                .get = stac92xx_dmux_enum_get,
                .put = stac92xx_dmux_enum_put,
        },
-       STAC_INPUT_SOURCE,
-       HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
-       HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
+       STAC_INPUT_SOURCE(2),
+       STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
+       STAC_VOLKNOB,
+
+       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 */
+};
+
+/* This needs to be generated dynamically based on sequence */
+static struct snd_kcontrol_new stac922x_mixer[] = {
+       STAC_INPUT_SOURCE(2),
+       STAC_VOLKNOB,
+       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 */
+};
+
+
+static struct snd_kcontrol_new stac927x_mixer[] = {
+       STAC_INPUT_SOURCE(3),
+       STAC_VOLKNOB,
+       STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
+
+       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 */
 };
 
@@ -446,8 +570,8 @@ static unsigned int ref9200_pin_configs[8] = {
     102801E8
 */
 static unsigned int dell9200_d21_pin_configs[8] = {
-       0x400001f0, 0x400001f1, 0x01a19021, 0x90100140,
-       0x01813122, 0x02214030, 0x01014010, 0x02a19020,
+       0x400001f0, 0x400001f1, 0x02214030, 0x01014010, 
+       0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
 };
 
 /* 
@@ -456,8 +580,8 @@ static unsigned int dell9200_d21_pin_configs[8] = {
     102801C1
 */
 static unsigned int dell9200_d22_pin_configs[8] = {
-       0x400001f0, 0x400001f1, 0x02a19021, 0x90100140,
-       0x400001f2, 0x0221401f, 0x01014010, 0x01813020,
+       0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
+       0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
 };
 
 /* 
@@ -470,8 +594,8 @@ static unsigned int dell9200_d22_pin_configs[8] = {
     102801E3
 */
 static unsigned int dell9200_d23_pin_configs[8] = {
-       0x400001f0, 0x400001f1, 0x01a19021, 0x90100140,
-       0x400001f2, 0x0221401f, 0x01014010, 0x01813020,
+       0x400001f0, 0x400001f1, 0x0221401f, 0x01014010, 
+       0x01813020, 0x01a19021, 0x90100140, 0x400001f2, 
 };
 
 
@@ -481,8 +605,8 @@ static unsigned int dell9200_d23_pin_configs[8] = {
     102801D8 (Dell Inspiron 640m)
 */
 static unsigned int dell9200_m21_pin_configs[8] = {
-       0x40c003fa, 0x03441340, 0x03a11020, 0x401003fc,
-       0x403003fd, 0x0321121f, 0x0321121f, 0x408003fb,
+       0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
+       0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
 };
 
 /* 
@@ -494,8 +618,8 @@ static unsigned int dell9200_m21_pin_configs[8] = {
     102801D6 
 */
 static unsigned int dell9200_m22_pin_configs[8] = {
-       0x40c003fa, 0x0144131f, 0x03A11020, 0x401003fb
-       0x40f000fc, 0x0321121f, 0x90170310, 0x90a70321, 
+       0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310
+       0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
 };
 
 /* 
@@ -516,8 +640,8 @@ static unsigned int dell9200_m23_pin_configs[8] = {
     102801D3
 */
 static unsigned int dell9200_m24_pin_configs[8] = {
-       0x40c003fa, 0x404003fb, 0x03a11020, 0x401003fd
-       0x403003fe, 0x0321121f, 0x90170310, 0x408003fc,
+       0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310
+       0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe, 
 };
 
 /*
@@ -527,8 +651,8 @@ static unsigned int dell9200_m24_pin_configs[8] = {
     102801EF
 */
 static unsigned int dell9200_m25_pin_configs[8] = {
-       0x40c003fa, 0x01441340, 0x04a11020, 0x401003fc,
-       0x403003fd, 0x0421121f, 0x90170310, 0x408003fb,
+       0x40c003fa, 0x01441340, 0x0421121f, 0x90170310, 
+       0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
 };
 
 /*
@@ -537,8 +661,8 @@ static unsigned int dell9200_m25_pin_configs[8] = {
     102801F6
 */
 static unsigned int dell9200_m26_pin_configs[8] = {
-       0x40c003fa, 0x404003fb, 0x04a11020, 0x401003fd,
-       0x403003fe, 0x0421121f, 0x90170310, 0x408003fc,
+       0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310, 
+       0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
 };
 
 /*
@@ -546,8 +670,8 @@ static unsigned int dell9200_m26_pin_configs[8] = {
     102801CD (Dell Inspiron E1705/9400)
 */
 static unsigned int dell9200_m27_pin_configs[8] = {
-       0x40c003fa, 0x01441340, 0x04a11020, 0x90170310,
-       0x40f003fc, 0x0421121f, 0x90170310, 0x408003fb,
+       0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
+       0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
 };
 
 
@@ -577,6 +701,7 @@ static const char *stac9200_models[STAC_9200_MODELS] = {
        [STAC_9200_DELL_M25] = "dell-m25",
        [STAC_9200_DELL_M26] = "dell-m26",
        [STAC_9200_DELL_M27] = "dell-m27",
+       [STAC_9200_GATEWAY] = "gateway",
 };
 
 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
@@ -644,7 +769,12 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
                      "unknown Dell", STAC_9200_DELL_M26),
        /* Panasonic */
        SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
-
+       /* Gateway machines needs EAPD to be set on resume */
+       SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
+       SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
+                     STAC_9200_GATEWAY),
+       SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
+                     STAC_9200_GATEWAY),
        {} /* terminator */
 };
 
@@ -981,11 +1111,13 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
        SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
        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),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
        /* Dell 3 stack systems */
        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),
        /* 965 based 5 stack systems */
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL,  0x0209, "Dell XPS 1330", STAC_D965_5ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
        SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
@@ -1046,7 +1178,6 @@ static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
        [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
        [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
        [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
-       [STAC_9205_M43xx] = NULL,
 };
 
 static const char *stac9205_models[STAC_9205_MODELS] = {
@@ -1065,9 +1196,13 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
                      "unknown Dell", STAC_9205_DELL_M42),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
-                     "Dell Precision", STAC_9205_M43xx),
+                     "Dell Precision", STAC_9205_DELL_M43),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
+                         "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
                      "Dell Precision", STAC_9205_DELL_M43),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
+                     "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
                      "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
@@ -1303,10 +1438,9 @@ static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
 };
 
 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
-       .substreams = 2,
        .channels_min = 2,
        .channels_max = 2,
-       /* NID is set in stac92xx_build_pcms */
+       /* NID + .substreams is set in stac92xx_build_pcms */
        .ops = {
                .prepare = stac92xx_capture_pcm_prepare,
                .cleanup = stac92xx_capture_pcm_cleanup
@@ -1325,6 +1459,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
        info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
+       info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
 
        if (spec->alt_switch) {
                codec->num_pcms++;
@@ -1406,6 +1541,36 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
         return 1;
 }
 
+#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
+
+static int stac92xx_clfe_switch_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.integer.value[0] = spec->clfe_swap;
+       return 0;
+}
+
+static int stac92xx_clfe_switch_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 = kcontrol->private_value & 0xff;
+
+       if (spec->clfe_swap == ucontrol->value.integer.value[0])
+               return 0;
+
+       spec->clfe_swap = ucontrol->value.integer.value[0];
+
+       snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
+               spec->clfe_swap ? 0x4 : 0x0);
+
+       return 1;
+}
+
 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
          .name = xname, \
@@ -1416,17 +1581,28 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
           .private_value = xpval, \
        }
 
+#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
+       { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+         .name = xname, \
+         .index = 0, \
+         .info = stac92xx_clfe_switch_info, \
+         .get = stac92xx_clfe_switch_get, \
+         .put = stac92xx_clfe_switch_put, \
+         .private_value = xpval, \
+       }
 
 enum {
        STAC_CTL_WIDGET_VOL,
        STAC_CTL_WIDGET_MUTE,
        STAC_CTL_WIDGET_IO_SWITCH,
+       STAC_CTL_WIDGET_CLFE_SWITCH
 };
 
 static struct snd_kcontrol_new stac92xx_control_templates[] = {
        HDA_CODEC_VOLUME(NULL, 0, 0, 0),
        HDA_CODEC_MUTE(NULL, 0, 0, 0),
        STAC_CODEC_IO_SWITCH(NULL, 0),
+       STAC_CODEC_CLFE_SWITCH(NULL, 0),
 };
 
 /* add dynamic controls */
@@ -1479,7 +1655,8 @@ static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cf
        case 3:
                /* add line-in as side */
                if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
-                       cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
+                       cfg->line_out_pins[cfg->line_outs] =
+                               cfg->input_pins[AUTO_PIN_LINE];
                        spec->line_switch = 1;
                        cfg->line_outs++;
                }
@@ -1487,12 +1664,14 @@ static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cf
        case 2:
                /* add line-in as clfe and mic as side */
                if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
-                       cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
+                       cfg->line_out_pins[cfg->line_outs] =
+                               cfg->input_pins[AUTO_PIN_LINE];
                        spec->line_switch = 1;
                        cfg->line_outs++;
                }
                if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
-                       cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
+                       cfg->line_out_pins[cfg->line_outs] =
+                               cfg->input_pins[AUTO_PIN_MIC];
                        spec->mic_switch = 1;
                        cfg->line_outs++;
                }
@@ -1500,12 +1679,14 @@ static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cf
        case 1:
                /* add line-in as surr and mic as clfe */
                if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
-                       cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
+                       cfg->line_out_pins[cfg->line_outs] =
+                               cfg->input_pins[AUTO_PIN_LINE];
                        spec->line_switch = 1;
                        cfg->line_outs++;
                }
                if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
-                       cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
+                       cfg->line_out_pins[cfg->line_outs] =
+                               cfg->input_pins[AUTO_PIN_MIC];
                        spec->mic_switch = 1;
                        cfg->line_outs++;
                }
@@ -1615,7 +1796,7 @@ static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_
 }
 
 /* add playback controls from the parsed DAC table */
-static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
+static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
                                               const struct auto_pin_cfg *cfg)
 {
        static const char *chname[4] = {
@@ -1624,6 +1805,10 @@ static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
        hda_nid_t nid;
        int i, err;
 
+       struct sigmatel_spec *spec = codec->spec;
+       unsigned int wid_caps;
+
+
        for (i = 0; i < cfg->line_outs; i++) {
                if (!spec->multiout.dac_nids[i])
                        continue;
@@ -1638,6 +1823,18 @@ static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
                        err = create_controls(spec, "LFE", nid, 2);
                        if (err < 0)
                                return err;
+
+                       wid_caps = get_wcaps(codec, nid);
+
+                       if (wid_caps & AC_WCAP_LR_SWAP) {
+                               err = stac92xx_add_control(spec,
+                                       STAC_CTL_WIDGET_CLFE_SWITCH,
+                                       "Swap Center/LFE Playback Switch", nid);
+
+                               if (err < 0)
+                                       return err;
+                       }
+
                } else {
                        err = create_controls(spec, chname[i], nid, 3);
                        if (err < 0)
@@ -1890,9 +2087,19 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
                if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
                        return err;
 
-       if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
-           (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
-           (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
+       err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
+
+       if (err < 0)
+               return err;
+
+       err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
+
+       if (err < 0)
+               return err;
+
+       err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
+
+       if (err < 0)
                return err;
 
        if (spec->num_dmics > 0)
@@ -2299,8 +2506,12 @@ static int patch_stac9200(struct hda_codec *codec)
        spec->mux_nids = stac9200_mux_nids;
        spec->num_muxes = 1;
        spec->num_dmics = 0;
+       spec->num_adcs = 1;
 
-       spec->init = stac9200_core_init;
+       if (spec->board_config == STAC_9200_GATEWAY)
+               spec->init = stac9200_eapd_init;
+       else
+               spec->init = stac9200_core_init;
        spec->mixer = stac9200_mixer;
 
        err = stac9200_parse_auto_config(codec);
@@ -2350,6 +2561,7 @@ static int patch_stac925x(struct hda_codec *codec)
        spec->adc_nids = stac925x_adc_nids;
        spec->mux_nids = stac925x_mux_nids;
        spec->num_muxes = 1;
+       spec->num_adcs = 1;
        switch (codec->vendor_id) {
        case 0x83847632: /* STAC9202  */
        case 0x83847633: /* STAC9202D */
@@ -2453,6 +2665,7 @@ static int patch_stac922x(struct hda_codec *codec)
        spec->adc_nids = stac922x_adc_nids;
        spec->mux_nids = stac922x_mux_nids;
        spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
+       spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
        spec->num_dmics = 0;
 
        spec->init = stac922x_core_init;
@@ -2521,22 +2734,25 @@ static int patch_stac927x(struct hda_codec *codec)
                spec->adc_nids = stac927x_adc_nids;
                spec->mux_nids = stac927x_mux_nids;
                spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
+               spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
                spec->num_dmics = 0;
                spec->init = d965_core_init;
-               spec->mixer = stac9227_mixer;
+               spec->mixer = stac927x_mixer;
                break;
        case STAC_D965_5ST:
                spec->adc_nids = stac927x_adc_nids;
                spec->mux_nids = stac927x_mux_nids;
                spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
+               spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
                spec->num_dmics = 0;
                spec->init = d965_core_init;
-               spec->mixer = stac9227_mixer;
+               spec->mixer = stac927x_mixer;
                break;
        default:
                spec->adc_nids = stac927x_adc_nids;
                spec->mux_nids = stac927x_mux_nids;
                spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
+               spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
                spec->num_dmics = 0;
                spec->init = stac927x_core_init;
                spec->mixer = stac927x_mixer;
@@ -2597,6 +2813,7 @@ static int patch_stac9205(struct hda_codec *codec)
        }
 
        spec->adc_nids = stac9205_adc_nids;
+       spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
        spec->mux_nids = stac9205_mux_nids;
        spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
        spec->dmic_nids = stac9205_dmic_nids;
@@ -2609,7 +2826,6 @@ static int patch_stac9205(struct hda_codec *codec)
        spec->multiout.dac_nids = spec->dac_nids;
        
        switch (spec->board_config){
-       case STAC_9205_M43xx:
        case STAC_9205_DELL_M43:
                /* Enable SPDIF in/out */
                stac92xx_set_config_reg(codec, 0x1f, 0x01441030);