[ALSA] hda-codec: Add 4 channel support for Realtek ALC883
[safe/jmp/linux-2.6] / sound / pci / hda / patch_realtek.c
index 4cbd0e6..93ff155 100644 (file)
@@ -155,6 +155,7 @@ enum {
        ALC882_W2JC,
        ALC882_TARGA,
        ALC882_ASUS_A7J,
+       ALC882_ASUS_A7M,
        ALC885_MACPRO,
        ALC885_MBP3,
        ALC885_IMAC24,
@@ -4998,8 +4999,10 @@ static struct snd_kcontrol_new alc882_targa_mixer[] = {
        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
        HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
        HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
        { } /* end */
 };
 
@@ -5019,6 +5022,23 @@ static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
        HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
+       { } /* end */
+};
+
+static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
+       HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
+       HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
+       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
+       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
+       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
+       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
+       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
+       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
+       HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
        { } /* end */
 };
 
@@ -5373,6 +5393,24 @@ static struct hda_verb alc882_asus_a7j_verbs[] = {
        { } /* end */
 };
 
+static struct hda_verb alc882_asus_a7m_verbs[] = {
+       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
+       {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
+
+       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
+       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
+       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
+        
+       {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
+       {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
+       {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
+
+       {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
+       {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
+       {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
+       { } /* end */
+};
+
 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
 {
        unsigned int gpiostate, gpiomask, gpiodir;
@@ -5550,6 +5588,9 @@ static const char *alc882_models[ALC882_MODEL_LAST] = {
        [ALC882_6ST_DIG]        = "6stack-dig",
        [ALC882_ARIMA]          = "arima",
        [ALC882_W2JC]           = "w2jc",
+       [ALC882_TARGA]          = "targa",
+       [ALC882_ASUS_A7J]       = "asus-a7j",
+       [ALC882_ASUS_A7M]       = "asus-a7m",
        [ALC885_MACPRO]         = "macpro",
        [ALC885_MBP3]           = "mbp3",
        [ALC885_IMAC24]         = "imac24",
@@ -5563,6 +5604,7 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
        SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
        SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
+       SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
        SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
        SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
        SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
@@ -5683,6 +5725,19 @@ static struct alc_config_preset alc882_presets[] = {
                .need_dac_fix = 1,
                .input_mux = &alc882_capture_source,
        },      
+       [ALC882_ASUS_A7M] = {
+               .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
+               .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
+                               alc880_gpio1_init_verbs,
+                               alc882_asus_a7m_verbs },
+               .num_dacs = ARRAY_SIZE(alc882_dac_nids),
+               .dac_nids = alc882_dac_nids,
+               .dig_out_nid = ALC882_DIGOUT_NID,
+               .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
+               .channel_mode = alc880_threestack_modes,
+               .need_dac_fix = 1,
+               .input_mux = &alc882_capture_source,
+       },      
 };
 
 
@@ -5782,6 +5837,32 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec)
        }
 }
 
+/* add mic boosts if needed */
+static int alc_auto_add_mic_boost(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       int err;
+       hda_nid_t nid;
+
+       nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
+       if (nid) {
+               err = add_control(spec, ALC_CTL_WIDGET_VOL,
+                                 "Mic Boost",
+                                 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
+               if (err < 0)
+                       return err;
+       }
+       nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
+       if (nid) {
+               err = add_control(spec, ALC_CTL_WIDGET_VOL,
+                                 "Front Mic Boost",
+                                 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
+               if (err < 0)
+                       return err;
+       }
+       return 0;
+}
+
 /* almost identical with ALC880 parser... */
 static int alc882_parse_auto_config(struct hda_codec *codec)
 {
@@ -5790,10 +5871,17 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
 
        if (err < 0)
                return err;
-       else if (err > 0)
-               /* hack - override the init verbs */
-               spec->init_verbs[0] = alc882_auto_init_verbs;
-       return err;
+       else if (!err)
+               return 0; /* no config found */
+
+       err = alc_auto_add_mic_boost(codec);
+       if (err < 0)
+               return err;
+
+       /* hack - override the init verbs */
+       spec->init_verbs[0] = alc882_auto_init_verbs;
+
+       return 1; /* config found */
 }
 
 /* additional initialization for auto-configuration model */
@@ -5999,6 +6087,18 @@ static struct hda_verb alc883_3ST_ch2_init[] = {
 };
 
 /*
+ * 4ch mode
+ */
+static struct hda_verb alc883_3ST_ch4_init[] = {
+       { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
+       { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
+       { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
+       { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
+       { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
+       { } /* end */
+};
+
+/*
  * 6ch mode
  */
 static struct hda_verb alc883_3ST_ch6_init[] = {
@@ -6011,8 +6111,9 @@ static struct hda_verb alc883_3ST_ch6_init[] = {
        { } /* end */
 };
 
-static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
+static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
        { 2, alc883_3ST_ch2_init },
+       { 4, alc883_3ST_ch4_init },
        { 6, alc883_3ST_ch6_init },
 };
 
@@ -6938,6 +7039,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
        SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
        SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
+       SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
        SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
        SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
        SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
@@ -7270,12 +7372,19 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
 
        if (err < 0)
                return err;
-       else if (err > 0)
-               /* hack - override the init verbs */
-               spec->init_verbs[0] = alc883_auto_init_verbs;
+       else if (!err)
+               return 0; /* no config found */
+
+       err = alc_auto_add_mic_boost(codec);
+       if (err < 0)
+               return err;
+
+       /* hack - override the init verbs */
+       spec->init_verbs[0] = alc883_auto_init_verbs;
        spec->mixers[spec->num_mixers] = alc883_capture_mixer;
        spec->num_mixers++;
-       return err;
+
+       return 1; /* config found */
 }
 
 /* additional initialization for auto-configuration model */
@@ -7706,13 +7815,23 @@ static struct hda_input_mux alc262_HP_capture_source = {
        .num_items = 5,
        .items = {
                { "Mic", 0x0 },
-               { "Front Mic", 0x3 },
+               { "Front Mic", 0x1 },
                { "Line", 0x2 },
                { "CD", 0x4 },
                { "AUX IN", 0x6 },
        },
 };
 
+static struct hda_input_mux alc262_HP_D7000_capture_source = {
+       .num_items = 4,
+       .items = {
+               { "Mic", 0x0 },
+               { "Front Mic", 0x2 },
+               { "Line", 0x1 },
+               { "CD", 0x4 },
+       },
+};
+
 /* mute/unmute internal speaker according to the hp jack and mute state */
 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
 {
@@ -8184,6 +8303,10 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
        spec->num_mux_defs = 1;
        spec->input_mux = &spec->private_imux;
 
+       err = alc_auto_add_mic_boost(codec);
+       if (err < 0)
+               return err;
+
        return 1;
 }
 
@@ -8313,7 +8436,7 @@ static struct alc_config_preset alc262_presets[] = {
                .hp_nid = 0x03,
                .num_channel_mode = ARRAY_SIZE(alc262_modes),
                .channel_mode = alc262_modes,
-               .input_mux = &alc262_HP_capture_source,
+               .input_mux = &alc262_HP_D7000_capture_source,
        },
        [ALC262_HP_BPC_D7000_WL] = {
                .mixers = { alc262_HP_BPC_WildWest_mixer,
@@ -8324,7 +8447,7 @@ static struct alc_config_preset alc262_presets[] = {
                .hp_nid = 0x03,
                .num_channel_mode = ARRAY_SIZE(alc262_modes),
                .channel_mode = alc262_modes,
-               .input_mux = &alc262_HP_capture_source,
+               .input_mux = &alc262_HP_D7000_capture_source,
        },
        [ALC262_BENQ_ED8] = {
                .mixers = { alc262_base_mixer },
@@ -8500,7 +8623,7 @@ static struct hda_verb alc268_toshiba_verbs[] = {
 };
 
 /* Acer specific */
-/* bind volumes of both NID 0x0c and 0x0d */
+/* bind volumes of both NID 0x02 and 0x03 */
 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
        .ops = &snd_hda_bind_vol,
        .values = {
@@ -8510,8 +8633,46 @@ static struct hda_bind_ctls alc268_acer_bind_master_vol = {
        },
 };
 
-#define alc268_acer_master_sw_put      alc262_fujitsu_master_sw_put
-#define alc268_acer_automute   alc262_fujitsu_automute
+/* mute/unmute internal speaker according to the hp jack and mute state */
+static void alc268_acer_automute(struct hda_codec *codec, int force)
+{
+       struct alc_spec *spec = codec->spec;
+       unsigned int mute;
+
+       if (force || !spec->sense_updated) {
+               unsigned int present;
+               present = snd_hda_codec_read(codec, 0x14, 0,
+                                        AC_VERB_GET_PIN_SENSE, 0);
+               spec->jack_present = (present & 0x80000000) != 0;
+               spec->sense_updated = 1;
+       }
+       if (spec->jack_present)
+               mute = HDA_AMP_MUTE; /* mute internal speaker */
+       else /* unmute internal speaker if necessary */
+               mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
+       snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE, mute);
+}
+
+
+/* bind hp and internal speaker mute (with plug check) */
+static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
+                                    struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       long *valp = ucontrol->value.integer.value;
+       int change;
+
+       change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
+                                         HDA_AMP_MUTE,
+                                         valp[0] ? 0 : HDA_AMP_MUTE);
+       change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
+                                          HDA_AMP_MUTE,
+                                          valp[1] ? 0 : HDA_AMP_MUTE);
+       if (change)
+               alc268_acer_automute(codec, 0);
+       return change;
+}
 
 static struct snd_kcontrol_new alc268_acer_mixer[] = {
        /* output mixer control */
@@ -8542,7 +8703,7 @@ static struct hda_verb alc268_acer_verbs[] = {
 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
                                       unsigned int res)
 {
-       if ((res >> 28) != ALC880_HP_EVENT)
+       if ((res >> 26) != ALC880_HP_EVENT)
                return;
        alc268_toshiba_automute(codec);
 }
@@ -8550,11 +8711,16 @@ static void alc268_toshiba_unsol_event(struct hda_codec *codec,
 static void alc268_acer_unsol_event(struct hda_codec *codec,
                                       unsigned int res)
 {
-       if ((res >> 28) != ALC880_HP_EVENT)
+       if ((res >> 26) != ALC880_HP_EVENT)
                return;
        alc268_acer_automute(codec, 1);
 }
 
+static void alc268_acer_init_hook(struct hda_codec *codec)
+{
+       alc268_acer_automute(codec, 1);
+}
+
 /*
  * generic initialization of ADC, input mixers and output mixers
  */
@@ -8914,6 +9080,10 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
        spec->num_mux_defs = 1;
        spec->input_mux = &spec->private_imux;
 
+       err = alc_auto_add_mic_boost(codec);
+       if (err < 0)
+               return err;
+
        return 1;
 }
 
@@ -8943,8 +9113,11 @@ static const char *alc268_models[ALC268_MODEL_LAST] = {
 static struct snd_pci_quirk alc268_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
        SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
+       SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
        SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
        SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
+       SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
+       SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
        {}
 };
 
@@ -8991,6 +9164,7 @@ static struct alc_config_preset alc268_presets[] = {
                .channel_mode = alc268_modes,
                .input_mux = &alc268_capture_source,
                .unsol_event = alc268_acer_unsol_event,
+               .init_hook = alc268_acer_init_hook,
        },
 };
 
@@ -11128,6 +11302,10 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
        spec->num_mux_defs = 1;
        spec->input_mux = &spec->private_imux;
 
+       err = alc_auto_add_mic_boost(codec);
+       if (err < 0)
+               return err;
+
        return 1;
 }