]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - sound/pci/hda/patch_realtek.c
ALSA: hda - Increase the connection list size for ALC662
[net-next-2.6.git] / sound / pci / hda / patch_realtek.c
index 17d4548cc353f72402693b0b39461226467a00d9..cf9f20805173e17996fab4c2e660dcefbc287382 100644 (file)
@@ -256,6 +256,13 @@ enum {
        ALC882_MODEL_LAST,
 };
 
+/* ALC680 models */
+enum {
+       ALC680_BASE,
+       ALC680_AUTO,
+       ALC680_MODEL_LAST,
+};
+
 /* for GPIO Poll */
 #define GPIO_MASK      0x03
 
@@ -326,6 +333,12 @@ struct alc_spec {
        hda_nid_t *capsrc_nids;
        hda_nid_t dig_in_nid;           /* digital-in NID; optional */
 
+       /* capture setup for dynamic dual-adc switch */
+       unsigned int cur_adc_idx;
+       hda_nid_t cur_adc;
+       unsigned int cur_adc_stream_tag;
+       unsigned int cur_adc_format;
+
        /* capture source */
        unsigned int num_mux_defs;
        const struct hda_input_mux *input_mux;
@@ -367,6 +380,7 @@ struct alc_spec {
 
        /* other flags */
        unsigned int no_analog :1; /* digital I/O only */
+       unsigned int dual_adc_switch:1; /* switch ADCs (for ALC275) */
        int init_amp;
 
        /* for virtual master */
@@ -1003,6 +1017,29 @@ static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
        return -1;
 }
 
+/* switch the current ADC according to the jack state */
+static void alc_dual_mic_adc_auto_switch(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       unsigned int present;
+       hda_nid_t new_adc;
+
+       present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
+       if (present)
+               spec->cur_adc_idx = 1;
+       else
+               spec->cur_adc_idx = 0;
+       new_adc = spec->adc_nids[spec->cur_adc_idx];
+       if (spec->cur_adc && spec->cur_adc != new_adc) {
+               /* stream is running, let's swap the current ADC */
+               snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
+               spec->cur_adc = new_adc;
+               snd_hda_codec_setup_stream(codec, new_adc,
+                                          spec->cur_adc_stream_tag, 0,
+                                          spec->cur_adc_format);
+       }
+}
+
 static void alc_mic_automute(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
@@ -1017,6 +1054,11 @@ static void alc_mic_automute(struct hda_codec *codec)
        if (snd_BUG_ON(!spec->adc_nids))
                return;
 
+       if (spec->dual_adc_switch) {
+               alc_dual_mic_adc_auto_switch(codec);
+               return;
+       }
+
        cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
 
        present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
@@ -1267,6 +1309,8 @@ static int alc_auto_parse_customize_define(struct hda_codec *codec)
        unsigned nid = 0;
        struct alc_spec *spec = codec->spec;
 
+       spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
+
        ass = codec->subsystem_id & 0xffff;
        if (ass != codec->bus->pci->subsystem_device && (ass & 1))
                goto do_sku;
@@ -2547,7 +2591,7 @@ static struct snd_kcontrol_new alc_beep_mixer[] = {
 static int alc_build_controls(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
-       struct snd_kcontrol *kctl;
+       struct snd_kcontrol *kctl = NULL;
        struct snd_kcontrol_new *knew;
        int i, j, err;
        unsigned int u;
@@ -2619,16 +2663,18 @@ static int alc_build_controls(struct hda_codec *codec)
        }
 
        /* assign Capture Source enums to NID */
-       kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
-       if (!kctl)
-               kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
-       for (i = 0; kctl && i < kctl->count; i++) {
-               hda_nid_t *nids = spec->capsrc_nids;
-               if (!nids)
-                       nids = spec->adc_nids;
-               err = snd_hda_add_nid(codec, kctl, i, nids[i]);
-               if (err < 0)
-                       return err;
+       if (spec->capsrc_nids || spec->adc_nids) {
+               kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
+               if (!kctl)
+                       kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
+               for (i = 0; kctl && i < kctl->count; i++) {
+                       hda_nid_t *nids = spec->capsrc_nids;
+                       if (!nids)
+                               nids = spec->adc_nids;
+                       err = snd_hda_add_nid(codec, kctl, i, nids[i]);
+                       if (err < 0)
+                               return err;
+               }
        }
        if (spec->cap_mixer) {
                const char *kname = kctl ? kctl->id.name : NULL;
@@ -3603,6 +3649,41 @@ static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
        return 0;
 }
 
+/* analog capture with dynamic dual-adc changes */
+static int dualmic_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
+                                      struct hda_codec *codec,
+                                      unsigned int stream_tag,
+                                      unsigned int format,
+                                      struct snd_pcm_substream *substream)
+{
+       struct alc_spec *spec = codec->spec;
+       spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
+       spec->cur_adc_stream_tag = stream_tag;
+       spec->cur_adc_format = format;
+       snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
+       return 0;
+}
+
+static int dualmic_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
+                                      struct hda_codec *codec,
+                                      struct snd_pcm_substream *substream)
+{
+       struct alc_spec *spec = codec->spec;
+       snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
+       spec->cur_adc = 0;
+       return 0;
+}
+
+static struct hda_pcm_stream dualmic_pcm_analog_capture = {
+       .substreams = 1,
+       .channels_min = 2,
+       .channels_max = 2,
+       .nid = 0, /* fill later */
+       .ops = {
+               .prepare = dualmic_capture_pcm_prepare,
+               .cleanup = dualmic_capture_pcm_cleanup
+       },
+};
 
 /*
  */
@@ -5041,24 +5122,12 @@ static void fixup_automic_adc(struct hda_codec *codec)
        spec->auto_mic = 0; /* disable auto-mic to be sure */
 }
 
-/* choose the ADC/MUX containing the input pin and initialize the setup */
-static void fixup_single_adc(struct hda_codec *codec)
+/* set the default connection to that pin */
+static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
 {
        struct alc_spec *spec = codec->spec;
-       hda_nid_t pin = 0;
        int i;
 
-       /* search for the input pin; there must be only one */
-       for (i = 0; i < AUTO_PIN_LAST; i++) {
-               if (spec->autocfg.input_pins[i]) {
-                       pin = spec->autocfg.input_pins[i];
-                       break;
-               }
-       }
-       if (!pin)
-               return;
-
-       /* set the default connection to that pin */
        for (i = 0; i < spec->num_adc_nids; i++) {
                hda_nid_t cap = spec->capsrc_nids ?
                        spec->capsrc_nids[i] : spec->adc_nids[i];
@@ -5067,11 +5136,6 @@ static void fixup_single_adc(struct hda_codec *codec)
                idx = get_connection_index(codec, cap, pin);
                if (idx < 0)
                        continue;
-               /* use only this ADC */
-               if (spec->capsrc_nids)
-                       spec->capsrc_nids += i;
-               spec->adc_nids += i;
-               spec->num_adc_nids = 1;
                /* select or unmute this route */
                if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
                        snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
@@ -5080,10 +5144,45 @@ static void fixup_single_adc(struct hda_codec *codec)
                        snd_hda_codec_write_cache(codec, cap, 0,
                                          AC_VERB_SET_CONNECT_SEL, idx);
                }
+               return i; /* return the found index */
+       }
+       return -1; /* not found */
+}
+
+/* choose the ADC/MUX containing the input pin and initialize the setup */
+static void fixup_single_adc(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       hda_nid_t pin = 0;
+       int i;
+
+       /* search for the input pin; there must be only one */
+       for (i = 0; i < AUTO_PIN_LAST; i++) {
+               if (spec->autocfg.input_pins[i]) {
+                       pin = spec->autocfg.input_pins[i];
+                       break;
+               }
+       }
+       if (!pin)
                return;
+       i = init_capsrc_for_pin(codec, pin);
+       if (i >= 0) {
+               /* use only this ADC */
+               if (spec->capsrc_nids)
+                       spec->capsrc_nids += i;
+               spec->adc_nids += i;
+               spec->num_adc_nids = 1;
        }
 }
 
+/* initialize dual adcs */
+static void fixup_dual_adc_switch(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       init_capsrc_for_pin(codec, spec->ext_mic.pin);
+       init_capsrc_for_pin(codec, spec->int_mic.pin);
+}
+
 static void set_capture_mixer(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
@@ -5097,7 +5196,10 @@ static void set_capture_mixer(struct hda_codec *codec)
        };
        if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
                int mux = 0;
-               if (spec->auto_mic)
+               int num_adcs = spec->num_adc_nids;
+               if (spec->dual_adc_switch)
+                       fixup_dual_adc_switch(codec);
+               else if (spec->auto_mic)
                        fixup_automic_adc(codec);
                else if (spec->input_mux) {
                        if (spec->input_mux->num_items > 1)
@@ -5105,7 +5207,9 @@ static void set_capture_mixer(struct hda_codec *codec)
                        else if (spec->input_mux->num_items == 1)
                                fixup_single_adc(codec);
                }
-               spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
+               if (spec->dual_adc_switch)
+                       num_adcs = 1;
+               spec->cap_mixer = caps[mux][num_adcs - 1];
        }
 }
 
@@ -5176,8 +5280,24 @@ static void fillup_priv_adc_nids(struct hda_codec *codec, hda_nid_t *nids,
 #ifdef CONFIG_SND_HDA_INPUT_BEEP
 #define set_beep_amp(spec, nid, idx, dir) \
        ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
+
+static struct snd_pci_quirk beep_white_list[] = {
+       SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
+       {}
+};
+
+static inline int has_cdefine_beep(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       const struct snd_pci_quirk *q;
+       q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
+       if (q)
+               return q->value;
+       return spec->cdefine.enable_pcbeep;
+}
 #else
 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
+#define has_cdefine_beep(codec)                0
 #endif
 
 /*
@@ -6948,7 +7068,7 @@ static struct hda_input_mux mb5_capture_source = {
        .num_items = 3,
        .items = {
                { "Mic", 0x1 },
-               { "Line", 0x2 },
+               { "Line", 0x7 },
                { "CD", 0x4 },
        },
 };
@@ -6983,7 +7103,7 @@ static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
        .num_items = 4,
        .items = {
                { "Mic", 0x0 },
-               { "iMic", 0x1 },
+               { "Int Mic", 0x1 },
                { "Line", 0x2 },
                { "CD", 0x4 },
        },
@@ -7469,8 +7589,8 @@ static struct snd_kcontrol_new alc885_mb5_mixer[] = {
        HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
        HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
        HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0f, 0x02, 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("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
+       HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
        HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
        HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
@@ -7853,10 +7973,9 @@ static struct hda_verb alc885_mb5_init_verbs[] = {
        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
 
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
-       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
+       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0x1)},
+       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x7)},
+       {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x4)},
        { }
 };
 
@@ -8554,8 +8673,8 @@ static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, 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("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
-       HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
        { } /* end */
 };
 
@@ -9476,11 +9595,16 @@ static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
        SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
        SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
        SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
+       SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889A_MB31),
+       SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_ASUS_A7M),
+       SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC885_MBP3),
+       SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC885_MBA21),
        SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
        SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
        SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
        SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC885_IMAC91),
        SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
+       SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC885_MB5),
        /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
         * so apparently no perfect solution yet
         */
@@ -10558,10 +10682,12 @@ static int patch_alc882(struct hda_codec *codec)
                }
        }
 
-       err = snd_hda_attach_beep_device(codec, 0x1);
-       if (err < 0) {
-               alc_free(codec);
-               return err;
+       if (has_cdefine_beep(codec)) {
+               err = snd_hda_attach_beep_device(codec, 0x1);
+               if (err < 0) {
+                       alc_free(codec);
+                       return err;
+               }
        }
 
        if (board_config != ALC882_AUTO)
@@ -10611,7 +10737,7 @@ static int patch_alc882(struct hda_codec *codec)
 
        set_capture_mixer(codec);
 
-       if (spec->cdefine.enable_pcbeep)
+       if (has_cdefine_beep(codec))
                set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
 
        if (board_config == ALC882_AUTO)
@@ -12427,7 +12553,7 @@ static int patch_alc262(struct hda_codec *codec)
                }
        }
 
-       if (!spec->no_analog) {
+       if (!spec->no_analog && has_cdefine_beep(codec)) {
                err = snd_hda_attach_beep_device(codec, 0x1);
                if (err < 0) {
                        alc_free(codec);
@@ -12478,7 +12604,7 @@ static int patch_alc262(struct hda_codec *codec)
        }
        if (!spec->cap_mixer && !spec->no_analog)
                set_capture_mixer(codec);
-       if (!spec->no_analog && spec->cdefine.enable_pcbeep)
+       if (!spec->no_analog && has_cdefine_beep(codec))
                set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
 
        spec->vmaster_nid = 0x0c;
@@ -14126,6 +14252,36 @@ static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
 }
 #endif /* CONFIG_SND_HDA_POWER_SAVE */
 
+static int alc275_setup_dual_adc(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+
+       if (codec->vendor_id != 0x10ec0275 || !spec->auto_mic)
+               return 0;
+       if ((spec->ext_mic.pin >= 0x18 && spec->int_mic.pin <= 0x13) ||
+           (spec->ext_mic.pin <= 0x12 && spec->int_mic.pin >= 0x18)) {
+               if (spec->ext_mic.pin <= 0x12) {
+                       spec->private_adc_nids[0] = 0x08;
+                       spec->private_adc_nids[1] = 0x11;
+                       spec->private_capsrc_nids[0] = 0x23;
+                       spec->private_capsrc_nids[1] = 0x22;
+               } else {
+                       spec->private_adc_nids[0] = 0x11;
+                       spec->private_adc_nids[1] = 0x08;
+                       spec->private_capsrc_nids[0] = 0x22;
+                       spec->private_capsrc_nids[1] = 0x23;
+               }
+               spec->adc_nids = spec->private_adc_nids;
+               spec->capsrc_nids = spec->private_capsrc_nids;
+               spec->num_adc_nids = 2;
+               spec->dual_adc_switch = 1;
+               snd_printdd("realtek: enabling dual ADC switchg (%02x:%02x)\n",
+                           spec->adc_nids[0], spec->adc_nids[1]);
+               return 1;
+       }
+       return 0;
+}
+
 /*
  * BIOS auto configuration
  */
@@ -14165,11 +14321,14 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
 
        spec->num_mux_defs = 1;
        spec->input_mux = &spec->private_imux[0];
-       fillup_priv_adc_nids(codec, alc269_adc_candidates,
-                            sizeof(alc269_adc_candidates));
+
+       if (!alc275_setup_dual_adc(codec))
+               fillup_priv_adc_nids(codec, alc269_adc_candidates,
+                                    sizeof(alc269_adc_candidates));
 
        /* set default input source */
-       snd_hda_codec_write_cache(codec, spec->capsrc_nids[0],
+       if (!spec->dual_adc_switch)
+               snd_hda_codec_write_cache(codec, spec->capsrc_nids[0],
                                  0, AC_VERB_SET_CONNECT_SEL,
                                  spec->input_mux->items[0].index);
 
@@ -14450,10 +14609,12 @@ static int patch_alc269(struct hda_codec *codec)
                }
        }
 
-       err = snd_hda_attach_beep_device(codec, 0x1);
-       if (err < 0) {
-               alc_free(codec);
-               return err;
+       if (has_cdefine_beep(codec)) {
+               err = snd_hda_attach_beep_device(codec, 0x1);
+               if (err < 0) {
+                       alc_free(codec);
+                       return err;
+               }
        }
 
        if (board_config != ALC269_AUTO)
@@ -14465,6 +14626,10 @@ static int patch_alc269(struct hda_codec *codec)
                 */
                spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
                spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
+       } else if (spec->dual_adc_switch) {
+               spec->stream_analog_playback = &alc269_pcm_analog_playback;
+               /* switch ADC dynamically */
+               spec->stream_analog_capture = &dualmic_pcm_analog_capture;
        } else {
                spec->stream_analog_playback = &alc269_pcm_analog_playback;
                spec->stream_analog_capture = &alc269_pcm_analog_capture;
@@ -14486,7 +14651,7 @@ static int patch_alc269(struct hda_codec *codec)
 
        if (!spec->cap_mixer)
                set_capture_mixer(codec);
-       if (spec->cdefine.enable_pcbeep)
+       if (has_cdefine_beep(codec))
                set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
 
        if (board_config == ALC269_AUTO)
@@ -18492,7 +18657,7 @@ static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
                                              hda_nid_t dac)
 {
        int i, num;
-       hda_nid_t srcs[4];
+       hda_nid_t srcs[HDA_MAX_CONNECTIONS];
 
        alc_set_pin_output(codec, nid, pin_type);
        /* need the manual connection? */
@@ -18607,7 +18772,7 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
 
        add_verb(spec, alc662_init_verbs);
        if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
-           codec->vendor_id == 0x10ec0665)
+           codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
                add_verb(spec, alc663_init_verbs);
 
        if (codec->vendor_id == 0x10ec0272)
@@ -18683,10 +18848,12 @@ static int patch_alc662(struct hda_codec *codec)
                }
        }
 
-       err = snd_hda_attach_beep_device(codec, 0x1);
-       if (err < 0) {
-               alc_free(codec);
-               return err;
+       if (has_cdefine_beep(codec)) {
+               err = snd_hda_attach_beep_device(codec, 0x1);
+               if (err < 0) {
+                       alc_free(codec);
+                       return err;
+               }
        }
 
        if (board_config != ALC662_AUTO)
@@ -18708,7 +18875,7 @@ static int patch_alc662(struct hda_codec *codec)
        if (!spec->cap_mixer)
                set_capture_mixer(codec);
 
-       if (spec->cdefine.enable_pcbeep) {
+       if (has_cdefine_beep(codec)) {
                switch (codec->vendor_id) {
                case 0x10ec0662:
                        set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
@@ -18750,6 +18917,335 @@ static int patch_alc888(struct hda_codec *codec)
        return patch_alc882(codec);
 }
 
+/*
+ * ALC680 support
+ */
+#define ALC680_DIGOUT_NID      ALC880_DIGOUT_NID
+#define alc680_modes           alc260_modes
+
+static hda_nid_t alc680_dac_nids[3] = {
+       /* Lout1, Lout2, hp */
+       0x02, 0x03, 0x04
+};
+
+static hda_nid_t alc680_adc_nids[3] = {
+       /* ADC0-2 */
+       /* DMIC, MIC, Line-in*/
+       0x07, 0x08, 0x09
+};
+
+static struct snd_kcontrol_new alc680_base_mixer[] = {
+       /* output mixer control */
+       HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Headphone Playback Volume", 0x4, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Headphone Playback Switch", 0x16, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
+       { }
+};
+
+static struct snd_kcontrol_new alc680_capture_mixer[] = {
+       HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
+       { } /* end */
+};
+
+/*
+ * generic initialization of ADC, input mixers and output mixers
+ */
+static struct hda_verb alc680_init_verbs[] = {
+       /* Unmute DAC0-1 and set vol = 0 */
+       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
+       {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
+       {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
+
+       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
+       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
+       {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
+       {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
+       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
+
+       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
+       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
+       {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
+       {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
+       {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
+       { }
+};
+
+/* create input playback/capture controls for the given pin */
+static int alc680_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
+                                   const char *ctlname, int idx)
+{
+       hda_nid_t dac;
+       int err;
+
+       switch (nid) {
+       case 0x14:
+               dac = 0x02;
+               break;
+       case 0x15:
+               dac = 0x03;
+               break;
+       case 0x16:
+               dac = 0x04;
+               break;
+       default:
+               return 0;
+       }
+       if (spec->multiout.dac_nids[0] != dac &&
+           spec->multiout.dac_nids[1] != dac) {
+               err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
+                                 HDA_COMPOSE_AMP_VAL(dac, 3, idx,
+                                                     HDA_OUTPUT));
+               if (err < 0)
+                       return err;
+
+               err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
+                         HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
+
+               if (err < 0)
+                       return err;
+               spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
+       }
+
+       return 0;
+}
+
+/* add playback controls from the parsed DAC table */
+static int alc680_auto_create_multi_out_ctls(struct alc_spec *spec,
+                                            const struct auto_pin_cfg *cfg)
+{
+       hda_nid_t nid;
+       int err;
+
+       spec->multiout.dac_nids = spec->private_dac_nids;
+
+       nid = cfg->line_out_pins[0];
+       if (nid) {
+               const char *name;
+               if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
+                       name = "Speaker";
+               else
+                       name = "Front";
+               err = alc680_new_analog_output(spec, nid, name, 0);
+               if (err < 0)
+                       return err;
+       }
+
+       nid = cfg->speaker_pins[0];
+       if (nid) {
+               err = alc680_new_analog_output(spec, nid, "Speaker", 0);
+               if (err < 0)
+                       return err;
+       }
+       nid = cfg->hp_pins[0];
+       if (nid) {
+               err = alc680_new_analog_output(spec, nid, "Headphone", 0);
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
+
+static void alc680_auto_set_output_and_unmute(struct hda_codec *codec,
+                                             hda_nid_t nid, int pin_type)
+{
+       alc_set_pin_output(codec, nid, pin_type);
+}
+
+static void alc680_auto_init_multi_out(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       hda_nid_t nid = spec->autocfg.line_out_pins[0];
+       if (nid) {
+               int pin_type = get_pin_type(spec->autocfg.line_out_type);
+               alc680_auto_set_output_and_unmute(codec, nid, pin_type);
+       }
+}
+
+static void alc680_auto_init_hp_out(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       hda_nid_t pin;
+
+       pin = spec->autocfg.hp_pins[0];
+       if (pin)
+               alc680_auto_set_output_and_unmute(codec, pin, PIN_HP);
+       pin = spec->autocfg.speaker_pins[0];
+       if (pin)
+               alc680_auto_set_output_and_unmute(codec, pin, PIN_OUT);
+}
+
+/* pcm configuration: identical with ALC880 */
+#define alc680_pcm_analog_playback     alc880_pcm_analog_playback
+#define alc680_pcm_analog_capture      alc880_pcm_analog_capture
+#define alc680_pcm_analog_alt_capture  alc880_pcm_analog_alt_capture
+#define alc680_pcm_digital_playback    alc880_pcm_digital_playback
+
+static struct hda_input_mux alc680_capture_source = {
+       .num_items = 1,
+       .items = {
+               { "Mic", 0x0 },
+       },
+};
+
+/*
+ * BIOS auto configuration
+ */
+static int alc680_parse_auto_config(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       int err;
+       static hda_nid_t alc680_ignore[] = { 0 };
+
+       err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
+                                          alc680_ignore);
+       if (err < 0)
+               return err;
+       if (!spec->autocfg.line_outs) {
+               if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
+                       spec->multiout.max_channels = 2;
+                       spec->no_analog = 1;
+                       goto dig_only;
+               }
+               return 0; /* can't find valid BIOS pin config */
+       }
+       err = alc680_auto_create_multi_out_ctls(spec, &spec->autocfg);
+       if (err < 0)
+               return err;
+
+       spec->multiout.max_channels = 2;
+
+ dig_only:
+       /* digital only support output */
+       if (spec->autocfg.dig_outs) {
+               spec->multiout.dig_out_nid = ALC680_DIGOUT_NID;
+               spec->dig_out_type = spec->autocfg.dig_out_type[0];
+       }
+       if (spec->kctls.list)
+               add_mixer(spec, spec->kctls.list);
+
+       add_verb(spec, alc680_init_verbs);
+       spec->num_mux_defs = 1;
+       spec->input_mux = &alc680_capture_source;
+
+       err = alc_auto_add_mic_boost(codec);
+       if (err < 0)
+               return err;
+
+       return 1;
+}
+
+#define alc680_auto_init_analog_input  alc882_auto_init_analog_input
+
+/* init callback for auto-configuration model -- overriding the default init */
+static void alc680_auto_init(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       alc680_auto_init_multi_out(codec);
+       alc680_auto_init_hp_out(codec);
+       alc680_auto_init_analog_input(codec);
+       if (spec->unsol_event)
+               alc_inithook(codec);
+}
+
+/*
+ * configuration and preset
+ */
+static const char *alc680_models[ALC680_MODEL_LAST] = {
+       [ALC680_BASE]           = "base",
+       [ALC680_AUTO]           = "auto",
+};
+
+static struct snd_pci_quirk alc680_cfg_tbl[] = {
+       SND_PCI_QUIRK(0x1043, 0x12f3, "ASUS NX90", ALC680_BASE),
+       {}
+};
+
+static struct alc_config_preset alc680_presets[] = {
+       [ALC680_BASE] = {
+               .mixers = { alc680_base_mixer },
+               .cap_mixer =  alc680_capture_mixer,
+               .init_verbs = { alc680_init_verbs },
+               .num_dacs = ARRAY_SIZE(alc680_dac_nids),
+               .dac_nids = alc680_dac_nids,
+               .num_adc_nids = ARRAY_SIZE(alc680_adc_nids),
+               .adc_nids = alc680_adc_nids,
+               .hp_nid = 0x04,
+               .dig_out_nid = ALC680_DIGOUT_NID,
+               .num_channel_mode = ARRAY_SIZE(alc680_modes),
+               .channel_mode = alc680_modes,
+               .input_mux = &alc680_capture_source,
+       },
+};
+
+static int patch_alc680(struct hda_codec *codec)
+{
+       struct alc_spec *spec;
+       int board_config;
+       int err;
+
+       spec = kzalloc(sizeof(*spec), GFP_KERNEL);
+       if (spec == NULL)
+               return -ENOMEM;
+
+       codec->spec = spec;
+
+       board_config = snd_hda_check_board_config(codec, ALC680_MODEL_LAST,
+                                                 alc680_models,
+                                                 alc680_cfg_tbl);
+
+       if (board_config < 0 || board_config >= ALC680_MODEL_LAST) {
+               printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
+                      codec->chip_name);
+               board_config = ALC680_AUTO;
+       }
+
+       if (board_config == ALC680_AUTO) {
+               /* automatic parse from the BIOS config */
+               err = alc680_parse_auto_config(codec);
+               if (err < 0) {
+                       alc_free(codec);
+                       return err;
+               } else if (!err) {
+                       printk(KERN_INFO
+                              "hda_codec: Cannot set up configuration "
+                              "from BIOS.  Using base mode...\n");
+                       board_config = ALC680_BASE;
+               }
+       }
+
+       if (board_config != ALC680_AUTO)
+               setup_preset(codec, &alc680_presets[board_config]);
+
+       spec->stream_analog_playback = &alc680_pcm_analog_playback;
+       spec->stream_analog_capture = &alc680_pcm_analog_capture;
+       spec->stream_analog_alt_capture = &alc680_pcm_analog_alt_capture;
+       spec->stream_digital_playback = &alc680_pcm_digital_playback;
+
+       if (!spec->adc_nids) {
+               spec->adc_nids = alc680_adc_nids;
+               spec->num_adc_nids = ARRAY_SIZE(alc680_adc_nids);
+       }
+
+       if (!spec->cap_mixer)
+               set_capture_mixer(codec);
+
+       spec->vmaster_nid = 0x02;
+
+       codec->patch_ops = alc_patch_ops;
+       if (board_config == ALC680_AUTO)
+               spec->init_hook = alc680_auto_init;
+
+       return 0;
+}
+
 /*
  * patch entries
  */
@@ -18774,6 +19270,7 @@ static struct hda_codec_preset snd_hda_preset_realtek[] = {
        { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
        { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
        { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
+       { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
        { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
        { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
        { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },