]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/pci/hda/patch_realtek.c
ALSA: hda - Fix auto-init of output volumes of Realtek codecs
[mv-sheeva.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34 #include "hda_beep.h"
35
36 #define ALC880_FRONT_EVENT              0x01
37 #define ALC880_DCVOL_EVENT              0x02
38 #define ALC880_HP_EVENT                 0x04
39 #define ALC880_MIC_EVENT                0x08
40
41 /* ALC880 board config type */
42 enum {
43         ALC880_3ST,
44         ALC880_3ST_DIG,
45         ALC880_5ST,
46         ALC880_5ST_DIG,
47         ALC880_W810,
48         ALC880_Z71V,
49         ALC880_6ST,
50         ALC880_6ST_DIG,
51         ALC880_F1734,
52         ALC880_ASUS,
53         ALC880_ASUS_DIG,
54         ALC880_ASUS_W1V,
55         ALC880_ASUS_DIG2,
56         ALC880_FUJITSU,
57         ALC880_UNIWILL_DIG,
58         ALC880_UNIWILL,
59         ALC880_UNIWILL_P53,
60         ALC880_CLEVO,
61         ALC880_TCL_S700,
62         ALC880_LG,
63         ALC880_LG_LW,
64         ALC880_MEDION_RIM,
65 #ifdef CONFIG_SND_DEBUG
66         ALC880_TEST,
67 #endif
68         ALC880_AUTO,
69         ALC880_MODEL_LAST /* last tag */
70 };
71
72 /* ALC260 models */
73 enum {
74         ALC260_BASIC,
75         ALC260_HP,
76         ALC260_HP_DC7600,
77         ALC260_HP_3013,
78         ALC260_FUJITSU_S702X,
79         ALC260_ACER,
80         ALC260_WILL,
81         ALC260_REPLACER_672V,
82         ALC260_FAVORIT100,
83 #ifdef CONFIG_SND_DEBUG
84         ALC260_TEST,
85 #endif
86         ALC260_AUTO,
87         ALC260_MODEL_LAST /* last tag */
88 };
89
90 /* ALC262 models */
91 enum {
92         ALC262_BASIC,
93         ALC262_HIPPO,
94         ALC262_HIPPO_1,
95         ALC262_FUJITSU,
96         ALC262_HP_BPC,
97         ALC262_HP_BPC_D7000_WL,
98         ALC262_HP_BPC_D7000_WF,
99         ALC262_HP_TC_T5735,
100         ALC262_HP_RP5700,
101         ALC262_BENQ_ED8,
102         ALC262_SONY_ASSAMD,
103         ALC262_BENQ_T31,
104         ALC262_ULTRA,
105         ALC262_LENOVO_3000,
106         ALC262_NEC,
107         ALC262_TOSHIBA_S06,
108         ALC262_TOSHIBA_RX1,
109         ALC262_TYAN,
110         ALC262_AUTO,
111         ALC262_MODEL_LAST /* last tag */
112 };
113
114 /* ALC268 models */
115 enum {
116         ALC267_QUANTA_IL1,
117         ALC268_3ST,
118         ALC268_TOSHIBA,
119         ALC268_ACER,
120         ALC268_ACER_DMIC,
121         ALC268_ACER_ASPIRE_ONE,
122         ALC268_DELL,
123         ALC268_ZEPTO,
124 #ifdef CONFIG_SND_DEBUG
125         ALC268_TEST,
126 #endif
127         ALC268_AUTO,
128         ALC268_MODEL_LAST /* last tag */
129 };
130
131 /* ALC269 models */
132 enum {
133         ALC269_BASIC,
134         ALC269_QUANTA_FL1,
135         ALC269_AMIC,
136         ALC269_DMIC,
137         ALC269VB_AMIC,
138         ALC269VB_DMIC,
139         ALC269_FUJITSU,
140         ALC269_LIFEBOOK,
141         ALC271_ACER,
142         ALC269_AUTO,
143         ALC269_MODEL_LAST /* last tag */
144 };
145
146 /* ALC861 models */
147 enum {
148         ALC861_3ST,
149         ALC660_3ST,
150         ALC861_3ST_DIG,
151         ALC861_6ST_DIG,
152         ALC861_UNIWILL_M31,
153         ALC861_TOSHIBA,
154         ALC861_ASUS,
155         ALC861_ASUS_LAPTOP,
156         ALC861_AUTO,
157         ALC861_MODEL_LAST,
158 };
159
160 /* ALC861-VD models */
161 enum {
162         ALC660VD_3ST,
163         ALC660VD_3ST_DIG,
164         ALC660VD_ASUS_V1S,
165         ALC861VD_3ST,
166         ALC861VD_3ST_DIG,
167         ALC861VD_6ST_DIG,
168         ALC861VD_LENOVO,
169         ALC861VD_DALLAS,
170         ALC861VD_HP,
171         ALC861VD_AUTO,
172         ALC861VD_MODEL_LAST,
173 };
174
175 /* ALC662 models */
176 enum {
177         ALC662_3ST_2ch_DIG,
178         ALC662_3ST_6ch_DIG,
179         ALC662_3ST_6ch,
180         ALC662_5ST_DIG,
181         ALC662_LENOVO_101E,
182         ALC662_ASUS_EEEPC_P701,
183         ALC662_ASUS_EEEPC_EP20,
184         ALC663_ASUS_M51VA,
185         ALC663_ASUS_G71V,
186         ALC663_ASUS_H13,
187         ALC663_ASUS_G50V,
188         ALC662_ECS,
189         ALC663_ASUS_MODE1,
190         ALC662_ASUS_MODE2,
191         ALC663_ASUS_MODE3,
192         ALC663_ASUS_MODE4,
193         ALC663_ASUS_MODE5,
194         ALC663_ASUS_MODE6,
195         ALC663_ASUS_MODE7,
196         ALC663_ASUS_MODE8,
197         ALC272_DELL,
198         ALC272_DELL_ZM1,
199         ALC272_SAMSUNG_NC10,
200         ALC662_AUTO,
201         ALC662_MODEL_LAST,
202 };
203
204 /* ALC882 models */
205 enum {
206         ALC882_3ST_DIG,
207         ALC882_6ST_DIG,
208         ALC882_ARIMA,
209         ALC882_W2JC,
210         ALC882_TARGA,
211         ALC882_ASUS_A7J,
212         ALC882_ASUS_A7M,
213         ALC885_MACPRO,
214         ALC885_MBA21,
215         ALC885_MBP3,
216         ALC885_MB5,
217         ALC885_MACMINI3,
218         ALC885_IMAC24,
219         ALC885_IMAC91,
220         ALC883_3ST_2ch_DIG,
221         ALC883_3ST_6ch_DIG,
222         ALC883_3ST_6ch,
223         ALC883_6ST_DIG,
224         ALC883_TARGA_DIG,
225         ALC883_TARGA_2ch_DIG,
226         ALC883_TARGA_8ch_DIG,
227         ALC883_ACER,
228         ALC883_ACER_ASPIRE,
229         ALC888_ACER_ASPIRE_4930G,
230         ALC888_ACER_ASPIRE_6530G,
231         ALC888_ACER_ASPIRE_8930G,
232         ALC888_ACER_ASPIRE_7730G,
233         ALC883_MEDION,
234         ALC883_MEDION_WIM2160,
235         ALC883_LAPTOP_EAPD,
236         ALC883_LENOVO_101E_2ch,
237         ALC883_LENOVO_NB0763,
238         ALC888_LENOVO_MS7195_DIG,
239         ALC888_LENOVO_SKY,
240         ALC883_HAIER_W66,
241         ALC888_3ST_HP,
242         ALC888_6ST_DELL,
243         ALC883_MITAC,
244         ALC883_CLEVO_M540R,
245         ALC883_CLEVO_M720,
246         ALC883_FUJITSU_PI2515,
247         ALC888_FUJITSU_XA3530,
248         ALC883_3ST_6ch_INTEL,
249         ALC889A_INTEL,
250         ALC889_INTEL,
251         ALC888_ASUS_M90V,
252         ALC888_ASUS_EEE1601,
253         ALC889A_MB31,
254         ALC1200_ASUS_P5Q,
255         ALC883_SONY_VAIO_TT,
256         ALC882_AUTO,
257         ALC882_MODEL_LAST,
258 };
259
260 /* ALC680 models */
261 enum {
262         ALC680_BASE,
263         ALC680_AUTO,
264         ALC680_MODEL_LAST,
265 };
266
267 /* for GPIO Poll */
268 #define GPIO_MASK       0x03
269
270 /* extra amp-initialization sequence types */
271 enum {
272         ALC_INIT_NONE,
273         ALC_INIT_DEFAULT,
274         ALC_INIT_GPIO1,
275         ALC_INIT_GPIO2,
276         ALC_INIT_GPIO3,
277 };
278
279 struct alc_mic_route {
280         hda_nid_t pin;
281         unsigned char mux_idx;
282         unsigned char amix_idx;
283 };
284
285 #define MUX_IDX_UNDEF   ((unsigned char)-1)
286
287 struct alc_customize_define {
288         unsigned int  sku_cfg;
289         unsigned char port_connectivity;
290         unsigned char check_sum;
291         unsigned char customization;
292         unsigned char external_amp;
293         unsigned int  enable_pcbeep:1;
294         unsigned int  platform_type:1;
295         unsigned int  swap:1;
296         unsigned int  override:1;
297         unsigned int  fixup:1; /* Means that this sku is set by driver, not read from hw */
298 };
299
300 struct alc_fixup;
301
302 struct alc_multi_io {
303         hda_nid_t pin;          /* multi-io widget pin NID */
304         hda_nid_t dac;          /* DAC to be connected */
305         unsigned int ctl_in;    /* cached input-pin control value */
306 };
307
308 enum {
309         ALC_AUTOMUTE_PIN,       /* change the pin control */
310         ALC_AUTOMUTE_AMP,       /* mute/unmute the pin AMP */
311         ALC_AUTOMUTE_MIXER,     /* mute/unmute mixer widget AMP */
312 };
313
314 struct alc_spec {
315         /* codec parameterization */
316         const struct snd_kcontrol_new *mixers[5];       /* mixer arrays */
317         unsigned int num_mixers;
318         const struct snd_kcontrol_new *cap_mixer;       /* capture mixer */
319         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
320
321         const struct hda_verb *init_verbs[10];  /* initialization verbs
322                                                  * don't forget NULL
323                                                  * termination!
324                                                  */
325         unsigned int num_init_verbs;
326
327         char stream_name_analog[32];    /* analog PCM stream */
328         const struct hda_pcm_stream *stream_analog_playback;
329         const struct hda_pcm_stream *stream_analog_capture;
330         const struct hda_pcm_stream *stream_analog_alt_playback;
331         const struct hda_pcm_stream *stream_analog_alt_capture;
332
333         char stream_name_digital[32];   /* digital PCM stream */
334         const struct hda_pcm_stream *stream_digital_playback;
335         const struct hda_pcm_stream *stream_digital_capture;
336
337         /* playback */
338         struct hda_multi_out multiout;  /* playback set-up
339                                          * max_channels, dacs must be set
340                                          * dig_out_nid and hp_nid are optional
341                                          */
342         hda_nid_t alt_dac_nid;
343         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
344         int dig_out_type;
345
346         /* capture */
347         unsigned int num_adc_nids;
348         const hda_nid_t *adc_nids;
349         const hda_nid_t *capsrc_nids;
350         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
351         hda_nid_t mixer_nid;            /* analog-mixer NID */
352
353         /* capture setup for dynamic dual-adc switch */
354         unsigned int cur_adc_idx;
355         hda_nid_t cur_adc;
356         unsigned int cur_adc_stream_tag;
357         unsigned int cur_adc_format;
358
359         /* capture source */
360         unsigned int num_mux_defs;
361         const struct hda_input_mux *input_mux;
362         unsigned int cur_mux[3];
363         struct alc_mic_route ext_mic;
364         struct alc_mic_route dock_mic;
365         struct alc_mic_route int_mic;
366
367         /* channel model */
368         const struct hda_channel_mode *channel_mode;
369         int num_channel_mode;
370         int need_dac_fix;
371         int const_channel_count;
372         int ext_channel_count;
373
374         /* PCM information */
375         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
376
377         /* dynamic controls, init_verbs and input_mux */
378         struct auto_pin_cfg autocfg;
379         struct alc_customize_define cdefine;
380         struct snd_array kctls;
381         struct hda_input_mux private_imux[3];
382         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
383         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
384         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
385
386         /* hooks */
387         void (*init_hook)(struct hda_codec *codec);
388         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
389 #ifdef CONFIG_SND_HDA_POWER_SAVE
390         void (*power_hook)(struct hda_codec *codec);
391 #endif
392         void (*shutup)(struct hda_codec *codec);
393
394         /* for pin sensing */
395         unsigned int jack_present: 1;
396         unsigned int line_jack_present:1;
397         unsigned int master_mute:1;
398         unsigned int auto_mic:1;
399         unsigned int automute:1;        /* HP automute enabled */
400         unsigned int detect_line:1;     /* Line-out detection enabled */
401         unsigned int automute_lines:1;  /* automute line-out as well */
402         unsigned int automute_hp_lo:1;  /* both HP and LO available */
403
404         /* other flags */
405         unsigned int no_analog :1; /* digital I/O only */
406         unsigned int dual_adc_switch:1; /* switch ADCs (for ALC275) */
407         unsigned int single_input_src:1;
408
409         /* auto-mute control */
410         int automute_mode;
411         hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
412
413         int init_amp;
414         int codec_variant;      /* flag for other variants */
415
416         /* for virtual master */
417         hda_nid_t vmaster_nid;
418 #ifdef CONFIG_SND_HDA_POWER_SAVE
419         struct hda_loopback_check loopback;
420 #endif
421
422         /* for PLL fix */
423         hda_nid_t pll_nid;
424         unsigned int pll_coef_idx, pll_coef_bit;
425
426         /* fix-up list */
427         int fixup_id;
428         const struct alc_fixup *fixup_list;
429         const char *fixup_name;
430
431         /* multi-io */
432         int multi_ios;
433         struct alc_multi_io multi_io[4];
434 };
435
436 /*
437  * configuration template - to be copied to the spec instance
438  */
439 struct alc_config_preset {
440         const struct snd_kcontrol_new *mixers[5]; /* should be identical size
441                                              * with spec
442                                              */
443         const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
444         const struct hda_verb *init_verbs[5];
445         unsigned int num_dacs;
446         const hda_nid_t *dac_nids;
447         hda_nid_t dig_out_nid;          /* optional */
448         hda_nid_t hp_nid;               /* optional */
449         const hda_nid_t *slave_dig_outs;
450         unsigned int num_adc_nids;
451         const hda_nid_t *adc_nids;
452         const hda_nid_t *capsrc_nids;
453         hda_nid_t dig_in_nid;
454         unsigned int num_channel_mode;
455         const struct hda_channel_mode *channel_mode;
456         int need_dac_fix;
457         int const_channel_count;
458         unsigned int num_mux_defs;
459         const struct hda_input_mux *input_mux;
460         void (*unsol_event)(struct hda_codec *, unsigned int);
461         void (*setup)(struct hda_codec *);
462         void (*init_hook)(struct hda_codec *);
463 #ifdef CONFIG_SND_HDA_POWER_SAVE
464         const struct hda_amp_list *loopbacks;
465         void (*power_hook)(struct hda_codec *codec);
466 #endif
467 };
468
469
470 /*
471  * input MUX handling
472  */
473 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
474                              struct snd_ctl_elem_info *uinfo)
475 {
476         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
477         struct alc_spec *spec = codec->spec;
478         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
479         if (mux_idx >= spec->num_mux_defs)
480                 mux_idx = 0;
481         if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
482                 mux_idx = 0;
483         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
484 }
485
486 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
487                             struct snd_ctl_elem_value *ucontrol)
488 {
489         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
490         struct alc_spec *spec = codec->spec;
491         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
492
493         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
494         return 0;
495 }
496
497 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
498                             struct snd_ctl_elem_value *ucontrol)
499 {
500         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
501         struct alc_spec *spec = codec->spec;
502         const struct hda_input_mux *imux;
503         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
504         unsigned int mux_idx;
505         hda_nid_t nid = spec->capsrc_nids ?
506                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
507         unsigned int type;
508
509         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
510         imux = &spec->input_mux[mux_idx];
511         if (!imux->num_items && mux_idx > 0)
512                 imux = &spec->input_mux[0];
513
514         type = get_wcaps_type(get_wcaps(codec, nid));
515         if (type == AC_WID_AUD_MIX) {
516                 /* Matrix-mixer style (e.g. ALC882) */
517                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
518                 unsigned int i, idx;
519
520                 idx = ucontrol->value.enumerated.item[0];
521                 if (idx >= imux->num_items)
522                         idx = imux->num_items - 1;
523                 if (*cur_val == idx)
524                         return 0;
525                 for (i = 0; i < imux->num_items; i++) {
526                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
527                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
528                                                  imux->items[i].index,
529                                                  HDA_AMP_MUTE, v);
530                 }
531                 *cur_val = idx;
532                 return 1;
533         } else {
534                 /* MUX style (e.g. ALC880) */
535                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
536                                              &spec->cur_mux[adc_idx]);
537         }
538 }
539
540 /*
541  * channel mode setting
542  */
543 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
544                             struct snd_ctl_elem_info *uinfo)
545 {
546         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
547         struct alc_spec *spec = codec->spec;
548         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
549                                     spec->num_channel_mode);
550 }
551
552 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
553                            struct snd_ctl_elem_value *ucontrol)
554 {
555         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
556         struct alc_spec *spec = codec->spec;
557         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
558                                    spec->num_channel_mode,
559                                    spec->ext_channel_count);
560 }
561
562 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
563                            struct snd_ctl_elem_value *ucontrol)
564 {
565         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
566         struct alc_spec *spec = codec->spec;
567         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
568                                       spec->num_channel_mode,
569                                       &spec->ext_channel_count);
570         if (err >= 0 && !spec->const_channel_count) {
571                 spec->multiout.max_channels = spec->ext_channel_count;
572                 if (spec->need_dac_fix)
573                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
574         }
575         return err;
576 }
577
578 /*
579  * Control the mode of pin widget settings via the mixer.  "pc" is used
580  * instead of "%" to avoid consequences of accidentally treating the % as
581  * being part of a format specifier.  Maximum allowed length of a value is
582  * 63 characters plus NULL terminator.
583  *
584  * Note: some retasking pin complexes seem to ignore requests for input
585  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
586  * are requested.  Therefore order this list so that this behaviour will not
587  * cause problems when mixer clients move through the enum sequentially.
588  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
589  * March 2006.
590  */
591 static const char * const alc_pin_mode_names[] = {
592         "Mic 50pc bias", "Mic 80pc bias",
593         "Line in", "Line out", "Headphone out",
594 };
595 static const unsigned char alc_pin_mode_values[] = {
596         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
597 };
598 /* The control can present all 5 options, or it can limit the options based
599  * in the pin being assumed to be exclusively an input or an output pin.  In
600  * addition, "input" pins may or may not process the mic bias option
601  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
602  * accept requests for bias as of chip versions up to March 2006) and/or
603  * wiring in the computer.
604  */
605 #define ALC_PIN_DIR_IN              0x00
606 #define ALC_PIN_DIR_OUT             0x01
607 #define ALC_PIN_DIR_INOUT           0x02
608 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
609 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
610
611 /* Info about the pin modes supported by the different pin direction modes.
612  * For each direction the minimum and maximum values are given.
613  */
614 static const signed char alc_pin_mode_dir_info[5][2] = {
615         { 0, 2 },    /* ALC_PIN_DIR_IN */
616         { 3, 4 },    /* ALC_PIN_DIR_OUT */
617         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
618         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
619         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
620 };
621 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
622 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
623 #define alc_pin_mode_n_items(_dir) \
624         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
625
626 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
627                              struct snd_ctl_elem_info *uinfo)
628 {
629         unsigned int item_num = uinfo->value.enumerated.item;
630         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
631
632         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
633         uinfo->count = 1;
634         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
635
636         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
637                 item_num = alc_pin_mode_min(dir);
638         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
639         return 0;
640 }
641
642 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
643                             struct snd_ctl_elem_value *ucontrol)
644 {
645         unsigned int i;
646         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647         hda_nid_t nid = kcontrol->private_value & 0xffff;
648         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
649         long *valp = ucontrol->value.integer.value;
650         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
651                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
652                                                  0x00);
653
654         /* Find enumerated value for current pinctl setting */
655         i = alc_pin_mode_min(dir);
656         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
657                 i++;
658         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
659         return 0;
660 }
661
662 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
663                             struct snd_ctl_elem_value *ucontrol)
664 {
665         signed int change;
666         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667         hda_nid_t nid = kcontrol->private_value & 0xffff;
668         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
669         long val = *ucontrol->value.integer.value;
670         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
671                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
672                                                  0x00);
673
674         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
675                 val = alc_pin_mode_min(dir);
676
677         change = pinctl != alc_pin_mode_values[val];
678         if (change) {
679                 /* Set pin mode to that requested */
680                 snd_hda_codec_write_cache(codec, nid, 0,
681                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
682                                           alc_pin_mode_values[val]);
683
684                 /* Also enable the retasking pin's input/output as required
685                  * for the requested pin mode.  Enum values of 2 or less are
686                  * input modes.
687                  *
688                  * Dynamically switching the input/output buffers probably
689                  * reduces noise slightly (particularly on input) so we'll
690                  * do it.  However, having both input and output buffers
691                  * enabled simultaneously doesn't seem to be problematic if
692                  * this turns out to be necessary in the future.
693                  */
694                 if (val <= 2) {
695                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
696                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
697                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
698                                                  HDA_AMP_MUTE, 0);
699                 } else {
700                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
701                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
702                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
703                                                  HDA_AMP_MUTE, 0);
704                 }
705         }
706         return change;
707 }
708
709 #define ALC_PIN_MODE(xname, nid, dir) \
710         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
711           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
712           .info = alc_pin_mode_info, \
713           .get = alc_pin_mode_get, \
714           .put = alc_pin_mode_put, \
715           .private_value = nid | (dir<<16) }
716
717 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
718  * together using a mask with more than one bit set.  This control is
719  * currently used only by the ALC260 test model.  At this stage they are not
720  * needed for any "production" models.
721  */
722 #ifdef CONFIG_SND_DEBUG
723 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
724
725 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
726                              struct snd_ctl_elem_value *ucontrol)
727 {
728         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
729         hda_nid_t nid = kcontrol->private_value & 0xffff;
730         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
731         long *valp = ucontrol->value.integer.value;
732         unsigned int val = snd_hda_codec_read(codec, nid, 0,
733                                               AC_VERB_GET_GPIO_DATA, 0x00);
734
735         *valp = (val & mask) != 0;
736         return 0;
737 }
738 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
739                              struct snd_ctl_elem_value *ucontrol)
740 {
741         signed int change;
742         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
743         hda_nid_t nid = kcontrol->private_value & 0xffff;
744         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
745         long val = *ucontrol->value.integer.value;
746         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
747                                                     AC_VERB_GET_GPIO_DATA,
748                                                     0x00);
749
750         /* Set/unset the masked GPIO bit(s) as needed */
751         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
752         if (val == 0)
753                 gpio_data &= ~mask;
754         else
755                 gpio_data |= mask;
756         snd_hda_codec_write_cache(codec, nid, 0,
757                                   AC_VERB_SET_GPIO_DATA, gpio_data);
758
759         return change;
760 }
761 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
762         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
763           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
764           .info = alc_gpio_data_info, \
765           .get = alc_gpio_data_get, \
766           .put = alc_gpio_data_put, \
767           .private_value = nid | (mask<<16) }
768 #endif   /* CONFIG_SND_DEBUG */
769
770 /* A switch control to allow the enabling of the digital IO pins on the
771  * ALC260.  This is incredibly simplistic; the intention of this control is
772  * to provide something in the test model allowing digital outputs to be
773  * identified if present.  If models are found which can utilise these
774  * outputs a more complete mixer control can be devised for those models if
775  * necessary.
776  */
777 #ifdef CONFIG_SND_DEBUG
778 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
779
780 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
781                               struct snd_ctl_elem_value *ucontrol)
782 {
783         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
784         hda_nid_t nid = kcontrol->private_value & 0xffff;
785         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
786         long *valp = ucontrol->value.integer.value;
787         unsigned int val = snd_hda_codec_read(codec, nid, 0,
788                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
789
790         *valp = (val & mask) != 0;
791         return 0;
792 }
793 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
794                               struct snd_ctl_elem_value *ucontrol)
795 {
796         signed int change;
797         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798         hda_nid_t nid = kcontrol->private_value & 0xffff;
799         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
800         long val = *ucontrol->value.integer.value;
801         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
802                                                     AC_VERB_GET_DIGI_CONVERT_1,
803                                                     0x00);
804
805         /* Set/unset the masked control bit(s) as needed */
806         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
807         if (val==0)
808                 ctrl_data &= ~mask;
809         else
810                 ctrl_data |= mask;
811         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
812                                   ctrl_data);
813
814         return change;
815 }
816 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
817         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
818           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
819           .info = alc_spdif_ctrl_info, \
820           .get = alc_spdif_ctrl_get, \
821           .put = alc_spdif_ctrl_put, \
822           .private_value = nid | (mask<<16) }
823 #endif   /* CONFIG_SND_DEBUG */
824
825 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
826  * Again, this is only used in the ALC26x test models to help identify when
827  * the EAPD line must be asserted for features to work.
828  */
829 #ifdef CONFIG_SND_DEBUG
830 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
831
832 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
833                               struct snd_ctl_elem_value *ucontrol)
834 {
835         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
836         hda_nid_t nid = kcontrol->private_value & 0xffff;
837         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
838         long *valp = ucontrol->value.integer.value;
839         unsigned int val = snd_hda_codec_read(codec, nid, 0,
840                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
841
842         *valp = (val & mask) != 0;
843         return 0;
844 }
845
846 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
847                               struct snd_ctl_elem_value *ucontrol)
848 {
849         int change;
850         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851         hda_nid_t nid = kcontrol->private_value & 0xffff;
852         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
853         long val = *ucontrol->value.integer.value;
854         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
855                                                     AC_VERB_GET_EAPD_BTLENABLE,
856                                                     0x00);
857
858         /* Set/unset the masked control bit(s) as needed */
859         change = (!val ? 0 : mask) != (ctrl_data & mask);
860         if (!val)
861                 ctrl_data &= ~mask;
862         else
863                 ctrl_data |= mask;
864         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
865                                   ctrl_data);
866
867         return change;
868 }
869
870 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
871         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
872           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
873           .info = alc_eapd_ctrl_info, \
874           .get = alc_eapd_ctrl_get, \
875           .put = alc_eapd_ctrl_put, \
876           .private_value = nid | (mask<<16) }
877 #endif   /* CONFIG_SND_DEBUG */
878
879 /*
880  * set up the input pin config (depending on the given auto-pin type)
881  */
882 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
883                               int auto_pin_type)
884 {
885         unsigned int val = PIN_IN;
886
887         if (auto_pin_type == AUTO_PIN_MIC) {
888                 unsigned int pincap;
889                 unsigned int oldval;
890                 oldval = snd_hda_codec_read(codec, nid, 0,
891                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
892                 pincap = snd_hda_query_pin_caps(codec, nid);
893                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
894                 /* if the default pin setup is vref50, we give it priority */
895                 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
896                         val = PIN_VREF80;
897                 else if (pincap & AC_PINCAP_VREF_50)
898                         val = PIN_VREF50;
899                 else if (pincap & AC_PINCAP_VREF_100)
900                         val = PIN_VREF100;
901                 else if (pincap & AC_PINCAP_VREF_GRD)
902                         val = PIN_VREFGRD;
903         }
904         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
905 }
906
907 static void alc_fixup_autocfg_pin_nums(struct hda_codec *codec)
908 {
909         struct alc_spec *spec = codec->spec;
910         struct auto_pin_cfg *cfg = &spec->autocfg;
911
912         if (!cfg->line_outs) {
913                 while (cfg->line_outs < AUTO_CFG_MAX_OUTS &&
914                        cfg->line_out_pins[cfg->line_outs])
915                         cfg->line_outs++;
916         }
917         if (!cfg->speaker_outs) {
918                 while (cfg->speaker_outs < AUTO_CFG_MAX_OUTS &&
919                        cfg->speaker_pins[cfg->speaker_outs])
920                         cfg->speaker_outs++;
921         }
922         if (!cfg->hp_outs) {
923                 while (cfg->hp_outs < AUTO_CFG_MAX_OUTS &&
924                        cfg->hp_pins[cfg->hp_outs])
925                         cfg->hp_outs++;
926         }
927 }
928
929 /*
930  */
931 static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
932 {
933         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
934                 return;
935         spec->mixers[spec->num_mixers++] = mix;
936 }
937
938 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
939 {
940         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
941                 return;
942         spec->init_verbs[spec->num_init_verbs++] = verb;
943 }
944
945 /*
946  * set up from the preset table
947  */
948 static void setup_preset(struct hda_codec *codec,
949                          const struct alc_config_preset *preset)
950 {
951         struct alc_spec *spec = codec->spec;
952         int i;
953
954         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
955                 add_mixer(spec, preset->mixers[i]);
956         spec->cap_mixer = preset->cap_mixer;
957         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
958              i++)
959                 add_verb(spec, preset->init_verbs[i]);
960
961         spec->channel_mode = preset->channel_mode;
962         spec->num_channel_mode = preset->num_channel_mode;
963         spec->need_dac_fix = preset->need_dac_fix;
964         spec->const_channel_count = preset->const_channel_count;
965
966         if (preset->const_channel_count)
967                 spec->multiout.max_channels = preset->const_channel_count;
968         else
969                 spec->multiout.max_channels = spec->channel_mode[0].channels;
970         spec->ext_channel_count = spec->channel_mode[0].channels;
971
972         spec->multiout.num_dacs = preset->num_dacs;
973         spec->multiout.dac_nids = preset->dac_nids;
974         spec->multiout.dig_out_nid = preset->dig_out_nid;
975         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
976         spec->multiout.hp_nid = preset->hp_nid;
977
978         spec->num_mux_defs = preset->num_mux_defs;
979         if (!spec->num_mux_defs)
980                 spec->num_mux_defs = 1;
981         spec->input_mux = preset->input_mux;
982
983         spec->num_adc_nids = preset->num_adc_nids;
984         spec->adc_nids = preset->adc_nids;
985         spec->capsrc_nids = preset->capsrc_nids;
986         spec->dig_in_nid = preset->dig_in_nid;
987
988         spec->unsol_event = preset->unsol_event;
989         spec->init_hook = preset->init_hook;
990 #ifdef CONFIG_SND_HDA_POWER_SAVE
991         spec->power_hook = preset->power_hook;
992         spec->loopback.amplist = preset->loopbacks;
993 #endif
994
995         if (preset->setup)
996                 preset->setup(codec);
997
998         alc_fixup_autocfg_pin_nums(codec);
999 }
1000
1001 /* Enable GPIO mask and set output */
1002 static const struct hda_verb alc_gpio1_init_verbs[] = {
1003         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
1004         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
1005         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
1006         { }
1007 };
1008
1009 static const struct hda_verb alc_gpio2_init_verbs[] = {
1010         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
1011         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
1012         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
1013         { }
1014 };
1015
1016 static const struct hda_verb alc_gpio3_init_verbs[] = {
1017         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
1018         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
1019         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
1020         { }
1021 };
1022
1023 /*
1024  * Fix hardware PLL issue
1025  * On some codecs, the analog PLL gating control must be off while
1026  * the default value is 1.
1027  */
1028 static void alc_fix_pll(struct hda_codec *codec)
1029 {
1030         struct alc_spec *spec = codec->spec;
1031         unsigned int val;
1032
1033         if (!spec->pll_nid)
1034                 return;
1035         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1036                             spec->pll_coef_idx);
1037         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
1038                                  AC_VERB_GET_PROC_COEF, 0);
1039         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1040                             spec->pll_coef_idx);
1041         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
1042                             val & ~(1 << spec->pll_coef_bit));
1043 }
1044
1045 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
1046                              unsigned int coef_idx, unsigned int coef_bit)
1047 {
1048         struct alc_spec *spec = codec->spec;
1049         spec->pll_nid = nid;
1050         spec->pll_coef_idx = coef_idx;
1051         spec->pll_coef_bit = coef_bit;
1052         alc_fix_pll(codec);
1053 }
1054
1055 static int alc_init_jacks(struct hda_codec *codec)
1056 {
1057 #ifdef CONFIG_SND_HDA_INPUT_JACK
1058         struct alc_spec *spec = codec->spec;
1059         int err;
1060         unsigned int hp_nid = spec->autocfg.hp_pins[0];
1061         unsigned int mic_nid = spec->ext_mic.pin;
1062         unsigned int dock_nid = spec->dock_mic.pin;
1063
1064         if (hp_nid) {
1065                 err = snd_hda_input_jack_add(codec, hp_nid,
1066                                              SND_JACK_HEADPHONE, NULL);
1067                 if (err < 0)
1068                         return err;
1069                 snd_hda_input_jack_report(codec, hp_nid);
1070         }
1071
1072         if (mic_nid) {
1073                 err = snd_hda_input_jack_add(codec, mic_nid,
1074                                              SND_JACK_MICROPHONE, NULL);
1075                 if (err < 0)
1076                         return err;
1077                 snd_hda_input_jack_report(codec, mic_nid);
1078         }
1079         if (dock_nid) {
1080                 err = snd_hda_input_jack_add(codec, dock_nid,
1081                                              SND_JACK_MICROPHONE, NULL);
1082                 if (err < 0)
1083                         return err;
1084                 snd_hda_input_jack_report(codec, dock_nid);
1085         }
1086 #endif /* CONFIG_SND_HDA_INPUT_JACK */
1087         return 0;
1088 }
1089
1090 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
1091 {
1092         int i, present = 0;
1093
1094         for (i = 0; i < num_pins; i++) {
1095                 hda_nid_t nid = pins[i];
1096                 if (!nid)
1097                         break;
1098                 snd_hda_input_jack_report(codec, nid);
1099                 present |= snd_hda_jack_detect(codec, nid);
1100         }
1101         return present;
1102 }
1103
1104 static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
1105                         bool mute, bool hp_out)
1106 {
1107         struct alc_spec *spec = codec->spec;
1108         unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
1109         unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
1110         int i;
1111
1112         for (i = 0; i < num_pins; i++) {
1113                 hda_nid_t nid = pins[i];
1114                 if (!nid)
1115                         break;
1116                 switch (spec->automute_mode) {
1117                 case ALC_AUTOMUTE_PIN:
1118                         snd_hda_codec_write(codec, nid, 0,
1119                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
1120                                             pin_bits);
1121                         break;
1122                 case ALC_AUTOMUTE_AMP:
1123                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1124                                                  HDA_AMP_MUTE, mute_bits);
1125                         break;
1126                 case ALC_AUTOMUTE_MIXER:
1127                         nid = spec->automute_mixer_nid[i];
1128                         if (!nid)
1129                                 break;
1130                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
1131                                                  HDA_AMP_MUTE, mute_bits);
1132                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
1133                                                  HDA_AMP_MUTE, mute_bits);
1134                         break;
1135                 }
1136         }
1137 }
1138
1139 /* Toggle internal speakers muting */
1140 static void update_speakers(struct hda_codec *codec)
1141 {
1142         struct alc_spec *spec = codec->spec;
1143         int on;
1144
1145         /* Control HP pins/amps depending on master_mute state;
1146          * in general, HP pins/amps control should be enabled in all cases,
1147          * but currently set only for master_mute, just to be safe
1148          */
1149         do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
1150                     spec->autocfg.hp_pins, spec->master_mute, true);
1151
1152         if (!spec->automute)
1153                 on = 0;
1154         else
1155                 on = spec->jack_present | spec->line_jack_present;
1156         on |= spec->master_mute;
1157         do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
1158                     spec->autocfg.speaker_pins, on, false);
1159
1160         /* toggle line-out mutes if needed, too */
1161         /* if LO is a copy of either HP or Speaker, don't need to handle it */
1162         if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
1163             spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
1164                 return;
1165         if (!spec->automute_lines || !spec->automute)
1166                 on = 0;
1167         else
1168                 on = spec->jack_present;
1169         on |= spec->master_mute;
1170         do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
1171                     spec->autocfg.line_out_pins, on, false);
1172 }
1173
1174 static void alc_hp_automute(struct hda_codec *codec)
1175 {
1176         struct alc_spec *spec = codec->spec;
1177
1178         if (!spec->automute)
1179                 return;
1180         spec->jack_present =
1181                 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
1182                              spec->autocfg.hp_pins);
1183         update_speakers(codec);
1184 }
1185
1186 static void alc_line_automute(struct hda_codec *codec)
1187 {
1188         struct alc_spec *spec = codec->spec;
1189
1190         if (!spec->automute || !spec->detect_line)
1191                 return;
1192         spec->line_jack_present =
1193                 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
1194                              spec->autocfg.line_out_pins);
1195         update_speakers(codec);
1196 }
1197
1198 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
1199                                 hda_nid_t nid)
1200 {
1201         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
1202         int i, nums;
1203
1204         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
1205         for (i = 0; i < nums; i++)
1206                 if (conn[i] == nid)
1207                         return i;
1208         return -1;
1209 }
1210
1211 /* switch the current ADC according to the jack state */
1212 static void alc_dual_mic_adc_auto_switch(struct hda_codec *codec)
1213 {
1214         struct alc_spec *spec = codec->spec;
1215         unsigned int present;
1216         hda_nid_t new_adc;
1217
1218         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1219         if (present)
1220                 spec->cur_adc_idx = 1;
1221         else
1222                 spec->cur_adc_idx = 0;
1223         new_adc = spec->adc_nids[spec->cur_adc_idx];
1224         if (spec->cur_adc && spec->cur_adc != new_adc) {
1225                 /* stream is running, let's swap the current ADC */
1226                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1227                 spec->cur_adc = new_adc;
1228                 snd_hda_codec_setup_stream(codec, new_adc,
1229                                            spec->cur_adc_stream_tag, 0,
1230                                            spec->cur_adc_format);
1231         }
1232 }
1233
1234 static void alc_mic_automute(struct hda_codec *codec)
1235 {
1236         struct alc_spec *spec = codec->spec;
1237         struct alc_mic_route *dead1, *dead2, *alive;
1238         unsigned int present, type;
1239         hda_nid_t cap_nid;
1240
1241         if (!spec->auto_mic)
1242                 return;
1243         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1244                 return;
1245         if (snd_BUG_ON(!spec->adc_nids))
1246                 return;
1247
1248         if (spec->dual_adc_switch) {
1249                 alc_dual_mic_adc_auto_switch(codec);
1250                 return;
1251         }
1252
1253         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1254
1255         alive = &spec->int_mic;
1256         dead1 = &spec->ext_mic;
1257         dead2 = &spec->dock_mic;
1258
1259         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1260         if (present) {
1261                 alive = &spec->ext_mic;
1262                 dead1 = &spec->int_mic;
1263                 dead2 = &spec->dock_mic;
1264         }
1265         if (!present && spec->dock_mic.pin > 0) {
1266                 present = snd_hda_jack_detect(codec, spec->dock_mic.pin);
1267                 if (present) {
1268                         alive = &spec->dock_mic;
1269                         dead1 = &spec->int_mic;
1270                         dead2 = &spec->ext_mic;
1271                 }
1272                 snd_hda_input_jack_report(codec, spec->dock_mic.pin);
1273         }
1274
1275         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1276         if (type == AC_WID_AUD_MIX) {
1277                 /* Matrix-mixer style (e.g. ALC882) */
1278                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1279                                          alive->mux_idx,
1280                                          HDA_AMP_MUTE, 0);
1281                 if (dead1->pin > 0)
1282                         snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1283                                                  dead1->mux_idx,
1284                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
1285                 if (dead2->pin > 0)
1286                         snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1287                                                  dead2->mux_idx,
1288                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
1289         } else {
1290                 /* MUX style (e.g. ALC880) */
1291                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1292                                           AC_VERB_SET_CONNECT_SEL,
1293                                           alive->mux_idx);
1294         }
1295         snd_hda_input_jack_report(codec, spec->ext_mic.pin);
1296
1297         /* FIXME: analog mixer */
1298 }
1299
1300 /* unsolicited event for HP jack sensing */
1301 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1302 {
1303         if (codec->vendor_id == 0x10ec0880)
1304                 res >>= 28;
1305         else
1306                 res >>= 26;
1307         switch (res) {
1308         case ALC880_HP_EVENT:
1309                 alc_hp_automute(codec);
1310                 break;
1311         case ALC880_FRONT_EVENT:
1312                 alc_line_automute(codec);
1313                 break;
1314         case ALC880_MIC_EVENT:
1315                 alc_mic_automute(codec);
1316                 break;
1317         }
1318 }
1319
1320 static void alc_inithook(struct hda_codec *codec)
1321 {
1322         alc_hp_automute(codec);
1323         alc_line_automute(codec);
1324         alc_mic_automute(codec);
1325 }
1326
1327 /* additional initialization for ALC888 variants */
1328 static void alc888_coef_init(struct hda_codec *codec)
1329 {
1330         unsigned int tmp;
1331
1332         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1333         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1334         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1335         if ((tmp & 0xf0) == 0x20)
1336                 /* alc888S-VC */
1337                 snd_hda_codec_read(codec, 0x20, 0,
1338                                    AC_VERB_SET_PROC_COEF, 0x830);
1339          else
1340                  /* alc888-VB */
1341                  snd_hda_codec_read(codec, 0x20, 0,
1342                                     AC_VERB_SET_PROC_COEF, 0x3030);
1343 }
1344
1345 static void alc889_coef_init(struct hda_codec *codec)
1346 {
1347         unsigned int tmp;
1348
1349         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1350         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1351         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1352         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1353 }
1354
1355 /* turn on/off EAPD control (only if available) */
1356 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
1357 {
1358         if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
1359                 return;
1360         if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
1361                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1362                                     on ? 2 : 0);
1363 }
1364
1365 /* turn on/off EAPD controls of the codec */
1366 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
1367 {
1368         /* We currently only handle front, HP */
1369         switch (codec->vendor_id) {
1370         case 0x10ec0260:
1371                 set_eapd(codec, 0x0f, on);
1372                 set_eapd(codec, 0x10, on);
1373                 break;
1374         case 0x10ec0262:
1375         case 0x10ec0267:
1376         case 0x10ec0268:
1377         case 0x10ec0269:
1378         case 0x10ec0270:
1379         case 0x10ec0272:
1380         case 0x10ec0660:
1381         case 0x10ec0662:
1382         case 0x10ec0663:
1383         case 0x10ec0665:
1384         case 0x10ec0862:
1385         case 0x10ec0889:
1386         case 0x10ec0892:
1387                 set_eapd(codec, 0x14, on);
1388                 set_eapd(codec, 0x15, on);
1389                 break;
1390         }
1391 }
1392
1393 /* generic shutup callback;
1394  * just turning off EPAD and a little pause for avoiding pop-noise
1395  */
1396 static void alc_eapd_shutup(struct hda_codec *codec)
1397 {
1398         alc_auto_setup_eapd(codec, false);
1399         msleep(200);
1400 }
1401
1402 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1403 {
1404         unsigned int tmp;
1405
1406         switch (type) {
1407         case ALC_INIT_GPIO1:
1408                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1409                 break;
1410         case ALC_INIT_GPIO2:
1411                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1412                 break;
1413         case ALC_INIT_GPIO3:
1414                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1415                 break;
1416         case ALC_INIT_DEFAULT:
1417                 alc_auto_setup_eapd(codec, true);
1418                 switch (codec->vendor_id) {
1419                 case 0x10ec0260:
1420                         snd_hda_codec_write(codec, 0x1a, 0,
1421                                             AC_VERB_SET_COEF_INDEX, 7);
1422                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1423                                                  AC_VERB_GET_PROC_COEF, 0);
1424                         snd_hda_codec_write(codec, 0x1a, 0,
1425                                             AC_VERB_SET_COEF_INDEX, 7);
1426                         snd_hda_codec_write(codec, 0x1a, 0,
1427                                             AC_VERB_SET_PROC_COEF,
1428                                             tmp | 0x2010);
1429                         break;
1430                 case 0x10ec0262:
1431                 case 0x10ec0880:
1432                 case 0x10ec0882:
1433                 case 0x10ec0883:
1434                 case 0x10ec0885:
1435                 case 0x10ec0887:
1436                 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
1437                         alc889_coef_init(codec);
1438                         break;
1439                 case 0x10ec0888:
1440                         alc888_coef_init(codec);
1441                         break;
1442 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
1443                 case 0x10ec0267:
1444                 case 0x10ec0268:
1445                         snd_hda_codec_write(codec, 0x20, 0,
1446                                             AC_VERB_SET_COEF_INDEX, 7);
1447                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1448                                                  AC_VERB_GET_PROC_COEF, 0);
1449                         snd_hda_codec_write(codec, 0x20, 0,
1450                                             AC_VERB_SET_COEF_INDEX, 7);
1451                         snd_hda_codec_write(codec, 0x20, 0,
1452                                             AC_VERB_SET_PROC_COEF,
1453                                             tmp | 0x3000);
1454                         break;
1455 #endif /* XXX */
1456                 }
1457                 break;
1458         }
1459 }
1460
1461 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
1462                                   struct snd_ctl_elem_info *uinfo)
1463 {
1464         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1465         struct alc_spec *spec = codec->spec;
1466         static const char * const texts2[] = {
1467                 "Disabled", "Enabled"
1468         };
1469         static const char * const texts3[] = {
1470                 "Disabled", "Speaker Only", "Line-Out+Speaker"
1471         };
1472         const char * const *texts;
1473
1474         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1475         uinfo->count = 1;
1476         if (spec->automute_hp_lo) {
1477                 uinfo->value.enumerated.items = 3;
1478                 texts = texts3;
1479         } else {
1480                 uinfo->value.enumerated.items = 2;
1481                 texts = texts2;
1482         }
1483         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1484                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1485         strcpy(uinfo->value.enumerated.name,
1486                texts[uinfo->value.enumerated.item]);
1487         return 0;
1488 }
1489
1490 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
1491                                  struct snd_ctl_elem_value *ucontrol)
1492 {
1493         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1494         struct alc_spec *spec = codec->spec;
1495         unsigned int val;
1496         if (!spec->automute)
1497                 val = 0;
1498         else if (!spec->automute_lines)
1499                 val = 1;
1500         else
1501                 val = 2;
1502         ucontrol->value.enumerated.item[0] = val;
1503         return 0;
1504 }
1505
1506 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
1507                                  struct snd_ctl_elem_value *ucontrol)
1508 {
1509         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1510         struct alc_spec *spec = codec->spec;
1511
1512         switch (ucontrol->value.enumerated.item[0]) {
1513         case 0:
1514                 if (!spec->automute)
1515                         return 0;
1516                 spec->automute = 0;
1517                 break;
1518         case 1:
1519                 if (spec->automute && !spec->automute_lines)
1520                         return 0;
1521                 spec->automute = 1;
1522                 spec->automute_lines = 0;
1523                 break;
1524         case 2:
1525                 if (!spec->automute_hp_lo)
1526                         return -EINVAL;
1527                 if (spec->automute && spec->automute_lines)
1528                         return 0;
1529                 spec->automute = 1;
1530                 spec->automute_lines = 1;
1531                 break;
1532         default:
1533                 return -EINVAL;
1534         }
1535         update_speakers(codec);
1536         return 1;
1537 }
1538
1539 static const struct snd_kcontrol_new alc_automute_mode_enum = {
1540         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1541         .name = "Auto-Mute Mode",
1542         .info = alc_automute_mode_info,
1543         .get = alc_automute_mode_get,
1544         .put = alc_automute_mode_put,
1545 };
1546
1547 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec);
1548
1549 static int alc_add_automute_mode_enum(struct hda_codec *codec)
1550 {
1551         struct alc_spec *spec = codec->spec;
1552         struct snd_kcontrol_new *knew;
1553
1554         knew = alc_kcontrol_new(spec);
1555         if (!knew)
1556                 return -ENOMEM;
1557         *knew = alc_automute_mode_enum;
1558         knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
1559         if (!knew->name)
1560                 return -ENOMEM;
1561         return 0;
1562 }
1563
1564 static void alc_init_auto_hp(struct hda_codec *codec)
1565 {
1566         struct alc_spec *spec = codec->spec;
1567         struct auto_pin_cfg *cfg = &spec->autocfg;
1568         int present = 0;
1569         int i;
1570
1571         if (cfg->hp_pins[0])
1572                 present++;
1573         if (cfg->line_out_pins[0])
1574                 present++;
1575         if (cfg->speaker_pins[0])
1576                 present++;
1577         if (present < 2) /* need two different output types */
1578                 return;
1579         if (present == 3)
1580                 spec->automute_hp_lo = 1; /* both HP and LO automute */
1581
1582         if (!cfg->speaker_pins[0]) {
1583                 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1584                        sizeof(cfg->speaker_pins));
1585                 cfg->speaker_outs = cfg->line_outs;
1586         }
1587
1588         if (!cfg->hp_pins[0]) {
1589                 memcpy(cfg->hp_pins, cfg->line_out_pins,
1590                        sizeof(cfg->hp_pins));
1591                 cfg->hp_outs = cfg->line_outs;
1592         }
1593
1594         for (i = 0; i < cfg->hp_outs; i++) {
1595                 hda_nid_t nid = cfg->hp_pins[i];
1596                 if (!is_jack_detectable(codec, nid))
1597                         continue;
1598                 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1599                             nid);
1600                 snd_hda_codec_write_cache(codec, nid, 0,
1601                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1602                                   AC_USRSP_EN | ALC880_HP_EVENT);
1603                 spec->automute = 1;
1604                 spec->automute_mode = ALC_AUTOMUTE_PIN;
1605         }
1606         if (spec->automute && cfg->line_out_pins[0] &&
1607             cfg->line_out_pins[0] != cfg->hp_pins[0] &&
1608             cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
1609                 for (i = 0; i < cfg->line_outs; i++) {
1610                         hda_nid_t nid = cfg->line_out_pins[i];
1611                         if (!is_jack_detectable(codec, nid))
1612                                 continue;
1613                         snd_printdd("realtek: Enable Line-Out auto-muting "
1614                                     "on NID 0x%x\n", nid);
1615                         snd_hda_codec_write_cache(codec, nid, 0,
1616                                         AC_VERB_SET_UNSOLICITED_ENABLE,
1617                                         AC_USRSP_EN | ALC880_FRONT_EVENT);
1618                         spec->detect_line = 1;
1619                 }
1620                 spec->automute_lines = spec->detect_line;
1621         }
1622
1623         if (spec->automute) {
1624                 /* create a control for automute mode */
1625                 alc_add_automute_mode_enum(codec);
1626                 spec->unsol_event = alc_sku_unsol_event;
1627         }
1628 }
1629
1630 static void alc_init_auto_mic(struct hda_codec *codec)
1631 {
1632         struct alc_spec *spec = codec->spec;
1633         struct auto_pin_cfg *cfg = &spec->autocfg;
1634         hda_nid_t fixed, ext, dock;
1635         int i;
1636
1637         fixed = ext = dock = 0;
1638         for (i = 0; i < cfg->num_inputs; i++) {
1639                 hda_nid_t nid = cfg->inputs[i].pin;
1640                 unsigned int defcfg;
1641                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1642                 switch (snd_hda_get_input_pin_attr(defcfg)) {
1643                 case INPUT_PIN_ATTR_INT:
1644                         if (fixed)
1645                                 return; /* already occupied */
1646                         if (cfg->inputs[i].type != AUTO_PIN_MIC)
1647                                 return; /* invalid type */
1648                         fixed = nid;
1649                         break;
1650                 case INPUT_PIN_ATTR_UNUSED:
1651                         return; /* invalid entry */
1652                 case INPUT_PIN_ATTR_DOCK:
1653                         if (dock)
1654                                 return; /* already occupied */
1655                         if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1656                                 return; /* invalid type */
1657                         dock = nid;
1658                         break;
1659                 default:
1660                         if (ext)
1661                                 return; /* already occupied */
1662                         if (cfg->inputs[i].type != AUTO_PIN_MIC)
1663                                 return; /* invalid type */
1664                         ext = nid;
1665                         break;
1666                 }
1667         }
1668         if (!ext && dock) {
1669                 ext = dock;
1670                 dock = 0;
1671         }
1672         if (!ext || !fixed)
1673                 return;
1674         if (!is_jack_detectable(codec, ext))
1675                 return; /* no unsol support */
1676         if (dock && !is_jack_detectable(codec, dock))
1677                 return; /* no unsol support */
1678         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1679                     ext, fixed, dock);
1680         spec->ext_mic.pin = ext;
1681         spec->dock_mic.pin = dock;
1682         spec->int_mic.pin = fixed;
1683         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1684         spec->dock_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1685         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1686         spec->auto_mic = 1;
1687         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1688                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1689                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1690         spec->unsol_event = alc_sku_unsol_event;
1691 }
1692
1693 /* Could be any non-zero and even value. When used as fixup, tells
1694  * the driver to ignore any present sku defines.
1695  */
1696 #define ALC_FIXUP_SKU_IGNORE (2)
1697
1698 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1699 {
1700         unsigned int ass, tmp, i;
1701         unsigned nid = 0;
1702         struct alc_spec *spec = codec->spec;
1703
1704         spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1705
1706         if (spec->cdefine.fixup) {
1707                 ass = spec->cdefine.sku_cfg;
1708                 if (ass == ALC_FIXUP_SKU_IGNORE)
1709                         return -1;
1710                 goto do_sku;
1711         }
1712
1713         ass = codec->subsystem_id & 0xffff;
1714         if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1715                 goto do_sku;
1716
1717         nid = 0x1d;
1718         if (codec->vendor_id == 0x10ec0260)
1719                 nid = 0x17;
1720         ass = snd_hda_codec_get_pincfg(codec, nid);
1721
1722         if (!(ass & 1)) {
1723                 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1724                        codec->chip_name, ass);
1725                 return -1;
1726         }
1727
1728         /* check sum */
1729         tmp = 0;
1730         for (i = 1; i < 16; i++) {
1731                 if ((ass >> i) & 1)
1732                         tmp++;
1733         }
1734         if (((ass >> 16) & 0xf) != tmp)
1735                 return -1;
1736
1737         spec->cdefine.port_connectivity = ass >> 30;
1738         spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1739         spec->cdefine.check_sum = (ass >> 16) & 0xf;
1740         spec->cdefine.customization = ass >> 8;
1741 do_sku:
1742         spec->cdefine.sku_cfg = ass;
1743         spec->cdefine.external_amp = (ass & 0x38) >> 3;
1744         spec->cdefine.platform_type = (ass & 0x4) >> 2;
1745         spec->cdefine.swap = (ass & 0x2) >> 1;
1746         spec->cdefine.override = ass & 0x1;
1747
1748         snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1749                    nid, spec->cdefine.sku_cfg);
1750         snd_printd("SKU: port_connectivity=0x%x\n",
1751                    spec->cdefine.port_connectivity);
1752         snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1753         snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1754         snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1755         snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1756         snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1757         snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1758         snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1759
1760         return 0;
1761 }
1762
1763 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1764 {
1765         int i;
1766         for (i = 0; i < nums; i++)
1767                 if (list[i] == nid)
1768                         return true;
1769         return false;
1770 }
1771
1772 /* check subsystem ID and set up device-specific initialization;
1773  * return 1 if initialized, 0 if invalid SSID
1774  */
1775 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1776  *      31 ~ 16 :       Manufacture ID
1777  *      15 ~ 8  :       SKU ID
1778  *      7  ~ 0  :       Assembly ID
1779  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1780  */
1781 static int alc_subsystem_id(struct hda_codec *codec,
1782                             hda_nid_t porta, hda_nid_t porte,
1783                             hda_nid_t portd, hda_nid_t porti)
1784 {
1785         unsigned int ass, tmp, i;
1786         unsigned nid;
1787         struct alc_spec *spec = codec->spec;
1788
1789         if (spec->cdefine.fixup) {
1790                 ass = spec->cdefine.sku_cfg;
1791                 if (ass == ALC_FIXUP_SKU_IGNORE)
1792                         return 0;
1793                 goto do_sku;
1794         }
1795
1796         ass = codec->subsystem_id & 0xffff;
1797         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1798                 goto do_sku;
1799
1800         /* invalid SSID, check the special NID pin defcfg instead */
1801         /*
1802          * 31~30        : port connectivity
1803          * 29~21        : reserve
1804          * 20           : PCBEEP input
1805          * 19~16        : Check sum (15:1)
1806          * 15~1         : Custom
1807          * 0            : override
1808         */
1809         nid = 0x1d;
1810         if (codec->vendor_id == 0x10ec0260)
1811                 nid = 0x17;
1812         ass = snd_hda_codec_get_pincfg(codec, nid);
1813         snd_printd("realtek: No valid SSID, "
1814                    "checking pincfg 0x%08x for NID 0x%x\n",
1815                    ass, nid);
1816         if (!(ass & 1))
1817                 return 0;
1818         if ((ass >> 30) != 1)   /* no physical connection */
1819                 return 0;
1820
1821         /* check sum */
1822         tmp = 0;
1823         for (i = 1; i < 16; i++) {
1824                 if ((ass >> i) & 1)
1825                         tmp++;
1826         }
1827         if (((ass >> 16) & 0xf) != tmp)
1828                 return 0;
1829 do_sku:
1830         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1831                    ass & 0xffff, codec->vendor_id);
1832         /*
1833          * 0 : override
1834          * 1 :  Swap Jack
1835          * 2 : 0 --> Desktop, 1 --> Laptop
1836          * 3~5 : External Amplifier control
1837          * 7~6 : Reserved
1838         */
1839         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1840         switch (tmp) {
1841         case 1:
1842                 spec->init_amp = ALC_INIT_GPIO1;
1843                 break;
1844         case 3:
1845                 spec->init_amp = ALC_INIT_GPIO2;
1846                 break;
1847         case 7:
1848                 spec->init_amp = ALC_INIT_GPIO3;
1849                 break;
1850         case 5:
1851         default:
1852                 spec->init_amp = ALC_INIT_DEFAULT;
1853                 break;
1854         }
1855
1856         /* is laptop or Desktop and enable the function "Mute internal speaker
1857          * when the external headphone out jack is plugged"
1858          */
1859         if (!(ass & 0x8000))
1860                 return 1;
1861         /*
1862          * 10~8 : Jack location
1863          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1864          * 14~13: Resvered
1865          * 15   : 1 --> enable the function "Mute internal speaker
1866          *              when the external headphone out jack is plugged"
1867          */
1868         if (!spec->autocfg.hp_pins[0]) {
1869                 hda_nid_t nid;
1870                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1871                 if (tmp == 0)
1872                         nid = porta;
1873                 else if (tmp == 1)
1874                         nid = porte;
1875                 else if (tmp == 2)
1876                         nid = portd;
1877                 else if (tmp == 3)
1878                         nid = porti;
1879                 else
1880                         return 1;
1881                 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1882                                       spec->autocfg.line_outs))
1883                         return 1;
1884                 spec->autocfg.hp_pins[0] = nid;
1885         }
1886         return 1;
1887 }
1888
1889 static void alc_ssid_check(struct hda_codec *codec,
1890                            hda_nid_t porta, hda_nid_t porte,
1891                            hda_nid_t portd, hda_nid_t porti)
1892 {
1893         if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1894                 struct alc_spec *spec = codec->spec;
1895                 snd_printd("realtek: "
1896                            "Enable default setup for auto mode as fallback\n");
1897                 spec->init_amp = ALC_INIT_DEFAULT;
1898         }
1899
1900         alc_init_auto_hp(codec);
1901         alc_init_auto_mic(codec);
1902 }
1903
1904 /*
1905  * Fix-up pin default configurations and add default verbs
1906  */
1907
1908 struct alc_pincfg {
1909         hda_nid_t nid;
1910         u32 val;
1911 };
1912
1913 struct alc_model_fixup {
1914         const int id;
1915         const char *name;
1916 };
1917
1918 struct alc_fixup {
1919         int type;
1920         bool chained;
1921         int chain_id;
1922         union {
1923                 unsigned int sku;
1924                 const struct alc_pincfg *pins;
1925                 const struct hda_verb *verbs;
1926                 void (*func)(struct hda_codec *codec,
1927                              const struct alc_fixup *fix,
1928                              int action);
1929         } v;
1930 };
1931
1932 enum {
1933         ALC_FIXUP_INVALID,
1934         ALC_FIXUP_SKU,
1935         ALC_FIXUP_PINS,
1936         ALC_FIXUP_VERBS,
1937         ALC_FIXUP_FUNC,
1938 };
1939
1940 enum {
1941         ALC_FIXUP_ACT_PRE_PROBE,
1942         ALC_FIXUP_ACT_PROBE,
1943         ALC_FIXUP_ACT_INIT,
1944 };
1945
1946 static void alc_apply_fixup(struct hda_codec *codec, int action)
1947 {
1948         struct alc_spec *spec = codec->spec;
1949         int id = spec->fixup_id;
1950 #ifdef CONFIG_SND_DEBUG_VERBOSE
1951         const char *modelname = spec->fixup_name;
1952 #endif
1953         int depth = 0;
1954
1955         if (!spec->fixup_list)
1956                 return;
1957
1958         while (id >= 0) {
1959                 const struct alc_fixup *fix = spec->fixup_list + id;
1960                 const struct alc_pincfg *cfg;
1961
1962                 switch (fix->type) {
1963                 case ALC_FIXUP_SKU:
1964                         if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1965                                 break;;
1966                         snd_printdd(KERN_INFO "hda_codec: %s: "
1967                                     "Apply sku override for %s\n",
1968                                     codec->chip_name, modelname);
1969                         spec->cdefine.sku_cfg = fix->v.sku;
1970                         spec->cdefine.fixup = 1;
1971                         break;
1972                 case ALC_FIXUP_PINS:
1973                         cfg = fix->v.pins;
1974                         if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1975                                 break;
1976                         snd_printdd(KERN_INFO "hda_codec: %s: "
1977                                     "Apply pincfg for %s\n",
1978                                     codec->chip_name, modelname);
1979                         for (; cfg->nid; cfg++)
1980                                 snd_hda_codec_set_pincfg(codec, cfg->nid,
1981                                                          cfg->val);
1982                         break;
1983                 case ALC_FIXUP_VERBS:
1984                         if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1985                                 break;
1986                         snd_printdd(KERN_INFO "hda_codec: %s: "
1987                                     "Apply fix-verbs for %s\n",
1988                                     codec->chip_name, modelname);
1989                         add_verb(codec->spec, fix->v.verbs);
1990                         break;
1991                 case ALC_FIXUP_FUNC:
1992                         if (!fix->v.func)
1993                                 break;
1994                         snd_printdd(KERN_INFO "hda_codec: %s: "
1995                                     "Apply fix-func for %s\n",
1996                                     codec->chip_name, modelname);
1997                         fix->v.func(codec, fix, action);
1998                         break;
1999                 default:
2000                         snd_printk(KERN_ERR "hda_codec: %s: "
2001                                    "Invalid fixup type %d\n",
2002                                    codec->chip_name, fix->type);
2003                         break;
2004                 }
2005                 if (!fix->chained)
2006                         break;
2007                 if (++depth > 10)
2008                         break;
2009                 id = fix->chain_id;
2010         }
2011 }
2012
2013 static void alc_pick_fixup(struct hda_codec *codec,
2014                            const struct alc_model_fixup *models,
2015                            const struct snd_pci_quirk *quirk,
2016                            const struct alc_fixup *fixlist)
2017 {
2018         struct alc_spec *spec = codec->spec;
2019         int id = -1;
2020         const char *name = NULL;
2021
2022         if (codec->modelname && models) {
2023                 while (models->name) {
2024                         if (!strcmp(codec->modelname, models->name)) {
2025                                 id = models->id;
2026                                 name = models->name;
2027                                 break;
2028                         }
2029                         models++;
2030                 }
2031         }
2032         if (id < 0) {
2033                 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
2034                 if (quirk) {
2035                         id = quirk->value;
2036 #ifdef CONFIG_SND_DEBUG_VERBOSE
2037                         name = quirk->name;
2038 #endif
2039                 }
2040         }
2041
2042         spec->fixup_id = id;
2043         if (id >= 0) {
2044                 spec->fixup_list = fixlist;
2045                 spec->fixup_name = name;
2046         }
2047 }
2048
2049 static int alc_read_coef_idx(struct hda_codec *codec,
2050                         unsigned int coef_idx)
2051 {
2052         unsigned int val;
2053         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
2054                                 coef_idx);
2055         val = snd_hda_codec_read(codec, 0x20, 0,
2056                                 AC_VERB_GET_PROC_COEF, 0);
2057         return val;
2058 }
2059
2060 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
2061                                                         unsigned int coef_val)
2062 {
2063         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
2064                             coef_idx);
2065         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
2066                             coef_val);
2067 }
2068
2069 /* set right pin controls for digital I/O */
2070 static void alc_auto_init_digital(struct hda_codec *codec)
2071 {
2072         struct alc_spec *spec = codec->spec;
2073         int i;
2074         hda_nid_t pin, dac;
2075
2076         for (i = 0; i < spec->autocfg.dig_outs; i++) {
2077                 pin = spec->autocfg.dig_out_pins[i];
2078                 if (!pin)
2079                         continue;
2080                 snd_hda_codec_write(codec, pin, 0,
2081                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2082                 if (!i)
2083                         dac = spec->multiout.dig_out_nid;
2084                 else
2085                         dac = spec->slave_dig_outs[i - 1];
2086                 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
2087                         continue;
2088                 snd_hda_codec_write(codec, dac, 0,
2089                                     AC_VERB_SET_AMP_GAIN_MUTE,
2090                                     AMP_OUT_UNMUTE);
2091         }
2092         pin = spec->autocfg.dig_in_pin;
2093         if (pin)
2094                 snd_hda_codec_write(codec, pin, 0,
2095                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
2096                                     PIN_IN);
2097 }
2098
2099 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
2100 static void alc_auto_parse_digital(struct hda_codec *codec)
2101 {
2102         struct alc_spec *spec = codec->spec;
2103         int i, err;
2104         hda_nid_t dig_nid;
2105
2106         /* support multiple SPDIFs; the secondary is set up as a slave */
2107         for (i = 0; i < spec->autocfg.dig_outs; i++) {
2108                 err = snd_hda_get_connections(codec,
2109                                               spec->autocfg.dig_out_pins[i],
2110                                               &dig_nid, 1);
2111                 if (err < 0)
2112                         continue;
2113                 if (!i) {
2114                         spec->multiout.dig_out_nid = dig_nid;
2115                         spec->dig_out_type = spec->autocfg.dig_out_type[0];
2116                 } else {
2117                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
2118                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
2119                                 break;
2120                         spec->slave_dig_outs[i - 1] = dig_nid;
2121                 }
2122         }
2123
2124         if (spec->autocfg.dig_in_pin) {
2125                 dig_nid = codec->start_nid;
2126                 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2127                         unsigned int wcaps = get_wcaps(codec, dig_nid);
2128                         if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2129                                 continue;
2130                         if (!(wcaps & AC_WCAP_DIGITAL))
2131                                 continue;
2132                         if (!(wcaps & AC_WCAP_CONN_LIST))
2133                                 continue;
2134                         err = get_connection_index(codec, dig_nid,
2135                                                    spec->autocfg.dig_in_pin);
2136                         if (err >= 0) {
2137                                 spec->dig_in_nid = dig_nid;
2138                                 break;
2139                         }
2140                 }
2141         }
2142 }
2143
2144 /*
2145  * ALC888
2146  */
2147
2148 /*
2149  * 2ch mode
2150  */
2151 static const struct hda_verb alc888_4ST_ch2_intel_init[] = {
2152 /* Mic-in jack as mic in */
2153         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2154         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2155 /* Line-in jack as Line in */
2156         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2157         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2158 /* Line-Out as Front */
2159         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
2160         { } /* end */
2161 };
2162
2163 /*
2164  * 4ch mode
2165  */
2166 static const struct hda_verb alc888_4ST_ch4_intel_init[] = {
2167 /* Mic-in jack as mic in */
2168         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2169         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2170 /* Line-in jack as Surround */
2171         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2172         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2173 /* Line-Out as Front */
2174         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
2175         { } /* end */
2176 };
2177
2178 /*
2179  * 6ch mode
2180  */
2181 static const struct hda_verb alc888_4ST_ch6_intel_init[] = {
2182 /* Mic-in jack as CLFE */
2183         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2184         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2185 /* Line-in jack as Surround */
2186         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2187         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2188 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
2189         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
2190         { } /* end */
2191 };
2192
2193 /*
2194  * 8ch mode
2195  */
2196 static const struct hda_verb alc888_4ST_ch8_intel_init[] = {
2197 /* Mic-in jack as CLFE */
2198         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2199         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2200 /* Line-in jack as Surround */
2201         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2202         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2203 /* Line-Out as Side */
2204         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
2205         { } /* end */
2206 };
2207
2208 static const struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
2209         { 2, alc888_4ST_ch2_intel_init },
2210         { 4, alc888_4ST_ch4_intel_init },
2211         { 6, alc888_4ST_ch6_intel_init },
2212         { 8, alc888_4ST_ch8_intel_init },
2213 };
2214
2215 /*
2216  * ALC888 Fujitsu Siemens Amillo xa3530
2217  */
2218
2219 static const struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
2220 /* Front Mic: set to PIN_IN (empty by default) */
2221         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2222 /* Connect Internal HP to Front */
2223         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2224         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2225         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2226 /* Connect Bass HP to Front */
2227         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2228         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2229         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2230 /* Connect Line-Out side jack (SPDIF) to Side */
2231         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2232         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2233         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
2234 /* Connect Mic jack to CLFE */
2235         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2236         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2237         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
2238 /* Connect Line-in jack to Surround */
2239         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2240         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2241         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
2242 /* Connect HP out jack to Front */
2243         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2244         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2245         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2246 /* Enable unsolicited event for HP jack and Line-out jack */
2247         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2248         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2249         {}
2250 };
2251
2252 static void alc889_automute_setup(struct hda_codec *codec)
2253 {
2254         struct alc_spec *spec = codec->spec;
2255
2256         spec->autocfg.hp_pins[0] = 0x15;
2257         spec->autocfg.speaker_pins[0] = 0x14;
2258         spec->autocfg.speaker_pins[1] = 0x16;
2259         spec->autocfg.speaker_pins[2] = 0x17;
2260         spec->autocfg.speaker_pins[3] = 0x19;
2261         spec->autocfg.speaker_pins[4] = 0x1a;
2262         spec->automute = 1;
2263         spec->automute_mode = ALC_AUTOMUTE_AMP;
2264 }
2265
2266 static void alc889_intel_init_hook(struct hda_codec *codec)
2267 {
2268         alc889_coef_init(codec);
2269         alc_hp_automute(codec);
2270 }
2271
2272 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
2273 {
2274         struct alc_spec *spec = codec->spec;
2275
2276         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
2277         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
2278         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
2279         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
2280         spec->automute = 1;
2281         spec->automute_mode = ALC_AUTOMUTE_AMP;
2282 }
2283
2284 /*
2285  * ALC888 Acer Aspire 4930G model
2286  */
2287
2288 static const struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
2289 /* Front Mic: set to PIN_IN (empty by default) */
2290         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2291 /* Unselect Front Mic by default in input mixer 3 */
2292         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2293 /* Enable unsolicited event for HP jack */
2294         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2295 /* Connect Internal HP to front */
2296         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2297         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2298         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2299 /* Connect HP out to front */
2300         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2301         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2302         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2303         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2304         { }
2305 };
2306
2307 /*
2308  * ALC888 Acer Aspire 6530G model
2309  */
2310
2311 static const struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
2312 /* Route to built-in subwoofer as well as speakers */
2313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2315         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2316         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2317 /* Bias voltage on for external mic port */
2318         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2319 /* Front Mic: set to PIN_IN (empty by default) */
2320         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2321 /* Unselect Front Mic by default in input mixer 3 */
2322         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2323 /* Enable unsolicited event for HP jack */
2324         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2325 /* Enable speaker output */
2326         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2327         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2328         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2329 /* Enable headphone output */
2330         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2331         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2332         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2333         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2334         { }
2335 };
2336
2337 /*
2338  *ALC888 Acer Aspire 7730G model
2339  */
2340
2341 static const struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
2342 /* Bias voltage on for external mic port */
2343         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2344 /* Front Mic: set to PIN_IN (empty by default) */
2345         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2346 /* Unselect Front Mic by default in input mixer 3 */
2347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2348 /* Enable unsolicited event for HP jack */
2349         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2350 /* Enable speaker output */
2351         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2352         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2353         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2354 /* Enable headphone output */
2355         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2356         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2357         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2358         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2359 /*Enable internal subwoofer */
2360         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2361         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2362         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
2363         {0x17, AC_VERB_SET_EAPD_BTLENABLE, 2},
2364         { }
2365 };
2366
2367 /*
2368  * ALC889 Acer Aspire 8930G model
2369  */
2370
2371 static const struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
2372 /* Front Mic: set to PIN_IN (empty by default) */
2373         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2374 /* Unselect Front Mic by default in input mixer 3 */
2375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2376 /* Enable unsolicited event for HP jack */
2377         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2378 /* Connect Internal Front to Front */
2379         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2380         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2381         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2382 /* Connect Internal Rear to Rear */
2383         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2384         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2385         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
2386 /* Connect Internal CLFE to CLFE */
2387         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2388         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2389         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
2390 /* Connect HP out to Front */
2391         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2392         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2393         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2394 /* Enable all DACs */
2395 /*  DAC DISABLE/MUTE 1? */
2396 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
2397         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
2398         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2399 /*  DAC DISABLE/MUTE 2? */
2400 /*  some bit here disables the other DACs. Init=0x4900 */
2401         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
2402         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2403 /* DMIC fix
2404  * This laptop has a stereo digital microphone. The mics are only 1cm apart
2405  * which makes the stereo useless. However, either the mic or the ALC889
2406  * makes the signal become a difference/sum signal instead of standard
2407  * stereo, which is annoying. So instead we flip this bit which makes the
2408  * codec replicate the sum signal to both channels, turning it into a
2409  * normal mono mic.
2410  */
2411 /*  DMIC_CONTROL? Init value = 0x0001 */
2412         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
2413         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
2414         { }
2415 };
2416
2417 static const struct hda_input_mux alc888_2_capture_sources[2] = {
2418         /* Front mic only available on one ADC */
2419         {
2420                 .num_items = 4,
2421                 .items = {
2422                         { "Mic", 0x0 },
2423                         { "Line", 0x2 },
2424                         { "CD", 0x4 },
2425                         { "Front Mic", 0xb },
2426                 },
2427         },
2428         {
2429                 .num_items = 3,
2430                 .items = {
2431                         { "Mic", 0x0 },
2432                         { "Line", 0x2 },
2433                         { "CD", 0x4 },
2434                 },
2435         }
2436 };
2437
2438 static const struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
2439         /* Interal mic only available on one ADC */
2440         {
2441                 .num_items = 5,
2442                 .items = {
2443                         { "Mic", 0x0 },
2444                         { "Line In", 0x2 },
2445                         { "CD", 0x4 },
2446                         { "Input Mix", 0xa },
2447                         { "Internal Mic", 0xb },
2448                 },
2449         },
2450         {
2451                 .num_items = 4,
2452                 .items = {
2453                         { "Mic", 0x0 },
2454                         { "Line In", 0x2 },
2455                         { "CD", 0x4 },
2456                         { "Input Mix", 0xa },
2457                 },
2458         }
2459 };
2460
2461 static const struct hda_input_mux alc889_capture_sources[3] = {
2462         /* Digital mic only available on first "ADC" */
2463         {
2464                 .num_items = 5,
2465                 .items = {
2466                         { "Mic", 0x0 },
2467                         { "Line", 0x2 },
2468                         { "CD", 0x4 },
2469                         { "Front Mic", 0xb },
2470                         { "Input Mix", 0xa },
2471                 },
2472         },
2473         {
2474                 .num_items = 4,
2475                 .items = {
2476                         { "Mic", 0x0 },
2477                         { "Line", 0x2 },
2478                         { "CD", 0x4 },
2479                         { "Input Mix", 0xa },
2480                 },
2481         },
2482         {
2483                 .num_items = 4,
2484                 .items = {
2485                         { "Mic", 0x0 },
2486                         { "Line", 0x2 },
2487                         { "CD", 0x4 },
2488                         { "Input Mix", 0xa },
2489                 },
2490         }
2491 };
2492
2493 static const struct snd_kcontrol_new alc888_base_mixer[] = {
2494         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2495         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2496         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2497         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2498         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2499                 HDA_OUTPUT),
2500         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2501         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2502         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2503         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2504         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2505         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2506         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2507         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2508         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2509         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2510         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2511         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2512         { } /* end */
2513 };
2514
2515 static const struct snd_kcontrol_new alc888_acer_aspire_4930g_mixer[] = {
2516         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2517         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2518         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2519         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2520         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2521                 HDA_OUTPUT),
2522         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2523         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2524         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2525         HDA_CODEC_VOLUME_MONO("Internal LFE Playback Volume", 0x0f, 1, 0x0, HDA_OUTPUT),
2526         HDA_BIND_MUTE_MONO("Internal LFE Playback Switch", 0x0f, 1, 2, HDA_INPUT),
2527         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2528         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2529         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2530         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2531         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2532         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2533         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2534         { } /* end */
2535 };
2536
2537 static const struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
2538         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2539         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2540         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2541         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2542         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2543                 HDA_OUTPUT),
2544         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2545         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2546         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2547         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2548         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2549         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2550         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2551         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2552         { } /* end */
2553 };
2554
2555
2556 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
2557 {
2558         struct alc_spec *spec = codec->spec;
2559
2560         spec->autocfg.hp_pins[0] = 0x15;
2561         spec->autocfg.speaker_pins[0] = 0x14;
2562         spec->autocfg.speaker_pins[1] = 0x16;
2563         spec->autocfg.speaker_pins[2] = 0x17;
2564         spec->automute = 1;
2565         spec->automute_mode = ALC_AUTOMUTE_AMP;
2566 }
2567
2568 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
2569 {
2570         struct alc_spec *spec = codec->spec;
2571
2572         spec->autocfg.hp_pins[0] = 0x15;
2573         spec->autocfg.speaker_pins[0] = 0x14;
2574         spec->autocfg.speaker_pins[1] = 0x16;
2575         spec->autocfg.speaker_pins[2] = 0x17;
2576         spec->automute = 1;
2577         spec->automute_mode = ALC_AUTOMUTE_AMP;
2578 }
2579
2580 static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
2581 {
2582         struct alc_spec *spec = codec->spec;
2583
2584         spec->autocfg.hp_pins[0] = 0x15;
2585         spec->autocfg.speaker_pins[0] = 0x14;
2586         spec->autocfg.speaker_pins[1] = 0x16;
2587         spec->autocfg.speaker_pins[2] = 0x17;
2588         spec->automute = 1;
2589         spec->automute_mode = ALC_AUTOMUTE_AMP;
2590 }
2591
2592 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
2593 {
2594         struct alc_spec *spec = codec->spec;
2595
2596         spec->autocfg.hp_pins[0] = 0x15;
2597         spec->autocfg.speaker_pins[0] = 0x14;
2598         spec->autocfg.speaker_pins[1] = 0x16;
2599         spec->autocfg.speaker_pins[2] = 0x1b;
2600         spec->automute = 1;
2601         spec->automute_mode = ALC_AUTOMUTE_AMP;
2602 }
2603
2604 /*
2605  * ALC880 3-stack model
2606  *
2607  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
2608  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
2609  *                 F-Mic = 0x1b, HP = 0x19
2610  */
2611
2612 static const hda_nid_t alc880_dac_nids[4] = {
2613         /* front, rear, clfe, rear_surr */
2614         0x02, 0x05, 0x04, 0x03
2615 };
2616
2617 static const hda_nid_t alc880_adc_nids[3] = {
2618         /* ADC0-2 */
2619         0x07, 0x08, 0x09,
2620 };
2621
2622 /* The datasheet says the node 0x07 is connected from inputs,
2623  * but it shows zero connection in the real implementation on some devices.
2624  * Note: this is a 915GAV bug, fixed on 915GLV
2625  */
2626 static const hda_nid_t alc880_adc_nids_alt[2] = {
2627         /* ADC1-2 */
2628         0x08, 0x09,
2629 };
2630
2631 #define ALC880_DIGOUT_NID       0x06
2632 #define ALC880_DIGIN_NID        0x0a
2633
2634 static const struct hda_input_mux alc880_capture_source = {
2635         .num_items = 4,
2636         .items = {
2637                 { "Mic", 0x0 },
2638                 { "Front Mic", 0x3 },
2639                 { "Line", 0x2 },
2640                 { "CD", 0x4 },
2641         },
2642 };
2643
2644 /* channel source setting (2/6 channel selection for 3-stack) */
2645 /* 2ch mode */
2646 static const struct hda_verb alc880_threestack_ch2_init[] = {
2647         /* set line-in to input, mute it */
2648         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2649         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2650         /* set mic-in to input vref 80%, mute it */
2651         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2652         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2653         { } /* end */
2654 };
2655
2656 /* 6ch mode */
2657 static const struct hda_verb alc880_threestack_ch6_init[] = {
2658         /* set line-in to output, unmute it */
2659         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2660         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2661         /* set mic-in to output, unmute it */
2662         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2663         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2664         { } /* end */
2665 };
2666
2667 static const struct hda_channel_mode alc880_threestack_modes[2] = {
2668         { 2, alc880_threestack_ch2_init },
2669         { 6, alc880_threestack_ch6_init },
2670 };
2671
2672 static const struct snd_kcontrol_new alc880_three_stack_mixer[] = {
2673         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2674         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2675         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2676         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2677         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2678         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2679         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2680         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2681         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2682         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2683         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2684         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2685         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2686         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2687         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
2688         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
2689         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
2690         {
2691                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2692                 .name = "Channel Mode",
2693                 .info = alc_ch_mode_info,
2694                 .get = alc_ch_mode_get,
2695                 .put = alc_ch_mode_put,
2696         },
2697         { } /* end */
2698 };
2699
2700 /* capture mixer elements */
2701 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
2702                             struct snd_ctl_elem_info *uinfo)
2703 {
2704         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2705         struct alc_spec *spec = codec->spec;
2706         int err;
2707
2708         mutex_lock(&codec->control_mutex);
2709         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2710                                                       HDA_INPUT);
2711         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
2712         mutex_unlock(&codec->control_mutex);
2713         return err;
2714 }
2715
2716 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2717                            unsigned int size, unsigned int __user *tlv)
2718 {
2719         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2720         struct alc_spec *spec = codec->spec;
2721         int err;
2722
2723         mutex_lock(&codec->control_mutex);
2724         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2725                                                       HDA_INPUT);
2726         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
2727         mutex_unlock(&codec->control_mutex);
2728         return err;
2729 }
2730
2731 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
2732                              struct snd_ctl_elem_value *ucontrol);
2733
2734 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
2735                                  struct snd_ctl_elem_value *ucontrol,
2736                                  getput_call_t func)
2737 {
2738         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2739         struct alc_spec *spec = codec->spec;
2740         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2741         int err;
2742
2743         mutex_lock(&codec->control_mutex);
2744         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
2745                                                       3, 0, HDA_INPUT);
2746         err = func(kcontrol, ucontrol);
2747         mutex_unlock(&codec->control_mutex);
2748         return err;
2749 }
2750
2751 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
2752                            struct snd_ctl_elem_value *ucontrol)
2753 {
2754         return alc_cap_getput_caller(kcontrol, ucontrol,
2755                                      snd_hda_mixer_amp_volume_get);
2756 }
2757
2758 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
2759                            struct snd_ctl_elem_value *ucontrol)
2760 {
2761         return alc_cap_getput_caller(kcontrol, ucontrol,
2762                                      snd_hda_mixer_amp_volume_put);
2763 }
2764
2765 /* capture mixer elements */
2766 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
2767
2768 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
2769                           struct snd_ctl_elem_value *ucontrol)
2770 {
2771         return alc_cap_getput_caller(kcontrol, ucontrol,
2772                                      snd_hda_mixer_amp_switch_get);
2773 }
2774
2775 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
2776                           struct snd_ctl_elem_value *ucontrol)
2777 {
2778         return alc_cap_getput_caller(kcontrol, ucontrol,
2779                                      snd_hda_mixer_amp_switch_put);
2780 }
2781
2782 #define _DEFINE_CAPMIX(num) \
2783         { \
2784                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2785                 .name = "Capture Switch", \
2786                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
2787                 .count = num, \
2788                 .info = alc_cap_sw_info, \
2789                 .get = alc_cap_sw_get, \
2790                 .put = alc_cap_sw_put, \
2791         }, \
2792         { \
2793                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2794                 .name = "Capture Volume", \
2795                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2796                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2797                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2798                 .count = num, \
2799                 .info = alc_cap_vol_info, \
2800                 .get = alc_cap_vol_get, \
2801                 .put = alc_cap_vol_put, \
2802                 .tlv = { .c = alc_cap_vol_tlv }, \
2803         }
2804
2805 #define _DEFINE_CAPSRC(num) \
2806         { \
2807                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2808                 /* .name = "Capture Source", */ \
2809                 .name = "Input Source", \
2810                 .count = num, \
2811                 .info = alc_mux_enum_info, \
2812                 .get = alc_mux_enum_get, \
2813                 .put = alc_mux_enum_put, \
2814         }
2815
2816 #define DEFINE_CAPMIX(num) \
2817 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2818         _DEFINE_CAPMIX(num),                                  \
2819         _DEFINE_CAPSRC(num),                                  \
2820         { } /* end */                                         \
2821 }
2822
2823 #define DEFINE_CAPMIX_NOSRC(num) \
2824 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2825         _DEFINE_CAPMIX(num),                                        \
2826         { } /* end */                                               \
2827 }
2828
2829 /* up to three ADCs */
2830 DEFINE_CAPMIX(1);
2831 DEFINE_CAPMIX(2);
2832 DEFINE_CAPMIX(3);
2833 DEFINE_CAPMIX_NOSRC(1);
2834 DEFINE_CAPMIX_NOSRC(2);
2835 DEFINE_CAPMIX_NOSRC(3);
2836
2837 /*
2838  * ALC880 5-stack model
2839  *
2840  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2841  *      Side = 0x02 (0xd)
2842  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2843  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2844  */
2845
2846 /* additional mixers to alc880_three_stack_mixer */
2847 static const struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2848         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2849         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2850         { } /* end */
2851 };
2852
2853 /* channel source setting (6/8 channel selection for 5-stack) */
2854 /* 6ch mode */
2855 static const struct hda_verb alc880_fivestack_ch6_init[] = {
2856         /* set line-in to input, mute it */
2857         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2858         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2859         { } /* end */
2860 };
2861
2862 /* 8ch mode */
2863 static const struct hda_verb alc880_fivestack_ch8_init[] = {
2864         /* set line-in to output, unmute it */
2865         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2866         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2867         { } /* end */
2868 };
2869
2870 static const struct hda_channel_mode alc880_fivestack_modes[2] = {
2871         { 6, alc880_fivestack_ch6_init },
2872         { 8, alc880_fivestack_ch8_init },
2873 };
2874
2875
2876 /*
2877  * ALC880 6-stack model
2878  *
2879  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2880  *      Side = 0x05 (0x0f)
2881  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2882  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2883  */
2884
2885 static const hda_nid_t alc880_6st_dac_nids[4] = {
2886         /* front, rear, clfe, rear_surr */
2887         0x02, 0x03, 0x04, 0x05
2888 };
2889
2890 static const struct hda_input_mux alc880_6stack_capture_source = {
2891         .num_items = 4,
2892         .items = {
2893                 { "Mic", 0x0 },
2894                 { "Front Mic", 0x1 },
2895                 { "Line", 0x2 },
2896                 { "CD", 0x4 },
2897         },
2898 };
2899
2900 /* fixed 8-channels */
2901 static const struct hda_channel_mode alc880_sixstack_modes[1] = {
2902         { 8, NULL },
2903 };
2904
2905 static const struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2906         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2907         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2908         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2909         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2910         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2911         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2912         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2913         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2914         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2915         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2916         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2917         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2918         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2919         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2920         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2921         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2922         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2923         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2924         {
2925                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2926                 .name = "Channel Mode",
2927                 .info = alc_ch_mode_info,
2928                 .get = alc_ch_mode_get,
2929                 .put = alc_ch_mode_put,
2930         },
2931         { } /* end */
2932 };
2933
2934
2935 /*
2936  * ALC880 W810 model
2937  *
2938  * W810 has rear IO for:
2939  * Front (DAC 02)
2940  * Surround (DAC 03)
2941  * Center/LFE (DAC 04)
2942  * Digital out (06)
2943  *
2944  * The system also has a pair of internal speakers, and a headphone jack.
2945  * These are both connected to Line2 on the codec, hence to DAC 02.
2946  *
2947  * There is a variable resistor to control the speaker or headphone
2948  * volume. This is a hardware-only device without a software API.
2949  *
2950  * Plugging headphones in will disable the internal speakers. This is
2951  * implemented in hardware, not via the driver using jack sense. In
2952  * a similar fashion, plugging into the rear socket marked "front" will
2953  * disable both the speakers and headphones.
2954  *
2955  * For input, there's a microphone jack, and an "audio in" jack.
2956  * These may not do anything useful with this driver yet, because I
2957  * haven't setup any initialization verbs for these yet...
2958  */
2959
2960 static const hda_nid_t alc880_w810_dac_nids[3] = {
2961         /* front, rear/surround, clfe */
2962         0x02, 0x03, 0x04
2963 };
2964
2965 /* fixed 6 channels */
2966 static const struct hda_channel_mode alc880_w810_modes[1] = {
2967         { 6, NULL }
2968 };
2969
2970 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2971 static const struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2972         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2973         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2974         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2975         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2976         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2977         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2978         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2979         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2980         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2981         { } /* end */
2982 };
2983
2984
2985 /*
2986  * Z710V model
2987  *
2988  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2989  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2990  *                 Line = 0x1a
2991  */
2992
2993 static const hda_nid_t alc880_z71v_dac_nids[1] = {
2994         0x02
2995 };
2996 #define ALC880_Z71V_HP_DAC      0x03
2997
2998 /* fixed 2 channels */
2999 static const struct hda_channel_mode alc880_2_jack_modes[1] = {
3000         { 2, NULL }
3001 };
3002
3003 static const struct snd_kcontrol_new alc880_z71v_mixer[] = {
3004         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3005         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3006         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3007         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
3008         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3009         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3010         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3011         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3012         { } /* end */
3013 };
3014
3015
3016 /*
3017  * ALC880 F1734 model
3018  *
3019  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
3020  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
3021  */
3022
3023 static const hda_nid_t alc880_f1734_dac_nids[1] = {
3024         0x03
3025 };
3026 #define ALC880_F1734_HP_DAC     0x02
3027
3028 static const struct snd_kcontrol_new alc880_f1734_mixer[] = {
3029         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3030         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3031         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3032         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3033         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3034         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3035         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3036         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3037         { } /* end */
3038 };
3039
3040 static const struct hda_input_mux alc880_f1734_capture_source = {
3041         .num_items = 2,
3042         .items = {
3043                 { "Mic", 0x1 },
3044                 { "CD", 0x4 },
3045         },
3046 };
3047
3048
3049 /*
3050  * ALC880 ASUS model
3051  *
3052  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
3053  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
3054  *  Mic = 0x18, Line = 0x1a
3055  */
3056
3057 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
3058 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
3059
3060 static const struct snd_kcontrol_new alc880_asus_mixer[] = {
3061         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3062         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3063         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3064         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3065         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3066         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3067         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3068         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3069         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3070         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3071         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3072         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3073         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3074         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3075         {
3076                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3077                 .name = "Channel Mode",
3078                 .info = alc_ch_mode_info,
3079                 .get = alc_ch_mode_get,
3080                 .put = alc_ch_mode_put,
3081         },
3082         { } /* end */
3083 };
3084
3085 /*
3086  * ALC880 ASUS W1V model
3087  *
3088  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
3089  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
3090  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
3091  */
3092
3093 /* additional mixers to alc880_asus_mixer */
3094 static const struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
3095         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
3096         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
3097         { } /* end */
3098 };
3099
3100 /* TCL S700 */
3101 static const struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
3102         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3103         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
3104         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
3105         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
3106         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
3107         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
3108         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
3109         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
3110         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
3111         { } /* end */
3112 };
3113
3114 /* Uniwill */
3115 static const struct snd_kcontrol_new alc880_uniwill_mixer[] = {
3116         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3117         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3118         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3119         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3120         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3121         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3122         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3123         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3124         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3125         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3126         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3127         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3128         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3129         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3130         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3131         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3132         {
3133                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3134                 .name = "Channel Mode",
3135                 .info = alc_ch_mode_info,
3136                 .get = alc_ch_mode_get,
3137                 .put = alc_ch_mode_put,
3138         },
3139         { } /* end */
3140 };
3141
3142 static const struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
3143         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3144         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3145         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3146         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3147         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3148         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3149         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3150         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3151         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3152         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3153         { } /* end */
3154 };
3155
3156 static const struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
3157         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3158         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3159         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3160         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3161         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3162         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3163         { } /* end */
3164 };
3165
3166 /*
3167  * virtual master controls
3168  */
3169
3170 /*
3171  * slave controls for virtual master
3172  */
3173 static const char * const alc_slave_vols[] = {
3174         "Front Playback Volume",
3175         "Surround Playback Volume",
3176         "Center Playback Volume",
3177         "LFE Playback Volume",
3178         "Side Playback Volume",
3179         "Headphone Playback Volume",
3180         "Speaker Playback Volume",
3181         "Mono Playback Volume",
3182         "Line-Out Playback Volume",
3183         NULL,
3184 };
3185
3186 static const char * const alc_slave_sws[] = {
3187         "Front Playback Switch",
3188         "Surround Playback Switch",
3189         "Center Playback Switch",
3190         "LFE Playback Switch",
3191         "Side Playback Switch",
3192         "Headphone Playback Switch",
3193         "Speaker Playback Switch",
3194         "Mono Playback Switch",
3195         "IEC958 Playback Switch",
3196         "Line-Out Playback Switch",
3197         NULL,
3198 };
3199
3200 /*
3201  * build control elements
3202  */
3203
3204 #define NID_MAPPING             (-1)
3205
3206 #define SUBDEV_SPEAKER_         (0 << 6)
3207 #define SUBDEV_HP_              (1 << 6)
3208 #define SUBDEV_LINE_            (2 << 6)
3209 #define SUBDEV_SPEAKER(x)       (SUBDEV_SPEAKER_ | ((x) & 0x3f))
3210 #define SUBDEV_HP(x)            (SUBDEV_HP_ | ((x) & 0x3f))
3211 #define SUBDEV_LINE(x)          (SUBDEV_LINE_ | ((x) & 0x3f))
3212
3213 static void alc_free_kctls(struct hda_codec *codec);
3214
3215 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3216 /* additional beep mixers; the actual parameters are overwritten at build */
3217 static const struct snd_kcontrol_new alc_beep_mixer[] = {
3218         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
3219         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
3220         { } /* end */
3221 };
3222 #endif
3223
3224 static int alc_build_controls(struct hda_codec *codec)
3225 {
3226         struct alc_spec *spec = codec->spec;
3227         struct snd_kcontrol *kctl = NULL;
3228         const struct snd_kcontrol_new *knew;
3229         int i, j, err;
3230         unsigned int u;
3231         hda_nid_t nid;
3232
3233         for (i = 0; i < spec->num_mixers; i++) {
3234                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
3235                 if (err < 0)
3236                         return err;
3237         }
3238         if (spec->cap_mixer) {
3239                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
3240                 if (err < 0)
3241                         return err;
3242         }
3243         if (spec->multiout.dig_out_nid) {
3244                 err = snd_hda_create_spdif_out_ctls(codec,
3245                                                     spec->multiout.dig_out_nid,
3246                                                     spec->multiout.dig_out_nid);
3247                 if (err < 0)
3248                         return err;
3249                 if (!spec->no_analog) {
3250                         err = snd_hda_create_spdif_share_sw(codec,
3251                                                             &spec->multiout);
3252                         if (err < 0)
3253                                 return err;
3254                         spec->multiout.share_spdif = 1;
3255                 }
3256         }
3257         if (spec->dig_in_nid) {
3258                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
3259                 if (err < 0)
3260                         return err;
3261         }
3262
3263 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3264         /* create beep controls if needed */
3265         if (spec->beep_amp) {
3266                 const struct snd_kcontrol_new *knew;
3267                 for (knew = alc_beep_mixer; knew->name; knew++) {
3268                         struct snd_kcontrol *kctl;
3269                         kctl = snd_ctl_new1(knew, codec);
3270                         if (!kctl)
3271                                 return -ENOMEM;
3272                         kctl->private_value = spec->beep_amp;
3273                         err = snd_hda_ctl_add(codec, 0, kctl);
3274                         if (err < 0)
3275                                 return err;
3276                 }
3277         }
3278 #endif
3279
3280         /* if we have no master control, let's create it */
3281         if (!spec->no_analog &&
3282             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
3283                 unsigned int vmaster_tlv[4];
3284                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
3285                                         HDA_OUTPUT, vmaster_tlv);
3286                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
3287                                           vmaster_tlv, alc_slave_vols);
3288                 if (err < 0)
3289                         return err;
3290         }
3291         if (!spec->no_analog &&
3292             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
3293                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
3294                                           NULL, alc_slave_sws);
3295                 if (err < 0)
3296                         return err;
3297         }
3298
3299         /* assign Capture Source enums to NID */
3300         if (spec->capsrc_nids || spec->adc_nids) {
3301                 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
3302                 if (!kctl)
3303                         kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
3304                 for (i = 0; kctl && i < kctl->count; i++) {
3305                         const hda_nid_t *nids = spec->capsrc_nids;
3306                         if (!nids)
3307                                 nids = spec->adc_nids;
3308                         err = snd_hda_add_nid(codec, kctl, i, nids[i]);
3309                         if (err < 0)
3310                                 return err;
3311                 }
3312         }
3313         if (spec->cap_mixer) {
3314                 const char *kname = kctl ? kctl->id.name : NULL;
3315                 for (knew = spec->cap_mixer; knew->name; knew++) {
3316                         if (kname && strcmp(knew->name, kname) == 0)
3317                                 continue;
3318                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3319                         for (i = 0; kctl && i < kctl->count; i++) {
3320                                 err = snd_hda_add_nid(codec, kctl, i,
3321                                                       spec->adc_nids[i]);
3322                                 if (err < 0)
3323                                         return err;
3324                         }
3325                 }
3326         }
3327
3328         /* other nid->control mapping */
3329         for (i = 0; i < spec->num_mixers; i++) {
3330                 for (knew = spec->mixers[i]; knew->name; knew++) {
3331                         if (knew->iface != NID_MAPPING)
3332                                 continue;
3333                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3334                         if (kctl == NULL)
3335                                 continue;
3336                         u = knew->subdevice;
3337                         for (j = 0; j < 4; j++, u >>= 8) {
3338                                 nid = u & 0x3f;
3339                                 if (nid == 0)
3340                                         continue;
3341                                 switch (u & 0xc0) {
3342                                 case SUBDEV_SPEAKER_:
3343                                         nid = spec->autocfg.speaker_pins[nid];
3344                                         break;
3345                                 case SUBDEV_LINE_:
3346                                         nid = spec->autocfg.line_out_pins[nid];
3347                                         break;
3348                                 case SUBDEV_HP_:
3349                                         nid = spec->autocfg.hp_pins[nid];
3350                                         break;
3351                                 default:
3352                                         continue;
3353                                 }
3354                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
3355                                 if (err < 0)
3356                                         return err;
3357                         }
3358                         u = knew->private_value;
3359                         for (j = 0; j < 4; j++, u >>= 8) {
3360                                 nid = u & 0xff;
3361                                 if (nid == 0)
3362                                         continue;
3363                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
3364                                 if (err < 0)
3365                                         return err;
3366                         }
3367                 }
3368         }
3369
3370         alc_free_kctls(codec); /* no longer needed */
3371
3372         return 0;
3373 }
3374
3375
3376 /*
3377  * initialize the codec volumes, etc
3378  */
3379
3380 /*
3381  * generic initialization of ADC, input mixers and output mixers
3382  */
3383 static const struct hda_verb alc880_volume_init_verbs[] = {
3384         /*
3385          * Unmute ADC0-2 and set the default input to mic-in
3386          */
3387         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3388         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3389         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3390         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3391         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3392         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3393
3394         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3395          * mixer widget
3396          * Note: PASD motherboards uses the Line In 2 as the input for front
3397          * panel mic (mic 2)
3398          */
3399         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
3400         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3401         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3402         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3403         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3404         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3405         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3406         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3407
3408         /*
3409          * Set up output mixers (0x0c - 0x0f)
3410          */
3411         /* set vol=0 to output mixers */
3412         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3413         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3414         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3415         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3416         /* set up input amps for analog loopback */
3417         /* Amp Indices: DAC = 0, mixer = 1 */
3418         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3419         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3420         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3421         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3422         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3423         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3424         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3425         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3426
3427         { }
3428 };
3429
3430 /*
3431  * 3-stack pin configuration:
3432  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
3433  */
3434 static const struct hda_verb alc880_pin_3stack_init_verbs[] = {
3435         /*
3436          * preset connection lists of input pins
3437          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3438          */
3439         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3440         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3441         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3442
3443         /*
3444          * Set pin mode and muting
3445          */
3446         /* set front pin widgets 0x14 for output */
3447         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3448         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3449         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3450         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3451         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3452         /* Mic2 (as headphone out) for HP output */
3453         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3454         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3455         /* Line In pin widget for input */
3456         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3457         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3458         /* Line2 (as front mic) pin widget for input and vref at 80% */
3459         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3460         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3461         /* CD pin widget for input */
3462         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3463
3464         { }
3465 };
3466
3467 /*
3468  * 5-stack pin configuration:
3469  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
3470  * line-in/side = 0x1a, f-mic = 0x1b
3471  */
3472 static const struct hda_verb alc880_pin_5stack_init_verbs[] = {
3473         /*
3474          * preset connection lists of input pins
3475          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3476          */
3477         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3478         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
3479
3480         /*
3481          * Set pin mode and muting
3482          */
3483         /* set pin widgets 0x14-0x17 for output */
3484         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3485         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3486         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3487         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3488         /* unmute pins for output (no gain on this amp) */
3489         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3490         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3491         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3492         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3493
3494         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3495         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3496         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3497         /* Mic2 (as headphone out) for HP output */
3498         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3499         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3500         /* Line In pin widget for input */
3501         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3502         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3503         /* Line2 (as front mic) pin widget for input and vref at 80% */
3504         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3505         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3506         /* CD pin widget for input */
3507         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3508
3509         { }
3510 };
3511
3512 /*
3513  * W810 pin configuration:
3514  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
3515  */
3516 static const struct hda_verb alc880_pin_w810_init_verbs[] = {
3517         /* hphone/speaker input selector: front DAC */
3518         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
3519
3520         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3521         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3522         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3523         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3524         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3525         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3526
3527         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3528         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3529
3530         { }
3531 };
3532
3533 /*
3534  * Z71V pin configuration:
3535  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
3536  */
3537 static const struct hda_verb alc880_pin_z71v_init_verbs[] = {
3538         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3539         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3540         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3541         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3542
3543         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3544         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3545         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3546         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3547
3548         { }
3549 };
3550
3551 /*
3552  * 6-stack pin configuration:
3553  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
3554  * f-mic = 0x19, line = 0x1a, HP = 0x1b
3555  */
3556 static const struct hda_verb alc880_pin_6stack_init_verbs[] = {
3557         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3558
3559         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3560         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3561         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3562         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3563         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3564         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3565         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3566         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3567
3568         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3569         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3570         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3571         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3572         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3573         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3574         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3575         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3576         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3577
3578         { }
3579 };
3580
3581 /*
3582  * Uniwill pin configuration:
3583  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
3584  * line = 0x1a
3585  */
3586 static const struct hda_verb alc880_uniwill_init_verbs[] = {
3587         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3588
3589         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3590         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3591         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3592         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3593         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3594         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3595         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3596         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3597         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3598         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3599         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3600         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3601         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3602         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3603
3604         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3605         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3606         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3607         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3608         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3609         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3610         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
3611         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
3612         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3613
3614         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3615         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
3616
3617         { }
3618 };
3619
3620 /*
3621 * Uniwill P53
3622 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
3623  */
3624 static const struct hda_verb alc880_uniwill_p53_init_verbs[] = {
3625         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3626
3627         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3628         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3629         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3630         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3631         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3632         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3633         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3634         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3635         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3636         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3637         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3638         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3639
3640         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3641         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3642         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3643         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3644         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3645         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3646
3647         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3648         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
3649
3650         { }
3651 };
3652
3653 static const struct hda_verb alc880_beep_init_verbs[] = {
3654         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
3655         { }
3656 };
3657
3658 /* auto-toggle front mic */
3659 static void alc88x_simple_mic_automute(struct hda_codec *codec)
3660 {
3661         unsigned int present;
3662         unsigned char bits;
3663
3664         present = snd_hda_jack_detect(codec, 0x18);
3665         bits = present ? HDA_AMP_MUTE : 0;
3666         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
3667 }
3668
3669 static void alc880_uniwill_setup(struct hda_codec *codec)
3670 {
3671         struct alc_spec *spec = codec->spec;
3672
3673         spec->autocfg.hp_pins[0] = 0x14;
3674         spec->autocfg.speaker_pins[0] = 0x15;
3675         spec->autocfg.speaker_pins[0] = 0x16;
3676         spec->automute = 1;
3677         spec->automute_mode = ALC_AUTOMUTE_AMP;
3678 }
3679
3680 static void alc880_uniwill_init_hook(struct hda_codec *codec)
3681 {
3682         alc_hp_automute(codec);
3683         alc88x_simple_mic_automute(codec);
3684 }
3685
3686 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
3687                                        unsigned int res)
3688 {
3689         /* Looks like the unsol event is incompatible with the standard
3690          * definition.  4bit tag is placed at 28 bit!
3691          */
3692         switch (res >> 28) {
3693         case ALC880_MIC_EVENT:
3694                 alc88x_simple_mic_automute(codec);
3695                 break;
3696         default:
3697                 alc_sku_unsol_event(codec, res);
3698                 break;
3699         }
3700 }
3701
3702 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
3703 {
3704         struct alc_spec *spec = codec->spec;
3705
3706         spec->autocfg.hp_pins[0] = 0x14;
3707         spec->autocfg.speaker_pins[0] = 0x15;
3708         spec->automute = 1;
3709         spec->automute_mode = ALC_AUTOMUTE_AMP;
3710 }
3711
3712 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
3713 {
3714         unsigned int present;
3715
3716         present = snd_hda_codec_read(codec, 0x21, 0,
3717                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
3718         present &= HDA_AMP_VOLMASK;
3719         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
3720                                  HDA_AMP_VOLMASK, present);
3721         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
3722                                  HDA_AMP_VOLMASK, present);
3723 }
3724
3725 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
3726                                            unsigned int res)
3727 {
3728         /* Looks like the unsol event is incompatible with the standard
3729          * definition.  4bit tag is placed at 28 bit!
3730          */
3731         if ((res >> 28) == ALC880_DCVOL_EVENT)
3732                 alc880_uniwill_p53_dcvol_automute(codec);
3733         else
3734                 alc_sku_unsol_event(codec, res);
3735 }
3736
3737 /*
3738  * F1734 pin configuration:
3739  * HP = 0x14, speaker-out = 0x15, mic = 0x18
3740  */
3741 static const struct hda_verb alc880_pin_f1734_init_verbs[] = {
3742         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
3743         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3744         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3745         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3746         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3747
3748         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3749         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3750         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3751         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3752
3753         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3754         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3755         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3756         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3757         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3758         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3759         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3760         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3761         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3762
3763         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
3764         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
3765
3766         { }
3767 };
3768
3769 /*
3770  * ASUS pin configuration:
3771  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
3772  */
3773 static const struct hda_verb alc880_pin_asus_init_verbs[] = {
3774         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3775         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3776         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3777         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3778
3779         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3780         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3781         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3782         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3783         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3784         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3785         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3786         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3787
3788         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3789         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3790         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3791         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3792         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3793         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3794         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3795         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3796         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3797
3798         { }
3799 };
3800
3801 /* Enable GPIO mask and set output */
3802 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
3803 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
3804 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
3805
3806 /* Clevo m520g init */
3807 static const struct hda_verb alc880_pin_clevo_init_verbs[] = {
3808         /* headphone output */
3809         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3810         /* line-out */
3811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3813         /* Line-in */
3814         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3815         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3816         /* CD */
3817         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3818         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3819         /* Mic1 (rear panel) */
3820         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3821         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3822         /* Mic2 (front panel) */
3823         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3824         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3825         /* headphone */
3826         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3827         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3828         /* change to EAPD mode */
3829         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3830         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3831
3832         { }
3833 };
3834
3835 static const struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
3836         /* change to EAPD mode */
3837         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3838         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3839
3840         /* Headphone output */
3841         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3842         /* Front output*/
3843         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3844         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
3845
3846         /* Line In pin widget for input */
3847         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3848         /* CD pin widget for input */
3849         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3850         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3851         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3852
3853         /* change to EAPD mode */
3854         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3855         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
3856
3857         { }
3858 };
3859
3860 /*
3861  * LG m1 express dual
3862  *
3863  * Pin assignment:
3864  *   Rear Line-In/Out (blue): 0x14
3865  *   Build-in Mic-In: 0x15
3866  *   Speaker-out: 0x17
3867  *   HP-Out (green): 0x1b
3868  *   Mic-In/Out (red): 0x19
3869  *   SPDIF-Out: 0x1e
3870  */
3871
3872 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
3873 static const hda_nid_t alc880_lg_dac_nids[3] = {
3874         0x05, 0x02, 0x03
3875 };
3876
3877 /* seems analog CD is not working */
3878 static const struct hda_input_mux alc880_lg_capture_source = {
3879         .num_items = 3,
3880         .items = {
3881                 { "Mic", 0x1 },
3882                 { "Line", 0x5 },
3883                 { "Internal Mic", 0x6 },
3884         },
3885 };
3886
3887 /* 2,4,6 channel modes */
3888 static const struct hda_verb alc880_lg_ch2_init[] = {
3889         /* set line-in and mic-in to input */
3890         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3891         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3892         { }
3893 };
3894
3895 static const struct hda_verb alc880_lg_ch4_init[] = {
3896         /* set line-in to out and mic-in to input */
3897         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3898         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3899         { }
3900 };
3901
3902 static const struct hda_verb alc880_lg_ch6_init[] = {
3903         /* set line-in and mic-in to output */
3904         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3905         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3906         { }
3907 };
3908
3909 static const struct hda_channel_mode alc880_lg_ch_modes[3] = {
3910         { 2, alc880_lg_ch2_init },
3911         { 4, alc880_lg_ch4_init },
3912         { 6, alc880_lg_ch6_init },
3913 };
3914
3915 static const struct snd_kcontrol_new alc880_lg_mixer[] = {
3916         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3917         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3918         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3919         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3920         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3921         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3922         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3923         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3924         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3925         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3926         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3927         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3928         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3929         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3930         {
3931                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3932                 .name = "Channel Mode",
3933                 .info = alc_ch_mode_info,
3934                 .get = alc_ch_mode_get,
3935                 .put = alc_ch_mode_put,
3936         },
3937         { } /* end */
3938 };
3939
3940 static const struct hda_verb alc880_lg_init_verbs[] = {
3941         /* set capture source to mic-in */
3942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3943         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3944         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3945         /* mute all amp mixer inputs */
3946         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3947         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3948         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3949         /* line-in to input */
3950         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3951         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3952         /* built-in mic */
3953         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3954         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3955         /* speaker-out */
3956         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3957         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3958         /* mic-in to input */
3959         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3960         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3961         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3962         /* HP-out */
3963         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3964         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3965         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3966         /* jack sense */
3967         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3968         { }
3969 };
3970
3971 /* toggle speaker-output according to the hp-jack state */
3972 static void alc880_lg_setup(struct hda_codec *codec)
3973 {
3974         struct alc_spec *spec = codec->spec;
3975
3976         spec->autocfg.hp_pins[0] = 0x1b;
3977         spec->autocfg.speaker_pins[0] = 0x17;
3978         spec->automute = 1;
3979         spec->automute_mode = ALC_AUTOMUTE_AMP;
3980 }
3981
3982 /*
3983  * LG LW20
3984  *
3985  * Pin assignment:
3986  *   Speaker-out: 0x14
3987  *   Mic-In: 0x18
3988  *   Built-in Mic-In: 0x19
3989  *   Line-In: 0x1b
3990  *   HP-Out: 0x1a
3991  *   SPDIF-Out: 0x1e
3992  */
3993
3994 static const struct hda_input_mux alc880_lg_lw_capture_source = {
3995         .num_items = 3,
3996         .items = {
3997                 { "Mic", 0x0 },
3998                 { "Internal Mic", 0x1 },
3999                 { "Line In", 0x2 },
4000         },
4001 };
4002
4003 #define alc880_lg_lw_modes alc880_threestack_modes
4004
4005 static const struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
4006         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4007         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4008         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4009         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
4010         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4011         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4012         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4013         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4014         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4015         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4016         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4017         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4018         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
4019         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
4020         {
4021                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4022                 .name = "Channel Mode",
4023                 .info = alc_ch_mode_info,
4024                 .get = alc_ch_mode_get,
4025                 .put = alc_ch_mode_put,
4026         },
4027         { } /* end */
4028 };
4029
4030 static const struct hda_verb alc880_lg_lw_init_verbs[] = {
4031         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
4032         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
4033         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
4034
4035         /* set capture source to mic-in */
4036         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4037         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4038         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4040         /* speaker-out */
4041         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4042         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4043         /* HP-out */
4044         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4045         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4046         /* mic-in to input */
4047         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4048         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4049         /* built-in mic */
4050         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4051         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4052         /* jack sense */
4053         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4054         { }
4055 };
4056
4057 /* toggle speaker-output according to the hp-jack state */
4058 static void alc880_lg_lw_setup(struct hda_codec *codec)
4059 {
4060         struct alc_spec *spec = codec->spec;
4061
4062         spec->autocfg.hp_pins[0] = 0x1b;
4063         spec->autocfg.speaker_pins[0] = 0x14;
4064         spec->automute = 1;
4065         spec->automute_mode = ALC_AUTOMUTE_AMP;
4066 }
4067
4068 static const struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
4069         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4070         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
4071         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4072         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4073         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4074         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
4075         { } /* end */
4076 };
4077
4078 static const struct hda_input_mux alc880_medion_rim_capture_source = {
4079         .num_items = 2,
4080         .items = {
4081                 { "Mic", 0x0 },
4082                 { "Internal Mic", 0x1 },
4083         },
4084 };
4085
4086 static const struct hda_verb alc880_medion_rim_init_verbs[] = {
4087         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
4088
4089         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4090         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4091
4092         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4093         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4094         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4095         /* Mic2 (as headphone out) for HP output */
4096         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4097         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4098         /* Internal Speaker */
4099         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4100         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4101
4102         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
4103         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
4104
4105         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4106         { }
4107 };
4108
4109 /* toggle speaker-output according to the hp-jack state */
4110 static void alc880_medion_rim_automute(struct hda_codec *codec)
4111 {
4112         struct alc_spec *spec = codec->spec;
4113         alc_hp_automute(codec);
4114         /* toggle EAPD */
4115         if (spec->jack_present)
4116                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
4117         else
4118                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
4119 }
4120
4121 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
4122                                           unsigned int res)
4123 {
4124         /* Looks like the unsol event is incompatible with the standard
4125          * definition.  4bit tag is placed at 28 bit!
4126          */
4127         if ((res >> 28) == ALC880_HP_EVENT)
4128                 alc880_medion_rim_automute(codec);
4129 }
4130
4131 static void alc880_medion_rim_setup(struct hda_codec *codec)
4132 {
4133         struct alc_spec *spec = codec->spec;
4134
4135         spec->autocfg.hp_pins[0] = 0x14;
4136         spec->autocfg.speaker_pins[0] = 0x1b;
4137         spec->automute = 1;
4138         spec->automute_mode = ALC_AUTOMUTE_AMP;
4139 }
4140
4141 #ifdef CONFIG_SND_HDA_POWER_SAVE
4142 static const struct hda_amp_list alc880_loopbacks[] = {
4143         { 0x0b, HDA_INPUT, 0 },
4144         { 0x0b, HDA_INPUT, 1 },
4145         { 0x0b, HDA_INPUT, 2 },
4146         { 0x0b, HDA_INPUT, 3 },
4147         { 0x0b, HDA_INPUT, 4 },
4148         { } /* end */
4149 };
4150
4151 static const struct hda_amp_list alc880_lg_loopbacks[] = {
4152         { 0x0b, HDA_INPUT, 1 },
4153         { 0x0b, HDA_INPUT, 6 },
4154         { 0x0b, HDA_INPUT, 7 },
4155         { } /* end */
4156 };
4157 #endif
4158
4159 /*
4160  * Common callbacks
4161  */
4162
4163 static void alc_init_special_input_src(struct hda_codec *codec);
4164
4165 static int alc_init(struct hda_codec *codec)
4166 {
4167         struct alc_spec *spec = codec->spec;
4168         unsigned int i;
4169
4170         alc_fix_pll(codec);
4171         alc_auto_init_amp(codec, spec->init_amp);
4172
4173         for (i = 0; i < spec->num_init_verbs; i++)
4174                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
4175         alc_init_special_input_src(codec);
4176
4177         if (spec->init_hook)
4178                 spec->init_hook(codec);
4179
4180         alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
4181
4182         hda_call_check_power_status(codec, 0x01);
4183         return 0;
4184 }
4185
4186 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
4187 {
4188         struct alc_spec *spec = codec->spec;
4189
4190         if (spec->unsol_event)
4191                 spec->unsol_event(codec, res);
4192 }
4193
4194 #ifdef CONFIG_SND_HDA_POWER_SAVE
4195 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
4196 {
4197         struct alc_spec *spec = codec->spec;
4198         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
4199 }
4200 #endif
4201
4202 /*
4203  * Analog playback callbacks
4204  */
4205 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
4206                                     struct hda_codec *codec,
4207                                     struct snd_pcm_substream *substream)
4208 {
4209         struct alc_spec *spec = codec->spec;
4210         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
4211                                              hinfo);
4212 }
4213
4214 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4215                                        struct hda_codec *codec,
4216                                        unsigned int stream_tag,
4217                                        unsigned int format,
4218                                        struct snd_pcm_substream *substream)
4219 {
4220         struct alc_spec *spec = codec->spec;
4221         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
4222                                                 stream_tag, format, substream);
4223 }
4224
4225 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4226                                        struct hda_codec *codec,
4227                                        struct snd_pcm_substream *substream)
4228 {
4229         struct alc_spec *spec = codec->spec;
4230         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
4231 }
4232
4233 /*
4234  * Digital out
4235  */
4236 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
4237                                         struct hda_codec *codec,
4238                                         struct snd_pcm_substream *substream)
4239 {
4240         struct alc_spec *spec = codec->spec;
4241         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
4242 }
4243
4244 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4245                                            struct hda_codec *codec,
4246                                            unsigned int stream_tag,
4247                                            unsigned int format,
4248                                            struct snd_pcm_substream *substream)
4249 {
4250         struct alc_spec *spec = codec->spec;
4251         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
4252                                              stream_tag, format, substream);
4253 }
4254
4255 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4256                                            struct hda_codec *codec,
4257                                            struct snd_pcm_substream *substream)
4258 {
4259         struct alc_spec *spec = codec->spec;
4260         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
4261 }
4262
4263 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
4264                                          struct hda_codec *codec,
4265                                          struct snd_pcm_substream *substream)
4266 {
4267         struct alc_spec *spec = codec->spec;
4268         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
4269 }
4270
4271 /*
4272  * Analog capture
4273  */
4274 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4275                                       struct hda_codec *codec,
4276                                       unsigned int stream_tag,
4277                                       unsigned int format,
4278                                       struct snd_pcm_substream *substream)
4279 {
4280         struct alc_spec *spec = codec->spec;
4281
4282         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
4283                                    stream_tag, 0, format);
4284         return 0;
4285 }
4286
4287 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4288                                       struct hda_codec *codec,
4289                                       struct snd_pcm_substream *substream)
4290 {
4291         struct alc_spec *spec = codec->spec;
4292
4293         snd_hda_codec_cleanup_stream(codec,
4294                                      spec->adc_nids[substream->number + 1]);
4295         return 0;
4296 }
4297
4298 /* analog capture with dynamic dual-adc changes */
4299 static int dualmic_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4300                                        struct hda_codec *codec,
4301                                        unsigned int stream_tag,
4302                                        unsigned int format,
4303                                        struct snd_pcm_substream *substream)
4304 {
4305         struct alc_spec *spec = codec->spec;
4306         spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
4307         spec->cur_adc_stream_tag = stream_tag;
4308         spec->cur_adc_format = format;
4309         snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
4310         return 0;
4311 }
4312
4313 static int dualmic_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4314                                        struct hda_codec *codec,
4315                                        struct snd_pcm_substream *substream)
4316 {
4317         struct alc_spec *spec = codec->spec;
4318         snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4319         spec->cur_adc = 0;
4320         return 0;
4321 }
4322
4323 static const struct hda_pcm_stream dualmic_pcm_analog_capture = {
4324         .substreams = 1,
4325         .channels_min = 2,
4326         .channels_max = 2,
4327         .nid = 0, /* fill later */
4328         .ops = {
4329                 .prepare = dualmic_capture_pcm_prepare,
4330                 .cleanup = dualmic_capture_pcm_cleanup
4331         },
4332 };
4333
4334 /*
4335  */
4336 static const struct hda_pcm_stream alc880_pcm_analog_playback = {
4337         .substreams = 1,
4338         .channels_min = 2,
4339         .channels_max = 8,
4340         /* NID is set in alc_build_pcms */
4341         .ops = {
4342                 .open = alc880_playback_pcm_open,
4343                 .prepare = alc880_playback_pcm_prepare,
4344                 .cleanup = alc880_playback_pcm_cleanup
4345         },
4346 };
4347
4348 static const struct hda_pcm_stream alc880_pcm_analog_capture = {
4349         .substreams = 1,
4350         .channels_min = 2,
4351         .channels_max = 2,
4352         /* NID is set in alc_build_pcms */
4353 };
4354
4355 static const struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
4356         .substreams = 1,
4357         .channels_min = 2,
4358         .channels_max = 2,
4359         /* NID is set in alc_build_pcms */
4360 };
4361
4362 static const struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
4363         .substreams = 2, /* can be overridden */
4364         .channels_min = 2,
4365         .channels_max = 2,
4366         /* NID is set in alc_build_pcms */
4367         .ops = {
4368                 .prepare = alc880_alt_capture_pcm_prepare,
4369                 .cleanup = alc880_alt_capture_pcm_cleanup
4370         },
4371 };
4372
4373 static const struct hda_pcm_stream alc880_pcm_digital_playback = {
4374         .substreams = 1,
4375         .channels_min = 2,
4376         .channels_max = 2,
4377         /* NID is set in alc_build_pcms */
4378         .ops = {
4379                 .open = alc880_dig_playback_pcm_open,
4380                 .close = alc880_dig_playback_pcm_close,
4381                 .prepare = alc880_dig_playback_pcm_prepare,
4382                 .cleanup = alc880_dig_playback_pcm_cleanup
4383         },
4384 };
4385
4386 static const struct hda_pcm_stream alc880_pcm_digital_capture = {
4387         .substreams = 1,
4388         .channels_min = 2,
4389         .channels_max = 2,
4390         /* NID is set in alc_build_pcms */
4391 };
4392
4393 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
4394 static const struct hda_pcm_stream alc_pcm_null_stream = {
4395         .substreams = 0,
4396         .channels_min = 0,
4397         .channels_max = 0,
4398 };
4399
4400 static int alc_build_pcms(struct hda_codec *codec)
4401 {
4402         struct alc_spec *spec = codec->spec;
4403         struct hda_pcm *info = spec->pcm_rec;
4404         int i;
4405
4406         codec->num_pcms = 1;
4407         codec->pcm_info = info;
4408
4409         if (spec->no_analog)
4410                 goto skip_analog;
4411
4412         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
4413                  "%s Analog", codec->chip_name);
4414         info->name = spec->stream_name_analog;
4415
4416         if (spec->stream_analog_playback) {
4417                 if (snd_BUG_ON(!spec->multiout.dac_nids))
4418                         return -EINVAL;
4419                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
4420                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
4421         }
4422         if (spec->stream_analog_capture) {
4423                 if (snd_BUG_ON(!spec->adc_nids))
4424                         return -EINVAL;
4425                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
4426                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4427         }
4428
4429         if (spec->channel_mode) {
4430                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
4431                 for (i = 0; i < spec->num_channel_mode; i++) {
4432                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
4433                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
4434                         }
4435                 }
4436         }
4437
4438  skip_analog:
4439         /* SPDIF for stream index #1 */
4440         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
4441                 snprintf(spec->stream_name_digital,
4442                          sizeof(spec->stream_name_digital),
4443                          "%s Digital", codec->chip_name);
4444                 codec->num_pcms = 2;
4445                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
4446                 info = spec->pcm_rec + 1;
4447                 info->name = spec->stream_name_digital;
4448                 if (spec->dig_out_type)
4449                         info->pcm_type = spec->dig_out_type;
4450                 else
4451                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
4452                 if (spec->multiout.dig_out_nid &&
4453                     spec->stream_digital_playback) {
4454                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
4455                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
4456                 }
4457                 if (spec->dig_in_nid &&
4458                     spec->stream_digital_capture) {
4459                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
4460                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
4461                 }
4462                 /* FIXME: do we need this for all Realtek codec models? */
4463                 codec->spdif_status_reset = 1;
4464         }
4465
4466         if (spec->no_analog)
4467                 return 0;
4468
4469         /* If the use of more than one ADC is requested for the current
4470          * model, configure a second analog capture-only PCM.
4471          */
4472         /* Additional Analaog capture for index #2 */
4473         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
4474             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
4475                 codec->num_pcms = 3;
4476                 info = spec->pcm_rec + 2;
4477                 info->name = spec->stream_name_analog;
4478                 if (spec->alt_dac_nid) {
4479                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4480                                 *spec->stream_analog_alt_playback;
4481                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
4482                                 spec->alt_dac_nid;
4483                 } else {
4484                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4485                                 alc_pcm_null_stream;
4486                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
4487                 }
4488                 if (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture) {
4489                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4490                                 *spec->stream_analog_alt_capture;
4491                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
4492                                 spec->adc_nids[1];
4493                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
4494                                 spec->num_adc_nids - 1;
4495                 } else {
4496                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4497                                 alc_pcm_null_stream;
4498                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
4499                 }
4500         }
4501
4502         return 0;
4503 }
4504
4505 static inline void alc_shutup(struct hda_codec *codec)
4506 {
4507         struct alc_spec *spec = codec->spec;
4508
4509         if (spec && spec->shutup)
4510                 spec->shutup(codec);
4511         snd_hda_shutup_pins(codec);
4512 }
4513
4514 static void alc_free_kctls(struct hda_codec *codec)
4515 {
4516         struct alc_spec *spec = codec->spec;
4517
4518         if (spec->kctls.list) {
4519                 struct snd_kcontrol_new *kctl = spec->kctls.list;
4520                 int i;
4521                 for (i = 0; i < spec->kctls.used; i++)
4522                         kfree(kctl[i].name);
4523         }
4524         snd_array_free(&spec->kctls);
4525 }
4526
4527 static void alc_free(struct hda_codec *codec)
4528 {
4529         struct alc_spec *spec = codec->spec;
4530
4531         if (!spec)
4532                 return;
4533
4534         alc_shutup(codec);
4535         snd_hda_input_jack_free(codec);
4536         alc_free_kctls(codec);
4537         kfree(spec);
4538         snd_hda_detach_beep_device(codec);
4539 }
4540
4541 #ifdef CONFIG_SND_HDA_POWER_SAVE
4542 static void alc_power_eapd(struct hda_codec *codec)
4543 {
4544         alc_auto_setup_eapd(codec, false);
4545 }
4546
4547 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
4548 {
4549         struct alc_spec *spec = codec->spec;
4550         alc_shutup(codec);
4551         if (spec && spec->power_hook)
4552                 spec->power_hook(codec);
4553         return 0;
4554 }
4555 #endif
4556
4557 #ifdef SND_HDA_NEEDS_RESUME
4558 static int alc_resume(struct hda_codec *codec)
4559 {
4560         msleep(150); /* to avoid pop noise */
4561         codec->patch_ops.init(codec);
4562         snd_hda_codec_resume_amp(codec);
4563         snd_hda_codec_resume_cache(codec);
4564         hda_call_check_power_status(codec, 0x01);
4565         return 0;
4566 }
4567 #endif
4568
4569 /*
4570  */
4571 static const struct hda_codec_ops alc_patch_ops = {
4572         .build_controls = alc_build_controls,
4573         .build_pcms = alc_build_pcms,
4574         .init = alc_init,
4575         .free = alc_free,
4576         .unsol_event = alc_unsol_event,
4577 #ifdef SND_HDA_NEEDS_RESUME
4578         .resume = alc_resume,
4579 #endif
4580 #ifdef CONFIG_SND_HDA_POWER_SAVE
4581         .suspend = alc_suspend,
4582         .check_power_status = alc_check_power_status,
4583 #endif
4584         .reboot_notify = alc_shutup,
4585 };
4586
4587 /* replace the codec chip_name with the given string */
4588 static int alc_codec_rename(struct hda_codec *codec, const char *name)
4589 {
4590         kfree(codec->chip_name);
4591         codec->chip_name = kstrdup(name, GFP_KERNEL);
4592         if (!codec->chip_name) {
4593                 alc_free(codec);
4594                 return -ENOMEM;
4595         }
4596         return 0;
4597 }
4598
4599 /*
4600  * Test configuration for debugging
4601  *
4602  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
4603  * enum controls.
4604  */
4605 #ifdef CONFIG_SND_DEBUG
4606 static const hda_nid_t alc880_test_dac_nids[4] = {
4607         0x02, 0x03, 0x04, 0x05
4608 };
4609
4610 static const struct hda_input_mux alc880_test_capture_source = {
4611         .num_items = 7,
4612         .items = {
4613                 { "In-1", 0x0 },
4614                 { "In-2", 0x1 },
4615                 { "In-3", 0x2 },
4616                 { "In-4", 0x3 },
4617                 { "CD", 0x4 },
4618                 { "Front", 0x5 },
4619                 { "Surround", 0x6 },
4620         },
4621 };
4622
4623 static const struct hda_channel_mode alc880_test_modes[4] = {
4624         { 2, NULL },
4625         { 4, NULL },
4626         { 6, NULL },
4627         { 8, NULL },
4628 };
4629
4630 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
4631                                  struct snd_ctl_elem_info *uinfo)
4632 {
4633         static const char * const texts[] = {
4634                 "N/A", "Line Out", "HP Out",
4635                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
4636         };
4637         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4638         uinfo->count = 1;
4639         uinfo->value.enumerated.items = 8;
4640         if (uinfo->value.enumerated.item >= 8)
4641                 uinfo->value.enumerated.item = 7;
4642         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4643         return 0;
4644 }
4645
4646 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
4647                                 struct snd_ctl_elem_value *ucontrol)
4648 {
4649         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4650         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4651         unsigned int pin_ctl, item = 0;
4652
4653         pin_ctl = snd_hda_codec_read(codec, nid, 0,
4654                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4655         if (pin_ctl & AC_PINCTL_OUT_EN) {
4656                 if (pin_ctl & AC_PINCTL_HP_EN)
4657                         item = 2;
4658                 else
4659                         item = 1;
4660         } else if (pin_ctl & AC_PINCTL_IN_EN) {
4661                 switch (pin_ctl & AC_PINCTL_VREFEN) {
4662                 case AC_PINCTL_VREF_HIZ: item = 3; break;
4663                 case AC_PINCTL_VREF_50:  item = 4; break;
4664                 case AC_PINCTL_VREF_GRD: item = 5; break;
4665                 case AC_PINCTL_VREF_80:  item = 6; break;
4666                 case AC_PINCTL_VREF_100: item = 7; break;
4667                 }
4668         }
4669         ucontrol->value.enumerated.item[0] = item;
4670         return 0;
4671 }
4672
4673 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
4674                                 struct snd_ctl_elem_value *ucontrol)
4675 {
4676         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4677         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4678         static const unsigned int ctls[] = {
4679                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
4680                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
4681                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
4682                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
4683                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
4684                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
4685         };
4686         unsigned int old_ctl, new_ctl;
4687
4688         old_ctl = snd_hda_codec_read(codec, nid, 0,
4689                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4690         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
4691         if (old_ctl != new_ctl) {
4692                 int val;
4693                 snd_hda_codec_write_cache(codec, nid, 0,
4694                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4695                                           new_ctl);
4696                 val = ucontrol->value.enumerated.item[0] >= 3 ?
4697                         HDA_AMP_MUTE : 0;
4698                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4699                                          HDA_AMP_MUTE, val);
4700                 return 1;
4701         }
4702         return 0;
4703 }
4704
4705 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
4706                                  struct snd_ctl_elem_info *uinfo)
4707 {
4708         static const char * const texts[] = {
4709                 "Front", "Surround", "CLFE", "Side"
4710         };
4711         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4712         uinfo->count = 1;
4713         uinfo->value.enumerated.items = 4;
4714         if (uinfo->value.enumerated.item >= 4)
4715                 uinfo->value.enumerated.item = 3;
4716         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4717         return 0;
4718 }
4719
4720 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
4721                                 struct snd_ctl_elem_value *ucontrol)
4722 {
4723         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4724         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4725         unsigned int sel;
4726
4727         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
4728         ucontrol->value.enumerated.item[0] = sel & 3;
4729         return 0;
4730 }
4731
4732 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
4733                                 struct snd_ctl_elem_value *ucontrol)
4734 {
4735         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4736         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4737         unsigned int sel;
4738
4739         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
4740         if (ucontrol->value.enumerated.item[0] != sel) {
4741                 sel = ucontrol->value.enumerated.item[0] & 3;
4742                 snd_hda_codec_write_cache(codec, nid, 0,
4743                                           AC_VERB_SET_CONNECT_SEL, sel);
4744                 return 1;
4745         }
4746         return 0;
4747 }
4748
4749 #define PIN_CTL_TEST(xname,nid) {                       \
4750                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4751                         .name = xname,                 \
4752                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4753                         .info = alc_test_pin_ctl_info, \
4754                         .get = alc_test_pin_ctl_get,   \
4755                         .put = alc_test_pin_ctl_put,   \
4756                         .private_value = nid           \
4757                         }
4758
4759 #define PIN_SRC_TEST(xname,nid) {                       \
4760                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4761                         .name = xname,                 \
4762                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4763                         .info = alc_test_pin_src_info, \
4764                         .get = alc_test_pin_src_get,   \
4765                         .put = alc_test_pin_src_put,   \
4766                         .private_value = nid           \
4767                         }
4768
4769 static const struct snd_kcontrol_new alc880_test_mixer[] = {
4770         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4771         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4772         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
4773         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4774         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4775         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4776         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
4777         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4778         PIN_CTL_TEST("Front Pin Mode", 0x14),
4779         PIN_CTL_TEST("Surround Pin Mode", 0x15),
4780         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
4781         PIN_CTL_TEST("Side Pin Mode", 0x17),
4782         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
4783         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
4784         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
4785         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
4786         PIN_SRC_TEST("In-1 Pin Source", 0x18),
4787         PIN_SRC_TEST("In-2 Pin Source", 0x19),
4788         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
4789         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
4790         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
4791         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
4792         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
4793         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
4794         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
4795         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
4796         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
4797         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
4798         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
4799         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
4800         {
4801                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4802                 .name = "Channel Mode",
4803                 .info = alc_ch_mode_info,
4804                 .get = alc_ch_mode_get,
4805                 .put = alc_ch_mode_put,
4806         },
4807         { } /* end */
4808 };
4809
4810 static const struct hda_verb alc880_test_init_verbs[] = {
4811         /* Unmute inputs of 0x0c - 0x0f */
4812         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4813         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4814         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4815         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4816         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4817         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4818         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4819         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4820         /* Vol output for 0x0c-0x0f */
4821         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4822         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4823         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4824         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4825         /* Set output pins 0x14-0x17 */
4826         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4827         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4828         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4829         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4830         /* Unmute output pins 0x14-0x17 */
4831         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4832         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4833         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4834         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4835         /* Set input pins 0x18-0x1c */
4836         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4837         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4838         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4839         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4840         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4841         /* Mute input pins 0x18-0x1b */
4842         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4843         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4844         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4845         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4846         /* ADC set up */
4847         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4848         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4849         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4850         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4851         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4852         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4853         /* Analog input/passthru */
4854         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4855         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4856         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4857         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4858         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4859         { }
4860 };
4861 #endif
4862
4863 /*
4864  */
4865
4866 static const char * const alc880_models[ALC880_MODEL_LAST] = {
4867         [ALC880_3ST]            = "3stack",
4868         [ALC880_TCL_S700]       = "tcl",
4869         [ALC880_3ST_DIG]        = "3stack-digout",
4870         [ALC880_CLEVO]          = "clevo",
4871         [ALC880_5ST]            = "5stack",
4872         [ALC880_5ST_DIG]        = "5stack-digout",
4873         [ALC880_W810]           = "w810",
4874         [ALC880_Z71V]           = "z71v",
4875         [ALC880_6ST]            = "6stack",
4876         [ALC880_6ST_DIG]        = "6stack-digout",
4877         [ALC880_ASUS]           = "asus",
4878         [ALC880_ASUS_W1V]       = "asus-w1v",
4879         [ALC880_ASUS_DIG]       = "asus-dig",
4880         [ALC880_ASUS_DIG2]      = "asus-dig2",
4881         [ALC880_UNIWILL_DIG]    = "uniwill",
4882         [ALC880_UNIWILL_P53]    = "uniwill-p53",
4883         [ALC880_FUJITSU]        = "fujitsu",
4884         [ALC880_F1734]          = "F1734",
4885         [ALC880_LG]             = "lg",
4886         [ALC880_LG_LW]          = "lg-lw",
4887         [ALC880_MEDION_RIM]     = "medion",
4888 #ifdef CONFIG_SND_DEBUG
4889         [ALC880_TEST]           = "test",
4890 #endif
4891         [ALC880_AUTO]           = "auto",
4892 };
4893
4894 static const struct snd_pci_quirk alc880_cfg_tbl[] = {
4895         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
4896         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
4897         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
4898         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
4899         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
4900         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
4901         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
4902         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
4903         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
4904         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
4905         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
4906         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
4907         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
4908         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
4909         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
4910         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
4911         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
4912         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
4913         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
4914         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
4915         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
4916         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
4917         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
4918         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
4919         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
4920         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
4921         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
4922         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
4923         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
4924         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
4925         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
4926         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
4927         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
4928         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
4929         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
4930         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
4931         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
4932         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
4933         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
4934         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_F1734),
4935         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
4936         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
4937         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
4938         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
4939         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
4940         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
4941         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
4942         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
4943         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_F1734),
4944         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
4945         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
4946         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
4947         SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_LG),
4948         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
4949         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
4950         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
4951         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
4952         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
4953         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
4954         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
4955         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
4956         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
4957         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
4958         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
4959         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
4960         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
4961         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
4962         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
4963         /* default Intel */
4964         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
4965         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
4966         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
4967         {}
4968 };
4969
4970 /*
4971  * ALC880 codec presets
4972  */
4973 static const struct alc_config_preset alc880_presets[] = {
4974         [ALC880_3ST] = {
4975                 .mixers = { alc880_three_stack_mixer },
4976                 .init_verbs = { alc880_volume_init_verbs,
4977                                 alc880_pin_3stack_init_verbs },
4978                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4979                 .dac_nids = alc880_dac_nids,
4980                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4981                 .channel_mode = alc880_threestack_modes,
4982                 .need_dac_fix = 1,
4983                 .input_mux = &alc880_capture_source,
4984         },
4985         [ALC880_3ST_DIG] = {
4986                 .mixers = { alc880_three_stack_mixer },
4987                 .init_verbs = { alc880_volume_init_verbs,
4988                                 alc880_pin_3stack_init_verbs },
4989                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4990                 .dac_nids = alc880_dac_nids,
4991                 .dig_out_nid = ALC880_DIGOUT_NID,
4992                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4993                 .channel_mode = alc880_threestack_modes,
4994                 .need_dac_fix = 1,
4995                 .input_mux = &alc880_capture_source,
4996         },
4997         [ALC880_TCL_S700] = {
4998                 .mixers = { alc880_tcl_s700_mixer },
4999                 .init_verbs = { alc880_volume_init_verbs,
5000                                 alc880_pin_tcl_S700_init_verbs,
5001                                 alc880_gpio2_init_verbs },
5002                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5003                 .dac_nids = alc880_dac_nids,
5004                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
5005                 .num_adc_nids = 1, /* single ADC */
5006                 .hp_nid = 0x03,
5007                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5008                 .channel_mode = alc880_2_jack_modes,
5009                 .input_mux = &alc880_capture_source,
5010         },
5011         [ALC880_5ST] = {
5012                 .mixers = { alc880_three_stack_mixer,
5013                             alc880_five_stack_mixer},
5014                 .init_verbs = { alc880_volume_init_verbs,
5015                                 alc880_pin_5stack_init_verbs },
5016                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5017                 .dac_nids = alc880_dac_nids,
5018                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
5019                 .channel_mode = alc880_fivestack_modes,
5020                 .input_mux = &alc880_capture_source,
5021         },
5022         [ALC880_5ST_DIG] = {
5023                 .mixers = { alc880_three_stack_mixer,
5024                             alc880_five_stack_mixer },
5025                 .init_verbs = { alc880_volume_init_verbs,
5026                                 alc880_pin_5stack_init_verbs },
5027                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5028                 .dac_nids = alc880_dac_nids,
5029                 .dig_out_nid = ALC880_DIGOUT_NID,
5030                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
5031                 .channel_mode = alc880_fivestack_modes,
5032                 .input_mux = &alc880_capture_source,
5033         },
5034         [ALC880_6ST] = {
5035                 .mixers = { alc880_six_stack_mixer },
5036                 .init_verbs = { alc880_volume_init_verbs,
5037                                 alc880_pin_6stack_init_verbs },
5038                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
5039                 .dac_nids = alc880_6st_dac_nids,
5040                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
5041                 .channel_mode = alc880_sixstack_modes,
5042                 .input_mux = &alc880_6stack_capture_source,
5043         },
5044         [ALC880_6ST_DIG] = {
5045                 .mixers = { alc880_six_stack_mixer },
5046                 .init_verbs = { alc880_volume_init_verbs,
5047                                 alc880_pin_6stack_init_verbs },
5048                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
5049                 .dac_nids = alc880_6st_dac_nids,
5050                 .dig_out_nid = ALC880_DIGOUT_NID,
5051                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
5052                 .channel_mode = alc880_sixstack_modes,
5053                 .input_mux = &alc880_6stack_capture_source,
5054         },
5055         [ALC880_W810] = {
5056                 .mixers = { alc880_w810_base_mixer },
5057                 .init_verbs = { alc880_volume_init_verbs,
5058                                 alc880_pin_w810_init_verbs,
5059                                 alc880_gpio2_init_verbs },
5060                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
5061                 .dac_nids = alc880_w810_dac_nids,
5062                 .dig_out_nid = ALC880_DIGOUT_NID,
5063                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
5064                 .channel_mode = alc880_w810_modes,
5065                 .input_mux = &alc880_capture_source,
5066         },
5067         [ALC880_Z71V] = {
5068                 .mixers = { alc880_z71v_mixer },
5069                 .init_verbs = { alc880_volume_init_verbs,
5070                                 alc880_pin_z71v_init_verbs },
5071                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
5072                 .dac_nids = alc880_z71v_dac_nids,
5073                 .dig_out_nid = ALC880_DIGOUT_NID,
5074                 .hp_nid = 0x03,
5075                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5076                 .channel_mode = alc880_2_jack_modes,
5077                 .input_mux = &alc880_capture_source,
5078         },
5079         [ALC880_F1734] = {
5080                 .mixers = { alc880_f1734_mixer },
5081                 .init_verbs = { alc880_volume_init_verbs,
5082                                 alc880_pin_f1734_init_verbs },
5083                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
5084                 .dac_nids = alc880_f1734_dac_nids,
5085                 .hp_nid = 0x02,
5086                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5087                 .channel_mode = alc880_2_jack_modes,
5088                 .input_mux = &alc880_f1734_capture_source,
5089                 .unsol_event = alc880_uniwill_p53_unsol_event,
5090                 .setup = alc880_uniwill_p53_setup,
5091                 .init_hook = alc_hp_automute,
5092         },
5093         [ALC880_ASUS] = {
5094                 .mixers = { alc880_asus_mixer },
5095                 .init_verbs = { alc880_volume_init_verbs,
5096                                 alc880_pin_asus_init_verbs,
5097                                 alc880_gpio1_init_verbs },
5098                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5099                 .dac_nids = alc880_asus_dac_nids,
5100                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
5101                 .channel_mode = alc880_asus_modes,
5102                 .need_dac_fix = 1,
5103                 .input_mux = &alc880_capture_source,
5104         },
5105         [ALC880_ASUS_DIG] = {
5106                 .mixers = { alc880_asus_mixer },
5107                 .init_verbs = { alc880_volume_init_verbs,
5108                                 alc880_pin_asus_init_verbs,
5109                                 alc880_gpio1_init_verbs },
5110                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5111                 .dac_nids = alc880_asus_dac_nids,
5112                 .dig_out_nid = ALC880_DIGOUT_NID,
5113                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
5114                 .channel_mode = alc880_asus_modes,
5115                 .need_dac_fix = 1,
5116                 .input_mux = &alc880_capture_source,
5117         },
5118         [ALC880_ASUS_DIG2] = {
5119                 .mixers = { alc880_asus_mixer },
5120                 .init_verbs = { alc880_volume_init_verbs,
5121                                 alc880_pin_asus_init_verbs,
5122                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
5123                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5124                 .dac_nids = alc880_asus_dac_nids,
5125                 .dig_out_nid = ALC880_DIGOUT_NID,
5126                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
5127                 .channel_mode = alc880_asus_modes,
5128                 .need_dac_fix = 1,
5129                 .input_mux = &alc880_capture_source,
5130         },
5131         [ALC880_ASUS_W1V] = {
5132                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
5133                 .init_verbs = { alc880_volume_init_verbs,
5134                                 alc880_pin_asus_init_verbs,
5135                                 alc880_gpio1_init_verbs },
5136                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5137                 .dac_nids = alc880_asus_dac_nids,
5138                 .dig_out_nid = ALC880_DIGOUT_NID,
5139                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
5140                 .channel_mode = alc880_asus_modes,
5141                 .need_dac_fix = 1,
5142                 .input_mux = &alc880_capture_source,
5143         },
5144         [ALC880_UNIWILL_DIG] = {
5145                 .mixers = { alc880_asus_mixer },
5146                 .init_verbs = { alc880_volume_init_verbs,
5147                                 alc880_pin_asus_init_verbs },
5148                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5149                 .dac_nids = alc880_asus_dac_nids,
5150                 .dig_out_nid = ALC880_DIGOUT_NID,
5151                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
5152                 .channel_mode = alc880_asus_modes,
5153                 .need_dac_fix = 1,
5154                 .input_mux = &alc880_capture_source,
5155         },
5156         [ALC880_UNIWILL] = {
5157                 .mixers = { alc880_uniwill_mixer },
5158                 .init_verbs = { alc880_volume_init_verbs,
5159                                 alc880_uniwill_init_verbs },
5160                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5161                 .dac_nids = alc880_asus_dac_nids,
5162                 .dig_out_nid = ALC880_DIGOUT_NID,
5163                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5164                 .channel_mode = alc880_threestack_modes,
5165                 .need_dac_fix = 1,
5166                 .input_mux = &alc880_capture_source,
5167                 .unsol_event = alc880_uniwill_unsol_event,
5168                 .setup = alc880_uniwill_setup,
5169                 .init_hook = alc880_uniwill_init_hook,
5170         },
5171         [ALC880_UNIWILL_P53] = {
5172                 .mixers = { alc880_uniwill_p53_mixer },
5173                 .init_verbs = { alc880_volume_init_verbs,
5174                                 alc880_uniwill_p53_init_verbs },
5175                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5176                 .dac_nids = alc880_asus_dac_nids,
5177                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
5178                 .channel_mode = alc880_threestack_modes,
5179                 .input_mux = &alc880_capture_source,
5180                 .unsol_event = alc880_uniwill_p53_unsol_event,
5181                 .setup = alc880_uniwill_p53_setup,
5182                 .init_hook = alc_hp_automute,
5183         },
5184         [ALC880_FUJITSU] = {
5185                 .mixers = { alc880_fujitsu_mixer },
5186                 .init_verbs = { alc880_volume_init_verbs,
5187                                 alc880_uniwill_p53_init_verbs,
5188                                 alc880_beep_init_verbs },
5189                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5190                 .dac_nids = alc880_dac_nids,
5191                 .dig_out_nid = ALC880_DIGOUT_NID,
5192                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5193                 .channel_mode = alc880_2_jack_modes,
5194                 .input_mux = &alc880_capture_source,
5195                 .unsol_event = alc880_uniwill_p53_unsol_event,
5196                 .setup = alc880_uniwill_p53_setup,
5197                 .init_hook = alc_hp_automute,
5198         },
5199         [ALC880_CLEVO] = {
5200                 .mixers = { alc880_three_stack_mixer },
5201                 .init_verbs = { alc880_volume_init_verbs,
5202                                 alc880_pin_clevo_init_verbs },
5203                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5204                 .dac_nids = alc880_dac_nids,
5205                 .hp_nid = 0x03,
5206                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5207                 .channel_mode = alc880_threestack_modes,
5208                 .need_dac_fix = 1,
5209                 .input_mux = &alc880_capture_source,
5210         },
5211         [ALC880_LG] = {
5212                 .mixers = { alc880_lg_mixer },
5213                 .init_verbs = { alc880_volume_init_verbs,
5214                                 alc880_lg_init_verbs },
5215                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
5216                 .dac_nids = alc880_lg_dac_nids,
5217                 .dig_out_nid = ALC880_DIGOUT_NID,
5218                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
5219                 .channel_mode = alc880_lg_ch_modes,
5220                 .need_dac_fix = 1,
5221                 .input_mux = &alc880_lg_capture_source,
5222                 .unsol_event = alc_sku_unsol_event,
5223                 .setup = alc880_lg_setup,
5224                 .init_hook = alc_hp_automute,
5225 #ifdef CONFIG_SND_HDA_POWER_SAVE
5226                 .loopbacks = alc880_lg_loopbacks,
5227 #endif
5228         },
5229         [ALC880_LG_LW] = {
5230                 .mixers = { alc880_lg_lw_mixer },
5231                 .init_verbs = { alc880_volume_init_verbs,
5232                                 alc880_lg_lw_init_verbs },
5233                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5234                 .dac_nids = alc880_dac_nids,
5235                 .dig_out_nid = ALC880_DIGOUT_NID,
5236                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
5237                 .channel_mode = alc880_lg_lw_modes,
5238                 .input_mux = &alc880_lg_lw_capture_source,
5239                 .unsol_event = alc_sku_unsol_event,
5240                 .setup = alc880_lg_lw_setup,
5241                 .init_hook = alc_hp_automute,
5242         },
5243         [ALC880_MEDION_RIM] = {
5244                 .mixers = { alc880_medion_rim_mixer },
5245                 .init_verbs = { alc880_volume_init_verbs,
5246                                 alc880_medion_rim_init_verbs,
5247                                 alc_gpio2_init_verbs },
5248                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5249                 .dac_nids = alc880_dac_nids,
5250                 .dig_out_nid = ALC880_DIGOUT_NID,
5251                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5252                 .channel_mode = alc880_2_jack_modes,
5253                 .input_mux = &alc880_medion_rim_capture_source,
5254                 .unsol_event = alc880_medion_rim_unsol_event,
5255                 .setup = alc880_medion_rim_setup,
5256                 .init_hook = alc880_medion_rim_automute,
5257         },
5258 #ifdef CONFIG_SND_DEBUG
5259         [ALC880_TEST] = {
5260                 .mixers = { alc880_test_mixer },
5261                 .init_verbs = { alc880_test_init_verbs },
5262                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
5263                 .dac_nids = alc880_test_dac_nids,
5264                 .dig_out_nid = ALC880_DIGOUT_NID,
5265                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
5266                 .channel_mode = alc880_test_modes,
5267                 .input_mux = &alc880_test_capture_source,
5268         },
5269 #endif
5270 };
5271
5272 /*
5273  * Automatic parse of I/O pins from the BIOS configuration
5274  */
5275
5276 enum {
5277         ALC_CTL_WIDGET_VOL,
5278         ALC_CTL_WIDGET_MUTE,
5279         ALC_CTL_BIND_MUTE,
5280 };
5281 static const struct snd_kcontrol_new alc880_control_templates[] = {
5282         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
5283         HDA_CODEC_MUTE(NULL, 0, 0, 0),
5284         HDA_BIND_MUTE(NULL, 0, 0, 0),
5285 };
5286
5287 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
5288 {
5289         snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
5290         return snd_array_new(&spec->kctls);
5291 }
5292
5293 /* add dynamic controls */
5294 static int add_control(struct alc_spec *spec, int type, const char *name,
5295                        int cidx, unsigned long val)
5296 {
5297         struct snd_kcontrol_new *knew;
5298
5299         knew = alc_kcontrol_new(spec);
5300         if (!knew)
5301                 return -ENOMEM;
5302         *knew = alc880_control_templates[type];
5303         knew->name = kstrdup(name, GFP_KERNEL);
5304         if (!knew->name)
5305                 return -ENOMEM;
5306         knew->index = cidx;
5307         if (get_amp_nid_(val))
5308                 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
5309         knew->private_value = val;
5310         return 0;
5311 }
5312
5313 static int add_control_with_pfx(struct alc_spec *spec, int type,
5314                                 const char *pfx, const char *dir,
5315                                 const char *sfx, int cidx, unsigned long val)
5316 {
5317         char name[32];
5318         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
5319         return add_control(spec, type, name, cidx, val);
5320 }
5321
5322 #define add_pb_vol_ctrl(spec, type, pfx, val)                   \
5323         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
5324 #define add_pb_sw_ctrl(spec, type, pfx, val)                    \
5325         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
5326 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val)                   \
5327         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
5328 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val)                    \
5329         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
5330
5331 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
5332 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
5333 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
5334 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
5335 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
5336 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
5337 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
5338 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
5339 #define ALC880_PIN_CD_NID               0x1c
5340
5341 /* fill in the dac_nids table from the parsed pin configuration */
5342 static int alc880_auto_fill_dac_nids(struct hda_codec *codec)
5343 {
5344         struct alc_spec *spec = codec->spec;
5345         const struct auto_pin_cfg *cfg = &spec->autocfg;
5346         hda_nid_t nid;
5347         int assigned[4];
5348         int i, j;
5349
5350         memset(assigned, 0, sizeof(assigned));
5351         spec->multiout.dac_nids = spec->private_dac_nids;
5352
5353         /* check the pins hardwired to audio widget */
5354         for (i = 0; i < cfg->line_outs; i++) {
5355                 nid = cfg->line_out_pins[i];
5356                 if (alc880_is_fixed_pin(nid)) {
5357                         int idx = alc880_fixed_pin_idx(nid);
5358                         spec->private_dac_nids[i] = alc880_idx_to_dac(idx);
5359                         assigned[idx] = 1;
5360                 }
5361         }
5362         /* left pins can be connect to any audio widget */
5363         for (i = 0; i < cfg->line_outs; i++) {
5364                 nid = cfg->line_out_pins[i];
5365                 if (alc880_is_fixed_pin(nid))
5366                         continue;
5367                 /* search for an empty channel */
5368                 for (j = 0; j < cfg->line_outs; j++) {
5369                         if (!assigned[j]) {
5370                                 spec->private_dac_nids[i] =
5371                                         alc880_idx_to_dac(j);
5372                                 assigned[j] = 1;
5373                                 break;
5374                         }
5375                 }
5376         }
5377         spec->multiout.num_dacs = cfg->line_outs;
5378         return 0;
5379 }
5380
5381 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
5382                                         bool can_be_master, int *index)
5383 {
5384         struct auto_pin_cfg *cfg = &spec->autocfg;
5385         static const char * const chname[4] = {
5386                 "Front", "Surround", NULL /*CLFE*/, "Side"
5387         };
5388
5389         *index = 0;
5390         if (cfg->line_outs == 1 && !spec->multi_ios &&
5391             !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
5392                 return "Master";
5393
5394         switch (cfg->line_out_type) {
5395         case AUTO_PIN_SPEAKER_OUT:
5396                 if (cfg->line_outs == 1)
5397                         return "Speaker";
5398                 break;
5399         case AUTO_PIN_HP_OUT:
5400                 /* for multi-io case, only the primary out */
5401                 if (ch && spec->multi_ios)
5402                         break;
5403                 *index = ch;
5404                 return "Headphone";
5405         default:
5406                 if (cfg->line_outs == 1 && !spec->multi_ios)
5407                         return "PCM";
5408                 break;
5409         }
5410         return chname[ch];
5411 }
5412
5413 /* add playback controls from the parsed DAC table */
5414 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
5415                                              const struct auto_pin_cfg *cfg)
5416 {
5417         hda_nid_t nid;
5418         int i, err, noutputs;
5419
5420         noutputs = cfg->line_outs;
5421         if (spec->multi_ios > 0)
5422                 noutputs += spec->multi_ios;
5423
5424         for (i = 0; i < noutputs; i++) {
5425                 const char *name;
5426                 int index;
5427                 if (!spec->multiout.dac_nids[i])
5428                         continue;
5429                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
5430                 name = alc_get_line_out_pfx(spec, i, false, &index);
5431                 if (!name) {
5432                         /* Center/LFE */
5433                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5434                                               "Center",
5435                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
5436                                                               HDA_OUTPUT));
5437                         if (err < 0)
5438                                 return err;
5439                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5440                                               "LFE",
5441                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
5442                                                               HDA_OUTPUT));
5443                         if (err < 0)
5444                                 return err;
5445                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5446                                              "Center",
5447                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
5448                                                               HDA_INPUT));
5449                         if (err < 0)
5450                                 return err;
5451                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5452                                              "LFE",
5453                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
5454                                                               HDA_INPUT));
5455                         if (err < 0)
5456                                 return err;
5457                 } else {
5458                         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5459                                                 name, index,
5460                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
5461                                                               HDA_OUTPUT));
5462                         if (err < 0)
5463                                 return err;
5464                         err = __add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5465                                                name, index,
5466                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
5467                                                               HDA_INPUT));
5468                         if (err < 0)
5469                                 return err;
5470                 }
5471         }
5472         return 0;
5473 }
5474
5475 /* add playback controls for speaker and HP outputs */
5476 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
5477                                         const char *pfx)
5478 {
5479         hda_nid_t nid;
5480         int err;
5481
5482         if (!pin)
5483                 return 0;
5484
5485         if (alc880_is_fixed_pin(pin)) {
5486                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
5487                 /* specify the DAC as the extra output */
5488                 if (!spec->multiout.hp_nid)
5489                         spec->multiout.hp_nid = nid;
5490                 else
5491                         spec->multiout.extra_out_nid[0] = nid;
5492                 /* control HP volume/switch on the output mixer amp */
5493                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
5494                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
5495                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
5496                 if (err < 0)
5497                         return err;
5498                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
5499                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
5500                 if (err < 0)
5501                         return err;
5502         } else if (alc880_is_multi_pin(pin)) {
5503                 /* set manual connection */
5504                 /* we have only a switch on HP-out PIN */
5505                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
5506                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5507                 if (err < 0)
5508                         return err;
5509         }
5510         return 0;
5511 }
5512
5513 /* create input playback/capture controls for the given pin */
5514 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
5515                             const char *ctlname, int ctlidx,
5516                             int idx, hda_nid_t mix_nid)
5517 {
5518         int err;
5519
5520         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
5521                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5522         if (err < 0)
5523                 return err;
5524         err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
5525                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5526         if (err < 0)
5527                 return err;
5528         return 0;
5529 }
5530
5531 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
5532 {
5533         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
5534         return (pincap & AC_PINCAP_IN) != 0;
5535 }
5536
5537 /* create playback/capture controls for input pins */
5538 static int alc_auto_create_input_ctls(struct hda_codec *codec,
5539                                       const struct auto_pin_cfg *cfg,
5540                                       hda_nid_t mixer,
5541                                       hda_nid_t cap1, hda_nid_t cap2)
5542 {
5543         struct alc_spec *spec = codec->spec;
5544         struct hda_input_mux *imux = &spec->private_imux[0];
5545         int i, err, idx, type_idx = 0;
5546         const char *prev_label = NULL;
5547
5548         for (i = 0; i < cfg->num_inputs; i++) {
5549                 hda_nid_t pin;
5550                 const char *label;
5551
5552                 pin = cfg->inputs[i].pin;
5553                 if (!alc_is_input_pin(codec, pin))
5554                         continue;
5555
5556                 label = hda_get_autocfg_input_label(codec, cfg, i);
5557                 if (prev_label && !strcmp(label, prev_label))
5558                         type_idx++;
5559                 else
5560                         type_idx = 0;
5561                 prev_label = label;
5562
5563                 if (mixer) {
5564                         idx = get_connection_index(codec, mixer, pin);
5565                         if (idx >= 0) {
5566                                 err = new_analog_input(spec, pin,
5567                                                        label, type_idx,
5568                                                        idx, mixer);
5569                                 if (err < 0)
5570                                         return err;
5571                         }
5572                 }
5573
5574                 if (!cap1)
5575                         continue;
5576                 idx = get_connection_index(codec, cap1, pin);
5577                 if (idx < 0 && cap2)
5578                         idx = get_connection_index(codec, cap2, pin);
5579                 if (idx >= 0)
5580                         snd_hda_add_imux_item(imux, label, idx, NULL);
5581         }
5582         return 0;
5583 }
5584
5585 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
5586                                                 const struct auto_pin_cfg *cfg)
5587 {
5588         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
5589 }
5590
5591 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
5592                                unsigned int pin_type)
5593 {
5594         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5595                             pin_type);
5596         /* unmute pin */
5597         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5598                             AMP_OUT_UNMUTE);
5599 }
5600
5601 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
5602                                               hda_nid_t nid, int pin_type,
5603                                               int dac_idx)
5604 {
5605         alc_set_pin_output(codec, nid, pin_type);
5606         /* need the manual connection? */
5607         if (alc880_is_multi_pin(nid)) {
5608                 struct alc_spec *spec = codec->spec;
5609                 int idx = alc880_multi_pin_idx(nid);
5610                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
5611                                     AC_VERB_SET_CONNECT_SEL,
5612                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
5613         }
5614 }
5615
5616 static int get_pin_type(int line_out_type)
5617 {
5618         if (line_out_type == AUTO_PIN_HP_OUT)
5619                 return PIN_HP;
5620         else
5621                 return PIN_OUT;
5622 }
5623
5624 static void alc880_auto_init_dac(struct hda_codec *codec, hda_nid_t nid)
5625 {
5626         if (!nid)
5627                 return;
5628         nid = alc880_idx_to_mixer(alc880_dac_to_idx(nid));
5629         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5630                             AMP_OUT_ZERO);
5631         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5632                             AMP_IN_UNMUTE(0));
5633         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5634                             AMP_IN_UNMUTE(1));
5635 }
5636
5637 static void alc880_auto_init_multi_out(struct hda_codec *codec)
5638 {
5639         struct alc_spec *spec = codec->spec;
5640         int i;
5641
5642         for (i = 0; i < spec->autocfg.line_outs; i++) {
5643                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5644                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5645                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
5646         }
5647         /* mute DACs */
5648         for (i = 0; i < spec->multiout.num_dacs; i++)
5649                 alc880_auto_init_dac(codec, spec->multiout.dac_nids[i]);
5650 }
5651
5652 static void alc880_auto_init_extra_out(struct hda_codec *codec)
5653 {
5654         struct alc_spec *spec = codec->spec;
5655         hda_nid_t pin;
5656         int i;
5657
5658         pin = spec->autocfg.speaker_pins[0];
5659         if (pin) /* connect to front */
5660                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
5661         pin = spec->autocfg.hp_pins[0];
5662         if (pin) /* connect to front */
5663                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5664         /* mute DACs */
5665         alc880_auto_init_dac(codec, spec->multiout.hp_nid);
5666         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
5667                 alc880_auto_init_dac(codec, spec->multiout.extra_out_nid[i]);
5668 }
5669
5670 static void alc880_auto_init_analog_input(struct hda_codec *codec)
5671 {
5672         struct alc_spec *spec = codec->spec;
5673         struct auto_pin_cfg *cfg = &spec->autocfg;
5674         int i;
5675
5676         for (i = 0; i < cfg->num_inputs; i++) {
5677                 hda_nid_t nid = cfg->inputs[i].pin;
5678                 if (alc_is_input_pin(codec, nid)) {
5679                         alc_set_input_pin(codec, nid, cfg->inputs[i].type);
5680                         if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
5681                                 snd_hda_codec_write(codec, nid, 0,
5682                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5683                                                     AMP_OUT_MUTE);
5684                 }
5685         }
5686
5687         /* mute all loopback inputs */
5688         if (spec->mixer_nid) {
5689                 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
5690                 for (i = 0; i < nums; i++)
5691                         snd_hda_codec_write(codec, spec->mixer_nid, 0,
5692                                             AC_VERB_SET_AMP_GAIN_MUTE,
5693                                             AMP_IN_MUTE(i));
5694         }
5695 }
5696
5697 static void alc880_auto_init_input_src(struct hda_codec *codec)
5698 {
5699         struct alc_spec *spec = codec->spec;
5700         int c;
5701
5702         for (c = 0; c < spec->num_adc_nids; c++) {
5703                 unsigned int mux_idx;
5704                 const struct hda_input_mux *imux;
5705                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
5706                 imux = &spec->input_mux[mux_idx];
5707                 if (!imux->num_items && mux_idx > 0)
5708                         imux = &spec->input_mux[0];
5709                 if (imux)
5710                         snd_hda_codec_write(codec, spec->adc_nids[c], 0,
5711                                             AC_VERB_SET_CONNECT_SEL,
5712                                             imux->items[0].index);
5713                 snd_hda_codec_write(codec, spec->adc_nids[c], 0,
5714                                     AC_VERB_SET_AMP_GAIN_MUTE,
5715                                     AMP_IN_MUTE(0));
5716         }
5717 }
5718
5719 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
5720                                            int (*fill_dac)(struct hda_codec *));
5721
5722 /* parse the BIOS configuration and set up the alc_spec */
5723 /* return 1 if successful, 0 if the proper config is not found,
5724  * or a negative error code
5725  */
5726 static int alc880_parse_auto_config(struct hda_codec *codec)
5727 {
5728         struct alc_spec *spec = codec->spec;
5729         int err;
5730         static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
5731
5732         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5733                                            alc880_ignore);
5734         if (err < 0)
5735                 return err;
5736         if (!spec->autocfg.line_outs)
5737                 return 0; /* can't find valid BIOS pin config */
5738
5739         err = alc880_auto_fill_dac_nids(codec);
5740         if (err < 0)
5741                 return err;
5742         err = alc_auto_add_multi_channel_mode(codec, alc880_auto_fill_dac_nids);
5743         if (err < 0)
5744                 return err;
5745         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
5746         if (err < 0)
5747                 return err;
5748         err = alc880_auto_create_extra_out(spec,
5749                                            spec->autocfg.speaker_pins[0],
5750                                            "Speaker");
5751         if (err < 0)
5752                 return err;
5753         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
5754                                            "Headphone");
5755         if (err < 0)
5756                 return err;
5757         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
5758         if (err < 0)
5759                 return err;
5760
5761         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5762
5763         alc_auto_parse_digital(codec);
5764
5765         if (spec->kctls.list)
5766                 add_mixer(spec, spec->kctls.list);
5767
5768         spec->num_mux_defs = 1;
5769         spec->input_mux = &spec->private_imux[0];
5770
5771         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
5772
5773         return 1;
5774 }
5775
5776 /* additional initialization for auto-configuration model */
5777 static void alc880_auto_init(struct hda_codec *codec)
5778 {
5779         struct alc_spec *spec = codec->spec;
5780         alc880_auto_init_multi_out(codec);
5781         alc880_auto_init_extra_out(codec);
5782         alc880_auto_init_analog_input(codec);
5783         alc880_auto_init_input_src(codec);
5784         alc_auto_init_digital(codec);
5785         if (spec->unsol_event)
5786                 alc_inithook(codec);
5787 }
5788
5789 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
5790  * one of two digital mic pins, e.g. on ALC272
5791  */
5792 static void fixup_automic_adc(struct hda_codec *codec)
5793 {
5794         struct alc_spec *spec = codec->spec;
5795         int i;
5796
5797         for (i = 0; i < spec->num_adc_nids; i++) {
5798                 hda_nid_t cap = spec->capsrc_nids ?
5799                         spec->capsrc_nids[i] : spec->adc_nids[i];
5800                 int iidx, eidx;
5801
5802                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
5803                 if (iidx < 0)
5804                         continue;
5805                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
5806                 if (eidx < 0)
5807                         continue;
5808                 spec->int_mic.mux_idx = iidx;
5809                 spec->ext_mic.mux_idx = eidx;
5810                 if (spec->capsrc_nids)
5811                         spec->capsrc_nids += i;
5812                 spec->adc_nids += i;
5813                 spec->num_adc_nids = 1;
5814                 /* optional dock-mic */
5815                 eidx = get_connection_index(codec, cap, spec->dock_mic.pin);
5816                 if (eidx < 0)
5817                         spec->dock_mic.pin = 0;
5818                 else
5819                         spec->dock_mic.mux_idx = eidx;
5820                 return;
5821         }
5822         snd_printd(KERN_INFO "hda_codec: %s: "
5823                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
5824                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
5825         spec->auto_mic = 0; /* disable auto-mic to be sure */
5826 }
5827
5828 /* select or unmute the given capsrc route */
5829 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
5830                                     int idx)
5831 {
5832         if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
5833                 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
5834                                          HDA_AMP_MUTE, 0);
5835         } else {
5836                 snd_hda_codec_write_cache(codec, cap, 0,
5837                                           AC_VERB_SET_CONNECT_SEL, idx);
5838         }
5839 }
5840
5841 /* set the default connection to that pin */
5842 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
5843 {
5844         struct alc_spec *spec = codec->spec;
5845         int i;
5846
5847         if (!pin)
5848                 return 0;
5849         for (i = 0; i < spec->num_adc_nids; i++) {
5850                 hda_nid_t cap = spec->capsrc_nids ?
5851                         spec->capsrc_nids[i] : spec->adc_nids[i];
5852                 int idx;
5853
5854                 idx = get_connection_index(codec, cap, pin);
5855                 if (idx < 0)
5856                         continue;
5857                 select_or_unmute_capsrc(codec, cap, idx);
5858                 return i; /* return the found index */
5859         }
5860         return -1; /* not found */
5861 }
5862
5863 /* choose the ADC/MUX containing the input pin and initialize the setup */
5864 static void fixup_single_adc(struct hda_codec *codec)
5865 {
5866         struct alc_spec *spec = codec->spec;
5867         struct auto_pin_cfg *cfg = &spec->autocfg;
5868         int i;
5869
5870         /* search for the input pin; there must be only one */
5871         if (cfg->num_inputs != 1)
5872                 return;
5873         i = init_capsrc_for_pin(codec, cfg->inputs[0].pin);
5874         if (i >= 0) {
5875                 /* use only this ADC */
5876                 if (spec->capsrc_nids)
5877                         spec->capsrc_nids += i;
5878                 spec->adc_nids += i;
5879                 spec->num_adc_nids = 1;
5880                 spec->single_input_src = 1;
5881         }
5882 }
5883
5884 /* initialize dual adcs */
5885 static void fixup_dual_adc_switch(struct hda_codec *codec)
5886 {
5887         struct alc_spec *spec = codec->spec;
5888         init_capsrc_for_pin(codec, spec->ext_mic.pin);
5889         init_capsrc_for_pin(codec, spec->dock_mic.pin);
5890         init_capsrc_for_pin(codec, spec->int_mic.pin);
5891 }
5892
5893 /* initialize some special cases for input sources */
5894 static void alc_init_special_input_src(struct hda_codec *codec)
5895 {
5896         struct alc_spec *spec = codec->spec;
5897         if (spec->dual_adc_switch)
5898                 fixup_dual_adc_switch(codec);
5899         else if (spec->single_input_src)
5900                 init_capsrc_for_pin(codec, spec->autocfg.inputs[0].pin);
5901 }
5902
5903 static void set_capture_mixer(struct hda_codec *codec)
5904 {
5905         struct alc_spec *spec = codec->spec;
5906         static const struct snd_kcontrol_new *caps[2][3] = {
5907                 { alc_capture_mixer_nosrc1,
5908                   alc_capture_mixer_nosrc2,
5909                   alc_capture_mixer_nosrc3 },
5910                 { alc_capture_mixer1,
5911                   alc_capture_mixer2,
5912                   alc_capture_mixer3 },
5913         };
5914         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
5915                 int mux = 0;
5916                 int num_adcs = spec->num_adc_nids;
5917                 if (spec->dual_adc_switch)
5918                         num_adcs = 1;
5919                 else if (spec->auto_mic)
5920                         fixup_automic_adc(codec);
5921                 else if (spec->input_mux) {
5922                         if (spec->input_mux->num_items > 1)
5923                                 mux = 1;
5924                         else if (spec->input_mux->num_items == 1)
5925                                 fixup_single_adc(codec);
5926                 }
5927                 spec->cap_mixer = caps[mux][num_adcs - 1];
5928         }
5929 }
5930
5931 /* fill adc_nids (and capsrc_nids) containing all active input pins */
5932 static void fillup_priv_adc_nids(struct hda_codec *codec, const hda_nid_t *nids,
5933                                  int num_nids)
5934 {
5935         struct alc_spec *spec = codec->spec;
5936         struct auto_pin_cfg *cfg = &spec->autocfg;
5937         int n;
5938         hda_nid_t fallback_adc = 0, fallback_cap = 0;
5939
5940         for (n = 0; n < num_nids; n++) {
5941                 hda_nid_t adc, cap;
5942                 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
5943                 int nconns, i, j;
5944
5945                 adc = nids[n];
5946                 if (get_wcaps_type(get_wcaps(codec, adc)) != AC_WID_AUD_IN)
5947                         continue;
5948                 cap = adc;
5949                 nconns = snd_hda_get_connections(codec, cap, conn,
5950                                                  ARRAY_SIZE(conn));
5951                 if (nconns == 1) {
5952                         cap = conn[0];
5953                         nconns = snd_hda_get_connections(codec, cap, conn,
5954                                                          ARRAY_SIZE(conn));
5955                 }
5956                 if (nconns <= 0)
5957                         continue;
5958                 if (!fallback_adc) {
5959                         fallback_adc = adc;
5960                         fallback_cap = cap;
5961                 }
5962                 for (i = 0; i < cfg->num_inputs; i++) {
5963                         hda_nid_t nid = cfg->inputs[i].pin;
5964                         for (j = 0; j < nconns; j++) {
5965                                 if (conn[j] == nid)
5966                                         break;
5967                         }
5968                         if (j >= nconns)
5969                                 break;
5970                 }
5971                 if (i >= cfg->num_inputs) {
5972                         int num_adcs = spec->num_adc_nids;
5973                         spec->private_adc_nids[num_adcs] = adc;
5974                         spec->private_capsrc_nids[num_adcs] = cap;
5975                         spec->num_adc_nids++;
5976                         spec->adc_nids = spec->private_adc_nids;
5977                         if (adc != cap)
5978                                 spec->capsrc_nids = spec->private_capsrc_nids;
5979                 }
5980         }
5981         if (!spec->num_adc_nids) {
5982                 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
5983                        " using fallback 0x%x\n",
5984                        codec->chip_name, fallback_adc);
5985                 spec->private_adc_nids[0] = fallback_adc;
5986                 spec->adc_nids = spec->private_adc_nids;
5987                 if (fallback_adc != fallback_cap) {
5988                         spec->private_capsrc_nids[0] = fallback_cap;
5989                         spec->capsrc_nids = spec->private_adc_nids;
5990                 }
5991         }
5992 }
5993
5994 #ifdef CONFIG_SND_HDA_INPUT_BEEP
5995 #define set_beep_amp(spec, nid, idx, dir) \
5996         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
5997
5998 static const struct snd_pci_quirk beep_white_list[] = {
5999         SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
6000         SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
6001         SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
6002         SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
6003         SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
6004         {}
6005 };
6006
6007 static inline int has_cdefine_beep(struct hda_codec *codec)
6008 {
6009         struct alc_spec *spec = codec->spec;
6010         const struct snd_pci_quirk *q;
6011         q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
6012         if (q)
6013                 return q->value;
6014         return spec->cdefine.enable_pcbeep;
6015 }
6016 #else
6017 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
6018 #define has_cdefine_beep(codec)         0
6019 #endif
6020
6021 /*
6022  * OK, here we have finally the patch for ALC880
6023  */
6024
6025 static int patch_alc880(struct hda_codec *codec)
6026 {
6027         struct alc_spec *spec;
6028         int board_config;
6029         int err;
6030
6031         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6032         if (spec == NULL)
6033                 return -ENOMEM;
6034
6035         codec->spec = spec;
6036
6037         spec->mixer_nid = 0x0b;
6038
6039         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
6040                                                   alc880_models,
6041                                                   alc880_cfg_tbl);
6042         if (board_config < 0) {
6043                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6044                        codec->chip_name);
6045                 board_config = ALC880_AUTO;
6046         }
6047
6048         if (board_config == ALC880_AUTO) {
6049                 /* automatic parse from the BIOS config */
6050                 err = alc880_parse_auto_config(codec);
6051                 if (err < 0) {
6052                         alc_free(codec);
6053                         return err;
6054                 } else if (!err) {
6055                         printk(KERN_INFO
6056                                "hda_codec: Cannot set up configuration "
6057                                "from BIOS.  Using 3-stack mode...\n");
6058                         board_config = ALC880_3ST;
6059                 }
6060         }
6061
6062         err = snd_hda_attach_beep_device(codec, 0x1);
6063         if (err < 0) {
6064                 alc_free(codec);
6065                 return err;
6066         }
6067
6068         if (board_config != ALC880_AUTO)
6069                 setup_preset(codec, &alc880_presets[board_config]);
6070
6071         spec->stream_analog_playback = &alc880_pcm_analog_playback;
6072         spec->stream_analog_capture = &alc880_pcm_analog_capture;
6073         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6074
6075         spec->stream_digital_playback = &alc880_pcm_digital_playback;
6076         spec->stream_digital_capture = &alc880_pcm_digital_capture;
6077
6078         if (!spec->adc_nids && spec->input_mux) {
6079                 /* check whether NID 0x07 is valid */
6080                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
6081                 /* get type */
6082                 wcap = get_wcaps_type(wcap);
6083                 if (wcap != AC_WID_AUD_IN) {
6084                         spec->adc_nids = alc880_adc_nids_alt;
6085                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
6086                 } else {
6087                         spec->adc_nids = alc880_adc_nids;
6088                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
6089                 }
6090         }
6091         set_capture_mixer(codec);
6092         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6093
6094         spec->vmaster_nid = 0x0c;
6095
6096         codec->patch_ops = alc_patch_ops;
6097         if (board_config == ALC880_AUTO)
6098                 spec->init_hook = alc880_auto_init;
6099 #ifdef CONFIG_SND_HDA_POWER_SAVE
6100         if (!spec->loopback.amplist)
6101                 spec->loopback.amplist = alc880_loopbacks;
6102 #endif
6103
6104         return 0;
6105 }
6106
6107
6108 /*
6109  * ALC260 support
6110  */
6111
6112 static const hda_nid_t alc260_dac_nids[1] = {
6113         /* front */
6114         0x02,
6115 };
6116
6117 static const hda_nid_t alc260_adc_nids[1] = {
6118         /* ADC0 */
6119         0x04,
6120 };
6121
6122 static const hda_nid_t alc260_adc_nids_alt[1] = {
6123         /* ADC1 */
6124         0x05,
6125 };
6126
6127 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
6128  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
6129  */
6130 static const hda_nid_t alc260_dual_adc_nids[2] = {
6131         /* ADC0, ADC1 */
6132         0x04, 0x05
6133 };
6134
6135 #define ALC260_DIGOUT_NID       0x03
6136 #define ALC260_DIGIN_NID        0x06
6137
6138 static const struct hda_input_mux alc260_capture_source = {
6139         .num_items = 4,
6140         .items = {
6141                 { "Mic", 0x0 },
6142                 { "Front Mic", 0x1 },
6143                 { "Line", 0x2 },
6144                 { "CD", 0x4 },
6145         },
6146 };
6147
6148 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
6149  * headphone jack and the internal CD lines since these are the only pins at
6150  * which audio can appear.  For flexibility, also allow the option of
6151  * recording the mixer output on the second ADC (ADC0 doesn't have a
6152  * connection to the mixer output).
6153  */
6154 static const struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
6155         {
6156                 .num_items = 3,
6157                 .items = {
6158                         { "Mic/Line", 0x0 },
6159                         { "CD", 0x4 },
6160                         { "Headphone", 0x2 },
6161                 },
6162         },
6163         {
6164                 .num_items = 4,
6165                 .items = {
6166                         { "Mic/Line", 0x0 },
6167                         { "CD", 0x4 },
6168                         { "Headphone", 0x2 },
6169                         { "Mixer", 0x5 },
6170                 },
6171         },
6172
6173 };
6174
6175 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
6176  * the Fujitsu S702x, but jacks are marked differently.
6177  */
6178 static const struct hda_input_mux alc260_acer_capture_sources[2] = {
6179         {
6180                 .num_items = 4,
6181                 .items = {
6182                         { "Mic", 0x0 },
6183                         { "Line", 0x2 },
6184                         { "CD", 0x4 },
6185                         { "Headphone", 0x5 },
6186                 },
6187         },
6188         {
6189                 .num_items = 5,
6190                 .items = {
6191                         { "Mic", 0x0 },
6192                         { "Line", 0x2 },
6193                         { "CD", 0x4 },
6194                         { "Headphone", 0x6 },
6195                         { "Mixer", 0x5 },
6196                 },
6197         },
6198 };
6199
6200 /* Maxdata Favorit 100XS */
6201 static const struct hda_input_mux alc260_favorit100_capture_sources[2] = {
6202         {
6203                 .num_items = 2,
6204                 .items = {
6205                         { "Line/Mic", 0x0 },
6206                         { "CD", 0x4 },
6207                 },
6208         },
6209         {
6210                 .num_items = 3,
6211                 .items = {
6212                         { "Line/Mic", 0x0 },
6213                         { "CD", 0x4 },
6214                         { "Mixer", 0x5 },
6215                 },
6216         },
6217 };
6218
6219 /*
6220  * This is just place-holder, so there's something for alc_build_pcms to look
6221  * at when it calculates the maximum number of channels. ALC260 has no mixer
6222  * element which allows changing the channel mode, so the verb list is
6223  * never used.
6224  */
6225 static const struct hda_channel_mode alc260_modes[1] = {
6226         { 2, NULL },
6227 };
6228
6229
6230 /* Mixer combinations
6231  *
6232  * basic: base_output + input + pc_beep + capture
6233  * HP: base_output + input + capture_alt
6234  * HP_3013: hp_3013 + input + capture
6235  * fujitsu: fujitsu + capture
6236  * acer: acer + capture
6237  */
6238
6239 static const struct snd_kcontrol_new alc260_base_output_mixer[] = {
6240         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6241         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
6242         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6243         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
6244         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
6245         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
6246         { } /* end */
6247 };
6248
6249 static const struct snd_kcontrol_new alc260_input_mixer[] = {
6250         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6251         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6252         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6253         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6254         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6255         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6256         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
6257         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
6258         { } /* end */
6259 };
6260
6261 /* update HP, line and mono out pins according to the master switch */
6262 static void alc260_hp_master_update(struct hda_codec *codec)
6263 {
6264         update_speakers(codec);
6265 }
6266
6267 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
6268                                    struct snd_ctl_elem_value *ucontrol)
6269 {
6270         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6271         struct alc_spec *spec = codec->spec;
6272         *ucontrol->value.integer.value = !spec->master_mute;
6273         return 0;
6274 }
6275
6276 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
6277                                    struct snd_ctl_elem_value *ucontrol)
6278 {
6279         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6280         struct alc_spec *spec = codec->spec;
6281         int val = !*ucontrol->value.integer.value;
6282
6283         if (val == spec->master_mute)
6284                 return 0;
6285         spec->master_mute = val;
6286         alc260_hp_master_update(codec);
6287         return 1;
6288 }
6289
6290 static const struct snd_kcontrol_new alc260_hp_output_mixer[] = {
6291         {
6292                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6293                 .name = "Master Playback Switch",
6294                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
6295                 .info = snd_ctl_boolean_mono_info,
6296                 .get = alc260_hp_master_sw_get,
6297                 .put = alc260_hp_master_sw_put,
6298         },
6299         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6300         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
6301         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6302         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
6303         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
6304                               HDA_OUTPUT),
6305         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
6306         { } /* end */
6307 };
6308
6309 static const struct hda_verb alc260_hp_unsol_verbs[] = {
6310         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6311         {},
6312 };
6313
6314 static void alc260_hp_setup(struct hda_codec *codec)
6315 {
6316         struct alc_spec *spec = codec->spec;
6317
6318         spec->autocfg.hp_pins[0] = 0x0f;
6319         spec->autocfg.speaker_pins[0] = 0x10;
6320         spec->autocfg.speaker_pins[1] = 0x11;
6321         spec->automute = 1;
6322         spec->automute_mode = ALC_AUTOMUTE_PIN;
6323 }
6324
6325 static const struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
6326         {
6327                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6328                 .name = "Master Playback Switch",
6329                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
6330                 .info = snd_ctl_boolean_mono_info,
6331                 .get = alc260_hp_master_sw_get,
6332                 .put = alc260_hp_master_sw_put,
6333         },
6334         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6335         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
6336         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
6337         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
6338         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6339         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6340         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
6341         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
6342         { } /* end */
6343 };
6344
6345 static void alc260_hp_3013_setup(struct hda_codec *codec)
6346 {
6347         struct alc_spec *spec = codec->spec;
6348
6349         spec->autocfg.hp_pins[0] = 0x15;
6350         spec->autocfg.speaker_pins[0] = 0x10;
6351         spec->autocfg.speaker_pins[1] = 0x11;
6352         spec->automute = 1;
6353         spec->automute_mode = ALC_AUTOMUTE_PIN;
6354 }
6355
6356 static const struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
6357         .ops = &snd_hda_bind_vol,
6358         .values = {
6359                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
6360                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
6361                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
6362                 0
6363         },
6364 };
6365
6366 static const struct hda_bind_ctls alc260_dc7600_bind_switch = {
6367         .ops = &snd_hda_bind_sw,
6368         .values = {
6369                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
6370                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
6371                 0
6372         },
6373 };
6374
6375 static const struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
6376         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
6377         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
6378         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
6379         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
6380         { } /* end */
6381 };
6382
6383 static const struct hda_verb alc260_hp_3013_unsol_verbs[] = {
6384         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6385         {},
6386 };
6387
6388 static void alc260_hp_3012_setup(struct hda_codec *codec)
6389 {
6390         struct alc_spec *spec = codec->spec;
6391
6392         spec->autocfg.hp_pins[0] = 0x10;
6393         spec->autocfg.speaker_pins[0] = 0x0f;
6394         spec->autocfg.speaker_pins[1] = 0x11;
6395         spec->autocfg.speaker_pins[2] = 0x15;
6396         spec->automute = 1;
6397         spec->automute_mode = ALC_AUTOMUTE_PIN;
6398 }
6399
6400 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
6401  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
6402  */
6403 static const struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
6404         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6405         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
6406         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6407         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6408         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6409         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
6410         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
6411         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
6412         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6413         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
6414         { } /* end */
6415 };
6416
6417 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
6418  * versions of the ALC260 don't act on requests to enable mic bias from NID
6419  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
6420  * datasheet doesn't mention this restriction.  At this stage it's not clear
6421  * whether this behaviour is intentional or is a hardware bug in chip
6422  * revisions available in early 2006.  Therefore for now allow the
6423  * "Headphone Jack Mode" control to span all choices, but if it turns out
6424  * that the lack of mic bias for this NID is intentional we could change the
6425  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
6426  *
6427  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
6428  * don't appear to make the mic bias available from the "line" jack, even
6429  * though the NID used for this jack (0x14) can supply it.  The theory is
6430  * that perhaps Acer have included blocking capacitors between the ALC260
6431  * and the output jack.  If this turns out to be the case for all such
6432  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
6433  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
6434  *
6435  * The C20x Tablet series have a mono internal speaker which is controlled
6436  * via the chip's Mono sum widget and pin complex, so include the necessary
6437  * controls for such models.  On models without a "mono speaker" the control
6438  * won't do anything.
6439  */
6440 static const struct snd_kcontrol_new alc260_acer_mixer[] = {
6441         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6442         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
6443         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
6444         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
6445                               HDA_OUTPUT),
6446         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
6447                            HDA_INPUT),
6448         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6449         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6450         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6451         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6452         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6453         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6454         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6455         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6456         { } /* end */
6457 };
6458
6459 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
6460  */
6461 static const struct snd_kcontrol_new alc260_favorit100_mixer[] = {
6462         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6463         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
6464         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
6465         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6466         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6467         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6468         { } /* end */
6469 };
6470
6471 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
6472  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
6473  */
6474 static const struct snd_kcontrol_new alc260_will_mixer[] = {
6475         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6476         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
6477         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6478         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6479         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6480         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6481         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6482         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6483         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6484         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6485         { } /* end */
6486 };
6487
6488 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
6489  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
6490  */
6491 static const struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
6492         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6493         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
6494         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6495         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6496         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6497         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
6498         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
6499         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6500         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6501         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6502         { } /* end */
6503 };
6504
6505 /*
6506  * initialization verbs
6507  */
6508 static const struct hda_verb alc260_init_verbs[] = {
6509         /* Line In pin widget for input */
6510         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6511         /* CD pin widget for input */
6512         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6513         /* Mic1 (rear panel) pin widget for input and vref at 80% */
6514         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6515         /* Mic2 (front panel) pin widget for input and vref at 80% */
6516         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6517         /* LINE-2 is used for line-out in rear */
6518         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6519         /* select line-out */
6520         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
6521         /* LINE-OUT pin */
6522         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6523         /* enable HP */
6524         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6525         /* enable Mono */
6526         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6527         /* mute capture amp left and right */
6528         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6529         /* set connection select to line in (default select for this ADC) */
6530         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
6531         /* mute capture amp left and right */
6532         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6533         /* set connection select to line in (default select for this ADC) */
6534         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
6535         /* set vol=0 Line-Out mixer amp left and right */
6536         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6537         /* unmute pin widget amp left and right (no gain on this amp) */
6538         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6539         /* set vol=0 HP mixer amp left and right */
6540         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6541         /* unmute pin widget amp left and right (no gain on this amp) */
6542         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6543         /* set vol=0 Mono mixer amp left and right */
6544         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6545         /* unmute pin widget amp left and right (no gain on this amp) */
6546         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6547         /* unmute LINE-2 out pin */
6548         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6549         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
6550          * Line In 2 = 0x03
6551          */
6552         /* mute analog inputs */
6553         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6554         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6555         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6556         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6557         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6558         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
6559         /* mute Front out path */
6560         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6561         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6562         /* mute Headphone out path */
6563         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6564         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6565         /* mute Mono out path */
6566         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6567         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6568         { }
6569 };
6570
6571 #if 0 /* should be identical with alc260_init_verbs? */
6572 static const struct hda_verb alc260_hp_init_verbs[] = {
6573         /* Headphone and output */
6574         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6575         /* mono output */
6576         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6577         /* Mic1 (rear panel) pin widget for input and vref at 80% */
6578         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6579         /* Mic2 (front panel) pin widget for input and vref at 80% */
6580         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6581         /* Line In pin widget for input */
6582         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6583         /* Line-2 pin widget for output */
6584         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6585         /* CD pin widget for input */
6586         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6587         /* unmute amp left and right */
6588         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
6589         /* set connection select to line in (default select for this ADC) */
6590         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
6591         /* unmute Line-Out mixer amp left and right (volume = 0) */
6592         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6593         /* mute pin widget amp left and right (no gain on this amp) */
6594         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6595         /* unmute HP mixer amp left and right (volume = 0) */
6596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6597         /* mute pin widget amp left and right (no gain on this amp) */
6598         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6599         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
6600          * Line In 2 = 0x03
6601          */
6602         /* mute analog inputs */
6603         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6604         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6605         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6606         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6607         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6608         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
6609         /* Unmute Front out path */
6610         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6611         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6612         /* Unmute Headphone out path */
6613         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6614         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6615         /* Unmute Mono out path */
6616         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6617         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6618         { }
6619 };
6620 #endif
6621
6622 static const struct hda_verb alc260_hp_3013_init_verbs[] = {
6623         /* Line out and output */
6624         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6625         /* mono output */
6626         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6627         /* Mic1 (rear panel) pin widget for input and vref at 80% */
6628         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6629         /* Mic2 (front panel) pin widget for input and vref at 80% */
6630         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6631         /* Line In pin widget for input */
6632         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6633         /* Headphone pin widget for output */
6634         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6635         /* CD pin widget for input */
6636         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6637         /* unmute amp left and right */
6638         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
6639         /* set connection select to line in (default select for this ADC) */
6640         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
6641         /* unmute Line-Out mixer amp left and right (volume = 0) */
6642         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6643         /* mute pin widget amp left and right (no gain on this amp) */
6644         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6645         /* unmute HP mixer amp left and right (volume = 0) */
6646         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6647         /* mute pin widget amp left and right (no gain on this amp) */
6648         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6649         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
6650          * Line In 2 = 0x03
6651          */
6652         /* mute analog inputs */
6653         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6654         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6655         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6656         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6657         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6658         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
6659         /* Unmute Front out path */
6660         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6661         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6662         /* Unmute Headphone out path */
6663         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6664         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6665         /* Unmute Mono out path */
6666         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6667         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6668         { }
6669 };
6670
6671 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
6672  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
6673  * audio = 0x16, internal speaker = 0x10.
6674  */
6675 static const struct hda_verb alc260_fujitsu_init_verbs[] = {
6676         /* Disable all GPIOs */
6677         {0x01, AC_VERB_SET_GPIO_MASK, 0},
6678         /* Internal speaker is connected to headphone pin */
6679         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6680         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
6681         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6682         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
6683         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6684         /* Ensure all other unused pins are disabled and muted. */
6685         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6686         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6687         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6688         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6689         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6690         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6691         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6692         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6693
6694         /* Disable digital (SPDIF) pins */
6695         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
6696         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
6697
6698         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
6699          * when acting as an output.
6700          */
6701         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
6702
6703         /* Start with output sum widgets muted and their output gains at min */
6704         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6705         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6706         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6707         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6708         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6709         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6710         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6711         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6712         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6713
6714         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
6715         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6716         /* Unmute Line1 pin widget output buffer since it starts as an output.
6717          * If the pin mode is changed by the user the pin mode control will
6718          * take care of enabling the pin's input/output buffers as needed.
6719          * Therefore there's no need to enable the input buffer at this
6720          * stage.
6721          */
6722         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6723         /* Unmute input buffer of pin widget used for Line-in (no equiv
6724          * mixer ctrl)
6725          */
6726         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6727
6728         /* Mute capture amp left and right */
6729         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6730         /* Set ADC connection select to match default mixer setting - line
6731          * in (on mic1 pin)
6732          */
6733         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6734
6735         /* Do the same for the second ADC: mute capture input amp and
6736          * set ADC connection to line in (on mic1 pin)
6737          */
6738         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6739         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6740
6741         /* Mute all inputs to mixer widget (even unconnected ones) */
6742         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
6743         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
6744         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
6745         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
6746         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
6747         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
6748         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
6749         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
6750
6751         { }
6752 };
6753
6754 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
6755  * similar laptops (adapted from Fujitsu init verbs).
6756  */
6757 static const struct hda_verb alc260_acer_init_verbs[] = {
6758         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
6759          * the headphone jack.  Turn this on and rely on the standard mute
6760          * methods whenever the user wants to turn these outputs off.
6761          */
6762         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
6763         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6764         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6765         /* Internal speaker/Headphone jack is connected to Line-out pin */
6766         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6767         /* Internal microphone/Mic jack is connected to Mic1 pin */
6768         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
6769         /* Line In jack is connected to Line1 pin */
6770         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6771         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
6772         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6773         /* Ensure all other unused pins are disabled and muted. */
6774         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6775         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6776         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6777         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6778         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6779         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6780         /* Disable digital (SPDIF) pins */
6781         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
6782         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
6783
6784         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
6785          * bus when acting as outputs.
6786          */
6787         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
6788         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
6789
6790         /* Start with output sum widgets muted and their output gains at min */
6791         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6792         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6793         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6794         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6795         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6796         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6797         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6798         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6799         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6800
6801         /* Unmute Line-out pin widget amp left and right
6802          * (no equiv mixer ctrl)
6803          */
6804         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6805         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
6806         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6807         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
6808          * inputs. If the pin mode is changed by the user the pin mode control
6809          * will take care of enabling the pin's input/output buffers as needed.
6810          * Therefore there's no need to enable the input buffer at this
6811          * stage.
6812          */
6813         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6814         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6815
6816         /* Mute capture amp left and right */
6817         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6818         /* Set ADC connection select to match default mixer setting - mic
6819          * (on mic1 pin)
6820          */
6821         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6822
6823         /* Do similar with the second ADC: mute capture input amp and
6824          * set ADC connection to mic to match ALSA's default state.
6825          */
6826         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6827         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6828
6829         /* Mute all inputs to mixer widget (even unconnected ones) */
6830         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
6831         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
6832         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
6833         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
6834         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
6835         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
6836         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
6837         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
6838
6839         { }
6840 };
6841
6842 /* Initialisation sequence for Maxdata Favorit 100XS
6843  * (adapted from Acer init verbs).
6844  */
6845 static const struct hda_verb alc260_favorit100_init_verbs[] = {
6846         /* GPIO 0 enables the output jack.
6847          * Turn this on and rely on the standard mute
6848          * methods whenever the user wants to turn these outputs off.
6849          */
6850         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
6851         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6852         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6853         /* Line/Mic input jack is connected to Mic1 pin */
6854         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
6855         /* Ensure all other unused pins are disabled and muted. */
6856         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6857         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6858         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6859         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6860         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6861         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6862         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6863         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6864         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6865         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6866         /* Disable digital (SPDIF) pins */
6867         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
6868         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
6869
6870         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
6871          * bus when acting as outputs.
6872          */
6873         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
6874         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
6875
6876         /* Start with output sum widgets muted and their output gains at min */
6877         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6878         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6879         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6880         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6881         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6882         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6883         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6884         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6885         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6886
6887         /* Unmute Line-out pin widget amp left and right
6888          * (no equiv mixer ctrl)
6889          */
6890         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6891         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
6892          * inputs. If the pin mode is changed by the user the pin mode control
6893          * will take care of enabling the pin's input/output buffers as needed.
6894          * Therefore there's no need to enable the input buffer at this
6895          * stage.
6896          */
6897         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6898
6899         /* Mute capture amp left and right */
6900         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6901         /* Set ADC connection select to match default mixer setting - mic
6902          * (on mic1 pin)
6903          */
6904         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6905
6906         /* Do similar with the second ADC: mute capture input amp and
6907          * set ADC connection to mic to match ALSA's default state.
6908          */
6909         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6910         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6911
6912         /* Mute all inputs to mixer widget (even unconnected ones) */
6913         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
6914         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
6915         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
6916         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
6917         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
6918         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
6919         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
6920         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
6921
6922         { }
6923 };
6924
6925 static const struct hda_verb alc260_will_verbs[] = {
6926         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6927         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
6928         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
6929         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
6930         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
6931         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
6932         {}
6933 };
6934
6935 static const struct hda_verb alc260_replacer_672v_verbs[] = {
6936         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
6937         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
6938         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
6939
6940         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
6941         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6942         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6943
6944         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6945         {}
6946 };
6947
6948 /* toggle speaker-output according to the hp-jack state */
6949 static void alc260_replacer_672v_automute(struct hda_codec *codec)
6950 {
6951         unsigned int present;
6952
6953         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
6954         present = snd_hda_jack_detect(codec, 0x0f);
6955         if (present) {
6956                 snd_hda_codec_write_cache(codec, 0x01, 0,
6957                                           AC_VERB_SET_GPIO_DATA, 1);
6958                 snd_hda_codec_write_cache(codec, 0x0f, 0,
6959                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
6960                                           PIN_HP);
6961         } else {
6962                 snd_hda_codec_write_cache(codec, 0x01, 0,
6963                                           AC_VERB_SET_GPIO_DATA, 0);
6964                 snd_hda_codec_write_cache(codec, 0x0f, 0,
6965                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
6966                                           PIN_OUT);
6967         }
6968 }
6969
6970 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
6971                                        unsigned int res)
6972 {
6973         if ((res >> 26) == ALC880_HP_EVENT)
6974                 alc260_replacer_672v_automute(codec);
6975 }
6976
6977 static const struct hda_verb alc260_hp_dc7600_verbs[] = {
6978         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
6979         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6980         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6981         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6982         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6983         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6984         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6985         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6986         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6987         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6988         {}
6989 };
6990
6991 /* Test configuration for debugging, modelled after the ALC880 test
6992  * configuration.
6993  */
6994 #ifdef CONFIG_SND_DEBUG
6995 static const hda_nid_t alc260_test_dac_nids[1] = {
6996         0x02,
6997 };
6998 static const hda_nid_t alc260_test_adc_nids[2] = {
6999         0x04, 0x05,
7000 };
7001 /* For testing the ALC260, each input MUX needs its own definition since
7002  * the signal assignments are different.  This assumes that the first ADC
7003  * is NID 0x04.
7004  */
7005 static const struct hda_input_mux alc260_test_capture_sources[2] = {
7006         {
7007                 .num_items = 7,
7008                 .items = {
7009                         { "MIC1 pin", 0x0 },
7010                         { "MIC2 pin", 0x1 },
7011                         { "LINE1 pin", 0x2 },
7012                         { "LINE2 pin", 0x3 },
7013                         { "CD pin", 0x4 },
7014                         { "LINE-OUT pin", 0x5 },
7015                         { "HP-OUT pin", 0x6 },
7016                 },
7017         },
7018         {
7019                 .num_items = 8,
7020                 .items = {
7021                         { "MIC1 pin", 0x0 },
7022                         { "MIC2 pin", 0x1 },
7023                         { "LINE1 pin", 0x2 },
7024                         { "LINE2 pin", 0x3 },
7025                         { "CD pin", 0x4 },
7026                         { "Mixer", 0x5 },
7027                         { "LINE-OUT pin", 0x6 },
7028                         { "HP-OUT pin", 0x7 },
7029                 },
7030         },
7031 };
7032 static const struct snd_kcontrol_new alc260_test_mixer[] = {
7033         /* Output driver widgets */
7034         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
7035         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
7036         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
7037         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
7038         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
7039         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
7040
7041         /* Modes for retasking pin widgets
7042          * Note: the ALC260 doesn't seem to act on requests to enable mic
7043          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
7044          * mention this restriction.  At this stage it's not clear whether
7045          * this behaviour is intentional or is a hardware bug in chip
7046          * revisions available at least up until early 2006.  Therefore for
7047          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
7048          * choices, but if it turns out that the lack of mic bias for these
7049          * NIDs is intentional we could change their modes from
7050          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
7051          */
7052         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
7053         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
7054         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
7055         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
7056         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
7057         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
7058
7059         /* Loopback mixer controls */
7060         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
7061         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
7062         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
7063         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
7064         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
7065         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
7066         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
7067         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
7068         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
7069         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
7070         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
7071         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
7072         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
7073         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
7074
7075         /* Controls for GPIO pins, assuming they are configured as outputs */
7076         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
7077         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
7078         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
7079         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
7080
7081         /* Switches to allow the digital IO pins to be enabled.  The datasheet
7082          * is ambigious as to which NID is which; testing on laptops which
7083          * make this output available should provide clarification.
7084          */
7085         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
7086         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
7087
7088         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
7089          * this output to turn on an external amplifier.
7090          */
7091         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
7092         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
7093
7094         { } /* end */
7095 };
7096 static const struct hda_verb alc260_test_init_verbs[] = {
7097         /* Enable all GPIOs as outputs with an initial value of 0 */
7098         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
7099         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
7100         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
7101
7102         /* Enable retasking pins as output, initially without power amp */
7103         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7104         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7105         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7106         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7107         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7108         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7109
7110         /* Disable digital (SPDIF) pins initially, but users can enable
7111          * them via a mixer switch.  In the case of SPDIF-out, this initverb
7112          * payload also sets the generation to 0, output to be in "consumer"
7113          * PCM format, copyright asserted, no pre-emphasis and no validity
7114          * control.
7115          */
7116         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
7117         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
7118
7119         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
7120          * OUT1 sum bus when acting as an output.
7121          */
7122         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
7123         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
7124         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
7125         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
7126
7127         /* Start with output sum widgets muted and their output gains at min */
7128         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7129         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7130         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7131         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7132         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7133         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7134         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7135         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7136         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7137
7138         /* Unmute retasking pin widget output buffers since the default
7139          * state appears to be output.  As the pin mode is changed by the
7140          * user the pin mode control will take care of enabling the pin's
7141          * input/output buffers as needed.
7142          */
7143         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7144         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7145         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7146         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7147         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7148         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7149         /* Also unmute the mono-out pin widget */
7150         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7151
7152         /* Mute capture amp left and right */
7153         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7154         /* Set ADC connection select to match default mixer setting (mic1
7155          * pin)
7156          */
7157         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
7158
7159         /* Do the same for the second ADC: mute capture input amp and
7160          * set ADC connection to mic1 pin
7161          */
7162         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7163         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
7164
7165         /* Mute all inputs to mixer widget (even unconnected ones) */
7166         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
7167         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
7168         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
7169         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
7170         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
7171         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
7172         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
7173         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
7174
7175         { }
7176 };
7177 #endif
7178
7179 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
7180 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
7181
7182 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
7183 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
7184
7185 /*
7186  * for BIOS auto-configuration
7187  */
7188
7189 /* convert from pin to volume-mixer widget */
7190 static hda_nid_t alc260_pin_to_vol_mix(hda_nid_t nid)
7191 {
7192         if (nid >= 0x0f && nid <= 0x11)
7193                 return nid - 0x7;
7194         else if (nid >= 0x12 && nid <= 0x15)
7195                 return 0x08;
7196         else
7197                 return 0;
7198 }
7199
7200 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
7201                                         const char *pfx, int *vol_bits)
7202 {
7203         hda_nid_t nid_vol;
7204         unsigned long vol_val, sw_val;
7205         int chs, err;
7206
7207         nid_vol = alc260_pin_to_vol_mix(nid);
7208         if (!nid_vol)
7209                 return 0; /* N/A */
7210         if (nid == 0x11)
7211                 chs = 2;
7212         else
7213                 chs = 3;
7214         vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, chs, 0, HDA_OUTPUT);
7215         sw_val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
7216
7217         if (!(*vol_bits & (1 << nid_vol))) {
7218                 /* first control for the volume widget */
7219                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
7220                 if (err < 0)
7221                         return err;
7222                 *vol_bits |= (1 << nid_vol);
7223         }
7224         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
7225         if (err < 0)
7226                 return err;
7227         return 1;
7228 }
7229
7230 /* add playback controls from the parsed DAC table */
7231 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
7232                                              const struct auto_pin_cfg *cfg)
7233 {
7234         hda_nid_t nid;
7235         int err;
7236         int vols = 0;
7237
7238         spec->multiout.num_dacs = 1;
7239         spec->multiout.dac_nids = spec->private_dac_nids;
7240         spec->private_dac_nids[0] = 0x02;
7241
7242         nid = cfg->line_out_pins[0];
7243         if (nid) {
7244                 const char *pfx;
7245                 int index;
7246                 pfx = alc_get_line_out_pfx(spec, 0, true, &index);
7247                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
7248                 if (err < 0)
7249                         return err;
7250         }
7251
7252         nid = cfg->speaker_pins[0];
7253         if (nid) {
7254                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
7255                 if (err < 0)
7256                         return err;
7257         }
7258
7259         nid = cfg->hp_pins[0];
7260         if (nid) {
7261                 err = alc260_add_playback_controls(spec, nid, "Headphone",
7262                                                    &vols);
7263                 if (err < 0)
7264                         return err;
7265         }
7266         return 0;
7267 }
7268
7269 /* create playback/capture controls for input pins */
7270 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
7271                                                 const struct auto_pin_cfg *cfg)
7272 {
7273         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
7274 }
7275
7276 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
7277                                               hda_nid_t nid, int pin_type,
7278                                               int sel_idx)
7279 {
7280         hda_nid_t mix;
7281
7282         alc_set_pin_output(codec, nid, pin_type);
7283         /* need the manual connection? */
7284         if (nid >= 0x12) {
7285                 int idx = nid - 0x12;
7286                 snd_hda_codec_write(codec, idx + 0x0b, 0,
7287                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
7288         }
7289
7290         mix = alc260_pin_to_vol_mix(nid);
7291         if (!mix)
7292                 return;
7293         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7294                             AMP_OUT_ZERO);
7295         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7296                             AMP_IN_UNMUTE(0));
7297         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7298                             AMP_IN_UNMUTE(1));
7299 }
7300
7301 static void alc260_auto_init_multi_out(struct hda_codec *codec)
7302 {
7303         struct alc_spec *spec = codec->spec;
7304         hda_nid_t nid;
7305
7306         nid = spec->autocfg.line_out_pins[0];
7307         if (nid) {
7308                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7309                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
7310         }
7311
7312         nid = spec->autocfg.speaker_pins[0];
7313         if (nid)
7314                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
7315
7316         nid = spec->autocfg.hp_pins[0];
7317         if (nid)
7318                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
7319 }
7320
7321 #define alc260_auto_init_analog_input   alc880_auto_init_analog_input
7322 #define alc260_auto_init_input_src      alc880_auto_init_input_src
7323
7324 static int alc260_parse_auto_config(struct hda_codec *codec)
7325 {
7326         struct alc_spec *spec = codec->spec;
7327         int err;
7328         static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
7329
7330         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
7331                                            alc260_ignore);
7332         if (err < 0)
7333                 return err;
7334         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
7335         if (err < 0)
7336                 return err;
7337         if (!spec->kctls.list)
7338                 return 0; /* can't find valid BIOS pin config */
7339         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
7340         if (err < 0)
7341                 return err;
7342
7343         spec->multiout.max_channels = 2;
7344
7345         if (spec->autocfg.dig_outs)
7346                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
7347         if (spec->kctls.list)
7348                 add_mixer(spec, spec->kctls.list);
7349
7350         spec->num_mux_defs = 1;
7351         spec->input_mux = &spec->private_imux[0];
7352
7353         alc_ssid_check(codec, 0x10, 0x15, 0x0f, 0);
7354
7355         return 1;
7356 }
7357
7358 /* additional initialization for auto-configuration model */
7359 static void alc260_auto_init(struct hda_codec *codec)
7360 {
7361         struct alc_spec *spec = codec->spec;
7362         alc260_auto_init_multi_out(codec);
7363         alc260_auto_init_analog_input(codec);
7364         alc260_auto_init_input_src(codec);
7365         alc_auto_init_digital(codec);
7366         if (spec->unsol_event)
7367                 alc_inithook(codec);
7368 }
7369
7370 #ifdef CONFIG_SND_HDA_POWER_SAVE
7371 static const struct hda_amp_list alc260_loopbacks[] = {
7372         { 0x07, HDA_INPUT, 0 },
7373         { 0x07, HDA_INPUT, 1 },
7374         { 0x07, HDA_INPUT, 2 },
7375         { 0x07, HDA_INPUT, 3 },
7376         { 0x07, HDA_INPUT, 4 },
7377         { } /* end */
7378 };
7379 #endif
7380
7381 /*
7382  * Pin config fixes
7383  */
7384 enum {
7385         PINFIX_HP_DC5750,
7386 };
7387
7388 static const struct alc_fixup alc260_fixups[] = {
7389         [PINFIX_HP_DC5750] = {
7390                 .type = ALC_FIXUP_PINS,
7391                 .v.pins = (const struct alc_pincfg[]) {
7392                         { 0x11, 0x90130110 }, /* speaker */
7393                         { }
7394                 }
7395         },
7396 };
7397
7398 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
7399         SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
7400         {}
7401 };
7402
7403 /*
7404  * ALC260 configurations
7405  */
7406 static const char * const alc260_models[ALC260_MODEL_LAST] = {
7407         [ALC260_BASIC]          = "basic",
7408         [ALC260_HP]             = "hp",
7409         [ALC260_HP_3013]        = "hp-3013",
7410         [ALC260_HP_DC7600]      = "hp-dc7600",
7411         [ALC260_FUJITSU_S702X]  = "fujitsu",
7412         [ALC260_ACER]           = "acer",
7413         [ALC260_WILL]           = "will",
7414         [ALC260_REPLACER_672V]  = "replacer",
7415         [ALC260_FAVORIT100]     = "favorit100",
7416 #ifdef CONFIG_SND_DEBUG
7417         [ALC260_TEST]           = "test",
7418 #endif
7419         [ALC260_AUTO]           = "auto",
7420 };
7421
7422 static const struct snd_pci_quirk alc260_cfg_tbl[] = {
7423         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
7424         SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL),
7425         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
7426         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
7427         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
7428         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
7429         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
7430         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
7431         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
7432         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
7433         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
7434         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
7435         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
7436         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
7437         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
7438         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
7439         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
7440         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
7441         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
7442         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
7443         {}
7444 };
7445
7446 static const struct alc_config_preset alc260_presets[] = {
7447         [ALC260_BASIC] = {
7448                 .mixers = { alc260_base_output_mixer,
7449                             alc260_input_mixer },
7450                 .init_verbs = { alc260_init_verbs },
7451                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7452                 .dac_nids = alc260_dac_nids,
7453                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7454                 .adc_nids = alc260_dual_adc_nids,
7455                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7456                 .channel_mode = alc260_modes,
7457                 .input_mux = &alc260_capture_source,
7458         },
7459         [ALC260_HP] = {
7460                 .mixers = { alc260_hp_output_mixer,
7461                             alc260_input_mixer },
7462                 .init_verbs = { alc260_init_verbs,
7463                                 alc260_hp_unsol_verbs },
7464                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7465                 .dac_nids = alc260_dac_nids,
7466                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
7467                 .adc_nids = alc260_adc_nids_alt,
7468                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7469                 .channel_mode = alc260_modes,
7470                 .input_mux = &alc260_capture_source,
7471                 .unsol_event = alc_sku_unsol_event,
7472                 .setup = alc260_hp_setup,
7473                 .init_hook = alc_inithook,
7474         },
7475         [ALC260_HP_DC7600] = {
7476                 .mixers = { alc260_hp_dc7600_mixer,
7477                             alc260_input_mixer },
7478                 .init_verbs = { alc260_init_verbs,
7479                                 alc260_hp_dc7600_verbs },
7480                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7481                 .dac_nids = alc260_dac_nids,
7482                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
7483                 .adc_nids = alc260_adc_nids_alt,
7484                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7485                 .channel_mode = alc260_modes,
7486                 .input_mux = &alc260_capture_source,
7487                 .unsol_event = alc_sku_unsol_event,
7488                 .setup = alc260_hp_3012_setup,
7489                 .init_hook = alc_inithook,
7490         },
7491         [ALC260_HP_3013] = {
7492                 .mixers = { alc260_hp_3013_mixer,
7493                             alc260_input_mixer },
7494                 .init_verbs = { alc260_hp_3013_init_verbs,
7495                                 alc260_hp_3013_unsol_verbs },
7496                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7497                 .dac_nids = alc260_dac_nids,
7498                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
7499                 .adc_nids = alc260_adc_nids_alt,
7500                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7501                 .channel_mode = alc260_modes,
7502                 .input_mux = &alc260_capture_source,
7503                 .unsol_event = alc_sku_unsol_event,
7504                 .setup = alc260_hp_3013_setup,
7505                 .init_hook = alc_inithook,
7506         },
7507         [ALC260_FUJITSU_S702X] = {
7508                 .mixers = { alc260_fujitsu_mixer },
7509                 .init_verbs = { alc260_fujitsu_init_verbs },
7510                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7511                 .dac_nids = alc260_dac_nids,
7512                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7513                 .adc_nids = alc260_dual_adc_nids,
7514                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7515                 .channel_mode = alc260_modes,
7516                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
7517                 .input_mux = alc260_fujitsu_capture_sources,
7518         },
7519         [ALC260_ACER] = {
7520                 .mixers = { alc260_acer_mixer },
7521                 .init_verbs = { alc260_acer_init_verbs },
7522                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7523                 .dac_nids = alc260_dac_nids,
7524                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7525                 .adc_nids = alc260_dual_adc_nids,
7526                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7527                 .channel_mode = alc260_modes,
7528                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
7529                 .input_mux = alc260_acer_capture_sources,
7530         },
7531         [ALC260_FAVORIT100] = {
7532                 .mixers = { alc260_favorit100_mixer },
7533                 .init_verbs = { alc260_favorit100_init_verbs },
7534                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7535                 .dac_nids = alc260_dac_nids,
7536                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7537                 .adc_nids = alc260_dual_adc_nids,
7538                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7539                 .channel_mode = alc260_modes,
7540                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
7541                 .input_mux = alc260_favorit100_capture_sources,
7542         },
7543         [ALC260_WILL] = {
7544                 .mixers = { alc260_will_mixer },
7545                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
7546                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7547                 .dac_nids = alc260_dac_nids,
7548                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
7549                 .adc_nids = alc260_adc_nids,
7550                 .dig_out_nid = ALC260_DIGOUT_NID,
7551                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7552                 .channel_mode = alc260_modes,
7553                 .input_mux = &alc260_capture_source,
7554         },
7555         [ALC260_REPLACER_672V] = {
7556                 .mixers = { alc260_replacer_672v_mixer },
7557                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
7558                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7559                 .dac_nids = alc260_dac_nids,
7560                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
7561                 .adc_nids = alc260_adc_nids,
7562                 .dig_out_nid = ALC260_DIGOUT_NID,
7563                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7564                 .channel_mode = alc260_modes,
7565                 .input_mux = &alc260_capture_source,
7566                 .unsol_event = alc260_replacer_672v_unsol_event,
7567                 .init_hook = alc260_replacer_672v_automute,
7568         },
7569 #ifdef CONFIG_SND_DEBUG
7570         [ALC260_TEST] = {
7571                 .mixers = { alc260_test_mixer },
7572                 .init_verbs = { alc260_test_init_verbs },
7573                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
7574                 .dac_nids = alc260_test_dac_nids,
7575                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
7576                 .adc_nids = alc260_test_adc_nids,
7577                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7578                 .channel_mode = alc260_modes,
7579                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
7580                 .input_mux = alc260_test_capture_sources,
7581         },
7582 #endif
7583 };
7584
7585 static int patch_alc260(struct hda_codec *codec)
7586 {
7587         struct alc_spec *spec;
7588         int err, board_config;
7589
7590         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7591         if (spec == NULL)
7592                 return -ENOMEM;
7593
7594         codec->spec = spec;
7595
7596         spec->mixer_nid = 0x07;
7597
7598         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
7599                                                   alc260_models,
7600                                                   alc260_cfg_tbl);
7601         if (board_config < 0) {
7602                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
7603                            codec->chip_name);
7604                 board_config = ALC260_AUTO;
7605         }
7606
7607         if (board_config == ALC260_AUTO) {
7608                 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
7609                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7610         }
7611
7612         if (board_config == ALC260_AUTO) {
7613                 /* automatic parse from the BIOS config */
7614                 err = alc260_parse_auto_config(codec);
7615                 if (err < 0) {
7616                         alc_free(codec);
7617                         return err;
7618                 } else if (!err) {
7619                         printk(KERN_INFO
7620                                "hda_codec: Cannot set up configuration "
7621                                "from BIOS.  Using base mode...\n");
7622                         board_config = ALC260_BASIC;
7623                 }
7624         }
7625
7626         err = snd_hda_attach_beep_device(codec, 0x1);
7627         if (err < 0) {
7628                 alc_free(codec);
7629                 return err;
7630         }
7631
7632         if (board_config != ALC260_AUTO)
7633                 setup_preset(codec, &alc260_presets[board_config]);
7634
7635         spec->stream_analog_playback = &alc260_pcm_analog_playback;
7636         spec->stream_analog_capture = &alc260_pcm_analog_capture;
7637         spec->stream_analog_alt_capture = &alc260_pcm_analog_capture;
7638
7639         spec->stream_digital_playback = &alc260_pcm_digital_playback;
7640         spec->stream_digital_capture = &alc260_pcm_digital_capture;
7641
7642         if (!spec->adc_nids && spec->input_mux) {
7643                 /* check whether NID 0x04 is valid */
7644                 unsigned int wcap = get_wcaps(codec, 0x04);
7645                 wcap = get_wcaps_type(wcap);
7646                 /* get type */
7647                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
7648                         spec->adc_nids = alc260_adc_nids_alt;
7649                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
7650                 } else {
7651                         spec->adc_nids = alc260_adc_nids;
7652                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
7653                 }
7654         }
7655         set_capture_mixer(codec);
7656         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
7657
7658         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7659
7660         spec->vmaster_nid = 0x08;
7661
7662         codec->patch_ops = alc_patch_ops;
7663         if (board_config == ALC260_AUTO)
7664                 spec->init_hook = alc260_auto_init;
7665         spec->shutup = alc_eapd_shutup;
7666 #ifdef CONFIG_SND_HDA_POWER_SAVE
7667         if (!spec->loopback.amplist)
7668                 spec->loopback.amplist = alc260_loopbacks;
7669 #endif
7670
7671         return 0;
7672 }
7673
7674
7675 /*
7676  * ALC882/883/885/888/889 support
7677  *
7678  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
7679  * configuration.  Each pin widget can choose any input DACs and a mixer.
7680  * Each ADC is connected from a mixer of all inputs.  This makes possible
7681  * 6-channel independent captures.
7682  *
7683  * In addition, an independent DAC for the multi-playback (not used in this
7684  * driver yet).
7685  */
7686 #define ALC882_DIGOUT_NID       0x06
7687 #define ALC882_DIGIN_NID        0x0a
7688 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
7689 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
7690 #define ALC1200_DIGOUT_NID      0x10
7691
7692
7693 static const struct hda_channel_mode alc882_ch_modes[1] = {
7694         { 8, NULL }
7695 };
7696
7697 /* DACs */
7698 static const hda_nid_t alc882_dac_nids[4] = {
7699         /* front, rear, clfe, rear_surr */
7700         0x02, 0x03, 0x04, 0x05
7701 };
7702 #define alc883_dac_nids         alc882_dac_nids
7703
7704 /* ADCs */
7705 #define alc882_adc_nids         alc880_adc_nids
7706 #define alc882_adc_nids_alt     alc880_adc_nids_alt
7707 #define alc883_adc_nids         alc882_adc_nids_alt
7708 static const hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
7709 static const hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
7710 #define alc889_adc_nids         alc880_adc_nids
7711
7712 static const hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
7713 static const hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
7714 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
7715 static const hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7716 #define alc889_capsrc_nids      alc882_capsrc_nids
7717
7718 /* input MUX */
7719 /* FIXME: should be a matrix-type input source selection */
7720
7721 static const struct hda_input_mux alc882_capture_source = {
7722         .num_items = 4,
7723         .items = {
7724                 { "Mic", 0x0 },
7725                 { "Front Mic", 0x1 },
7726                 { "Line", 0x2 },
7727                 { "CD", 0x4 },
7728         },
7729 };
7730
7731 #define alc883_capture_source   alc882_capture_source
7732
7733 static const struct hda_input_mux alc889_capture_source = {
7734         .num_items = 3,
7735         .items = {
7736                 { "Front Mic", 0x0 },
7737                 { "Mic", 0x3 },
7738                 { "Line", 0x2 },
7739         },
7740 };
7741
7742 static const struct hda_input_mux mb5_capture_source = {
7743         .num_items = 3,
7744         .items = {
7745                 { "Mic", 0x1 },
7746                 { "Line", 0x7 },
7747                 { "CD", 0x4 },
7748         },
7749 };
7750
7751 static const struct hda_input_mux macmini3_capture_source = {
7752         .num_items = 2,
7753         .items = {
7754                 { "Line", 0x2 },
7755                 { "CD", 0x4 },
7756         },
7757 };
7758
7759 static const struct hda_input_mux alc883_3stack_6ch_intel = {
7760         .num_items = 4,
7761         .items = {
7762                 { "Mic", 0x1 },
7763                 { "Front Mic", 0x0 },
7764                 { "Line", 0x2 },
7765                 { "CD", 0x4 },
7766         },
7767 };
7768
7769 static const struct hda_input_mux alc883_lenovo_101e_capture_source = {
7770         .num_items = 2,
7771         .items = {
7772                 { "Mic", 0x1 },
7773                 { "Line", 0x2 },
7774         },
7775 };
7776
7777 static const struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7778         .num_items = 4,
7779         .items = {
7780                 { "Mic", 0x0 },
7781                 { "Internal Mic", 0x1 },
7782                 { "Line", 0x2 },
7783                 { "CD", 0x4 },
7784         },
7785 };
7786
7787 static const struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7788         .num_items = 2,
7789         .items = {
7790                 { "Mic", 0x0 },
7791                 { "Internal Mic", 0x1 },
7792         },
7793 };
7794
7795 static const struct hda_input_mux alc883_lenovo_sky_capture_source = {
7796         .num_items = 3,
7797         .items = {
7798                 { "Mic", 0x0 },
7799                 { "Front Mic", 0x1 },
7800                 { "Line", 0x4 },
7801         },
7802 };
7803
7804 static const struct hda_input_mux alc883_asus_eee1601_capture_source = {
7805         .num_items = 2,
7806         .items = {
7807                 { "Mic", 0x0 },
7808                 { "Line", 0x2 },
7809         },
7810 };
7811
7812 static const struct hda_input_mux alc889A_mb31_capture_source = {
7813         .num_items = 2,
7814         .items = {
7815                 { "Mic", 0x0 },
7816                 /* Front Mic (0x01) unused */
7817                 { "Line", 0x2 },
7818                 /* Line 2 (0x03) unused */
7819                 /* CD (0x04) unused? */
7820         },
7821 };
7822
7823 static const struct hda_input_mux alc889A_imac91_capture_source = {
7824         .num_items = 2,
7825         .items = {
7826                 { "Mic", 0x01 },
7827                 { "Line", 0x2 }, /* Not sure! */
7828         },
7829 };
7830
7831 /*
7832  * 2ch mode
7833  */
7834 static const struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7835         { 2, NULL }
7836 };
7837
7838 /*
7839  * 2ch mode
7840  */
7841 static const struct hda_verb alc882_3ST_ch2_init[] = {
7842         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7843         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7844         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7845         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7846         { } /* end */
7847 };
7848
7849 /*
7850  * 4ch mode
7851  */
7852 static const struct hda_verb alc882_3ST_ch4_init[] = {
7853         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7854         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7855         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7856         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7857         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7858         { } /* end */
7859 };
7860
7861 /*
7862  * 6ch mode
7863  */
7864 static const struct hda_verb alc882_3ST_ch6_init[] = {
7865         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7866         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7867         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7868         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7869         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7870         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7871         { } /* end */
7872 };
7873
7874 static const struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
7875         { 2, alc882_3ST_ch2_init },
7876         { 4, alc882_3ST_ch4_init },
7877         { 6, alc882_3ST_ch6_init },
7878 };
7879
7880 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
7881
7882 /*
7883  * 2ch mode
7884  */
7885 static const struct hda_verb alc883_3ST_ch2_clevo_init[] = {
7886         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
7887         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7888         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7889         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7890         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7891         { } /* end */
7892 };
7893
7894 /*
7895  * 4ch mode
7896  */
7897 static const struct hda_verb alc883_3ST_ch4_clevo_init[] = {
7898         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7899         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7900         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7901         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7902         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7903         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7904         { } /* end */
7905 };
7906
7907 /*
7908  * 6ch mode
7909  */
7910 static const struct hda_verb alc883_3ST_ch6_clevo_init[] = {
7911         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7912         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7913         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7914         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7915         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7916         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7917         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7918         { } /* end */
7919 };
7920
7921 static const struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
7922         { 2, alc883_3ST_ch2_clevo_init },
7923         { 4, alc883_3ST_ch4_clevo_init },
7924         { 6, alc883_3ST_ch6_clevo_init },
7925 };
7926
7927
7928 /*
7929  * 6ch mode
7930  */
7931 static const struct hda_verb alc882_sixstack_ch6_init[] = {
7932         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7933         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7934         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7935         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7936         { } /* end */
7937 };
7938
7939 /*
7940  * 8ch mode
7941  */
7942 static const struct hda_verb alc882_sixstack_ch8_init[] = {
7943         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7944         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7945         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7946         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7947         { } /* end */
7948 };
7949
7950 static const struct hda_channel_mode alc882_sixstack_modes[2] = {
7951         { 6, alc882_sixstack_ch6_init },
7952         { 8, alc882_sixstack_ch8_init },
7953 };
7954
7955
7956 /* Macbook Air 2,1 */
7957
7958 static const struct hda_channel_mode alc885_mba21_ch_modes[1] = {
7959       { 2, NULL },
7960 };
7961
7962 /*
7963  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
7964  */
7965
7966 /*
7967  * 2ch mode
7968  */
7969 static const struct hda_verb alc885_mbp_ch2_init[] = {
7970         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7971         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7972         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7973         { } /* end */
7974 };
7975
7976 /*
7977  * 4ch mode
7978  */
7979 static const struct hda_verb alc885_mbp_ch4_init[] = {
7980         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7981         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7982         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7983         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7984         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7985         { } /* end */
7986 };
7987
7988 static const struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
7989         { 2, alc885_mbp_ch2_init },
7990         { 4, alc885_mbp_ch4_init },
7991 };
7992
7993 /*
7994  * 2ch
7995  * Speakers/Woofer/HP = Front
7996  * LineIn = Input
7997  */
7998 static const struct hda_verb alc885_mb5_ch2_init[] = {
7999         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8001         { } /* end */
8002 };
8003
8004 /*
8005  * 6ch mode
8006  * Speakers/HP = Front
8007  * Woofer = LFE
8008  * LineIn = Surround
8009  */
8010 static const struct hda_verb alc885_mb5_ch6_init[] = {
8011         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8012         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8013         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8014         { } /* end */
8015 };
8016
8017 static const struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
8018         { 2, alc885_mb5_ch2_init },
8019         { 6, alc885_mb5_ch6_init },
8020 };
8021
8022 #define alc885_macmini3_6ch_modes       alc885_mb5_6ch_modes
8023
8024 /*
8025  * 2ch mode
8026  */
8027 static const struct hda_verb alc883_4ST_ch2_init[] = {
8028         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8029         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8030         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8031         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8032         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8033         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8034         { } /* end */
8035 };
8036
8037 /*
8038  * 4ch mode
8039  */
8040 static const struct hda_verb alc883_4ST_ch4_init[] = {
8041         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8042         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8043         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8044         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8045         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8046         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8047         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8048         { } /* end */
8049 };
8050
8051 /*
8052  * 6ch mode
8053  */
8054 static const struct hda_verb alc883_4ST_ch6_init[] = {
8055         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8056         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8057         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8058         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8059         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8060         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8061         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8062         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8063         { } /* end */
8064 };
8065
8066 /*
8067  * 8ch mode
8068  */
8069 static const struct hda_verb alc883_4ST_ch8_init[] = {
8070         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8071         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8072         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
8073         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8074         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8075         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8076         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8077         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8078         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8079         { } /* end */
8080 };
8081
8082 static const struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
8083         { 2, alc883_4ST_ch2_init },
8084         { 4, alc883_4ST_ch4_init },
8085         { 6, alc883_4ST_ch6_init },
8086         { 8, alc883_4ST_ch8_init },
8087 };
8088
8089
8090 /*
8091  * 2ch mode
8092  */
8093 static const struct hda_verb alc883_3ST_ch2_intel_init[] = {
8094         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8095         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8096         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8097         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8098         { } /* end */
8099 };
8100
8101 /*
8102  * 4ch mode
8103  */
8104 static const struct hda_verb alc883_3ST_ch4_intel_init[] = {
8105         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8106         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8107         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8108         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8109         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8110         { } /* end */
8111 };
8112
8113 /*
8114  * 6ch mode
8115  */
8116 static const struct hda_verb alc883_3ST_ch6_intel_init[] = {
8117         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8118         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8119         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
8120         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8121         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8122         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8123         { } /* end */
8124 };
8125
8126 static const struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
8127         { 2, alc883_3ST_ch2_intel_init },
8128         { 4, alc883_3ST_ch4_intel_init },
8129         { 6, alc883_3ST_ch6_intel_init },
8130 };
8131
8132 /*
8133  * 2ch mode
8134  */
8135 static const struct hda_verb alc889_ch2_intel_init[] = {
8136         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
8137         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
8138         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
8139         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
8140         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8141         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8142         { } /* end */
8143 };
8144
8145 /*
8146  * 6ch mode
8147  */
8148 static const struct hda_verb alc889_ch6_intel_init[] = {
8149         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
8150         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
8151         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
8152         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
8153         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8154         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8155         { } /* end */
8156 };
8157
8158 /*
8159  * 8ch mode
8160  */
8161 static const struct hda_verb alc889_ch8_intel_init[] = {
8162         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
8163         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
8164         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
8165         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
8166         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
8167         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8168         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8169         { } /* end */
8170 };
8171
8172 static const struct hda_channel_mode alc889_8ch_intel_modes[3] = {
8173         { 2, alc889_ch2_intel_init },
8174         { 6, alc889_ch6_intel_init },
8175         { 8, alc889_ch8_intel_init },
8176 };
8177
8178 /*
8179  * 6ch mode
8180  */
8181 static const struct hda_verb alc883_sixstack_ch6_init[] = {
8182         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8183         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8184         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8185         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8186         { } /* end */
8187 };
8188
8189 /*
8190  * 8ch mode
8191  */
8192 static const struct hda_verb alc883_sixstack_ch8_init[] = {
8193         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8194         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8195         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8196         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8197         { } /* end */
8198 };
8199
8200 static const struct hda_channel_mode alc883_sixstack_modes[2] = {
8201         { 6, alc883_sixstack_ch6_init },
8202         { 8, alc883_sixstack_ch8_init },
8203 };
8204
8205
8206 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
8207  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
8208  */
8209 static const struct snd_kcontrol_new alc882_base_mixer[] = {
8210         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8211         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8212         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8213         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8214         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8215         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8216         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8217         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8218         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8219         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8220         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8221         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8222         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8223         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8224         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8225         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8226         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8227         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8228         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8229         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8230         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8231         { } /* end */
8232 };
8233
8234 /* Macbook Air 2,1 same control for HP and internal Speaker */
8235
8236 static const struct snd_kcontrol_new alc885_mba21_mixer[] = {
8237       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8238       HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 0x02, HDA_OUTPUT),
8239      { }
8240 };
8241
8242
8243 static const struct snd_kcontrol_new alc885_mbp3_mixer[] = {
8244         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8245         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
8246         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
8247         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
8248         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8249         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8250         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8251         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8252         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8253         HDA_CODEC_VOLUME("Line Boost Volume", 0x1a, 0x00, HDA_INPUT),
8254         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x00, HDA_INPUT),
8255         { } /* end */
8256 };
8257
8258 static const struct snd_kcontrol_new alc885_mb5_mixer[] = {
8259         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8260         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8261         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8262         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8263         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
8264         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
8265         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
8266         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
8267         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
8268         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
8269         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8270         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8271         HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x00, HDA_INPUT),
8272         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0x00, HDA_INPUT),
8273         { } /* end */
8274 };
8275
8276 static const struct snd_kcontrol_new alc885_macmini3_mixer[] = {
8277         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8278         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8279         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8280         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8281         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
8282         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
8283         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
8284         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
8285         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
8286         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
8287         HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x00, HDA_INPUT),
8288         { } /* end */
8289 };
8290
8291 static const struct snd_kcontrol_new alc885_imac91_mixer[] = {
8292         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8293         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
8294         { } /* end */
8295 };
8296
8297
8298 static const struct snd_kcontrol_new alc882_w2jc_mixer[] = {
8299         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8300         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8301         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8302         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8303         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8304         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8305         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8306         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8307         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8308         { } /* end */
8309 };
8310
8311 static const struct snd_kcontrol_new alc882_targa_mixer[] = {
8312         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8313         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8314         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8315         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8316         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8317         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8318         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8319         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8320         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8321         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8322         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8323         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8324         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8325         { } /* end */
8326 };
8327
8328 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
8329  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
8330  */
8331 static const struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
8332         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8333         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8334         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8335         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8336         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8337         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8338         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8339         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8340         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
8341         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
8342         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8343         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8344         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8345         { } /* end */
8346 };
8347
8348 static const struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
8349         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8350         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8351         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8352         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8353         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8354         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8355         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8356         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8357         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8358         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8359         { } /* end */
8360 };
8361
8362 static const struct snd_kcontrol_new alc882_chmode_mixer[] = {
8363         {
8364                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8365                 .name = "Channel Mode",
8366                 .info = alc_ch_mode_info,
8367                 .get = alc_ch_mode_get,
8368                 .put = alc_ch_mode_put,
8369         },
8370         { } /* end */
8371 };
8372
8373 static const struct hda_verb alc882_base_init_verbs[] = {
8374         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8375         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8376         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8377         /* Rear mixer */
8378         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8379         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8380         /* CLFE mixer */
8381         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8382         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8383         /* Side mixer */
8384         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8385         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8386
8387         /* Front Pin: output 0 (0x0c) */
8388         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8389         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8390         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8391         /* Rear Pin: output 1 (0x0d) */
8392         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8393         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8394         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8395         /* CLFE Pin: output 2 (0x0e) */
8396         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8397         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8398         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8399         /* Side Pin: output 3 (0x0f) */
8400         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8401         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8402         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8403         /* Mic (rear) pin: input vref at 80% */
8404         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8405         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8406         /* Front Mic pin: input vref at 80% */
8407         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8408         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8409         /* Line In pin: input */
8410         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8411         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8412         /* Line-2 In: Headphone output (output 0 - 0x0c) */
8413         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8414         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8415         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8416         /* CD pin widget for input */
8417         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8418
8419         /* FIXME: use matrix-type input source selection */
8420         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8421         /* Input mixer2 */
8422         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8423         /* Input mixer3 */
8424         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8425         /* ADC2: mute amp left and right */
8426         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8427         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8428         /* ADC3: mute amp left and right */
8429         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8430         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8431
8432         { }
8433 };
8434
8435 static const struct hda_verb alc882_adc1_init_verbs[] = {
8436         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8437         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8438         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8439         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8440         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8441         /* ADC1: mute amp left and right */
8442         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8443         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8444         { }
8445 };
8446
8447 static const struct hda_verb alc882_eapd_verbs[] = {
8448         /* change to EAPD mode */
8449         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8450         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
8451         { }
8452 };
8453
8454 static const struct hda_verb alc889_eapd_verbs[] = {
8455         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
8456         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
8457         { }
8458 };
8459
8460 static const struct hda_verb alc_hp15_unsol_verbs[] = {
8461         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8462         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8463         {}
8464 };
8465
8466 static const struct hda_verb alc885_init_verbs[] = {
8467         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8468         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8469         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8470         /* Rear mixer */
8471         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8472         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8473         /* CLFE mixer */
8474         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8475         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8476         /* Side mixer */
8477         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8478         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8479
8480         /* Front HP Pin: output 0 (0x0c) */
8481         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8482         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8483         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8484         /* Front Pin: output 0 (0x0c) */
8485         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8486         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8487         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8488         /* Rear Pin: output 1 (0x0d) */
8489         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8490         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8491         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
8492         /* CLFE Pin: output 2 (0x0e) */
8493         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8494         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8495         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8496         /* Side Pin: output 3 (0x0f) */
8497         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8498         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8499         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8500         /* Mic (rear) pin: input vref at 80% */
8501         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8502         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8503         /* Front Mic pin: input vref at 80% */
8504         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8505         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8506         /* Line In pin: input */
8507         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8508         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8509
8510         /* Mixer elements: 0x18, , 0x1a, 0x1b */
8511         /* Input mixer1 */
8512         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8513         /* Input mixer2 */
8514         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8515         /* Input mixer3 */
8516         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8517         /* ADC2: mute amp left and right */
8518         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8519         /* ADC3: mute amp left and right */
8520         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8521
8522         { }
8523 };
8524
8525 static const struct hda_verb alc885_init_input_verbs[] = {
8526         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8527         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8528         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8529         { }
8530 };
8531
8532
8533 /* Unmute Selector 24h and set the default input to front mic */
8534 static const struct hda_verb alc889_init_input_verbs[] = {
8535         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
8536         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8537         { }
8538 };
8539
8540
8541 #define alc883_init_verbs       alc882_base_init_verbs
8542
8543 /* Mac Pro test */
8544 static const struct snd_kcontrol_new alc882_macpro_mixer[] = {
8545         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8546         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8547         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
8548         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8549         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8550         /* FIXME: this looks suspicious...
8551         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
8552         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
8553         */
8554         { } /* end */
8555 };
8556
8557 static const struct hda_verb alc882_macpro_init_verbs[] = {
8558         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8559         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8560         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8561         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8562         /* Front Pin: output 0 (0x0c) */
8563         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8564         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8565         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8566         /* Front Mic pin: input vref at 80% */
8567         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8568         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8569         /* Speaker:  output */
8570         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8571         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8572         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
8573         /* Headphone output (output 0 - 0x0c) */
8574         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8575         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8576         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8577
8578         /* FIXME: use matrix-type input source selection */
8579         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8580         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8581         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8582         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8583         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8584         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8585         /* Input mixer2 */
8586         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8587         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8588         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8589         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8590         /* Input mixer3 */
8591         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8592         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8593         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8594         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8595         /* ADC1: mute amp left and right */
8596         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8597         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8598         /* ADC2: mute amp left and right */
8599         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8600         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8601         /* ADC3: mute amp left and right */
8602         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8603         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8604
8605         { }
8606 };
8607
8608 /* Macbook 5,1 */
8609 static const struct hda_verb alc885_mb5_init_verbs[] = {
8610         /* DACs */
8611         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8612         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8613         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8614         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8615         /* Front mixer */
8616         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8617         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8618         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8619         /* Surround mixer */
8620         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8621         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8622         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8623         /* LFE mixer */
8624         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8625         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8626         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8627         /* HP mixer */
8628         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8629         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8630         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8631         /* Front Pin (0x0c) */
8632         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8633         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8634         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8635         /* LFE Pin (0x0e) */
8636         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8637         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8638         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
8639         /* HP Pin (0x0f) */
8640         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8641         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8642         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
8643         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8644         /* Front Mic pin: input vref at 80% */
8645         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8646         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8647         /* Line In pin */
8648         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8649         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8650
8651         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0x1)},
8652         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x7)},
8653         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x4)},
8654         { }
8655 };
8656
8657 /* Macmini 3,1 */
8658 static const struct hda_verb alc885_macmini3_init_verbs[] = {
8659         /* DACs */
8660         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8661         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8662         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8663         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8664         /* Front mixer */
8665         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8666         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8667         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8668         /* Surround mixer */
8669         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8670         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8671         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8672         /* LFE mixer */
8673         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8674         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8675         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8676         /* HP mixer */
8677         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8678         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8679         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8680         /* Front Pin (0x0c) */
8681         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8682         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8683         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8684         /* LFE Pin (0x0e) */
8685         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8686         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8687         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
8688         /* HP Pin (0x0f) */
8689         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8690         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8691         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
8692         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8693         /* Line In pin */
8694         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8695         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8696
8697         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8698         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8699         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8700         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8701         { }
8702 };
8703
8704
8705 static const struct hda_verb alc885_mba21_init_verbs[] = {
8706         /*Internal and HP Speaker Mixer*/
8707         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8708         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8709         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8710         /*Internal Speaker Pin (0x0c)*/
8711         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
8712         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8713         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8714         /* HP Pin: output 0 (0x0e) */
8715         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
8716         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8717         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8718         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, (ALC880_HP_EVENT | AC_USRSP_EN)},
8719         /* Line in (is hp when jack connected)*/
8720         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_VREF_50},
8721         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8722
8723         { }
8724  };
8725
8726
8727 /* Macbook Pro rev3 */
8728 static const struct hda_verb alc885_mbp3_init_verbs[] = {
8729         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8730         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8731         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8732         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8733         /* Rear mixer */
8734         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8735         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8736         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8737         /* HP mixer */
8738         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8739         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8740         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8741         /* Front Pin: output 0 (0x0c) */
8742         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8743         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8744         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8745         /* HP Pin: output 0 (0x0e) */
8746         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
8747         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8748         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
8749         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8750         /* Mic (rear) pin: input vref at 80% */
8751         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8752         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8753         /* Front Mic pin: input vref at 80% */
8754         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8755         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8756         /* Line In pin: use output 1 when in LineOut mode */
8757         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8758         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8759         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8760
8761         /* FIXME: use matrix-type input source selection */
8762         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8763         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8764         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8765         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8766         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8767         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8768         /* Input mixer2 */
8769         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8770         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8771         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8772         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8773         /* Input mixer3 */
8774         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8775         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8776         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8777         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8778         /* ADC1: mute amp left and right */
8779         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8780         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8781         /* ADC2: mute amp left and right */
8782         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8783         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8784         /* ADC3: mute amp left and right */
8785         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8786         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8787
8788         { }
8789 };
8790
8791 /* iMac 9,1 */
8792 static const struct hda_verb alc885_imac91_init_verbs[] = {
8793         /* Internal Speaker Pin (0x0c) */
8794         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
8795         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8796         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8797         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
8798         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8799         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8800         /* HP Pin: Rear */
8801         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8802         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8803         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8804         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, (ALC880_HP_EVENT | AC_USRSP_EN)},
8805         /* Line in Rear */
8806         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_VREF_50},
8807         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8808         /* Front Mic pin: input vref at 80% */
8809         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8810         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8811         /* Rear mixer */
8812         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8813         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8814         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8815         /* Line-Out mixer: unmute input/output amp left and right (volume = 0) */
8816         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8817         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8818         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8819         /* 0x24 [Audio Mixer] wcaps 0x20010b: Stereo Amp-In */
8820         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8821         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8822         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8823         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8824         /* 0x23 [Audio Mixer] wcaps 0x20010b: Stereo Amp-In */
8825         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8826         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8827         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8828         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8829         /* 0x22 [Audio Mixer] wcaps 0x20010b: Stereo Amp-In */
8830         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8831         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8832         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8833         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8834         /* 0x07 [Audio Input] wcaps 0x10011b: Stereo Amp-In */
8835         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8836         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8837         /* 0x08 [Audio Input] wcaps 0x10011b: Stereo Amp-In */
8838         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8839         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8840         /* 0x09 [Audio Input] wcaps 0x10011b: Stereo Amp-In */
8841         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8842         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8843         { }
8844 };
8845
8846 /* iMac 24 mixer. */
8847 static const struct snd_kcontrol_new alc885_imac24_mixer[] = {
8848         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8849         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
8850         { } /* end */
8851 };
8852
8853 /* iMac 24 init verbs. */
8854 static const struct hda_verb alc885_imac24_init_verbs[] = {
8855         /* Internal speakers: output 0 (0x0c) */
8856         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8857         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8858         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8859         /* Internal speakers: output 0 (0x0c) */
8860         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8861         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8862         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8863         /* Headphone: output 0 (0x0c) */
8864         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8865         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8866         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8867         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8868         /* Front Mic: input vref at 80% */
8869         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8870         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8871         { }
8872 };
8873
8874 /* Toggle speaker-output according to the hp-jack state */
8875 static void alc885_imac24_setup(struct hda_codec *codec)
8876 {
8877         struct alc_spec *spec = codec->spec;
8878
8879         spec->autocfg.hp_pins[0] = 0x14;
8880         spec->autocfg.speaker_pins[0] = 0x18;
8881         spec->autocfg.speaker_pins[1] = 0x1a;
8882         spec->automute = 1;
8883         spec->automute_mode = ALC_AUTOMUTE_AMP;
8884 }
8885
8886 #define alc885_mb5_setup        alc885_imac24_setup
8887 #define alc885_macmini3_setup   alc885_imac24_setup
8888
8889 /* Macbook Air 2,1 */
8890 static void alc885_mba21_setup(struct hda_codec *codec)
8891 {
8892        struct alc_spec *spec = codec->spec;
8893
8894        spec->autocfg.hp_pins[0] = 0x14;
8895        spec->autocfg.speaker_pins[0] = 0x18;
8896         spec->automute = 1;
8897         spec->automute_mode = ALC_AUTOMUTE_AMP;
8898 }
8899
8900
8901
8902 static void alc885_mbp3_setup(struct hda_codec *codec)
8903 {
8904         struct alc_spec *spec = codec->spec;
8905
8906         spec->autocfg.hp_pins[0] = 0x15;
8907         spec->autocfg.speaker_pins[0] = 0x14;
8908         spec->automute = 1;
8909         spec->automute_mode = ALC_AUTOMUTE_AMP;
8910 }
8911
8912 static void alc885_imac91_setup(struct hda_codec *codec)
8913 {
8914         struct alc_spec *spec = codec->spec;
8915
8916         spec->autocfg.hp_pins[0] = 0x14;
8917         spec->autocfg.speaker_pins[0] = 0x18;
8918         spec->autocfg.speaker_pins[1] = 0x1a;
8919         spec->automute = 1;
8920         spec->automute_mode = ALC_AUTOMUTE_AMP;
8921 }
8922
8923 static const struct hda_verb alc882_targa_verbs[] = {
8924         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8925         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8926
8927         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8928         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8929
8930         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8931         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8932         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8933
8934         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8935         { } /* end */
8936 };
8937
8938 /* toggle speaker-output according to the hp-jack state */
8939 static void alc882_targa_automute(struct hda_codec *codec)
8940 {
8941         struct alc_spec *spec = codec->spec;
8942         alc_hp_automute(codec);
8943         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8944                                   spec->jack_present ? 1 : 3);
8945 }
8946
8947 static void alc882_targa_setup(struct hda_codec *codec)
8948 {
8949         struct alc_spec *spec = codec->spec;
8950
8951         spec->autocfg.hp_pins[0] = 0x14;
8952         spec->autocfg.speaker_pins[0] = 0x1b;
8953         spec->automute = 1;
8954         spec->automute_mode = ALC_AUTOMUTE_AMP;
8955 }
8956
8957 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
8958 {
8959         if ((res >> 26) == ALC880_HP_EVENT)
8960                 alc882_targa_automute(codec);
8961 }
8962
8963 static const struct hda_verb alc882_asus_a7j_verbs[] = {
8964         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8965         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8966
8967         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8968         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8969         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8970
8971         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8972         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8973         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8974
8975         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8976         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8977         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8978         { } /* end */
8979 };
8980
8981 static const struct hda_verb alc882_asus_a7m_verbs[] = {
8982         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8983         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8984
8985         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8986         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8987         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8988
8989         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8990         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8991         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8992
8993         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8994         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8995         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8996         { } /* end */
8997 };
8998
8999 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
9000 {
9001         unsigned int gpiostate, gpiomask, gpiodir;
9002
9003         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
9004                                        AC_VERB_GET_GPIO_DATA, 0);
9005
9006         if (!muted)
9007                 gpiostate |= (1 << pin);
9008         else
9009                 gpiostate &= ~(1 << pin);
9010
9011         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
9012                                       AC_VERB_GET_GPIO_MASK, 0);
9013         gpiomask |= (1 << pin);
9014
9015         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
9016                                      AC_VERB_GET_GPIO_DIRECTION, 0);
9017         gpiodir |= (1 << pin);
9018
9019
9020         snd_hda_codec_write(codec, codec->afg, 0,
9021                             AC_VERB_SET_GPIO_MASK, gpiomask);
9022         snd_hda_codec_write(codec, codec->afg, 0,
9023                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
9024
9025         msleep(1);
9026
9027         snd_hda_codec_write(codec, codec->afg, 0,
9028                             AC_VERB_SET_GPIO_DATA, gpiostate);
9029 }
9030
9031 /* set up GPIO at initialization */
9032 static void alc885_macpro_init_hook(struct hda_codec *codec)
9033 {
9034         alc882_gpio_mute(codec, 0, 0);
9035         alc882_gpio_mute(codec, 1, 0);
9036 }
9037
9038 /* set up GPIO and update auto-muting at initialization */
9039 static void alc885_imac24_init_hook(struct hda_codec *codec)
9040 {
9041         alc885_macpro_init_hook(codec);
9042         alc_hp_automute(codec);
9043 }
9044
9045 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
9046 static const struct hda_verb alc889A_mb31_ch2_init[] = {
9047         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
9048         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
9049         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
9050         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
9051         { } /* end */
9052 };
9053
9054 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
9055 static const struct hda_verb alc889A_mb31_ch4_init[] = {
9056         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
9057         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
9058         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
9059         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
9060         { } /* end */
9061 };
9062
9063 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
9064 static const struct hda_verb alc889A_mb31_ch5_init[] = {
9065         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
9066         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
9067         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
9068         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
9069         { } /* end */
9070 };
9071
9072 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
9073 static const struct hda_verb alc889A_mb31_ch6_init[] = {
9074         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
9075         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
9076         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
9077         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
9078         { } /* end */
9079 };
9080
9081 static const struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
9082         { 2, alc889A_mb31_ch2_init },
9083         { 4, alc889A_mb31_ch4_init },
9084         { 5, alc889A_mb31_ch5_init },
9085         { 6, alc889A_mb31_ch6_init },
9086 };
9087
9088 static const struct hda_verb alc883_medion_eapd_verbs[] = {
9089         /* eanable EAPD on medion laptop */
9090         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9091         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
9092         { }
9093 };
9094
9095 #define alc883_base_mixer       alc882_base_mixer
9096
9097 static const struct snd_kcontrol_new alc883_mitac_mixer[] = {
9098         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9099         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9100         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9101         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9102         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9103         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9104         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9105         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9106         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9107         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9108         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9109         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9110         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9111         { } /* end */
9112 };
9113
9114 static const struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
9115         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9116         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
9117         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9118         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
9119         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9120         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9121         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9122         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9123         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9124         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9125         { } /* end */
9126 };
9127
9128 static const struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
9129         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9130         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
9131         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9132         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
9133         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9134         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9135         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9136         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9137         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9138         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9139         { } /* end */
9140 };
9141
9142 static const struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
9143         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9144         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9145         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9146         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9147         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9148         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9149         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9150         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9151         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9152         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9153         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9154         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9155         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9156         { } /* end */
9157 };
9158
9159 static const struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
9160         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9161         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9162         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9163         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9164         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9165         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9166         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9167         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9168         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9169         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9170         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9171         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9172         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9173         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9174         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9175         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9176         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9177         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9178         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9179         { } /* end */
9180 };
9181
9182 static const struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
9183         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9184         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9185         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9186         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9187         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
9188                               HDA_OUTPUT),
9189         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9190         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9191         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9192         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9193         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9194         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9195         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9196         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9197         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9198         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
9199         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9200         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9201         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x18, 0, HDA_INPUT),
9202         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9203         { } /* end */
9204 };
9205
9206 static const struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
9207         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9208         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9209         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9210         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9211         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
9212                               HDA_OUTPUT),
9213         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9214         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9215         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9216         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9217         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
9218         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9219         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9220         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9221         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
9222         HDA_CODEC_VOLUME("Mic Boost Volume", 0x1b, 0, HDA_INPUT),
9223         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
9224         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9225         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x18, 0, HDA_INPUT),
9226         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9227         { } /* end */
9228 };
9229
9230 static const struct snd_kcontrol_new alc883_fivestack_mixer[] = {
9231         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9232         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9233         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9234         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9235         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9236         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9237         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9238         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9239         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9240         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9241         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9242         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9243         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9244         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9245         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9246         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9247         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9248         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9249         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9250         { } /* end */
9251 };
9252
9253 static const struct snd_kcontrol_new alc883_targa_mixer[] = {
9254         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9255         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9256         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9257         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9258         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9259         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9260         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9261         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9262         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9263         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9264         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9265         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9266         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9267         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9268         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9269         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9270         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9271         { } /* end */
9272 };
9273
9274 static const struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
9275         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9276         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9277         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9278         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9279         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9280         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9281         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9282         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9283         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9284         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9285         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9286         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9287         { } /* end */
9288 };
9289
9290 static const struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
9291         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9292         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
9293         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9294         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9295         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9296         { } /* end */
9297 };
9298
9299 static const struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
9300         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9301         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9302         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9303         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
9304         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9305         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9306         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9307         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9308         { } /* end */
9309 };
9310
9311 static const struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
9312         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9313         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
9314         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9315         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9316         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9317         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9318         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9319         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9320         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9321         { } /* end */
9322 };
9323
9324 static const struct snd_kcontrol_new alc883_medion_wim2160_mixer[] = {
9325         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9326         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9327         HDA_CODEC_MUTE("Speaker Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9328         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
9329         HDA_CODEC_VOLUME("Line Playback Volume", 0x08, 0x0, HDA_INPUT),
9330         HDA_CODEC_MUTE("Line Playback Switch", 0x08, 0x0, HDA_INPUT),
9331         { } /* end */
9332 };
9333
9334 static const struct hda_verb alc883_medion_wim2160_verbs[] = {
9335         /* Unmute front mixer */
9336         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9337         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9338
9339         /* Set speaker pin to front mixer */
9340         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9341
9342         /* Init headphone pin */
9343         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9344         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9345         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
9346         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9347
9348         { } /* end */
9349 };
9350
9351 /* toggle speaker-output according to the hp-jack state */
9352 static void alc883_medion_wim2160_setup(struct hda_codec *codec)
9353 {
9354         struct alc_spec *spec = codec->spec;
9355
9356         spec->autocfg.hp_pins[0] = 0x1a;
9357         spec->autocfg.speaker_pins[0] = 0x15;
9358         spec->automute = 1;
9359         spec->automute_mode = ALC_AUTOMUTE_AMP;
9360 }
9361
9362 static const struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
9363         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9364         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9365         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9366         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9367         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9368         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9369         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9370         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9371         { } /* end */
9372 };
9373
9374 static const struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
9375         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9376         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9377         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9378         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9379         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9380         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9381         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9382         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9383         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9384         { } /* end */
9385 };
9386
9387 static const struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
9388         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9389         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9390         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9391         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
9392         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
9393                                                 0x0d, 1, 0x0, HDA_OUTPUT),
9394         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
9395         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
9396         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
9397         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9398         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
9399         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9400         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9401         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9402         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9403         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9404         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9405         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9406         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9407         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9408         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9409         { } /* end */
9410 };
9411
9412 static const struct snd_kcontrol_new alc889A_mb31_mixer[] = {
9413         /* Output mixers */
9414         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
9415         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
9416         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
9417         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
9418         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
9419                 HDA_OUTPUT),
9420         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
9421         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
9422         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
9423         /* Output switches */
9424         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
9425         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
9426         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
9427         /* Boost mixers */
9428         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x00, HDA_INPUT),
9429         HDA_CODEC_VOLUME("Line Boost Volume", 0x1a, 0x00, HDA_INPUT),
9430         /* Input mixers */
9431         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
9432         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
9433         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9434         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9435         { } /* end */
9436 };
9437
9438 static const struct snd_kcontrol_new alc883_vaiott_mixer[] = {
9439         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9440         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9441         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9442         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9443         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
9444         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9445         { } /* end */
9446 };
9447
9448 static const struct hda_bind_ctls alc883_bind_cap_vol = {
9449         .ops = &snd_hda_bind_vol,
9450         .values = {
9451                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
9452                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
9453                 0
9454         },
9455 };
9456
9457 static const struct hda_bind_ctls alc883_bind_cap_switch = {
9458         .ops = &snd_hda_bind_sw,
9459         .values = {
9460                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
9461                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
9462                 0
9463         },
9464 };
9465
9466 static const struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
9467         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9468         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9469         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9470         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9471         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9472         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9473         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9474         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9475         { } /* end */
9476 };
9477
9478 static const struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
9479         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
9480         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
9481         {
9482                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9483                 /* .name = "Capture Source", */
9484                 .name = "Input Source",
9485                 .count = 1,
9486                 .info = alc_mux_enum_info,
9487                 .get = alc_mux_enum_get,
9488                 .put = alc_mux_enum_put,
9489         },
9490         { } /* end */
9491 };
9492
9493 static const struct snd_kcontrol_new alc883_chmode_mixer[] = {
9494         {
9495                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9496                 .name = "Channel Mode",
9497                 .info = alc_ch_mode_info,
9498                 .get = alc_ch_mode_get,
9499                 .put = alc_ch_mode_put,
9500         },
9501         { } /* end */
9502 };
9503
9504 /* toggle speaker-output according to the hp-jack state */
9505 static void alc883_mitac_setup(struct hda_codec *codec)
9506 {
9507         struct alc_spec *spec = codec->spec;
9508
9509         spec->autocfg.hp_pins[0] = 0x15;
9510         spec->autocfg.speaker_pins[0] = 0x14;
9511         spec->autocfg.speaker_pins[1] = 0x17;
9512         spec->automute = 1;
9513         spec->automute_mode = ALC_AUTOMUTE_AMP;
9514 }
9515
9516 static const struct hda_verb alc883_mitac_verbs[] = {
9517         /* HP */
9518         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9519         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9520         /* Subwoofer */
9521         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
9522         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9523
9524         /* enable unsolicited event */
9525         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9526         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
9527
9528         { } /* end */
9529 };
9530
9531 static const struct hda_verb alc883_clevo_m540r_verbs[] = {
9532         /* HP */
9533         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9534         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9535         /* Int speaker */
9536         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
9537
9538         /* enable unsolicited event */
9539         /*
9540         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9541         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9542         */
9543
9544         { } /* end */
9545 };
9546
9547 static const struct hda_verb alc883_clevo_m720_verbs[] = {
9548         /* HP */
9549         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9550         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9551         /* Int speaker */
9552         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
9553         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9554
9555         /* enable unsolicited event */
9556         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9557         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9558
9559         { } /* end */
9560 };
9561
9562 static const struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
9563         /* HP */
9564         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9565         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9566         /* Subwoofer */
9567         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9568         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9569
9570         /* enable unsolicited event */
9571         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9572
9573         { } /* end */
9574 };
9575
9576 static const struct hda_verb alc883_targa_verbs[] = {
9577         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9578         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9579
9580         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9581         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9582
9583 /* Connect Line-Out side jack (SPDIF) to Side */
9584         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9585         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9586         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
9587 /* Connect Mic jack to CLFE */
9588         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9589         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9590         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
9591 /* Connect Line-in jack to Surround */
9592         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9593         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9594         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
9595 /* Connect HP out jack to Front */
9596         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9597         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9598         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9599
9600         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9601
9602         { } /* end */
9603 };
9604
9605 static const struct hda_verb alc883_lenovo_101e_verbs[] = {
9606         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9607         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
9608         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
9609         { } /* end */
9610 };
9611
9612 static const struct hda_verb alc883_lenovo_nb0763_verbs[] = {
9613         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9614         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9615         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9616         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9617         { } /* end */
9618 };
9619
9620 static const struct hda_verb alc888_lenovo_ms7195_verbs[] = {
9621         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9622         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9623         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9624         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
9625         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
9626         { } /* end */
9627 };
9628
9629 static const struct hda_verb alc883_haier_w66_verbs[] = {
9630         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9631         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9632
9633         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9634
9635         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9636         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9637         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9638         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9639         { } /* end */
9640 };
9641
9642 static const struct hda_verb alc888_lenovo_sky_verbs[] = {
9643         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9644         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9645         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9646         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9647         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9648         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9649         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
9650         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9651         { } /* end */
9652 };
9653
9654 static const struct hda_verb alc888_6st_dell_verbs[] = {
9655         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9656         { }
9657 };
9658
9659 static const struct hda_verb alc883_vaiott_verbs[] = {
9660         /* HP */
9661         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9662         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9663
9664         /* enable unsolicited event */
9665         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9666
9667         { } /* end */
9668 };
9669
9670 static void alc888_3st_hp_setup(struct hda_codec *codec)
9671 {
9672         struct alc_spec *spec = codec->spec;
9673
9674         spec->autocfg.hp_pins[0] = 0x1b;
9675         spec->autocfg.speaker_pins[0] = 0x14;
9676         spec->autocfg.speaker_pins[1] = 0x16;
9677         spec->autocfg.speaker_pins[2] = 0x18;
9678         spec->automute = 1;
9679         spec->automute_mode = ALC_AUTOMUTE_AMP;
9680 }
9681
9682 static const struct hda_verb alc888_3st_hp_verbs[] = {
9683         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
9684         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
9685         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
9686         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9687         { } /* end */
9688 };
9689
9690 /*
9691  * 2ch mode
9692  */
9693 static const struct hda_verb alc888_3st_hp_2ch_init[] = {
9694         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
9695         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
9696         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
9697         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
9698         { } /* end */
9699 };
9700
9701 /*
9702  * 4ch mode
9703  */
9704 static const struct hda_verb alc888_3st_hp_4ch_init[] = {
9705         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
9706         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
9707         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9708         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9709         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
9710         { } /* end */
9711 };
9712
9713 /*
9714  * 6ch mode
9715  */
9716 static const struct hda_verb alc888_3st_hp_6ch_init[] = {
9717         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9718         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9719         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
9720         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9721         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9722         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
9723         { } /* end */
9724 };
9725
9726 static const struct hda_channel_mode alc888_3st_hp_modes[3] = {
9727         { 2, alc888_3st_hp_2ch_init },
9728         { 4, alc888_3st_hp_4ch_init },
9729         { 6, alc888_3st_hp_6ch_init },
9730 };
9731
9732 static void alc888_lenovo_ms7195_setup(struct hda_codec *codec)
9733 {
9734         struct alc_spec *spec = codec->spec;
9735
9736         spec->autocfg.hp_pins[0] = 0x1b;
9737         spec->autocfg.line_out_pins[0] = 0x14;
9738         spec->autocfg.speaker_pins[0] = 0x15;
9739         spec->automute = 1;
9740         spec->automute_mode = ALC_AUTOMUTE_AMP;
9741 }
9742
9743 /* toggle speaker-output according to the hp-jack state */
9744 static void alc883_lenovo_nb0763_setup(struct hda_codec *codec)
9745 {
9746         struct alc_spec *spec = codec->spec;
9747
9748         spec->autocfg.hp_pins[0] = 0x14;
9749         spec->autocfg.speaker_pins[0] = 0x15;
9750         spec->automute = 1;
9751         spec->automute_mode = ALC_AUTOMUTE_AMP;
9752 }
9753
9754 /* toggle speaker-output according to the hp-jack state */
9755 #define alc883_targa_init_hook          alc882_targa_init_hook
9756 #define alc883_targa_unsol_event        alc882_targa_unsol_event
9757
9758 static void alc883_clevo_m720_setup(struct hda_codec *codec)
9759 {
9760         struct alc_spec *spec = codec->spec;
9761
9762         spec->autocfg.hp_pins[0] = 0x15;
9763         spec->autocfg.speaker_pins[0] = 0x14;
9764         spec->automute = 1;
9765         spec->automute_mode = ALC_AUTOMUTE_AMP;
9766 }
9767
9768 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
9769 {
9770         alc_hp_automute(codec);
9771         alc88x_simple_mic_automute(codec);
9772 }
9773
9774 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
9775                                            unsigned int res)
9776 {
9777         switch (res >> 26) {
9778         case ALC880_MIC_EVENT:
9779                 alc88x_simple_mic_automute(codec);
9780                 break;
9781         default:
9782                 alc_sku_unsol_event(codec, res);
9783                 break;
9784         }
9785 }
9786
9787 /* toggle speaker-output according to the hp-jack state */
9788 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
9789 {
9790         struct alc_spec *spec = codec->spec;
9791
9792         spec->autocfg.hp_pins[0] = 0x14;
9793         spec->autocfg.speaker_pins[0] = 0x15;
9794         spec->automute = 1;
9795         spec->automute_mode = ALC_AUTOMUTE_AMP;
9796 }
9797
9798 static void alc883_haier_w66_setup(struct hda_codec *codec)
9799 {
9800         struct alc_spec *spec = codec->spec;
9801
9802         spec->autocfg.hp_pins[0] = 0x1b;
9803         spec->autocfg.speaker_pins[0] = 0x14;
9804         spec->automute = 1;
9805         spec->automute_mode = ALC_AUTOMUTE_AMP;
9806 }
9807
9808 static void alc883_lenovo_101e_setup(struct hda_codec *codec)
9809 {
9810         struct alc_spec *spec = codec->spec;
9811
9812         spec->autocfg.hp_pins[0] = 0x1b;
9813         spec->autocfg.line_out_pins[0] = 0x14;
9814         spec->autocfg.speaker_pins[0] = 0x15;
9815         spec->automute = 1;
9816         spec->detect_line = 1;
9817         spec->automute_lines = 1;
9818         spec->automute_mode = ALC_AUTOMUTE_AMP;
9819 }
9820
9821 /* toggle speaker-output according to the hp-jack state */
9822 static void alc883_acer_aspire_setup(struct hda_codec *codec)
9823 {
9824         struct alc_spec *spec = codec->spec;
9825
9826         spec->autocfg.hp_pins[0] = 0x14;
9827         spec->autocfg.speaker_pins[0] = 0x15;
9828         spec->autocfg.speaker_pins[1] = 0x16;
9829         spec->automute = 1;
9830         spec->automute_mode = ALC_AUTOMUTE_AMP;
9831 }
9832
9833 static const struct hda_verb alc883_acer_eapd_verbs[] = {
9834         /* HP Pin: output 0 (0x0c) */
9835         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9836         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9837         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9838         /* Front Pin: output 0 (0x0c) */
9839         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9840         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9841         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9842         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
9843         /* eanable EAPD on medion laptop */
9844         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9845         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
9846         /* enable unsolicited event */
9847         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9848         { }
9849 };
9850
9851 static void alc888_6st_dell_setup(struct hda_codec *codec)
9852 {
9853         struct alc_spec *spec = codec->spec;
9854
9855         spec->autocfg.hp_pins[0] = 0x1b;
9856         spec->autocfg.speaker_pins[0] = 0x14;
9857         spec->autocfg.speaker_pins[1] = 0x15;
9858         spec->autocfg.speaker_pins[2] = 0x16;
9859         spec->autocfg.speaker_pins[3] = 0x17;
9860         spec->automute = 1;
9861         spec->automute_mode = ALC_AUTOMUTE_AMP;
9862 }
9863
9864 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
9865 {
9866         struct alc_spec *spec = codec->spec;
9867
9868         spec->autocfg.hp_pins[0] = 0x1b;
9869         spec->autocfg.speaker_pins[0] = 0x14;
9870         spec->autocfg.speaker_pins[1] = 0x15;
9871         spec->autocfg.speaker_pins[2] = 0x16;
9872         spec->autocfg.speaker_pins[3] = 0x17;
9873         spec->autocfg.speaker_pins[4] = 0x1a;
9874         spec->automute = 1;
9875         spec->automute_mode = ALC_AUTOMUTE_AMP;
9876 }
9877
9878 static void alc883_vaiott_setup(struct hda_codec *codec)
9879 {
9880         struct alc_spec *spec = codec->spec;
9881
9882         spec->autocfg.hp_pins[0] = 0x15;
9883         spec->autocfg.speaker_pins[0] = 0x14;
9884         spec->autocfg.speaker_pins[1] = 0x17;
9885         spec->automute = 1;
9886         spec->automute_mode = ALC_AUTOMUTE_AMP;
9887 }
9888
9889 static const struct hda_verb alc888_asus_m90v_verbs[] = {
9890         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9891         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9892         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9893         /* enable unsolicited event */
9894         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9895         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9896         { } /* end */
9897 };
9898
9899 static void alc883_mode2_setup(struct hda_codec *codec)
9900 {
9901         struct alc_spec *spec = codec->spec;
9902
9903         spec->autocfg.hp_pins[0] = 0x1b;
9904         spec->autocfg.speaker_pins[0] = 0x14;
9905         spec->autocfg.speaker_pins[1] = 0x15;
9906         spec->autocfg.speaker_pins[2] = 0x16;
9907         spec->ext_mic.pin = 0x18;
9908         spec->int_mic.pin = 0x19;
9909         spec->ext_mic.mux_idx = 0;
9910         spec->int_mic.mux_idx = 1;
9911         spec->auto_mic = 1;
9912         spec->automute = 1;
9913         spec->automute_mode = ALC_AUTOMUTE_AMP;
9914 }
9915
9916 static const struct hda_verb alc888_asus_eee1601_verbs[] = {
9917         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9918         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9919         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9920         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9921         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9922         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
9923         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
9924         /* enable unsolicited event */
9925         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9926         { } /* end */
9927 };
9928
9929 static void alc883_eee1601_inithook(struct hda_codec *codec)
9930 {
9931         struct alc_spec *spec = codec->spec;
9932
9933         spec->autocfg.hp_pins[0] = 0x14;
9934         spec->autocfg.speaker_pins[0] = 0x1b;
9935         alc_hp_automute(codec);
9936 }
9937
9938 static const struct hda_verb alc889A_mb31_verbs[] = {
9939         /* Init rear pin (used as headphone output) */
9940         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
9941         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
9942         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9943         /* Init line pin (used as output in 4ch and 6ch mode) */
9944         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
9945         /* Init line 2 pin (used as headphone out by default) */
9946         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
9947         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
9948         { } /* end */
9949 };
9950
9951 /* Mute speakers according to the headphone jack state */
9952 static void alc889A_mb31_automute(struct hda_codec *codec)
9953 {
9954         unsigned int present;
9955
9956         /* Mute only in 2ch or 4ch mode */
9957         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
9958             == 0x00) {
9959                 present = snd_hda_jack_detect(codec, 0x15);
9960                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
9961                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9962                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9963                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9964         }
9965 }
9966
9967 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
9968 {
9969         if ((res >> 26) == ALC880_HP_EVENT)
9970                 alc889A_mb31_automute(codec);
9971 }
9972
9973
9974 #ifdef CONFIG_SND_HDA_POWER_SAVE
9975 #define alc882_loopbacks        alc880_loopbacks
9976 #endif
9977
9978 /* pcm configuration: identical with ALC880 */
9979 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
9980 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
9981 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
9982 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
9983
9984 static const hda_nid_t alc883_slave_dig_outs[] = {
9985         ALC1200_DIGOUT_NID, 0,
9986 };
9987
9988 static const hda_nid_t alc1200_slave_dig_outs[] = {
9989         ALC883_DIGOUT_NID, 0,
9990 };
9991
9992 /*
9993  * configuration and preset
9994  */
9995 static const char * const alc882_models[ALC882_MODEL_LAST] = {
9996         [ALC882_3ST_DIG]        = "3stack-dig",
9997         [ALC882_6ST_DIG]        = "6stack-dig",
9998         [ALC882_ARIMA]          = "arima",
9999         [ALC882_W2JC]           = "w2jc",
10000         [ALC882_TARGA]          = "targa",
10001         [ALC882_ASUS_A7J]       = "asus-a7j",
10002         [ALC882_ASUS_A7M]       = "asus-a7m",
10003         [ALC885_MACPRO]         = "macpro",
10004         [ALC885_MB5]            = "mb5",
10005         [ALC885_MACMINI3]       = "macmini3",
10006         [ALC885_MBA21]          = "mba21",
10007         [ALC885_MBP3]           = "mbp3",
10008         [ALC885_IMAC24]         = "imac24",
10009         [ALC885_IMAC91]         = "imac91",
10010         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
10011         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
10012         [ALC883_3ST_6ch]        = "3stack-6ch",
10013         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
10014         [ALC883_TARGA_DIG]      = "targa-dig",
10015         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
10016         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
10017         [ALC883_ACER]           = "acer",
10018         [ALC883_ACER_ASPIRE]    = "acer-aspire",
10019         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
10020         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
10021         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
10022         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
10023         [ALC883_MEDION]         = "medion",
10024         [ALC883_MEDION_WIM2160] = "medion-wim2160",
10025         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
10026         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
10027         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
10028         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
10029         [ALC888_LENOVO_SKY] = "lenovo-sky",
10030         [ALC883_HAIER_W66]      = "haier-w66",
10031         [ALC888_3ST_HP]         = "3stack-hp",
10032         [ALC888_6ST_DELL]       = "6stack-dell",
10033         [ALC883_MITAC]          = "mitac",
10034         [ALC883_CLEVO_M540R]    = "clevo-m540r",
10035         [ALC883_CLEVO_M720]     = "clevo-m720",
10036         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
10037         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
10038         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
10039         [ALC889A_INTEL]         = "intel-alc889a",
10040         [ALC889_INTEL]          = "intel-x58",
10041         [ALC1200_ASUS_P5Q]      = "asus-p5q",
10042         [ALC889A_MB31]          = "mb31",
10043         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
10044         [ALC882_AUTO]           = "auto",
10045 };
10046
10047 static const struct snd_pci_quirk alc882_cfg_tbl[] = {
10048         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
10049
10050         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
10051         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
10052         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
10053         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
10054         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
10055         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
10056         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
10057                 ALC888_ACER_ASPIRE_4930G),
10058         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
10059                 ALC888_ACER_ASPIRE_4930G),
10060         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
10061                 ALC888_ACER_ASPIRE_8930G),
10062         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
10063                 ALC888_ACER_ASPIRE_8930G),
10064         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
10065         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
10066         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
10067                 ALC888_ACER_ASPIRE_6530G),
10068         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
10069                 ALC888_ACER_ASPIRE_6530G),
10070         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
10071                 ALC888_ACER_ASPIRE_7730G),
10072         /* default Acer -- disabled as it causes more problems.
10073          *    model=auto should work fine now
10074          */
10075         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
10076
10077         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
10078
10079         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavilion", ALC883_6ST_DIG),
10080         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
10081         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
10082         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
10083         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
10084         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
10085
10086         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
10087         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
10088         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
10089         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
10090         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
10091         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
10092         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
10093         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
10094         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
10095         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
10096         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
10097
10098         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
10099         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
10100         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
10101         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
10102         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
10103         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
10104         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
10105         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
10106         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
10107
10108         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
10109         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
10110         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
10111         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
10112         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC882_AUTO),
10113         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
10114         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
10115         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
10116         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
10117         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
10118         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
10119         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
10120         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
10121         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
10122         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
10123         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
10124         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
10125         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
10126         SND_PCI_QUIRK(0x1462, 0x4570, "MSI Wind Top AE2220", ALC883_TARGA_DIG),
10127         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
10128         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
10129         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
10130         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
10131         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
10132         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
10133         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
10134         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
10135         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
10136         SND_PCI_QUIRK(0x1462, 0x7437, "MSI NetOn AP1900", ALC883_TARGA_DIG),
10137         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
10138         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
10139
10140         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
10141         SND_PCI_QUIRK(0x1558, 0x0571, "Clevo laptop M570U", ALC883_3ST_6ch_DIG),
10142         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
10143         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
10144         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
10145         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
10146         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
10147         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
10148         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
10149         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
10150                       ALC883_FUJITSU_PI2515),
10151         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
10152                 ALC888_FUJITSU_XA3530),
10153         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
10154         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
10155         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
10156         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
10157         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
10158         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
10159         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
10160         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
10161
10162         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
10163         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
10164         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
10165         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
10166         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
10167         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
10168         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC882_6ST_DIG),
10169
10170         {}
10171 };
10172
10173 /* codec SSID table for Intel Mac */
10174 static const struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
10175         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
10176         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
10177         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
10178         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
10179         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
10180         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
10181         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
10182         SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889A_MB31),
10183         SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_ASUS_A7M),
10184         SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC885_MBP3),
10185         SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC885_MBA21),
10186         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
10187         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
10188         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
10189         SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC885_IMAC91),
10190         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
10191         SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC885_MB5),
10192         /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
10193          * so apparently no perfect solution yet
10194          */
10195         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
10196         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
10197         SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC885_MACMINI3),
10198         {} /* terminator */
10199 };
10200
10201 static const struct alc_config_preset alc882_presets[] = {
10202         [ALC882_3ST_DIG] = {
10203                 .mixers = { alc882_base_mixer },
10204                 .init_verbs = { alc882_base_init_verbs,
10205                                 alc882_adc1_init_verbs },
10206                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10207                 .dac_nids = alc882_dac_nids,
10208                 .dig_out_nid = ALC882_DIGOUT_NID,
10209                 .dig_in_nid = ALC882_DIGIN_NID,
10210                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
10211                 .channel_mode = alc882_ch_modes,
10212                 .need_dac_fix = 1,
10213                 .input_mux = &alc882_capture_source,
10214         },
10215         [ALC882_6ST_DIG] = {
10216                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
10217                 .init_verbs = { alc882_base_init_verbs,
10218                                 alc882_adc1_init_verbs },
10219                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10220                 .dac_nids = alc882_dac_nids,
10221                 .dig_out_nid = ALC882_DIGOUT_NID,
10222                 .dig_in_nid = ALC882_DIGIN_NID,
10223                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
10224                 .channel_mode = alc882_sixstack_modes,
10225                 .input_mux = &alc882_capture_source,
10226         },
10227         [ALC882_ARIMA] = {
10228                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
10229                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10230                                 alc882_eapd_verbs },
10231                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10232                 .dac_nids = alc882_dac_nids,
10233                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
10234                 .channel_mode = alc882_sixstack_modes,
10235                 .input_mux = &alc882_capture_source,
10236         },
10237         [ALC882_W2JC] = {
10238                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
10239                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10240                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
10241                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10242                 .dac_nids = alc882_dac_nids,
10243                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
10244                 .channel_mode = alc880_threestack_modes,
10245                 .need_dac_fix = 1,
10246                 .input_mux = &alc882_capture_source,
10247                 .dig_out_nid = ALC882_DIGOUT_NID,
10248         },
10249            [ALC885_MBA21] = {
10250                         .mixers = { alc885_mba21_mixer },
10251                         .init_verbs = { alc885_mba21_init_verbs, alc880_gpio1_init_verbs },
10252                         .num_dacs = 2,
10253                         .dac_nids = alc882_dac_nids,
10254                         .channel_mode = alc885_mba21_ch_modes,
10255                         .num_channel_mode = ARRAY_SIZE(alc885_mba21_ch_modes),
10256                         .input_mux = &alc882_capture_source,
10257                         .unsol_event = alc_sku_unsol_event,
10258                         .setup = alc885_mba21_setup,
10259                         .init_hook = alc_hp_automute,
10260        },
10261         [ALC885_MBP3] = {
10262                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
10263                 .init_verbs = { alc885_mbp3_init_verbs,
10264                                 alc880_gpio1_init_verbs },
10265                 .num_dacs = 2,
10266                 .dac_nids = alc882_dac_nids,
10267                 .hp_nid = 0x04,
10268                 .channel_mode = alc885_mbp_4ch_modes,
10269                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
10270                 .input_mux = &alc882_capture_source,
10271                 .dig_out_nid = ALC882_DIGOUT_NID,
10272                 .dig_in_nid = ALC882_DIGIN_NID,
10273                 .unsol_event = alc_sku_unsol_event,
10274                 .setup = alc885_mbp3_setup,
10275                 .init_hook = alc_hp_automute,
10276         },
10277         [ALC885_MB5] = {
10278                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
10279                 .init_verbs = { alc885_mb5_init_verbs,
10280                                 alc880_gpio1_init_verbs },
10281                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10282                 .dac_nids = alc882_dac_nids,
10283                 .channel_mode = alc885_mb5_6ch_modes,
10284                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
10285                 .input_mux = &mb5_capture_source,
10286                 .dig_out_nid = ALC882_DIGOUT_NID,
10287                 .dig_in_nid = ALC882_DIGIN_NID,
10288                 .unsol_event = alc_sku_unsol_event,
10289                 .setup = alc885_mb5_setup,
10290                 .init_hook = alc_hp_automute,
10291         },
10292         [ALC885_MACMINI3] = {
10293                 .mixers = { alc885_macmini3_mixer, alc882_chmode_mixer },
10294                 .init_verbs = { alc885_macmini3_init_verbs,
10295                                 alc880_gpio1_init_verbs },
10296                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10297                 .dac_nids = alc882_dac_nids,
10298                 .channel_mode = alc885_macmini3_6ch_modes,
10299                 .num_channel_mode = ARRAY_SIZE(alc885_macmini3_6ch_modes),
10300                 .input_mux = &macmini3_capture_source,
10301                 .dig_out_nid = ALC882_DIGOUT_NID,
10302                 .dig_in_nid = ALC882_DIGIN_NID,
10303                 .unsol_event = alc_sku_unsol_event,
10304                 .setup = alc885_macmini3_setup,
10305                 .init_hook = alc_hp_automute,
10306         },
10307         [ALC885_MACPRO] = {
10308                 .mixers = { alc882_macpro_mixer },
10309                 .init_verbs = { alc882_macpro_init_verbs },
10310                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10311                 .dac_nids = alc882_dac_nids,
10312                 .dig_out_nid = ALC882_DIGOUT_NID,
10313                 .dig_in_nid = ALC882_DIGIN_NID,
10314                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
10315                 .channel_mode = alc882_ch_modes,
10316                 .input_mux = &alc882_capture_source,
10317                 .init_hook = alc885_macpro_init_hook,
10318         },
10319         [ALC885_IMAC24] = {
10320                 .mixers = { alc885_imac24_mixer },
10321                 .init_verbs = { alc885_imac24_init_verbs },
10322                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10323                 .dac_nids = alc882_dac_nids,
10324                 .dig_out_nid = ALC882_DIGOUT_NID,
10325                 .dig_in_nid = ALC882_DIGIN_NID,
10326                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
10327                 .channel_mode = alc882_ch_modes,
10328                 .input_mux = &alc882_capture_source,
10329                 .unsol_event = alc_sku_unsol_event,
10330                 .setup = alc885_imac24_setup,
10331                 .init_hook = alc885_imac24_init_hook,
10332         },
10333         [ALC885_IMAC91] = {
10334                 .mixers = {alc885_imac91_mixer},
10335                 .init_verbs = { alc885_imac91_init_verbs,
10336                                 alc880_gpio1_init_verbs },
10337                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10338                 .dac_nids = alc882_dac_nids,
10339                 .channel_mode = alc885_mba21_ch_modes,
10340                 .num_channel_mode = ARRAY_SIZE(alc885_mba21_ch_modes),
10341                 .input_mux = &alc889A_imac91_capture_source,
10342                 .dig_out_nid = ALC882_DIGOUT_NID,
10343                 .dig_in_nid = ALC882_DIGIN_NID,
10344                 .unsol_event = alc_sku_unsol_event,
10345                 .setup = alc885_imac91_setup,
10346                 .init_hook = alc_hp_automute,
10347         },
10348         [ALC882_TARGA] = {
10349                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
10350                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10351                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
10352                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10353                 .dac_nids = alc882_dac_nids,
10354                 .dig_out_nid = ALC882_DIGOUT_NID,
10355                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
10356                 .adc_nids = alc882_adc_nids,
10357                 .capsrc_nids = alc882_capsrc_nids,
10358                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
10359                 .channel_mode = alc882_3ST_6ch_modes,
10360                 .need_dac_fix = 1,
10361                 .input_mux = &alc882_capture_source,
10362                 .unsol_event = alc_sku_unsol_event,
10363                 .setup = alc882_targa_setup,
10364                 .init_hook = alc882_targa_automute,
10365         },
10366         [ALC882_ASUS_A7J] = {
10367                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
10368                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10369                                 alc882_asus_a7j_verbs},
10370                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10371                 .dac_nids = alc882_dac_nids,
10372                 .dig_out_nid = ALC882_DIGOUT_NID,
10373                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
10374                 .adc_nids = alc882_adc_nids,
10375                 .capsrc_nids = alc882_capsrc_nids,
10376                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
10377                 .channel_mode = alc882_3ST_6ch_modes,
10378                 .need_dac_fix = 1,
10379                 .input_mux = &alc882_capture_source,
10380         },
10381         [ALC882_ASUS_A7M] = {
10382                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
10383                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10384                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
10385                                 alc882_asus_a7m_verbs },
10386                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10387                 .dac_nids = alc882_dac_nids,
10388                 .dig_out_nid = ALC882_DIGOUT_NID,
10389                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
10390                 .channel_mode = alc880_threestack_modes,
10391                 .need_dac_fix = 1,
10392                 .input_mux = &alc882_capture_source,
10393         },
10394         [ALC883_3ST_2ch_DIG] = {
10395                 .mixers = { alc883_3ST_2ch_mixer },
10396                 .init_verbs = { alc883_init_verbs },
10397                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10398                 .dac_nids = alc883_dac_nids,
10399                 .dig_out_nid = ALC883_DIGOUT_NID,
10400                 .dig_in_nid = ALC883_DIGIN_NID,
10401                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10402                 .channel_mode = alc883_3ST_2ch_modes,
10403                 .input_mux = &alc883_capture_source,
10404         },
10405         [ALC883_3ST_6ch_DIG] = {
10406                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10407                 .init_verbs = { alc883_init_verbs },
10408                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10409                 .dac_nids = alc883_dac_nids,
10410                 .dig_out_nid = ALC883_DIGOUT_NID,
10411                 .dig_in_nid = ALC883_DIGIN_NID,
10412                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10413                 .channel_mode = alc883_3ST_6ch_modes,
10414                 .need_dac_fix = 1,
10415                 .input_mux = &alc883_capture_source,
10416         },
10417         [ALC883_3ST_6ch] = {
10418                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10419                 .init_verbs = { alc883_init_verbs },
10420                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10421                 .dac_nids = alc883_dac_nids,
10422                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10423                 .channel_mode = alc883_3ST_6ch_modes,
10424                 .need_dac_fix = 1,
10425                 .input_mux = &alc883_capture_source,
10426         },
10427         [ALC883_3ST_6ch_INTEL] = {
10428                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
10429                 .init_verbs = { alc883_init_verbs },
10430                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10431                 .dac_nids = alc883_dac_nids,
10432                 .dig_out_nid = ALC883_DIGOUT_NID,
10433                 .dig_in_nid = ALC883_DIGIN_NID,
10434                 .slave_dig_outs = alc883_slave_dig_outs,
10435                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
10436                 .channel_mode = alc883_3ST_6ch_intel_modes,
10437                 .need_dac_fix = 1,
10438                 .input_mux = &alc883_3stack_6ch_intel,
10439         },
10440         [ALC889A_INTEL] = {
10441                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
10442                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
10443                                 alc_hp15_unsol_verbs },
10444                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10445                 .dac_nids = alc883_dac_nids,
10446                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
10447                 .adc_nids = alc889_adc_nids,
10448                 .dig_out_nid = ALC883_DIGOUT_NID,
10449                 .dig_in_nid = ALC883_DIGIN_NID,
10450                 .slave_dig_outs = alc883_slave_dig_outs,
10451                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
10452                 .channel_mode = alc889_8ch_intel_modes,
10453                 .capsrc_nids = alc889_capsrc_nids,
10454                 .input_mux = &alc889_capture_source,
10455                 .setup = alc889_automute_setup,
10456                 .init_hook = alc_hp_automute,
10457                 .unsol_event = alc_sku_unsol_event,
10458                 .need_dac_fix = 1,
10459         },
10460         [ALC889_INTEL] = {
10461                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
10462                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
10463                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
10464                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10465                 .dac_nids = alc883_dac_nids,
10466                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
10467                 .adc_nids = alc889_adc_nids,
10468                 .dig_out_nid = ALC883_DIGOUT_NID,
10469                 .dig_in_nid = ALC883_DIGIN_NID,
10470                 .slave_dig_outs = alc883_slave_dig_outs,
10471                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
10472                 .channel_mode = alc889_8ch_intel_modes,
10473                 .capsrc_nids = alc889_capsrc_nids,
10474                 .input_mux = &alc889_capture_source,
10475                 .setup = alc889_automute_setup,
10476                 .init_hook = alc889_intel_init_hook,
10477                 .unsol_event = alc_sku_unsol_event,
10478                 .need_dac_fix = 1,
10479         },
10480         [ALC883_6ST_DIG] = {
10481                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
10482                 .init_verbs = { alc883_init_verbs },
10483                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10484                 .dac_nids = alc883_dac_nids,
10485                 .dig_out_nid = ALC883_DIGOUT_NID,
10486                 .dig_in_nid = ALC883_DIGIN_NID,
10487                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10488                 .channel_mode = alc883_sixstack_modes,
10489                 .input_mux = &alc883_capture_source,
10490         },
10491         [ALC883_TARGA_DIG] = {
10492                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
10493                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
10494                                 alc883_targa_verbs},
10495                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10496                 .dac_nids = alc883_dac_nids,
10497                 .dig_out_nid = ALC883_DIGOUT_NID,
10498                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10499                 .channel_mode = alc883_3ST_6ch_modes,
10500                 .need_dac_fix = 1,
10501                 .input_mux = &alc883_capture_source,
10502                 .unsol_event = alc883_targa_unsol_event,
10503                 .setup = alc882_targa_setup,
10504                 .init_hook = alc882_targa_automute,
10505         },
10506         [ALC883_TARGA_2ch_DIG] = {
10507                 .mixers = { alc883_targa_2ch_mixer},
10508                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
10509                                 alc883_targa_verbs},
10510                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10511                 .dac_nids = alc883_dac_nids,
10512                 .adc_nids = alc883_adc_nids_alt,
10513                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
10514                 .capsrc_nids = alc883_capsrc_nids,
10515                 .dig_out_nid = ALC883_DIGOUT_NID,
10516                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10517                 .channel_mode = alc883_3ST_2ch_modes,
10518                 .input_mux = &alc883_capture_source,
10519                 .unsol_event = alc883_targa_unsol_event,
10520                 .setup = alc882_targa_setup,
10521                 .init_hook = alc882_targa_automute,
10522         },
10523         [ALC883_TARGA_8ch_DIG] = {
10524                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
10525                             alc883_chmode_mixer },
10526                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
10527                                 alc883_targa_verbs },
10528                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10529                 .dac_nids = alc883_dac_nids,
10530                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10531                 .adc_nids = alc883_adc_nids_rev,
10532                 .capsrc_nids = alc883_capsrc_nids_rev,
10533                 .dig_out_nid = ALC883_DIGOUT_NID,
10534                 .dig_in_nid = ALC883_DIGIN_NID,
10535                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
10536                 .channel_mode = alc883_4ST_8ch_modes,
10537                 .need_dac_fix = 1,
10538                 .input_mux = &alc883_capture_source,
10539                 .unsol_event = alc883_targa_unsol_event,
10540                 .setup = alc882_targa_setup,
10541                 .init_hook = alc882_targa_automute,
10542         },
10543         [ALC883_ACER] = {
10544                 .mixers = { alc883_base_mixer },
10545                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
10546                  * and the headphone jack.  Turn this on and rely on the
10547                  * standard mute methods whenever the user wants to turn
10548                  * these outputs off.
10549                  */
10550                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
10551                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10552                 .dac_nids = alc883_dac_nids,
10553                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10554                 .channel_mode = alc883_3ST_2ch_modes,
10555                 .input_mux = &alc883_capture_source,
10556         },
10557         [ALC883_ACER_ASPIRE] = {
10558                 .mixers = { alc883_acer_aspire_mixer },
10559                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
10560                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10561                 .dac_nids = alc883_dac_nids,
10562                 .dig_out_nid = ALC883_DIGOUT_NID,
10563                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10564                 .channel_mode = alc883_3ST_2ch_modes,
10565                 .input_mux = &alc883_capture_source,
10566                 .unsol_event = alc_sku_unsol_event,
10567                 .setup = alc883_acer_aspire_setup,
10568                 .init_hook = alc_hp_automute,
10569         },
10570         [ALC888_ACER_ASPIRE_4930G] = {
10571                 .mixers = { alc888_acer_aspire_4930g_mixer,
10572                                 alc883_chmode_mixer },
10573                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10574                                 alc888_acer_aspire_4930g_verbs },
10575                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10576                 .dac_nids = alc883_dac_nids,
10577                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10578                 .adc_nids = alc883_adc_nids_rev,
10579                 .capsrc_nids = alc883_capsrc_nids_rev,
10580                 .dig_out_nid = ALC883_DIGOUT_NID,
10581                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10582                 .channel_mode = alc883_3ST_6ch_modes,
10583                 .need_dac_fix = 1,
10584                 .const_channel_count = 6,
10585                 .num_mux_defs =
10586                         ARRAY_SIZE(alc888_2_capture_sources),
10587                 .input_mux = alc888_2_capture_sources,
10588                 .unsol_event = alc_sku_unsol_event,
10589                 .setup = alc888_acer_aspire_4930g_setup,
10590                 .init_hook = alc_hp_automute,
10591         },
10592         [ALC888_ACER_ASPIRE_6530G] = {
10593                 .mixers = { alc888_acer_aspire_6530_mixer },
10594                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10595                                 alc888_acer_aspire_6530g_verbs },
10596                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10597                 .dac_nids = alc883_dac_nids,
10598                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10599                 .adc_nids = alc883_adc_nids_rev,
10600                 .capsrc_nids = alc883_capsrc_nids_rev,
10601                 .dig_out_nid = ALC883_DIGOUT_NID,
10602                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10603                 .channel_mode = alc883_3ST_2ch_modes,
10604                 .num_mux_defs =
10605                         ARRAY_SIZE(alc888_2_capture_sources),
10606                 .input_mux = alc888_acer_aspire_6530_sources,
10607                 .unsol_event = alc_sku_unsol_event,
10608                 .setup = alc888_acer_aspire_6530g_setup,
10609                 .init_hook = alc_hp_automute,
10610         },
10611         [ALC888_ACER_ASPIRE_8930G] = {
10612                 .mixers = { alc889_acer_aspire_8930g_mixer,
10613                                 alc883_chmode_mixer },
10614                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10615                                 alc889_acer_aspire_8930g_verbs,
10616                                 alc889_eapd_verbs},
10617                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10618                 .dac_nids = alc883_dac_nids,
10619                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
10620                 .adc_nids = alc889_adc_nids,
10621                 .capsrc_nids = alc889_capsrc_nids,
10622                 .dig_out_nid = ALC883_DIGOUT_NID,
10623                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10624                 .channel_mode = alc883_3ST_6ch_modes,
10625                 .need_dac_fix = 1,
10626                 .const_channel_count = 6,
10627                 .num_mux_defs =
10628                         ARRAY_SIZE(alc889_capture_sources),
10629                 .input_mux = alc889_capture_sources,
10630                 .unsol_event = alc_sku_unsol_event,
10631                 .setup = alc889_acer_aspire_8930g_setup,
10632                 .init_hook = alc_hp_automute,
10633 #ifdef CONFIG_SND_HDA_POWER_SAVE
10634                 .power_hook = alc_power_eapd,
10635 #endif
10636         },
10637         [ALC888_ACER_ASPIRE_7730G] = {
10638                 .mixers = { alc883_3ST_6ch_mixer,
10639                                 alc883_chmode_mixer },
10640                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10641                                 alc888_acer_aspire_7730G_verbs },
10642                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10643                 .dac_nids = alc883_dac_nids,
10644                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10645                 .adc_nids = alc883_adc_nids_rev,
10646                 .capsrc_nids = alc883_capsrc_nids_rev,
10647                 .dig_out_nid = ALC883_DIGOUT_NID,
10648                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10649                 .channel_mode = alc883_3ST_6ch_modes,
10650                 .need_dac_fix = 1,
10651                 .const_channel_count = 6,
10652                 .input_mux = &alc883_capture_source,
10653                 .unsol_event = alc_sku_unsol_event,
10654                 .setup = alc888_acer_aspire_7730g_setup,
10655                 .init_hook = alc_hp_automute,
10656         },
10657         [ALC883_MEDION] = {
10658                 .mixers = { alc883_fivestack_mixer,
10659                             alc883_chmode_mixer },
10660                 .init_verbs = { alc883_init_verbs,
10661                                 alc883_medion_eapd_verbs },
10662                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10663                 .dac_nids = alc883_dac_nids,
10664                 .adc_nids = alc883_adc_nids_alt,
10665                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
10666                 .capsrc_nids = alc883_capsrc_nids,
10667                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10668                 .channel_mode = alc883_sixstack_modes,
10669                 .input_mux = &alc883_capture_source,
10670         },
10671         [ALC883_MEDION_WIM2160] = {
10672                 .mixers = { alc883_medion_wim2160_mixer },
10673                 .init_verbs = { alc883_init_verbs, alc883_medion_wim2160_verbs },
10674                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10675                 .dac_nids = alc883_dac_nids,
10676                 .dig_out_nid = ALC883_DIGOUT_NID,
10677                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
10678                 .adc_nids = alc883_adc_nids,
10679                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10680                 .channel_mode = alc883_3ST_2ch_modes,
10681                 .input_mux = &alc883_capture_source,
10682                 .unsol_event = alc_sku_unsol_event,
10683                 .setup = alc883_medion_wim2160_setup,
10684                 .init_hook = alc_hp_automute,
10685         },
10686         [ALC883_LAPTOP_EAPD] = {
10687                 .mixers = { alc883_base_mixer },
10688                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
10689                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10690                 .dac_nids = alc883_dac_nids,
10691                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10692                 .channel_mode = alc883_3ST_2ch_modes,
10693                 .input_mux = &alc883_capture_source,
10694         },
10695         [ALC883_CLEVO_M540R] = {
10696                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10697                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
10698                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10699                 .dac_nids = alc883_dac_nids,
10700                 .dig_out_nid = ALC883_DIGOUT_NID,
10701                 .dig_in_nid = ALC883_DIGIN_NID,
10702                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
10703                 .channel_mode = alc883_3ST_6ch_clevo_modes,
10704                 .need_dac_fix = 1,
10705                 .input_mux = &alc883_capture_source,
10706                 /* This machine has the hardware HP auto-muting, thus
10707                  * we need no software mute via unsol event
10708                  */
10709         },
10710         [ALC883_CLEVO_M720] = {
10711                 .mixers = { alc883_clevo_m720_mixer },
10712                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
10713                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10714                 .dac_nids = alc883_dac_nids,
10715                 .dig_out_nid = ALC883_DIGOUT_NID,
10716                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10717                 .channel_mode = alc883_3ST_2ch_modes,
10718                 .input_mux = &alc883_capture_source,
10719                 .unsol_event = alc883_clevo_m720_unsol_event,
10720                 .setup = alc883_clevo_m720_setup,
10721                 .init_hook = alc883_clevo_m720_init_hook,
10722         },
10723         [ALC883_LENOVO_101E_2ch] = {
10724                 .mixers = { alc883_lenovo_101e_2ch_mixer},
10725                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
10726                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10727                 .dac_nids = alc883_dac_nids,
10728                 .adc_nids = alc883_adc_nids_alt,
10729                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
10730                 .capsrc_nids = alc883_capsrc_nids,
10731                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10732                 .channel_mode = alc883_3ST_2ch_modes,
10733                 .input_mux = &alc883_lenovo_101e_capture_source,
10734                 .setup = alc883_lenovo_101e_setup,
10735                 .unsol_event = alc_sku_unsol_event,
10736                 .init_hook = alc_inithook,
10737         },
10738         [ALC883_LENOVO_NB0763] = {
10739                 .mixers = { alc883_lenovo_nb0763_mixer },
10740                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
10741                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10742                 .dac_nids = alc883_dac_nids,
10743                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10744                 .channel_mode = alc883_3ST_2ch_modes,
10745                 .need_dac_fix = 1,
10746                 .input_mux = &alc883_lenovo_nb0763_capture_source,
10747                 .unsol_event = alc_sku_unsol_event,
10748                 .setup = alc883_lenovo_nb0763_setup,
10749                 .init_hook = alc_hp_automute,
10750         },
10751         [ALC888_LENOVO_MS7195_DIG] = {
10752                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10753                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
10754                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10755                 .dac_nids = alc883_dac_nids,
10756                 .dig_out_nid = ALC883_DIGOUT_NID,
10757                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10758                 .channel_mode = alc883_3ST_6ch_modes,
10759                 .need_dac_fix = 1,
10760                 .input_mux = &alc883_capture_source,
10761                 .unsol_event = alc_sku_unsol_event,
10762                 .setup = alc888_lenovo_ms7195_setup,
10763                 .init_hook = alc_inithook,
10764         },
10765         [ALC883_HAIER_W66] = {
10766                 .mixers = { alc883_targa_2ch_mixer},
10767                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
10768                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10769                 .dac_nids = alc883_dac_nids,
10770                 .dig_out_nid = ALC883_DIGOUT_NID,
10771                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10772                 .channel_mode = alc883_3ST_2ch_modes,
10773                 .input_mux = &alc883_capture_source,
10774                 .unsol_event = alc_sku_unsol_event,
10775                 .setup = alc883_haier_w66_setup,
10776                 .init_hook = alc_hp_automute,
10777         },
10778         [ALC888_3ST_HP] = {
10779                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10780                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
10781                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10782                 .dac_nids = alc883_dac_nids,
10783                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
10784                 .channel_mode = alc888_3st_hp_modes,
10785                 .need_dac_fix = 1,
10786                 .input_mux = &alc883_capture_source,
10787                 .unsol_event = alc_sku_unsol_event,
10788                 .setup = alc888_3st_hp_setup,
10789                 .init_hook = alc_hp_automute,
10790         },
10791         [ALC888_6ST_DELL] = {
10792                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
10793                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
10794                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10795                 .dac_nids = alc883_dac_nids,
10796                 .dig_out_nid = ALC883_DIGOUT_NID,
10797                 .dig_in_nid = ALC883_DIGIN_NID,
10798                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10799                 .channel_mode = alc883_sixstack_modes,
10800                 .input_mux = &alc883_capture_source,
10801                 .unsol_event = alc_sku_unsol_event,
10802                 .setup = alc888_6st_dell_setup,
10803                 .init_hook = alc_hp_automute,
10804         },
10805         [ALC883_MITAC] = {
10806                 .mixers = { alc883_mitac_mixer },
10807                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
10808                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10809                 .dac_nids = alc883_dac_nids,
10810                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10811                 .channel_mode = alc883_3ST_2ch_modes,
10812                 .input_mux = &alc883_capture_source,
10813                 .unsol_event = alc_sku_unsol_event,
10814                 .setup = alc883_mitac_setup,
10815                 .init_hook = alc_hp_automute,
10816         },
10817         [ALC883_FUJITSU_PI2515] = {
10818                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
10819                 .init_verbs = { alc883_init_verbs,
10820                                 alc883_2ch_fujitsu_pi2515_verbs},
10821                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10822                 .dac_nids = alc883_dac_nids,
10823                 .dig_out_nid = ALC883_DIGOUT_NID,
10824                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10825                 .channel_mode = alc883_3ST_2ch_modes,
10826                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
10827                 .unsol_event = alc_sku_unsol_event,
10828                 .setup = alc883_2ch_fujitsu_pi2515_setup,
10829                 .init_hook = alc_hp_automute,
10830         },
10831         [ALC888_FUJITSU_XA3530] = {
10832                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
10833                 .init_verbs = { alc883_init_verbs,
10834                         alc888_fujitsu_xa3530_verbs },
10835                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10836                 .dac_nids = alc883_dac_nids,
10837                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10838                 .adc_nids = alc883_adc_nids_rev,
10839                 .capsrc_nids = alc883_capsrc_nids_rev,
10840                 .dig_out_nid = ALC883_DIGOUT_NID,
10841                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
10842                 .channel_mode = alc888_4ST_8ch_intel_modes,
10843                 .num_mux_defs =
10844                         ARRAY_SIZE(alc888_2_capture_sources),
10845                 .input_mux = alc888_2_capture_sources,
10846                 .unsol_event = alc_sku_unsol_event,
10847                 .setup = alc888_fujitsu_xa3530_setup,
10848                 .init_hook = alc_hp_automute,
10849         },
10850         [ALC888_LENOVO_SKY] = {
10851                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
10852                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
10853                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10854                 .dac_nids = alc883_dac_nids,
10855                 .dig_out_nid = ALC883_DIGOUT_NID,
10856                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10857                 .channel_mode = alc883_sixstack_modes,
10858                 .need_dac_fix = 1,
10859                 .input_mux = &alc883_lenovo_sky_capture_source,
10860                 .unsol_event = alc_sku_unsol_event,
10861                 .setup = alc888_lenovo_sky_setup,
10862                 .init_hook = alc_hp_automute,
10863         },
10864         [ALC888_ASUS_M90V] = {
10865                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10866                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
10867                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10868                 .dac_nids = alc883_dac_nids,
10869                 .dig_out_nid = ALC883_DIGOUT_NID,
10870                 .dig_in_nid = ALC883_DIGIN_NID,
10871                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10872                 .channel_mode = alc883_3ST_6ch_modes,
10873                 .need_dac_fix = 1,
10874                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
10875                 .unsol_event = alc_sku_unsol_event,
10876                 .setup = alc883_mode2_setup,
10877                 .init_hook = alc_inithook,
10878         },
10879         [ALC888_ASUS_EEE1601] = {
10880                 .mixers = { alc883_asus_eee1601_mixer },
10881                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
10882                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
10883                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10884                 .dac_nids = alc883_dac_nids,
10885                 .dig_out_nid = ALC883_DIGOUT_NID,
10886                 .dig_in_nid = ALC883_DIGIN_NID,
10887                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10888                 .channel_mode = alc883_3ST_2ch_modes,
10889                 .need_dac_fix = 1,
10890                 .input_mux = &alc883_asus_eee1601_capture_source,
10891                 .unsol_event = alc_sku_unsol_event,
10892                 .init_hook = alc883_eee1601_inithook,
10893         },
10894         [ALC1200_ASUS_P5Q] = {
10895                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
10896                 .init_verbs = { alc883_init_verbs },
10897                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10898                 .dac_nids = alc883_dac_nids,
10899                 .dig_out_nid = ALC1200_DIGOUT_NID,
10900                 .dig_in_nid = ALC883_DIGIN_NID,
10901                 .slave_dig_outs = alc1200_slave_dig_outs,
10902                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10903                 .channel_mode = alc883_sixstack_modes,
10904                 .input_mux = &alc883_capture_source,
10905         },
10906         [ALC889A_MB31] = {
10907                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
10908                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
10909                         alc880_gpio1_init_verbs },
10910                 .adc_nids = alc883_adc_nids,
10911                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
10912                 .capsrc_nids = alc883_capsrc_nids,
10913                 .dac_nids = alc883_dac_nids,
10914                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10915                 .channel_mode = alc889A_mb31_6ch_modes,
10916                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
10917                 .input_mux = &alc889A_mb31_capture_source,
10918                 .dig_out_nid = ALC883_DIGOUT_NID,
10919                 .unsol_event = alc889A_mb31_unsol_event,
10920                 .init_hook = alc889A_mb31_automute,
10921         },
10922         [ALC883_SONY_VAIO_TT] = {
10923                 .mixers = { alc883_vaiott_mixer },
10924                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
10925                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10926                 .dac_nids = alc883_dac_nids,
10927                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10928                 .channel_mode = alc883_3ST_2ch_modes,
10929                 .input_mux = &alc883_capture_source,
10930                 .unsol_event = alc_sku_unsol_event,
10931                 .setup = alc883_vaiott_setup,
10932                 .init_hook = alc_hp_automute,
10933         },
10934 };
10935
10936
10937 /*
10938  * Pin config fixes
10939  */
10940 enum {
10941         PINFIX_ABIT_AW9D_MAX,
10942         PINFIX_LENOVO_Y530,
10943         PINFIX_PB_M5210,
10944         PINFIX_ACER_ASPIRE_7736,
10945 };
10946
10947 static const struct alc_fixup alc882_fixups[] = {
10948         [PINFIX_ABIT_AW9D_MAX] = {
10949                 .type = ALC_FIXUP_PINS,
10950                 .v.pins = (const struct alc_pincfg[]) {
10951                         { 0x15, 0x01080104 }, /* side */
10952                         { 0x16, 0x01011012 }, /* rear */
10953                         { 0x17, 0x01016011 }, /* clfe */
10954                         { }
10955                 }
10956         },
10957         [PINFIX_LENOVO_Y530] = {
10958                 .type = ALC_FIXUP_PINS,
10959                 .v.pins = (const struct alc_pincfg[]) {
10960                         { 0x15, 0x99130112 }, /* rear int speakers */
10961                         { 0x16, 0x99130111 }, /* subwoofer */
10962                         { }
10963                 }
10964         },
10965         [PINFIX_PB_M5210] = {
10966                 .type = ALC_FIXUP_VERBS,
10967                 .v.verbs = (const struct hda_verb[]) {
10968                         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
10969                         {}
10970                 }
10971         },
10972         [PINFIX_ACER_ASPIRE_7736] = {
10973                 .type = ALC_FIXUP_SKU,
10974                 .v.sku = ALC_FIXUP_SKU_IGNORE,
10975         },
10976 };
10977
10978 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
10979         SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
10980         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
10981         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
10982         SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
10983         {}
10984 };
10985
10986 /*
10987  * BIOS auto configuration
10988  */
10989 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
10990                                                 const struct auto_pin_cfg *cfg)
10991 {
10992         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
10993 }
10994
10995 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
10996                                               hda_nid_t nid, int pin_type,
10997                                               hda_nid_t dac)
10998 {
10999         int idx;
11000
11001         /* set as output */
11002         alc_set_pin_output(codec, nid, pin_type);
11003
11004         if (snd_hda_get_conn_list(codec, nid, NULL) < 2)
11005                 return;
11006
11007         if (dac == 0x25)
11008                 idx = 4;
11009         else if (dac >= 0x02 && dac <= 0x05)
11010                 idx = dac - 2;
11011         else
11012                 return;
11013         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
11014 }
11015
11016 #define alc882_auto_init_dac    alc880_auto_init_dac
11017
11018 static void alc882_auto_init_multi_out(struct hda_codec *codec)
11019 {
11020         struct alc_spec *spec = codec->spec;
11021         int i;
11022
11023         for (i = 0; i <= HDA_SIDE; i++) {
11024                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11025                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11026                 if (nid)
11027                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
11028                                         spec->multiout.dac_nids[i]);
11029         }
11030         /* mute DACs */
11031         for (i = 0; i < spec->multiout.num_dacs; i++)
11032                 alc882_auto_init_dac(codec, spec->multiout.dac_nids[i]);
11033 }
11034
11035 static void alc882_auto_init_hp_out(struct hda_codec *codec)
11036 {
11037         struct alc_spec *spec = codec->spec;
11038         hda_nid_t pin, dac;
11039         int i;
11040
11041         if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT) {
11042                 for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
11043                         pin = spec->autocfg.hp_pins[i];
11044                         if (!pin)
11045                                 break;
11046                         dac = spec->multiout.hp_nid;
11047                         if (!dac)
11048                                 dac = spec->multiout.dac_nids[0]; /* to front */
11049                         alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
11050                 }
11051         }
11052
11053         if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT) {
11054                 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
11055                         pin = spec->autocfg.speaker_pins[i];
11056                         if (!pin)
11057                                 break;
11058                         dac = spec->multiout.extra_out_nid[0];
11059                         if (!dac)
11060                                 dac = spec->multiout.dac_nids[0]; /* to front */
11061                         alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
11062                 }
11063         }
11064
11065         /* mute DACs */
11066         alc882_auto_init_dac(codec, spec->multiout.hp_nid);
11067         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
11068                 alc882_auto_init_dac(codec, spec->multiout.extra_out_nid[i]);
11069 }
11070
11071 #define alc882_auto_init_analog_input   alc880_auto_init_analog_input
11072
11073 static void alc882_auto_init_input_src(struct hda_codec *codec)
11074 {
11075         struct alc_spec *spec = codec->spec;
11076         int c;
11077
11078         for (c = 0; c < spec->num_adc_nids; c++) {
11079                 hda_nid_t nid = spec->capsrc_nids[c];
11080                 unsigned int mux_idx;
11081                 const struct hda_input_mux *imux;
11082                 int conns, mute, idx, item;
11083
11084                 /* mute ADC */
11085                 snd_hda_codec_write(codec, spec->adc_nids[c], 0,
11086                                     AC_VERB_SET_AMP_GAIN_MUTE,
11087                                     AMP_IN_MUTE(0));
11088
11089                 conns = snd_hda_get_conn_list(codec, nid, NULL);
11090                 if (conns <= 0)
11091                         continue;
11092                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
11093                 imux = &spec->input_mux[mux_idx];
11094                 if (!imux->num_items && mux_idx > 0)
11095                         imux = &spec->input_mux[0];
11096                 for (idx = 0; idx < conns; idx++) {
11097                         /* if the current connection is the selected one,
11098                          * unmute it as default - otherwise mute it
11099                          */
11100                         mute = AMP_IN_MUTE(idx);
11101                         for (item = 0; item < imux->num_items; item++) {
11102                                 if (imux->items[item].index == idx) {
11103                                         if (spec->cur_mux[c] == item)
11104                                                 mute = AMP_IN_UNMUTE(idx);
11105                                         break;
11106                                 }
11107                         }
11108                         /* check if we have a selector or mixer
11109                          * we could check for the widget type instead, but
11110                          * just check for Amp-In presence (in case of mixer
11111                          * without amp-in there is something wrong, this
11112                          * function shouldn't be used or capsrc nid is wrong)
11113                          */
11114                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
11115                                 snd_hda_codec_write(codec, nid, 0,
11116                                                     AC_VERB_SET_AMP_GAIN_MUTE,
11117                                                     mute);
11118                         else if (mute != AMP_IN_MUTE(idx))
11119                                 snd_hda_codec_write(codec, nid, 0,
11120                                                     AC_VERB_SET_CONNECT_SEL,
11121                                                     idx);
11122                 }
11123         }
11124 }
11125
11126 /* add mic boosts if needed */
11127 static int alc_auto_add_mic_boost(struct hda_codec *codec)
11128 {
11129         struct alc_spec *spec = codec->spec;
11130         struct auto_pin_cfg *cfg = &spec->autocfg;
11131         int i, err;
11132         int type_idx = 0;
11133         hda_nid_t nid;
11134         const char *prev_label = NULL;
11135
11136         for (i = 0; i < cfg->num_inputs; i++) {
11137                 if (cfg->inputs[i].type > AUTO_PIN_MIC)
11138                         break;
11139                 nid = cfg->inputs[i].pin;
11140                 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
11141                         const char *label;
11142                         char boost_label[32];
11143
11144                         label = hda_get_autocfg_input_label(codec, cfg, i);
11145                         if (prev_label && !strcmp(label, prev_label))
11146                                 type_idx++;
11147                         else
11148                                 type_idx = 0;
11149                         prev_label = label;
11150
11151                         snprintf(boost_label, sizeof(boost_label),
11152                                  "%s Boost Volume", label);
11153                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11154                                           boost_label, type_idx,
11155                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11156                         if (err < 0)
11157                                 return err;
11158                 }
11159         }
11160         return 0;
11161 }
11162
11163 /* almost identical with ALC880 parser... */
11164 static int alc882_parse_auto_config(struct hda_codec *codec)
11165 {
11166         struct alc_spec *spec = codec->spec;
11167         static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
11168         int err;
11169
11170         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11171                                            alc882_ignore);
11172         if (err < 0)
11173                 return err;
11174         if (!spec->autocfg.line_outs)
11175                 return 0; /* can't find valid BIOS pin config */
11176
11177         err = alc880_auto_fill_dac_nids(codec);
11178         if (err < 0)
11179                 return err;
11180         err = alc_auto_add_multi_channel_mode(codec, alc880_auto_fill_dac_nids);
11181         if (err < 0)
11182                 return err;
11183         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
11184         if (err < 0)
11185                 return err;
11186         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
11187                                            "Headphone");
11188         if (err < 0)
11189                 return err;
11190         err = alc880_auto_create_extra_out(spec,
11191                                            spec->autocfg.speaker_pins[0],
11192                                            "Speaker");
11193         if (err < 0)
11194                 return err;
11195         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
11196         if (err < 0)
11197                 return err;
11198
11199         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11200
11201         alc_auto_parse_digital(codec);
11202
11203         if (spec->kctls.list)
11204                 add_mixer(spec, spec->kctls.list);
11205
11206         /* if ADC 0x07 is available, initialize it, too */
11207         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
11208                 add_verb(spec, alc882_adc1_init_verbs);
11209
11210         spec->num_mux_defs = 1;
11211         spec->input_mux = &spec->private_imux[0];
11212
11213         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
11214
11215         err = alc_auto_add_mic_boost(codec);
11216         if (err < 0)
11217                 return err;
11218
11219         return 1; /* config found */
11220 }
11221
11222 /* additional initialization for auto-configuration model */
11223 static void alc882_auto_init(struct hda_codec *codec)
11224 {
11225         struct alc_spec *spec = codec->spec;
11226         alc882_auto_init_multi_out(codec);
11227         alc882_auto_init_hp_out(codec);
11228         alc882_auto_init_analog_input(codec);
11229         alc882_auto_init_input_src(codec);
11230         alc_auto_init_digital(codec);
11231         if (spec->unsol_event)
11232                 alc_inithook(codec);
11233 }
11234
11235 static int patch_alc882(struct hda_codec *codec)
11236 {
11237         struct alc_spec *spec;
11238         int err, board_config;
11239
11240         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11241         if (spec == NULL)
11242                 return -ENOMEM;
11243
11244         codec->spec = spec;
11245
11246         spec->mixer_nid = 0x0b;
11247
11248         switch (codec->vendor_id) {
11249         case 0x10ec0882:
11250         case 0x10ec0885:
11251                 break;
11252         default:
11253                 /* ALC883 and variants */
11254                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11255                 break;
11256         }
11257
11258         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
11259                                                   alc882_models,
11260                                                   alc882_cfg_tbl);
11261
11262         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
11263                 board_config = snd_hda_check_board_codec_sid_config(codec,
11264                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
11265
11266         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
11267                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11268                        codec->chip_name);
11269                 board_config = ALC882_AUTO;
11270         }
11271
11272         if (board_config == ALC882_AUTO) {
11273                 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
11274                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
11275         }
11276
11277         alc_auto_parse_customize_define(codec);
11278
11279         if (board_config == ALC882_AUTO) {
11280                 /* automatic parse from the BIOS config */
11281                 err = alc882_parse_auto_config(codec);
11282                 if (err < 0) {
11283                         alc_free(codec);
11284                         return err;
11285                 } else if (!err) {
11286                         printk(KERN_INFO
11287                                "hda_codec: Cannot set up configuration "
11288                                "from BIOS.  Using base mode...\n");
11289                         board_config = ALC882_3ST_DIG;
11290                 }
11291         }
11292
11293         if (has_cdefine_beep(codec)) {
11294                 err = snd_hda_attach_beep_device(codec, 0x1);
11295                 if (err < 0) {
11296                         alc_free(codec);
11297                         return err;
11298                 }
11299         }
11300
11301         if (board_config != ALC882_AUTO)
11302                 setup_preset(codec, &alc882_presets[board_config]);
11303
11304         spec->stream_analog_playback = &alc882_pcm_analog_playback;
11305         spec->stream_analog_capture = &alc882_pcm_analog_capture;
11306         /* FIXME: setup DAC5 */
11307         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
11308         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
11309
11310         spec->stream_digital_playback = &alc882_pcm_digital_playback;
11311         spec->stream_digital_capture = &alc882_pcm_digital_capture;
11312
11313         if (!spec->adc_nids && spec->input_mux) {
11314                 int i, j;
11315                 spec->num_adc_nids = 0;
11316                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
11317                         const struct hda_input_mux *imux = spec->input_mux;
11318                         hda_nid_t cap;
11319                         hda_nid_t nid = alc882_adc_nids[i];
11320                         unsigned int wcap = get_wcaps(codec, nid);
11321                         /* get type */
11322                         wcap = get_wcaps_type(wcap);
11323                         if (wcap != AC_WID_AUD_IN)
11324                                 continue;
11325                         spec->private_adc_nids[spec->num_adc_nids] = nid;
11326                         err = snd_hda_get_connections(codec, nid, &cap, 1);
11327                         if (err < 0)
11328                                 continue;
11329                         err = snd_hda_get_conn_list(codec, cap, NULL);
11330                         if (err < 0)
11331                                 continue;
11332                         for (j = 0; j < imux->num_items; j++)
11333                                 if (imux->items[j].index >= err)
11334                                         break;
11335                         if (j < imux->num_items)
11336                                 continue;
11337                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
11338                         spec->num_adc_nids++;
11339                 }
11340                 spec->adc_nids = spec->private_adc_nids;
11341                 spec->capsrc_nids = spec->private_capsrc_nids;
11342         }
11343
11344         set_capture_mixer(codec);
11345
11346         if (has_cdefine_beep(codec))
11347                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11348
11349         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
11350
11351         spec->vmaster_nid = 0x0c;
11352
11353         codec->patch_ops = alc_patch_ops;
11354         if (board_config == ALC882_AUTO)
11355                 spec->init_hook = alc882_auto_init;
11356
11357         alc_init_jacks(codec);
11358 #ifdef CONFIG_SND_HDA_POWER_SAVE
11359         if (!spec->loopback.amplist)
11360                 spec->loopback.amplist = alc882_loopbacks;
11361 #endif
11362
11363         return 0;
11364 }
11365
11366
11367 /*
11368  * ALC262 support
11369  */
11370
11371 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
11372 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
11373
11374 #define alc262_dac_nids         alc260_dac_nids
11375 #define alc262_adc_nids         alc882_adc_nids
11376 #define alc262_adc_nids_alt     alc882_adc_nids_alt
11377 #define alc262_capsrc_nids      alc882_capsrc_nids
11378 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
11379
11380 #define alc262_modes            alc260_modes
11381 #define alc262_capture_source   alc882_capture_source
11382
11383 static const hda_nid_t alc262_dmic_adc_nids[1] = {
11384         /* ADC0 */
11385         0x09
11386 };
11387
11388 static const hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
11389
11390 static const struct snd_kcontrol_new alc262_base_mixer[] = {
11391         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11392         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11393         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11394         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11395         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11396         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11397         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11398         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11399         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11400         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11401         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11402         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11403         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
11404         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11405         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
11406         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11407         { } /* end */
11408 };
11409
11410 /* update HP, line and mono-out pins according to the master switch */
11411 #define alc262_hp_master_update         alc260_hp_master_update
11412
11413 static void alc262_hp_bpc_setup(struct hda_codec *codec)
11414 {
11415         struct alc_spec *spec = codec->spec;
11416
11417         spec->autocfg.hp_pins[0] = 0x1b;
11418         spec->autocfg.speaker_pins[0] = 0x16;
11419         spec->automute = 1;
11420         spec->automute_mode = ALC_AUTOMUTE_PIN;
11421 }
11422
11423 static void alc262_hp_wildwest_setup(struct hda_codec *codec)
11424 {
11425         struct alc_spec *spec = codec->spec;
11426
11427         spec->autocfg.hp_pins[0] = 0x15;
11428         spec->autocfg.speaker_pins[0] = 0x16;
11429         spec->automute = 1;
11430         spec->automute_mode = ALC_AUTOMUTE_PIN;
11431 }
11432
11433 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
11434 #define alc262_hp_master_sw_put         alc260_hp_master_sw_put
11435
11436 #define ALC262_HP_MASTER_SWITCH                                 \
11437         {                                                       \
11438                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
11439                 .name = "Master Playback Switch",               \
11440                 .info = snd_ctl_boolean_mono_info,              \
11441                 .get = alc262_hp_master_sw_get,                 \
11442                 .put = alc262_hp_master_sw_put,                 \
11443         }, \
11444         {                                                       \
11445                 .iface = NID_MAPPING,                           \
11446                 .name = "Master Playback Switch",               \
11447                 .private_value = 0x15 | (0x16 << 8) | (0x1b << 16),     \
11448         }
11449
11450
11451 static const struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
11452         ALC262_HP_MASTER_SWITCH,
11453         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11454         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11455         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11456         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
11457                               HDA_OUTPUT),
11458         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
11459                             HDA_OUTPUT),
11460         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11461         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11462         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11463         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11464         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11465         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11466         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11467         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11468         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11469         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11470         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
11471         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
11472         { } /* end */
11473 };
11474
11475 static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
11476         ALC262_HP_MASTER_SWITCH,
11477         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11478         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11479         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11480         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11481         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
11482                               HDA_OUTPUT),
11483         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
11484                             HDA_OUTPUT),
11485         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
11486         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
11487         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x1a, 0, HDA_INPUT),
11488         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
11489         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
11490         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11491         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11492         { } /* end */
11493 };
11494
11495 static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
11496         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11497         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11498         HDA_CODEC_VOLUME("Rear Mic Boost Volume", 0x18, 0, HDA_INPUT),
11499         { } /* end */
11500 };
11501
11502 /* mute/unmute internal speaker according to the hp jack and mute state */
11503 static void alc262_hp_t5735_setup(struct hda_codec *codec)
11504 {
11505         struct alc_spec *spec = codec->spec;
11506
11507         spec->autocfg.hp_pins[0] = 0x15;
11508         spec->autocfg.speaker_pins[0] = 0x14;
11509         spec->automute = 1;
11510         spec->automute_mode = ALC_AUTOMUTE_PIN;
11511 }
11512
11513 static const struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
11514         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11515         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11516         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11517         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11518         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11519         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11520         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11521         { } /* end */
11522 };
11523
11524 static const struct hda_verb alc262_hp_t5735_verbs[] = {
11525         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11526         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11527
11528         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11529         { }
11530 };
11531
11532 static const struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
11533         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11534         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11535         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
11536         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
11537         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
11538         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
11539         { } /* end */
11540 };
11541
11542 static const struct hda_verb alc262_hp_rp5700_verbs[] = {
11543         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11544         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11545         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11546         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11547         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11548         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11549         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11550         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11551         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
11552         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
11553         {}
11554 };
11555
11556 static const struct hda_input_mux alc262_hp_rp5700_capture_source = {
11557         .num_items = 1,
11558         .items = {
11559                 { "Line", 0x1 },
11560         },
11561 };
11562
11563 /* bind hp and internal speaker mute (with plug check) as master switch */
11564 #define alc262_hippo_master_update      alc262_hp_master_update
11565 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
11566 #define alc262_hippo_master_sw_put      alc262_hp_master_sw_put
11567
11568 #define ALC262_HIPPO_MASTER_SWITCH                              \
11569         {                                                       \
11570                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
11571                 .name = "Master Playback Switch",               \
11572                 .info = snd_ctl_boolean_mono_info,              \
11573                 .get = alc262_hippo_master_sw_get,              \
11574                 .put = alc262_hippo_master_sw_put,              \
11575         },                                                      \
11576         {                                                       \
11577                 .iface = NID_MAPPING,                           \
11578                 .name = "Master Playback Switch",               \
11579                 .subdevice = SUBDEV_HP(0) | (SUBDEV_LINE(0) << 8) | \
11580                              (SUBDEV_SPEAKER(0) << 16), \
11581         }
11582
11583 static const struct snd_kcontrol_new alc262_hippo_mixer[] = {
11584         ALC262_HIPPO_MASTER_SWITCH,
11585         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11586         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11587         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11588         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11589         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11590         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11591         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11592         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11593         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11594         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11595         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11596         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11597         { } /* end */
11598 };
11599
11600 static const struct snd_kcontrol_new alc262_hippo1_mixer[] = {
11601         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11602         ALC262_HIPPO_MASTER_SWITCH,
11603         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11604         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11605         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11606         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11607         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11608         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11609         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11610         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11611         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11612         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11613         { } /* end */
11614 };
11615
11616 /* mute/unmute internal speaker according to the hp jack and mute state */
11617 static void alc262_hippo_setup(struct hda_codec *codec)
11618 {
11619         struct alc_spec *spec = codec->spec;
11620
11621         spec->autocfg.hp_pins[0] = 0x15;
11622         spec->autocfg.speaker_pins[0] = 0x14;
11623         spec->automute = 1;
11624         spec->automute_mode = ALC_AUTOMUTE_AMP;
11625 }
11626
11627 static void alc262_hippo1_setup(struct hda_codec *codec)
11628 {
11629         struct alc_spec *spec = codec->spec;
11630
11631         spec->autocfg.hp_pins[0] = 0x1b;
11632         spec->autocfg.speaker_pins[0] = 0x14;
11633         spec->automute = 1;
11634         spec->automute_mode = ALC_AUTOMUTE_AMP;
11635 }
11636
11637
11638 static const struct snd_kcontrol_new alc262_sony_mixer[] = {
11639         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11640         ALC262_HIPPO_MASTER_SWITCH,
11641         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11642         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11643         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11644         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11645         { } /* end */
11646 };
11647
11648 static const struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
11649         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11650         ALC262_HIPPO_MASTER_SWITCH,
11651         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11652         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11653         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11654         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11655         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11656         { } /* end */
11657 };
11658
11659 static const struct snd_kcontrol_new alc262_tyan_mixer[] = {
11660         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11661         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
11662         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
11663         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
11664         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11665         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11666         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11667         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11668         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11669         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11670         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11671         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11672         { } /* end */
11673 };
11674
11675 static const struct hda_verb alc262_tyan_verbs[] = {
11676         /* Headphone automute */
11677         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11678         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11679         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11680
11681         /* P11 AUX_IN, white 4-pin connector */
11682         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11683         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
11684         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
11685         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
11686
11687         {}
11688 };
11689
11690 /* unsolicited event for HP jack sensing */
11691 static void alc262_tyan_setup(struct hda_codec *codec)
11692 {
11693         struct alc_spec *spec = codec->spec;
11694
11695         spec->autocfg.hp_pins[0] = 0x1b;
11696         spec->autocfg.speaker_pins[0] = 0x15;
11697         spec->automute = 1;
11698         spec->automute_mode = ALC_AUTOMUTE_AMP;
11699 }
11700
11701
11702 #define alc262_capture_mixer            alc882_capture_mixer
11703 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
11704
11705 /*
11706  * generic initialization of ADC, input mixers and output mixers
11707  */
11708 static const struct hda_verb alc262_init_verbs[] = {
11709         /*
11710          * Unmute ADC0-2 and set the default input to mic-in
11711          */
11712         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11713         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11714         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11715         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11716         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11717         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11718
11719         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11720          * mixer widget
11721          * Note: PASD motherboards uses the Line In 2 as the input for
11722          * front panel mic (mic 2)
11723          */
11724         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11725         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11726         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11727         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11728         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11729         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11730
11731         /*
11732          * Set up output mixers (0x0c - 0x0e)
11733          */
11734         /* set vol=0 to output mixers */
11735         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11736         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11737         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11738         /* set up input amps for analog loopback */
11739         /* Amp Indices: DAC = 0, mixer = 1 */
11740         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11741         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11742         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11743         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11744         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11745         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11746
11747         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11748         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11749         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11750         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11751         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11752         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11753
11754         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11755         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11756         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11757         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11758         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11759
11760         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11761         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11762
11763         /* FIXME: use matrix-type input source selection */
11764         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11765         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11766         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11767         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11768         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11769         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11770         /* Input mixer2 */
11771         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11772         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11773         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11774         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11775         /* Input mixer3 */
11776         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11777         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11778         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11779         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11780
11781         { }
11782 };
11783
11784 static const struct hda_verb alc262_eapd_verbs[] = {
11785         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11786         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11787         { }
11788 };
11789
11790 static const struct hda_verb alc262_hippo1_unsol_verbs[] = {
11791         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11792         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11793         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11794
11795         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11796         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11797         {}
11798 };
11799
11800 static const struct hda_verb alc262_sony_unsol_verbs[] = {
11801         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11802         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11803         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
11804
11805         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11806         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11807         {}
11808 };
11809
11810 static const struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
11811         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11812         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11813         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11814         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11815         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11816         { } /* end */
11817 };
11818
11819 static const struct hda_verb alc262_toshiba_s06_verbs[] = {
11820         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11821         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11822         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11823         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11824         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
11825         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11826         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11827         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11828         {}
11829 };
11830
11831 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
11832 {
11833         struct alc_spec *spec = codec->spec;
11834
11835         spec->autocfg.hp_pins[0] = 0x15;
11836         spec->autocfg.speaker_pins[0] = 0x14;
11837         spec->ext_mic.pin = 0x18;
11838         spec->ext_mic.mux_idx = 0;
11839         spec->int_mic.pin = 0x12;
11840         spec->int_mic.mux_idx = 9;
11841         spec->auto_mic = 1;
11842         spec->automute = 1;
11843         spec->automute_mode = ALC_AUTOMUTE_PIN;
11844 }
11845
11846 /*
11847  * nec model
11848  *  0x15 = headphone
11849  *  0x16 = internal speaker
11850  *  0x18 = external mic
11851  */
11852
11853 static const struct snd_kcontrol_new alc262_nec_mixer[] = {
11854         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
11855         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
11856
11857         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11858         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11859         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11860
11861         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11862         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11863         { } /* end */
11864 };
11865
11866 static const struct hda_verb alc262_nec_verbs[] = {
11867         /* Unmute Speaker */
11868         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11869
11870         /* Headphone */
11871         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11872         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11873
11874         /* External mic to headphone */
11875         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11876         /* External mic to speaker */
11877         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11878         {}
11879 };
11880
11881 /*
11882  * fujitsu model
11883  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
11884  *  0x1b = port replicator headphone out
11885  */
11886
11887 #define ALC_HP_EVENT    ALC880_HP_EVENT
11888
11889 static const struct hda_verb alc262_fujitsu_unsol_verbs[] = {
11890         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
11891         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11892         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
11893         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11894         {}
11895 };
11896
11897 static const struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
11898         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
11899         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11900         {}
11901 };
11902
11903 static const struct hda_verb alc262_lenovo_3000_init_verbs[] = {
11904         /* Front Mic pin: input vref at 50% */
11905         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
11906         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11907         {}
11908 };
11909
11910 static const struct hda_input_mux alc262_fujitsu_capture_source = {
11911         .num_items = 3,
11912         .items = {
11913                 { "Mic", 0x0 },
11914                 { "Internal Mic", 0x1 },
11915                 { "CD", 0x4 },
11916         },
11917 };
11918
11919 static const struct hda_input_mux alc262_HP_capture_source = {
11920         .num_items = 5,
11921         .items = {
11922                 { "Mic", 0x0 },
11923                 { "Front Mic", 0x1 },
11924                 { "Line", 0x2 },
11925                 { "CD", 0x4 },
11926                 { "AUX IN", 0x6 },
11927         },
11928 };
11929
11930 static const struct hda_input_mux alc262_HP_D7000_capture_source = {
11931         .num_items = 4,
11932         .items = {
11933                 { "Mic", 0x0 },
11934                 { "Front Mic", 0x2 },
11935                 { "Line", 0x1 },
11936                 { "CD", 0x4 },
11937         },
11938 };
11939
11940 static void alc262_fujitsu_setup(struct hda_codec *codec)
11941 {
11942         struct alc_spec *spec = codec->spec;
11943
11944         spec->autocfg.hp_pins[0] = 0x14;
11945         spec->autocfg.hp_pins[1] = 0x1b;
11946         spec->autocfg.speaker_pins[0] = 0x15;
11947         spec->automute = 1;
11948         spec->automute_mode = ALC_AUTOMUTE_AMP;
11949 }
11950
11951 /* bind volumes of both NID 0x0c and 0x0d */
11952 static const struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
11953         .ops = &snd_hda_bind_vol,
11954         .values = {
11955                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
11956                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
11957                 0
11958         },
11959 };
11960
11961 static const struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
11962         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
11963         {
11964                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11965                 .name = "Master Playback Switch",
11966                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
11967                 .info = snd_ctl_boolean_mono_info,
11968                 .get = alc262_hp_master_sw_get,
11969                 .put = alc262_hp_master_sw_put,
11970         },
11971         {
11972                 .iface = NID_MAPPING,
11973                 .name = "Master Playback Switch",
11974                 .private_value = 0x1b,
11975         },
11976         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11977         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11978         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11979         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11980         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11981         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
11982         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11983         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11984         { } /* end */
11985 };
11986
11987 static void alc262_lenovo_3000_setup(struct hda_codec *codec)
11988 {
11989         struct alc_spec *spec = codec->spec;
11990
11991         spec->autocfg.hp_pins[0] = 0x1b;
11992         spec->autocfg.speaker_pins[0] = 0x14;
11993         spec->autocfg.speaker_pins[1] = 0x16;
11994         spec->automute = 1;
11995         spec->automute_mode = ALC_AUTOMUTE_AMP;
11996 }
11997
11998 static const struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
11999         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
12000         {
12001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12002                 .name = "Master Playback Switch",
12003                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
12004                 .info = snd_ctl_boolean_mono_info,
12005                 .get = alc262_hp_master_sw_get,
12006                 .put = alc262_hp_master_sw_put,
12007         },
12008         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12009         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12010         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
12011         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12012         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12013         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
12014         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12015         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12016         { } /* end */
12017 };
12018
12019 static const struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
12020         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
12021         ALC262_HIPPO_MASTER_SWITCH,
12022         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12023         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12024         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
12025         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12026         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12027         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
12028         { } /* end */
12029 };
12030
12031 /* additional init verbs for Benq laptops */
12032 static const struct hda_verb alc262_EAPD_verbs[] = {
12033         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
12034         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
12035         {}
12036 };
12037
12038 static const struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
12039         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12040         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12041
12042         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
12043         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
12044         {}
12045 };
12046
12047 /* Samsung Q1 Ultra Vista model setup */
12048 static const struct snd_kcontrol_new alc262_ultra_mixer[] = {
12049         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
12050         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
12051         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12052         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12053         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
12054         HDA_CODEC_VOLUME("Headphone Mic Boost Volume", 0x15, 0, HDA_INPUT),
12055         { } /* end */
12056 };
12057
12058 static const struct hda_verb alc262_ultra_verbs[] = {
12059         /* output mixer */
12060         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12061         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12062         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12063         /* speaker */
12064         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12065         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12066         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12067         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12068         /* HP */
12069         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12070         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12071         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12072         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12073         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12074         /* internal mic */
12075         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12076         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12077         /* ADC, choose mic */
12078         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12079         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12080         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12081         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12082         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12083         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12084         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
12086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
12087         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
12088         {}
12089 };
12090
12091 /* mute/unmute internal speaker according to the hp jack and mute state */
12092 static void alc262_ultra_automute(struct hda_codec *codec)
12093 {
12094         struct alc_spec *spec = codec->spec;
12095         unsigned int mute;
12096
12097         mute = 0;
12098         /* auto-mute only when HP is used as HP */
12099         if (!spec->cur_mux[0]) {
12100                 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
12101                 if (spec->jack_present)
12102                         mute = HDA_AMP_MUTE;
12103         }
12104         /* mute/unmute internal speaker */
12105         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12106                                  HDA_AMP_MUTE, mute);
12107         /* mute/unmute HP */
12108         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12109                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
12110 }
12111
12112 /* unsolicited event for HP jack sensing */
12113 static void alc262_ultra_unsol_event(struct hda_codec *codec,
12114                                        unsigned int res)
12115 {
12116         if ((res >> 26) != ALC880_HP_EVENT)
12117                 return;
12118         alc262_ultra_automute(codec);
12119 }
12120
12121 static const struct hda_input_mux alc262_ultra_capture_source = {
12122         .num_items = 2,
12123         .items = {
12124                 { "Mic", 0x1 },
12125                 { "Headphone", 0x7 },
12126         },
12127 };
12128
12129 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
12130                                      struct snd_ctl_elem_value *ucontrol)
12131 {
12132         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12133         struct alc_spec *spec = codec->spec;
12134         int ret;
12135
12136         ret = alc_mux_enum_put(kcontrol, ucontrol);
12137         if (!ret)
12138                 return 0;
12139         /* reprogram the HP pin as mic or HP according to the input source */
12140         snd_hda_codec_write_cache(codec, 0x15, 0,
12141                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
12142                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
12143         alc262_ultra_automute(codec); /* mute/unmute HP */
12144         return ret;
12145 }
12146
12147 static const struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
12148         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
12149         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
12150         {
12151                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12152                 .name = "Capture Source",
12153                 .info = alc_mux_enum_info,
12154                 .get = alc_mux_enum_get,
12155                 .put = alc262_ultra_mux_enum_put,
12156         },
12157         {
12158                 .iface = NID_MAPPING,
12159                 .name = "Capture Source",
12160                 .private_value = 0x15,
12161         },
12162         { } /* end */
12163 };
12164
12165 /* We use two mixers depending on the output pin; 0x16 is a mono output
12166  * and thus it's bound with a different mixer.
12167  * This function returns which mixer amp should be used.
12168  */
12169 static int alc262_check_volbit(hda_nid_t nid)
12170 {
12171         if (!nid)
12172                 return 0;
12173         else if (nid == 0x16)
12174                 return 2;
12175         else
12176                 return 1;
12177 }
12178
12179 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
12180                                   const char *pfx, int *vbits, int idx)
12181 {
12182         unsigned long val;
12183         int vbit;
12184
12185         vbit = alc262_check_volbit(nid);
12186         if (!vbit)
12187                 return 0;
12188         if (*vbits & vbit) /* a volume control for this mixer already there */
12189                 return 0;
12190         *vbits |= vbit;
12191         if (vbit == 2)
12192                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
12193         else
12194                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
12195         return __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, idx, val);
12196 }
12197
12198 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
12199                                  const char *pfx, int idx)
12200 {
12201         unsigned long val;
12202
12203         if (!nid)
12204                 return 0;
12205         if (nid == 0x16)
12206                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
12207         else
12208                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
12209         return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, idx, val);
12210 }
12211
12212 /* add playback controls from the parsed DAC table */
12213 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
12214                                              const struct auto_pin_cfg *cfg)
12215 {
12216         const char *pfx;
12217         int vbits;
12218         int i, index, err;
12219
12220         spec->multiout.num_dacs = 1;    /* only use one dac */
12221         spec->multiout.dac_nids = spec->private_dac_nids;
12222         spec->private_dac_nids[0] = 2;
12223
12224         for (i = 0; i < 2; i++) {
12225                 pfx = alc_get_line_out_pfx(spec, i, true, &index);
12226                 if (!pfx)
12227                         pfx = "PCM";
12228                 err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[i], pfx,
12229                                             index);
12230                 if (err < 0)
12231                         return err;
12232                 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
12233                         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[i],
12234                                                     "Speaker", i);
12235                         if (err < 0)
12236                                 return err;
12237                 }
12238                 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
12239                         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[i],
12240                                                     "Headphone", i);
12241                         if (err < 0)
12242                                 return err;
12243                 }
12244         }
12245
12246         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
12247                 alc262_check_volbit(cfg->speaker_pins[0]) |
12248                 alc262_check_volbit(cfg->hp_pins[0]);
12249         vbits = 0;
12250         for (i = 0; i < 2; i++) {
12251                 pfx = alc_get_line_out_pfx(spec, i, true, &index);
12252                 if (!pfx)
12253                         pfx = "PCM";
12254                 err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[i], pfx,
12255                                              &vbits, i);
12256                 if (err < 0)
12257                         return err;
12258                 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
12259                         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[i],
12260                                                      "Speaker", &vbits, i);
12261                         if (err < 0)
12262                                 return err;
12263                 }
12264                 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
12265                         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[i],
12266                                                      "Headphone", &vbits, i);
12267                         if (err < 0)
12268                                 return err;
12269                 }
12270         }
12271         return 0;
12272 }
12273
12274 #define alc262_auto_create_input_ctls \
12275         alc882_auto_create_input_ctls
12276
12277 static const struct hda_verb alc262_HP_BPC_init_verbs[] = {
12278         /*
12279          * Unmute ADC0-2 and set the default input to mic-in
12280          */
12281         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
12282         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12283         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12284         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12285         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12286         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12287
12288         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
12289          * mixer widget
12290          * Note: PASD motherboards uses the Line In 2 as the input for
12291          * front panel mic (mic 2)
12292          */
12293         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12294         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12295         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12296         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12297         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12298         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12299         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12300         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
12301
12302         /*
12303          * Set up output mixers (0x0c - 0x0e)
12304          */
12305         /* set vol=0 to output mixers */
12306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12307         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12308         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12309
12310         /* set up input amps for analog loopback */
12311         /* Amp Indices: DAC = 0, mixer = 1 */
12312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12314         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12315         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12317         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12318
12319         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12320         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12321         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12322
12323         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12324         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12325
12326         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12327         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12328
12329         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12330         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12331         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12332         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12333         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12334
12335         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12336         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12337         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12338         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12339         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12340         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12341
12342
12343         /* FIXME: use matrix-type input source selection */
12344         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
12345         /* Input mixer1: only unmute Mic */
12346         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12347         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
12348         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
12349         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
12350         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
12351         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
12352         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
12353         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
12354         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
12355         /* Input mixer2 */
12356         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12357         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
12358         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
12359         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
12360         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
12361         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
12362         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
12363         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
12364         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
12365         /* Input mixer3 */
12366         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12367         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
12368         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
12369         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
12370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
12371         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
12372         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
12373         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
12374         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
12375
12376         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12377
12378         { }
12379 };
12380
12381 static const struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
12382         /*
12383          * Unmute ADC0-2 and set the default input to mic-in
12384          */
12385         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
12386         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12387         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12388         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12389         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12390         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12391
12392         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
12393          * mixer widget
12394          * Note: PASD motherboards uses the Line In 2 as the input for front
12395          * panel mic (mic 2)
12396          */
12397         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12398         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12399         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12400         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12401         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12402         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12403         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12404         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
12405         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
12406         /*
12407          * Set up output mixers (0x0c - 0x0e)
12408          */
12409         /* set vol=0 to output mixers */
12410         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12411         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12412         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12413
12414         /* set up input amps for analog loopback */
12415         /* Amp Indices: DAC = 0, mixer = 1 */
12416         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12417         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12418         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12419         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12420         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12421         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12422
12423
12424         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
12425         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
12426         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
12427         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
12428         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
12429         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
12430         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
12431
12432         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12433         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12434
12435         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12436         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12437
12438         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
12439         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12440         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12441         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
12442         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12443         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12444
12445         /* FIXME: use matrix-type input source selection */
12446         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12447         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12448         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
12449         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
12450         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
12451         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
12452         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
12453         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
12454         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
12455         /* Input mixer2 */
12456         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12457         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
12458         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
12459         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
12460         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
12461         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
12462         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
12463         /* Input mixer3 */
12464         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12465         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
12466         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
12467         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
12468         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
12469         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
12470         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
12471
12472         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12473
12474         { }
12475 };
12476
12477 static const struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
12478
12479         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
12480         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12481         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
12482
12483         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
12484         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
12485         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
12486         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
12487
12488         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
12489         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12490         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12491         {}
12492 };
12493
12494 /*
12495  * Pin config fixes
12496  */
12497 enum {
12498         PINFIX_FSC_H270,
12499         PINFIX_HP_Z200,
12500 };
12501
12502 static const struct alc_fixup alc262_fixups[] = {
12503         [PINFIX_FSC_H270] = {
12504                 .type = ALC_FIXUP_PINS,
12505                 .v.pins = (const struct alc_pincfg[]) {
12506                         { 0x14, 0x99130110 }, /* speaker */
12507                         { 0x15, 0x0221142f }, /* front HP */
12508                         { 0x1b, 0x0121141f }, /* rear HP */
12509                         { }
12510                 }
12511         },
12512         [PINFIX_HP_Z200] = {
12513                 .type = ALC_FIXUP_PINS,
12514                 .v.pins = (const struct alc_pincfg[]) {
12515                         { 0x16, 0x99130120 }, /* internal speaker */
12516                         { }
12517                 }
12518         },
12519 };
12520
12521 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
12522         SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
12523         SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
12524         {}
12525 };
12526
12527
12528 #ifdef CONFIG_SND_HDA_POWER_SAVE
12529 #define alc262_loopbacks        alc880_loopbacks
12530 #endif
12531
12532 /* pcm configuration: identical with ALC880 */
12533 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
12534 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
12535 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
12536 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
12537
12538 /*
12539  * BIOS auto configuration
12540  */
12541 static int alc262_parse_auto_config(struct hda_codec *codec)
12542 {
12543         struct alc_spec *spec = codec->spec;
12544         int err;
12545         static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
12546
12547         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12548                                            alc262_ignore);
12549         if (err < 0)
12550                 return err;
12551         if (!spec->autocfg.line_outs) {
12552                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12553                         spec->multiout.max_channels = 2;
12554                         spec->no_analog = 1;
12555                         goto dig_only;
12556                 }
12557                 return 0; /* can't find valid BIOS pin config */
12558         }
12559         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
12560         if (err < 0)
12561                 return err;
12562         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
12563         if (err < 0)
12564                 return err;
12565
12566         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12567
12568  dig_only:
12569         alc_auto_parse_digital(codec);
12570
12571         if (spec->kctls.list)
12572                 add_mixer(spec, spec->kctls.list);
12573
12574         spec->num_mux_defs = 1;
12575         spec->input_mux = &spec->private_imux[0];
12576
12577         err = alc_auto_add_mic_boost(codec);
12578         if (err < 0)
12579                 return err;
12580
12581         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
12582
12583         return 1;
12584 }
12585
12586 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
12587 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
12588 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
12589 #define alc262_auto_init_input_src      alc882_auto_init_input_src
12590
12591
12592 /* init callback for auto-configuration model -- overriding the default init */
12593 static void alc262_auto_init(struct hda_codec *codec)
12594 {
12595         struct alc_spec *spec = codec->spec;
12596         alc262_auto_init_multi_out(codec);
12597         alc262_auto_init_hp_out(codec);
12598         alc262_auto_init_analog_input(codec);
12599         alc262_auto_init_input_src(codec);
12600         alc_auto_init_digital(codec);
12601         if (spec->unsol_event)
12602                 alc_inithook(codec);
12603 }
12604
12605 /*
12606  * configuration and preset
12607  */
12608 static const char * const alc262_models[ALC262_MODEL_LAST] = {
12609         [ALC262_BASIC]          = "basic",
12610         [ALC262_HIPPO]          = "hippo",
12611         [ALC262_HIPPO_1]        = "hippo_1",
12612         [ALC262_FUJITSU]        = "fujitsu",
12613         [ALC262_HP_BPC]         = "hp-bpc",
12614         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
12615         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
12616         [ALC262_HP_RP5700]      = "hp-rp5700",
12617         [ALC262_BENQ_ED8]       = "benq",
12618         [ALC262_BENQ_T31]       = "benq-t31",
12619         [ALC262_SONY_ASSAMD]    = "sony-assamd",
12620         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
12621         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
12622         [ALC262_ULTRA]          = "ultra",
12623         [ALC262_LENOVO_3000]    = "lenovo-3000",
12624         [ALC262_NEC]            = "nec",
12625         [ALC262_TYAN]           = "tyan",
12626         [ALC262_AUTO]           = "auto",
12627 };
12628
12629 static const struct snd_pci_quirk alc262_cfg_tbl[] = {
12630         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
12631         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
12632         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
12633                            ALC262_HP_BPC),
12634         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
12635                            ALC262_HP_BPC),
12636         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1500, "HP z series",
12637                            ALC262_HP_BPC),
12638         SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200",
12639                            ALC262_AUTO),
12640         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
12641                            ALC262_HP_BPC),
12642         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
12643         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
12644         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
12645         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
12646         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
12647         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
12648         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
12649         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
12650         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
12651         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
12652         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
12653         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
12654                       ALC262_HP_TC_T5735),
12655         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
12656         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
12657         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
12658         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
12659         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
12660         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
12661         SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
12662         SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
12663 #if 0 /* disable the quirk since model=auto works better in recent versions */
12664         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
12665                            ALC262_SONY_ASSAMD),
12666 #endif
12667         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
12668                       ALC262_TOSHIBA_RX1),
12669         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
12670         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
12671         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
12672         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
12673         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
12674                            ALC262_ULTRA),
12675         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
12676         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
12677         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
12678         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
12679         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
12680         {}
12681 };
12682
12683 static const struct alc_config_preset alc262_presets[] = {
12684         [ALC262_BASIC] = {
12685                 .mixers = { alc262_base_mixer },
12686                 .init_verbs = { alc262_init_verbs },
12687                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12688                 .dac_nids = alc262_dac_nids,
12689                 .hp_nid = 0x03,
12690                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12691                 .channel_mode = alc262_modes,
12692                 .input_mux = &alc262_capture_source,
12693         },
12694         [ALC262_HIPPO] = {
12695                 .mixers = { alc262_hippo_mixer },
12696                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
12697                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12698                 .dac_nids = alc262_dac_nids,
12699                 .hp_nid = 0x03,
12700                 .dig_out_nid = ALC262_DIGOUT_NID,
12701                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12702                 .channel_mode = alc262_modes,
12703                 .input_mux = &alc262_capture_source,
12704                 .unsol_event = alc_sku_unsol_event,
12705                 .setup = alc262_hippo_setup,
12706                 .init_hook = alc_inithook,
12707         },
12708         [ALC262_HIPPO_1] = {
12709                 .mixers = { alc262_hippo1_mixer },
12710                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
12711                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12712                 .dac_nids = alc262_dac_nids,
12713                 .hp_nid = 0x02,
12714                 .dig_out_nid = ALC262_DIGOUT_NID,
12715                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12716                 .channel_mode = alc262_modes,
12717                 .input_mux = &alc262_capture_source,
12718                 .unsol_event = alc_sku_unsol_event,
12719                 .setup = alc262_hippo1_setup,
12720                 .init_hook = alc_inithook,
12721         },
12722         [ALC262_FUJITSU] = {
12723                 .mixers = { alc262_fujitsu_mixer },
12724                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
12725                                 alc262_fujitsu_unsol_verbs },
12726                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12727                 .dac_nids = alc262_dac_nids,
12728                 .hp_nid = 0x03,
12729                 .dig_out_nid = ALC262_DIGOUT_NID,
12730                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12731                 .channel_mode = alc262_modes,
12732                 .input_mux = &alc262_fujitsu_capture_source,
12733                 .unsol_event = alc_sku_unsol_event,
12734                 .setup = alc262_fujitsu_setup,
12735                 .init_hook = alc_inithook,
12736         },
12737         [ALC262_HP_BPC] = {
12738                 .mixers = { alc262_HP_BPC_mixer },
12739                 .init_verbs = { alc262_HP_BPC_init_verbs },
12740                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12741                 .dac_nids = alc262_dac_nids,
12742                 .hp_nid = 0x03,
12743                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12744                 .channel_mode = alc262_modes,
12745                 .input_mux = &alc262_HP_capture_source,
12746                 .unsol_event = alc_sku_unsol_event,
12747                 .setup = alc262_hp_bpc_setup,
12748                 .init_hook = alc_inithook,
12749         },
12750         [ALC262_HP_BPC_D7000_WF] = {
12751                 .mixers = { alc262_HP_BPC_WildWest_mixer },
12752                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
12753                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12754                 .dac_nids = alc262_dac_nids,
12755                 .hp_nid = 0x03,
12756                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12757                 .channel_mode = alc262_modes,
12758                 .input_mux = &alc262_HP_D7000_capture_source,
12759                 .unsol_event = alc_sku_unsol_event,
12760                 .setup = alc262_hp_wildwest_setup,
12761                 .init_hook = alc_inithook,
12762         },
12763         [ALC262_HP_BPC_D7000_WL] = {
12764                 .mixers = { alc262_HP_BPC_WildWest_mixer,
12765                             alc262_HP_BPC_WildWest_option_mixer },
12766                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
12767                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12768                 .dac_nids = alc262_dac_nids,
12769                 .hp_nid = 0x03,
12770                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12771                 .channel_mode = alc262_modes,
12772                 .input_mux = &alc262_HP_D7000_capture_source,
12773                 .unsol_event = alc_sku_unsol_event,
12774                 .setup = alc262_hp_wildwest_setup,
12775                 .init_hook = alc_inithook,
12776         },
12777         [ALC262_HP_TC_T5735] = {
12778                 .mixers = { alc262_hp_t5735_mixer },
12779                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
12780                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12781                 .dac_nids = alc262_dac_nids,
12782                 .hp_nid = 0x03,
12783                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12784                 .channel_mode = alc262_modes,
12785                 .input_mux = &alc262_capture_source,
12786                 .unsol_event = alc_sku_unsol_event,
12787                 .setup = alc262_hp_t5735_setup,
12788                 .init_hook = alc_inithook,
12789         },
12790         [ALC262_HP_RP5700] = {
12791                 .mixers = { alc262_hp_rp5700_mixer },
12792                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
12793                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12794                 .dac_nids = alc262_dac_nids,
12795                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12796                 .channel_mode = alc262_modes,
12797                 .input_mux = &alc262_hp_rp5700_capture_source,
12798         },
12799         [ALC262_BENQ_ED8] = {
12800                 .mixers = { alc262_base_mixer },
12801                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
12802                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12803                 .dac_nids = alc262_dac_nids,
12804                 .hp_nid = 0x03,
12805                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12806                 .channel_mode = alc262_modes,
12807                 .input_mux = &alc262_capture_source,
12808         },
12809         [ALC262_SONY_ASSAMD] = {
12810                 .mixers = { alc262_sony_mixer },
12811                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
12812                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12813                 .dac_nids = alc262_dac_nids,
12814                 .hp_nid = 0x02,
12815                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12816                 .channel_mode = alc262_modes,
12817                 .input_mux = &alc262_capture_source,
12818                 .unsol_event = alc_sku_unsol_event,
12819                 .setup = alc262_hippo_setup,
12820                 .init_hook = alc_inithook,
12821         },
12822         [ALC262_BENQ_T31] = {
12823                 .mixers = { alc262_benq_t31_mixer },
12824                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
12825                                 alc_hp15_unsol_verbs },
12826                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12827                 .dac_nids = alc262_dac_nids,
12828                 .hp_nid = 0x03,
12829                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12830                 .channel_mode = alc262_modes,
12831                 .input_mux = &alc262_capture_source,
12832                 .unsol_event = alc_sku_unsol_event,
12833                 .setup = alc262_hippo_setup,
12834                 .init_hook = alc_inithook,
12835         },
12836         [ALC262_ULTRA] = {
12837                 .mixers = { alc262_ultra_mixer },
12838                 .cap_mixer = alc262_ultra_capture_mixer,
12839                 .init_verbs = { alc262_ultra_verbs },
12840                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12841                 .dac_nids = alc262_dac_nids,
12842                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12843                 .channel_mode = alc262_modes,
12844                 .input_mux = &alc262_ultra_capture_source,
12845                 .adc_nids = alc262_adc_nids, /* ADC0 */
12846                 .capsrc_nids = alc262_capsrc_nids,
12847                 .num_adc_nids = 1, /* single ADC */
12848                 .unsol_event = alc262_ultra_unsol_event,
12849                 .init_hook = alc262_ultra_automute,
12850         },
12851         [ALC262_LENOVO_3000] = {
12852                 .mixers = { alc262_lenovo_3000_mixer },
12853                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
12854                                 alc262_lenovo_3000_unsol_verbs,
12855                                 alc262_lenovo_3000_init_verbs },
12856                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12857                 .dac_nids = alc262_dac_nids,
12858                 .hp_nid = 0x03,
12859                 .dig_out_nid = ALC262_DIGOUT_NID,
12860                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12861                 .channel_mode = alc262_modes,
12862                 .input_mux = &alc262_fujitsu_capture_source,
12863                 .unsol_event = alc_sku_unsol_event,
12864                 .setup = alc262_lenovo_3000_setup,
12865                 .init_hook = alc_inithook,
12866         },
12867         [ALC262_NEC] = {
12868                 .mixers = { alc262_nec_mixer },
12869                 .init_verbs = { alc262_nec_verbs },
12870                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12871                 .dac_nids = alc262_dac_nids,
12872                 .hp_nid = 0x03,
12873                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12874                 .channel_mode = alc262_modes,
12875                 .input_mux = &alc262_capture_source,
12876         },
12877         [ALC262_TOSHIBA_S06] = {
12878                 .mixers = { alc262_toshiba_s06_mixer },
12879                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
12880                                                         alc262_eapd_verbs },
12881                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12882                 .capsrc_nids = alc262_dmic_capsrc_nids,
12883                 .dac_nids = alc262_dac_nids,
12884                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
12885                 .num_adc_nids = 1, /* single ADC */
12886                 .dig_out_nid = ALC262_DIGOUT_NID,
12887                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12888                 .channel_mode = alc262_modes,
12889                 .unsol_event = alc_sku_unsol_event,
12890                 .setup = alc262_toshiba_s06_setup,
12891                 .init_hook = alc_inithook,
12892         },
12893         [ALC262_TOSHIBA_RX1] = {
12894                 .mixers = { alc262_toshiba_rx1_mixer },
12895                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
12896                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12897                 .dac_nids = alc262_dac_nids,
12898                 .hp_nid = 0x03,
12899                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12900                 .channel_mode = alc262_modes,
12901                 .input_mux = &alc262_capture_source,
12902                 .unsol_event = alc_sku_unsol_event,
12903                 .setup = alc262_hippo_setup,
12904                 .init_hook = alc_inithook,
12905         },
12906         [ALC262_TYAN] = {
12907                 .mixers = { alc262_tyan_mixer },
12908                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
12909                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12910                 .dac_nids = alc262_dac_nids,
12911                 .hp_nid = 0x02,
12912                 .dig_out_nid = ALC262_DIGOUT_NID,
12913                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12914                 .channel_mode = alc262_modes,
12915                 .input_mux = &alc262_capture_source,
12916                 .unsol_event = alc_sku_unsol_event,
12917                 .setup = alc262_tyan_setup,
12918                 .init_hook = alc_hp_automute,
12919         },
12920 };
12921
12922 static int patch_alc262(struct hda_codec *codec)
12923 {
12924         struct alc_spec *spec;
12925         int board_config;
12926         int err;
12927
12928         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12929         if (spec == NULL)
12930                 return -ENOMEM;
12931
12932         codec->spec = spec;
12933
12934         spec->mixer_nid = 0x0b;
12935
12936 #if 0
12937         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
12938          * under-run
12939          */
12940         {
12941         int tmp;
12942         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
12943         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
12944         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
12945         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
12946         }
12947 #endif
12948         alc_auto_parse_customize_define(codec);
12949
12950         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
12951
12952         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
12953                                                   alc262_models,
12954                                                   alc262_cfg_tbl);
12955
12956         if (board_config < 0) {
12957                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12958                        codec->chip_name);
12959                 board_config = ALC262_AUTO;
12960         }
12961
12962         if (board_config == ALC262_AUTO) {
12963                 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
12964                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
12965         }
12966
12967         if (board_config == ALC262_AUTO) {
12968                 /* automatic parse from the BIOS config */
12969                 err = alc262_parse_auto_config(codec);
12970                 if (err < 0) {
12971                         alc_free(codec);
12972                         return err;
12973                 } else if (!err) {
12974                         printk(KERN_INFO
12975                                "hda_codec: Cannot set up configuration "
12976                                "from BIOS.  Using base mode...\n");
12977                         board_config = ALC262_BASIC;
12978                 }
12979         }
12980
12981         if (!spec->no_analog && has_cdefine_beep(codec)) {
12982                 err = snd_hda_attach_beep_device(codec, 0x1);
12983                 if (err < 0) {
12984                         alc_free(codec);
12985                         return err;
12986                 }
12987         }
12988
12989         if (board_config != ALC262_AUTO)
12990                 setup_preset(codec, &alc262_presets[board_config]);
12991
12992         spec->stream_analog_playback = &alc262_pcm_analog_playback;
12993         spec->stream_analog_capture = &alc262_pcm_analog_capture;
12994
12995         spec->stream_digital_playback = &alc262_pcm_digital_playback;
12996         spec->stream_digital_capture = &alc262_pcm_digital_capture;
12997
12998         if (!spec->adc_nids && spec->input_mux) {
12999                 int i;
13000                 /* check whether the digital-mic has to be supported */
13001                 for (i = 0; i < spec->input_mux->num_items; i++) {
13002                         if (spec->input_mux->items[i].index >= 9)
13003                                 break;
13004                 }
13005                 if (i < spec->input_mux->num_items) {
13006                         /* use only ADC0 */
13007                         spec->adc_nids = alc262_dmic_adc_nids;
13008                         spec->num_adc_nids = 1;
13009                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
13010                 } else {
13011                         /* all analog inputs */
13012                         /* check whether NID 0x07 is valid */
13013                         unsigned int wcap = get_wcaps(codec, 0x07);
13014
13015                         /* get type */
13016                         wcap = get_wcaps_type(wcap);
13017                         if (wcap != AC_WID_AUD_IN) {
13018                                 spec->adc_nids = alc262_adc_nids_alt;
13019                                 spec->num_adc_nids =
13020                                         ARRAY_SIZE(alc262_adc_nids_alt);
13021                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
13022                         } else {
13023                                 spec->adc_nids = alc262_adc_nids;
13024                                 spec->num_adc_nids =
13025                                         ARRAY_SIZE(alc262_adc_nids);
13026                                 spec->capsrc_nids = alc262_capsrc_nids;
13027                         }
13028                 }
13029         }
13030         if (!spec->cap_mixer && !spec->no_analog)
13031                 set_capture_mixer(codec);
13032         if (!spec->no_analog && has_cdefine_beep(codec))
13033                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
13034
13035         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
13036
13037         spec->vmaster_nid = 0x0c;
13038
13039         codec->patch_ops = alc_patch_ops;
13040         if (board_config == ALC262_AUTO)
13041                 spec->init_hook = alc262_auto_init;
13042         spec->shutup = alc_eapd_shutup;
13043
13044         alc_init_jacks(codec);
13045 #ifdef CONFIG_SND_HDA_POWER_SAVE
13046         if (!spec->loopback.amplist)
13047                 spec->loopback.amplist = alc262_loopbacks;
13048 #endif
13049
13050         return 0;
13051 }
13052
13053 /*
13054  *  ALC268 channel source setting (2 channel)
13055  */
13056 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
13057 #define alc268_modes            alc260_modes
13058
13059 static const hda_nid_t alc268_dac_nids[2] = {
13060         /* front, hp */
13061         0x02, 0x03
13062 };
13063
13064 static const hda_nid_t alc268_adc_nids[2] = {
13065         /* ADC0-1 */
13066         0x08, 0x07
13067 };
13068
13069 static const hda_nid_t alc268_adc_nids_alt[1] = {
13070         /* ADC0 */
13071         0x08
13072 };
13073
13074 static const hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
13075
13076 static const struct snd_kcontrol_new alc268_base_mixer[] = {
13077         /* output mixer control */
13078         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13079         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13080         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13081         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13082         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13083         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
13084         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13085         { }
13086 };
13087
13088 static const struct snd_kcontrol_new alc268_toshiba_mixer[] = {
13089         /* output mixer control */
13090         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13091         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13092         ALC262_HIPPO_MASTER_SWITCH,
13093         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13094         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
13095         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13096         { }
13097 };
13098
13099 /* bind Beep switches of both NID 0x0f and 0x10 */
13100 static const struct hda_bind_ctls alc268_bind_beep_sw = {
13101         .ops = &snd_hda_bind_sw,
13102         .values = {
13103                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
13104                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
13105                 0
13106         },
13107 };
13108
13109 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
13110         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
13111         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
13112         { }
13113 };
13114
13115 static const struct hda_verb alc268_eapd_verbs[] = {
13116         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13117         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13118         { }
13119 };
13120
13121 /* Toshiba specific */
13122 static const struct hda_verb alc268_toshiba_verbs[] = {
13123         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13124         { } /* end */
13125 };
13126
13127 /* Acer specific */
13128 /* bind volumes of both NID 0x02 and 0x03 */
13129 static const struct hda_bind_ctls alc268_acer_bind_master_vol = {
13130         .ops = &snd_hda_bind_vol,
13131         .values = {
13132                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
13133                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
13134                 0
13135         },
13136 };
13137
13138 static void alc268_acer_setup(struct hda_codec *codec)
13139 {
13140         struct alc_spec *spec = codec->spec;
13141
13142         spec->autocfg.hp_pins[0] = 0x14;
13143         spec->autocfg.speaker_pins[0] = 0x15;
13144         spec->automute = 1;
13145         spec->automute_mode = ALC_AUTOMUTE_AMP;
13146 }
13147
13148 #define alc268_acer_master_sw_get       alc262_hp_master_sw_get
13149 #define alc268_acer_master_sw_put       alc262_hp_master_sw_put
13150
13151 static const struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
13152         /* output mixer control */
13153         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
13154         {
13155                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13156                 .name = "Master Playback Switch",
13157                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x15,
13158                 .info = snd_ctl_boolean_mono_info,
13159                 .get = alc268_acer_master_sw_get,
13160                 .put = alc268_acer_master_sw_put,
13161         },
13162         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
13163         { }
13164 };
13165
13166 static const struct snd_kcontrol_new alc268_acer_mixer[] = {
13167         /* output mixer control */
13168         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
13169         {
13170                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13171                 .name = "Master Playback Switch",
13172                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
13173                 .info = snd_ctl_boolean_mono_info,
13174                 .get = alc268_acer_master_sw_get,
13175                 .put = alc268_acer_master_sw_put,
13176         },
13177         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13178         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13179         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13180         { }
13181 };
13182
13183 static const struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
13184         /* output mixer control */
13185         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
13186         {
13187                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13188                 .name = "Master Playback Switch",
13189                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
13190                 .info = snd_ctl_boolean_mono_info,
13191                 .get = alc268_acer_master_sw_get,
13192                 .put = alc268_acer_master_sw_put,
13193         },
13194         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13195         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13196         { }
13197 };
13198
13199 static const struct hda_verb alc268_acer_aspire_one_verbs[] = {
13200         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13202         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13203         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13204         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
13205         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
13206         { }
13207 };
13208
13209 static const struct hda_verb alc268_acer_verbs[] = {
13210         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
13211         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13212         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13213         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13214         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13215         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13216         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13217         { }
13218 };
13219
13220 /* unsolicited event for HP jack sensing */
13221 #define alc268_toshiba_setup            alc262_hippo_setup
13222
13223 static void alc268_acer_lc_setup(struct hda_codec *codec)
13224 {
13225         struct alc_spec *spec = codec->spec;
13226         spec->autocfg.hp_pins[0] = 0x15;
13227         spec->autocfg.speaker_pins[0] = 0x14;
13228         spec->automute = 1;
13229         spec->automute_mode = ALC_AUTOMUTE_AMP;
13230         spec->ext_mic.pin = 0x18;
13231         spec->ext_mic.mux_idx = 0;
13232         spec->int_mic.pin = 0x12;
13233         spec->int_mic.mux_idx = 6;
13234         spec->auto_mic = 1;
13235 }
13236
13237 static const struct snd_kcontrol_new alc268_dell_mixer[] = {
13238         /* output mixer control */
13239         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13240         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13241         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13242         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13243         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13244         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13245         { }
13246 };
13247
13248 static const struct hda_verb alc268_dell_verbs[] = {
13249         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13250         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13251         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13252         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
13253         { }
13254 };
13255
13256 /* mute/unmute internal speaker according to the hp jack and mute state */
13257 static void alc268_dell_setup(struct hda_codec *codec)
13258 {
13259         struct alc_spec *spec = codec->spec;
13260
13261         spec->autocfg.hp_pins[0] = 0x15;
13262         spec->autocfg.speaker_pins[0] = 0x14;
13263         spec->ext_mic.pin = 0x18;
13264         spec->ext_mic.mux_idx = 0;
13265         spec->int_mic.pin = 0x19;
13266         spec->int_mic.mux_idx = 1;
13267         spec->auto_mic = 1;
13268         spec->automute = 1;
13269         spec->automute_mode = ALC_AUTOMUTE_PIN;
13270 }
13271
13272 static const struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
13273         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13274         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13275         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13276         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13277         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13278         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
13279         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13280         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13281         { }
13282 };
13283
13284 static const struct hda_verb alc267_quanta_il1_verbs[] = {
13285         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13286         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
13287         { }
13288 };
13289
13290 static void alc267_quanta_il1_setup(struct hda_codec *codec)
13291 {
13292         struct alc_spec *spec = codec->spec;
13293         spec->autocfg.hp_pins[0] = 0x15;
13294         spec->autocfg.speaker_pins[0] = 0x14;
13295         spec->ext_mic.pin = 0x18;
13296         spec->ext_mic.mux_idx = 0;
13297         spec->int_mic.pin = 0x19;
13298         spec->int_mic.mux_idx = 1;
13299         spec->auto_mic = 1;
13300         spec->automute = 1;
13301         spec->automute_mode = ALC_AUTOMUTE_PIN;
13302 }
13303
13304 /*
13305  * generic initialization of ADC, input mixers and output mixers
13306  */
13307 static const struct hda_verb alc268_base_init_verbs[] = {
13308         /* Unmute DAC0-1 and set vol = 0 */
13309         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13310         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13311
13312         /*
13313          * Set up output mixers (0x0c - 0x0e)
13314          */
13315         /* set vol=0 to output mixers */
13316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13317         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
13318
13319         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13320         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13321
13322         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
13323         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
13324         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
13325         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13326         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13327         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13328         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13329         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13330
13331         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13332         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13333         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13334         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13335         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13336
13337         /* set PCBEEP vol = 0, mute connections */
13338         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13339         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13340         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13341
13342         /* Unmute Selector 23h,24h and set the default input to mic-in */
13343
13344         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
13345         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13346         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
13347         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13348
13349         { }
13350 };
13351
13352 /* only for model=test */
13353 #ifdef CONFIG_SND_DEBUG
13354 /*
13355  * generic initialization of ADC, input mixers and output mixers
13356  */
13357 static const struct hda_verb alc268_volume_init_verbs[] = {
13358         /* set output DAC */
13359         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13360         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13361
13362         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13363         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13364         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13365         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13366         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13367
13368         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13369         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13370         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13371
13372         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13373         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13374         { }
13375 };
13376 #endif /* CONFIG_SND_DEBUG */
13377
13378 /* set PCBEEP vol = 0, mute connections */
13379 static const struct hda_verb alc268_beep_init_verbs[] = {
13380         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13381         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13382         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13383         { }
13384 };
13385
13386 static const struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
13387         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13388         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
13389         { } /* end */
13390 };
13391
13392 static const struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
13393         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13394         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
13395         _DEFINE_CAPSRC(1),
13396         { } /* end */
13397 };
13398
13399 static const struct snd_kcontrol_new alc268_capture_mixer[] = {
13400         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13401         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
13402         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
13403         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
13404         _DEFINE_CAPSRC(2),
13405         { } /* end */
13406 };
13407
13408 static const struct hda_input_mux alc268_capture_source = {
13409         .num_items = 4,
13410         .items = {
13411                 { "Mic", 0x0 },
13412                 { "Front Mic", 0x1 },
13413                 { "Line", 0x2 },
13414                 { "CD", 0x3 },
13415         },
13416 };
13417
13418 static const struct hda_input_mux alc268_acer_capture_source = {
13419         .num_items = 3,
13420         .items = {
13421                 { "Mic", 0x0 },
13422                 { "Internal Mic", 0x1 },
13423                 { "Line", 0x2 },
13424         },
13425 };
13426
13427 static const struct hda_input_mux alc268_acer_dmic_capture_source = {
13428         .num_items = 3,
13429         .items = {
13430                 { "Mic", 0x0 },
13431                 { "Internal Mic", 0x6 },
13432                 { "Line", 0x2 },
13433         },
13434 };
13435
13436 #ifdef CONFIG_SND_DEBUG
13437 static const struct snd_kcontrol_new alc268_test_mixer[] = {
13438         /* Volume widgets */
13439         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13440         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13441         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13442         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
13443         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
13444         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
13445         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
13446         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
13447         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
13448         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
13449         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
13450         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
13451         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
13452         /* The below appears problematic on some hardwares */
13453         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
13454         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13455         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
13456         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
13457         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
13458
13459         /* Modes for retasking pin widgets */
13460         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
13461         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
13462         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
13463         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
13464
13465         /* Controls for GPIO pins, assuming they are configured as outputs */
13466         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
13467         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
13468         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
13469         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
13470
13471         /* Switches to allow the digital SPDIF output pin to be enabled.
13472          * The ALC268 does not have an SPDIF input.
13473          */
13474         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
13475
13476         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
13477          * this output to turn on an external amplifier.
13478          */
13479         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
13480         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
13481
13482         { } /* end */
13483 };
13484 #endif
13485
13486 /* create input playback/capture controls for the given pin */
13487 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
13488                                     const char *ctlname, int idx)
13489 {
13490         hda_nid_t dac;
13491         int err;
13492
13493         switch (nid) {
13494         case 0x14:
13495         case 0x16:
13496                 dac = 0x02;
13497                 break;
13498         case 0x15:
13499         case 0x1a: /* ALC259/269 only */
13500         case 0x1b: /* ALC259/269 only */
13501         case 0x21: /* ALC269vb has this pin, too */
13502                 dac = 0x03;
13503                 break;
13504         default:
13505                 snd_printd(KERN_WARNING "hda_codec: "
13506                            "ignoring pin 0x%x as unknown\n", nid);
13507                 return 0;
13508         }
13509         if (spec->multiout.dac_nids[0] != dac &&
13510             spec->multiout.dac_nids[1] != dac) {
13511                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
13512                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
13513                                                       HDA_OUTPUT));
13514                 if (err < 0)
13515                         return err;
13516                 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
13517         }
13518
13519         if (nid != 0x16)
13520                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
13521                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
13522         else /* mono */
13523                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
13524                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
13525         if (err < 0)
13526                 return err;
13527         return 0;
13528 }
13529
13530 /* add playback controls from the parsed DAC table */
13531 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
13532                                              const struct auto_pin_cfg *cfg)
13533 {
13534         hda_nid_t nid;
13535         int err;
13536
13537         spec->multiout.dac_nids = spec->private_dac_nids;
13538
13539         nid = cfg->line_out_pins[0];
13540         if (nid) {
13541                 const char *name;
13542                 int index;
13543                 name = alc_get_line_out_pfx(spec, 0, true, &index);
13544                 err = alc268_new_analog_output(spec, nid, name, 0);
13545                 if (err < 0)
13546                         return err;
13547         }
13548
13549         nid = cfg->speaker_pins[0];
13550         if (nid == 0x1d) {
13551                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
13552                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
13553                 if (err < 0)
13554                         return err;
13555         } else if (nid) {
13556                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
13557                 if (err < 0)
13558                         return err;
13559         }
13560         nid = cfg->hp_pins[0];
13561         if (nid) {
13562                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
13563                 if (err < 0)
13564                         return err;
13565         }
13566
13567         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
13568         if (nid == 0x16) {
13569                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
13570                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
13571                 if (err < 0)
13572                         return err;
13573         }
13574         return 0;
13575 }
13576
13577 /* create playback/capture controls for input pins */
13578 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
13579                                                 const struct auto_pin_cfg *cfg)
13580 {
13581         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
13582 }
13583
13584 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
13585                                               hda_nid_t nid, int pin_type)
13586 {
13587         int idx;
13588
13589         alc_set_pin_output(codec, nid, pin_type);
13590         if (nid == 0x14 || nid == 0x16)
13591                 idx = 0;
13592         else
13593                 idx = 1;
13594         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
13595 }
13596
13597 static void alc268_auto_init_dac(struct hda_codec *codec, hda_nid_t nid)
13598 {
13599         if (!nid)
13600                 return;
13601         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13602                             AMP_OUT_MUTE);
13603 }
13604
13605 static void alc268_auto_init_multi_out(struct hda_codec *codec)
13606 {
13607         struct alc_spec *spec = codec->spec;
13608         int i;
13609
13610         for (i = 0; i < spec->autocfg.line_outs; i++) {
13611                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13612                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13613                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
13614         }
13615         /* mute DACs */
13616         for (i = 0; i < spec->multiout.num_dacs; i++)
13617                 alc268_auto_init_dac(codec, spec->multiout.dac_nids[i]);
13618 }
13619
13620 static void alc268_auto_init_hp_out(struct hda_codec *codec)
13621 {
13622         struct alc_spec *spec = codec->spec;
13623         hda_nid_t pin;
13624         int i;
13625
13626         for (i = 0; i < spec->autocfg.hp_outs; i++) {
13627                 pin = spec->autocfg.hp_pins[i];
13628                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
13629         }
13630         for (i = 0; i < spec->autocfg.speaker_outs; i++) {
13631                 pin = spec->autocfg.speaker_pins[i];
13632                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
13633         }
13634         if (spec->autocfg.mono_out_pin)
13635                 snd_hda_codec_write(codec, spec->autocfg.mono_out_pin, 0,
13636                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
13637         /* mute DACs */
13638         alc268_auto_init_dac(codec, spec->multiout.hp_nid);
13639         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
13640                 alc268_auto_init_dac(codec, spec->multiout.extra_out_nid[i]);
13641 }
13642
13643 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
13644 {
13645         struct alc_spec *spec = codec->spec;
13646         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
13647         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
13648         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
13649         unsigned int    dac_vol1, dac_vol2;
13650
13651         if (line_nid == 0x1d || speaker_nid == 0x1d) {
13652                 snd_hda_codec_write(codec, speaker_nid, 0,
13653                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
13654                 /* mute mixer inputs from 0x1d */
13655                 snd_hda_codec_write(codec, 0x0f, 0,
13656                                     AC_VERB_SET_AMP_GAIN_MUTE,
13657                                     AMP_IN_UNMUTE(1));
13658                 snd_hda_codec_write(codec, 0x10, 0,
13659                                     AC_VERB_SET_AMP_GAIN_MUTE,
13660                                     AMP_IN_UNMUTE(1));
13661         } else {
13662                 /* unmute mixer inputs from 0x1d */
13663                 snd_hda_codec_write(codec, 0x0f, 0,
13664                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
13665                 snd_hda_codec_write(codec, 0x10, 0,
13666                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
13667         }
13668
13669         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
13670         if (line_nid == 0x14)
13671                 dac_vol2 = AMP_OUT_ZERO;
13672         else if (line_nid == 0x15)
13673                 dac_vol1 = AMP_OUT_ZERO;
13674         if (hp_nid == 0x14)
13675                 dac_vol2 = AMP_OUT_ZERO;
13676         else if (hp_nid == 0x15)
13677                 dac_vol1 = AMP_OUT_ZERO;
13678         if (line_nid != 0x16 || hp_nid != 0x16 ||
13679             spec->autocfg.line_out_pins[1] != 0x16 ||
13680             spec->autocfg.line_out_pins[2] != 0x16)
13681                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
13682
13683         snd_hda_codec_write(codec, 0x02, 0,
13684                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
13685         snd_hda_codec_write(codec, 0x03, 0,
13686                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
13687 }
13688
13689 /* pcm configuration: identical with ALC880 */
13690 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
13691 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
13692 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
13693 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
13694
13695 /*
13696  * BIOS auto configuration
13697  */
13698 static int alc268_parse_auto_config(struct hda_codec *codec)
13699 {
13700         struct alc_spec *spec = codec->spec;
13701         int err;
13702         static const hda_nid_t alc268_ignore[] = { 0 };
13703
13704         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13705                                            alc268_ignore);
13706         if (err < 0)
13707                 return err;
13708         if (!spec->autocfg.line_outs) {
13709                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
13710                         spec->multiout.max_channels = 2;
13711                         spec->no_analog = 1;
13712                         goto dig_only;
13713                 }
13714                 return 0; /* can't find valid BIOS pin config */
13715         }
13716         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
13717         if (err < 0)
13718                 return err;
13719         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
13720         if (err < 0)
13721                 return err;
13722
13723         spec->multiout.max_channels = 2;
13724
13725  dig_only:
13726         /* digital only support output */
13727         alc_auto_parse_digital(codec);
13728         if (spec->kctls.list)
13729                 add_mixer(spec, spec->kctls.list);
13730
13731         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
13732                 add_mixer(spec, alc268_beep_mixer);
13733
13734         add_verb(spec, alc268_beep_init_verbs);
13735         spec->num_mux_defs = 2;
13736         spec->input_mux = &spec->private_imux[0];
13737
13738         err = alc_auto_add_mic_boost(codec);
13739         if (err < 0)
13740                 return err;
13741
13742         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
13743
13744         return 1;
13745 }
13746
13747 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
13748 #define alc268_auto_init_input_src      alc882_auto_init_input_src
13749
13750 /* init callback for auto-configuration model -- overriding the default init */
13751 static void alc268_auto_init(struct hda_codec *codec)
13752 {
13753         struct alc_spec *spec = codec->spec;
13754         alc268_auto_init_multi_out(codec);
13755         alc268_auto_init_hp_out(codec);
13756         alc268_auto_init_mono_speaker_out(codec);
13757         alc268_auto_init_analog_input(codec);
13758         alc268_auto_init_input_src(codec);
13759         alc_auto_init_digital(codec);
13760         if (spec->unsol_event)
13761                 alc_inithook(codec);
13762 }
13763
13764 /*
13765  * configuration and preset
13766  */
13767 static const char * const alc268_models[ALC268_MODEL_LAST] = {
13768         [ALC267_QUANTA_IL1]     = "quanta-il1",
13769         [ALC268_3ST]            = "3stack",
13770         [ALC268_TOSHIBA]        = "toshiba",
13771         [ALC268_ACER]           = "acer",
13772         [ALC268_ACER_DMIC]      = "acer-dmic",
13773         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
13774         [ALC268_DELL]           = "dell",
13775         [ALC268_ZEPTO]          = "zepto",
13776 #ifdef CONFIG_SND_DEBUG
13777         [ALC268_TEST]           = "test",
13778 #endif
13779         [ALC268_AUTO]           = "auto",
13780 };
13781
13782 static const struct snd_pci_quirk alc268_cfg_tbl[] = {
13783         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
13784         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
13785         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
13786         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
13787         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
13788         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
13789                                                 ALC268_ACER_ASPIRE_ONE),
13790         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
13791         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron 910", ALC268_AUTO),
13792         SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
13793                         "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
13794         /* almost compatible with toshiba but with optional digital outs;
13795          * auto-probing seems working fine
13796          */
13797         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
13798                            ALC268_AUTO),
13799         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
13800         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
13801         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
13802         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
13803         {}
13804 };
13805
13806 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
13807 static const struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
13808         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
13809         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
13810         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
13811                            ALC268_TOSHIBA),
13812         {}
13813 };
13814
13815 static const struct alc_config_preset alc268_presets[] = {
13816         [ALC267_QUANTA_IL1] = {
13817                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
13818                             alc268_capture_nosrc_mixer },
13819                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13820                                 alc267_quanta_il1_verbs },
13821                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13822                 .dac_nids = alc268_dac_nids,
13823                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13824                 .adc_nids = alc268_adc_nids_alt,
13825                 .hp_nid = 0x03,
13826                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13827                 .channel_mode = alc268_modes,
13828                 .unsol_event = alc_sku_unsol_event,
13829                 .setup = alc267_quanta_il1_setup,
13830                 .init_hook = alc_inithook,
13831         },
13832         [ALC268_3ST] = {
13833                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
13834                             alc268_beep_mixer },
13835                 .init_verbs = { alc268_base_init_verbs },
13836                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13837                 .dac_nids = alc268_dac_nids,
13838                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13839                 .adc_nids = alc268_adc_nids_alt,
13840                 .capsrc_nids = alc268_capsrc_nids,
13841                 .hp_nid = 0x03,
13842                 .dig_out_nid = ALC268_DIGOUT_NID,
13843                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13844                 .channel_mode = alc268_modes,
13845                 .input_mux = &alc268_capture_source,
13846         },
13847         [ALC268_TOSHIBA] = {
13848                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
13849                             alc268_beep_mixer },
13850                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13851                                 alc268_toshiba_verbs },
13852                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13853                 .dac_nids = alc268_dac_nids,
13854                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13855                 .adc_nids = alc268_adc_nids_alt,
13856                 .capsrc_nids = alc268_capsrc_nids,
13857                 .hp_nid = 0x03,
13858                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13859                 .channel_mode = alc268_modes,
13860                 .input_mux = &alc268_capture_source,
13861                 .unsol_event = alc_sku_unsol_event,
13862                 .setup = alc268_toshiba_setup,
13863                 .init_hook = alc_inithook,
13864         },
13865         [ALC268_ACER] = {
13866                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
13867                             alc268_beep_mixer },
13868                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13869                                 alc268_acer_verbs },
13870                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13871                 .dac_nids = alc268_dac_nids,
13872                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13873                 .adc_nids = alc268_adc_nids_alt,
13874                 .capsrc_nids = alc268_capsrc_nids,
13875                 .hp_nid = 0x02,
13876                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13877                 .channel_mode = alc268_modes,
13878                 .input_mux = &alc268_acer_capture_source,
13879                 .unsol_event = alc_sku_unsol_event,
13880                 .setup = alc268_acer_setup,
13881                 .init_hook = alc_inithook,
13882         },
13883         [ALC268_ACER_DMIC] = {
13884                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
13885                             alc268_beep_mixer },
13886                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13887                                 alc268_acer_verbs },
13888                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13889                 .dac_nids = alc268_dac_nids,
13890                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13891                 .adc_nids = alc268_adc_nids_alt,
13892                 .capsrc_nids = alc268_capsrc_nids,
13893                 .hp_nid = 0x02,
13894                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13895                 .channel_mode = alc268_modes,
13896                 .input_mux = &alc268_acer_dmic_capture_source,
13897                 .unsol_event = alc_sku_unsol_event,
13898                 .setup = alc268_acer_setup,
13899                 .init_hook = alc_inithook,
13900         },
13901         [ALC268_ACER_ASPIRE_ONE] = {
13902                 .mixers = { alc268_acer_aspire_one_mixer,
13903                             alc268_beep_mixer,
13904                             alc268_capture_nosrc_mixer },
13905                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13906                                 alc268_acer_aspire_one_verbs },
13907                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13908                 .dac_nids = alc268_dac_nids,
13909                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13910                 .adc_nids = alc268_adc_nids_alt,
13911                 .capsrc_nids = alc268_capsrc_nids,
13912                 .hp_nid = 0x03,
13913                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13914                 .channel_mode = alc268_modes,
13915                 .unsol_event = alc_sku_unsol_event,
13916                 .setup = alc268_acer_lc_setup,
13917                 .init_hook = alc_inithook,
13918         },
13919         [ALC268_DELL] = {
13920                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
13921                             alc268_capture_nosrc_mixer },
13922                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13923                                 alc268_dell_verbs },
13924                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13925                 .dac_nids = alc268_dac_nids,
13926                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13927                 .adc_nids = alc268_adc_nids_alt,
13928                 .capsrc_nids = alc268_capsrc_nids,
13929                 .hp_nid = 0x02,
13930                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13931                 .channel_mode = alc268_modes,
13932                 .unsol_event = alc_sku_unsol_event,
13933                 .setup = alc268_dell_setup,
13934                 .init_hook = alc_inithook,
13935         },
13936         [ALC268_ZEPTO] = {
13937                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
13938                             alc268_beep_mixer },
13939                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13940                                 alc268_toshiba_verbs },
13941                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13942                 .dac_nids = alc268_dac_nids,
13943                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13944                 .adc_nids = alc268_adc_nids_alt,
13945                 .capsrc_nids = alc268_capsrc_nids,
13946                 .hp_nid = 0x03,
13947                 .dig_out_nid = ALC268_DIGOUT_NID,
13948                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13949                 .channel_mode = alc268_modes,
13950                 .input_mux = &alc268_capture_source,
13951                 .unsol_event = alc_sku_unsol_event,
13952                 .setup = alc268_toshiba_setup,
13953                 .init_hook = alc_inithook,
13954         },
13955 #ifdef CONFIG_SND_DEBUG
13956         [ALC268_TEST] = {
13957                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
13958                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13959                                 alc268_volume_init_verbs,
13960                                 alc268_beep_init_verbs },
13961                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13962                 .dac_nids = alc268_dac_nids,
13963                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13964                 .adc_nids = alc268_adc_nids_alt,
13965                 .capsrc_nids = alc268_capsrc_nids,
13966                 .hp_nid = 0x03,
13967                 .dig_out_nid = ALC268_DIGOUT_NID,
13968                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13969                 .channel_mode = alc268_modes,
13970                 .input_mux = &alc268_capture_source,
13971         },
13972 #endif
13973 };
13974
13975 static int patch_alc268(struct hda_codec *codec)
13976 {
13977         struct alc_spec *spec;
13978         int board_config;
13979         int i, has_beep, err;
13980
13981         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13982         if (spec == NULL)
13983                 return -ENOMEM;
13984
13985         codec->spec = spec;
13986
13987         /* ALC268 has no aa-loopback mixer */
13988
13989         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
13990                                                   alc268_models,
13991                                                   alc268_cfg_tbl);
13992
13993         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
13994                 board_config = snd_hda_check_board_codec_sid_config(codec,
13995                         ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
13996
13997         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
13998                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13999                        codec->chip_name);
14000                 board_config = ALC268_AUTO;
14001         }
14002
14003         if (board_config == ALC268_AUTO) {
14004                 /* automatic parse from the BIOS config */
14005                 err = alc268_parse_auto_config(codec);
14006                 if (err < 0) {
14007                         alc_free(codec);
14008                         return err;
14009                 } else if (!err) {
14010                         printk(KERN_INFO
14011                                "hda_codec: Cannot set up configuration "
14012                                "from BIOS.  Using base mode...\n");
14013                         board_config = ALC268_3ST;
14014                 }
14015         }
14016
14017         if (board_config != ALC268_AUTO)
14018                 setup_preset(codec, &alc268_presets[board_config]);
14019
14020         spec->stream_analog_playback = &alc268_pcm_analog_playback;
14021         spec->stream_analog_capture = &alc268_pcm_analog_capture;
14022         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
14023
14024         spec->stream_digital_playback = &alc268_pcm_digital_playback;
14025
14026         has_beep = 0;
14027         for (i = 0; i < spec->num_mixers; i++) {
14028                 if (spec->mixers[i] == alc268_beep_mixer) {
14029                         has_beep = 1;
14030                         break;
14031                 }
14032         }
14033
14034         if (has_beep) {
14035                 err = snd_hda_attach_beep_device(codec, 0x1);
14036                 if (err < 0) {
14037                         alc_free(codec);
14038                         return err;
14039                 }
14040                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
14041                         /* override the amp caps for beep generator */
14042                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
14043                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
14044                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
14045                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
14046                                           (0 << AC_AMPCAP_MUTE_SHIFT));
14047         }
14048
14049         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
14050                 /* check whether NID 0x07 is valid */
14051                 unsigned int wcap = get_wcaps(codec, 0x07);
14052
14053                 spec->capsrc_nids = alc268_capsrc_nids;
14054                 /* get type */
14055                 wcap = get_wcaps_type(wcap);
14056                 if (spec->auto_mic ||
14057                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
14058                         spec->adc_nids = alc268_adc_nids_alt;
14059                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
14060                         if (spec->auto_mic)
14061                                 fixup_automic_adc(codec);
14062                         if (spec->auto_mic || spec->input_mux->num_items == 1)
14063                                 add_mixer(spec, alc268_capture_nosrc_mixer);
14064                         else
14065                                 add_mixer(spec, alc268_capture_alt_mixer);
14066                 } else {
14067                         spec->adc_nids = alc268_adc_nids;
14068                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
14069                         add_mixer(spec, alc268_capture_mixer);
14070                 }
14071         }
14072
14073         spec->vmaster_nid = 0x02;
14074
14075         codec->patch_ops = alc_patch_ops;
14076         if (board_config == ALC268_AUTO)
14077                 spec->init_hook = alc268_auto_init;
14078         spec->shutup = alc_eapd_shutup;
14079
14080         alc_init_jacks(codec);
14081
14082         return 0;
14083 }
14084
14085 /*
14086  *  ALC269 channel source setting (2 channel)
14087  */
14088 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
14089
14090 #define alc269_dac_nids         alc260_dac_nids
14091
14092 static const hda_nid_t alc269_adc_nids[1] = {
14093         /* ADC1 */
14094         0x08,
14095 };
14096
14097 static const hda_nid_t alc269_capsrc_nids[1] = {
14098         0x23,
14099 };
14100
14101 static const hda_nid_t alc269vb_adc_nids[1] = {
14102         /* ADC1 */
14103         0x09,
14104 };
14105
14106 static const hda_nid_t alc269vb_capsrc_nids[1] = {
14107         0x22,
14108 };
14109
14110 static const hda_nid_t alc269_adc_candidates[] = {
14111         0x08, 0x09, 0x07, 0x11,
14112 };
14113
14114 #define alc269_modes            alc260_modes
14115 #define alc269_capture_source   alc880_lg_lw_capture_source
14116
14117 static const struct snd_kcontrol_new alc269_base_mixer[] = {
14118         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14119         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14120         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14121         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14122         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14123         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14124         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14125         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14126         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14127         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
14128         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14129         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
14130         { } /* end */
14131 };
14132
14133 static const struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
14134         /* output mixer control */
14135         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
14136         {
14137                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14138                 .name = "Master Playback Switch",
14139                 .subdevice = HDA_SUBDEV_AMP_FLAG,
14140                 .info = snd_hda_mixer_amp_switch_info,
14141                 .get = snd_hda_mixer_amp_switch_get,
14142                 .put = alc268_acer_master_sw_put,
14143                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14144         },
14145         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14146         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14147         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14148         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14149         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14150         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14151         { }
14152 };
14153
14154 static const struct snd_kcontrol_new alc269_lifebook_mixer[] = {
14155         /* output mixer control */
14156         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
14157         {
14158                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14159                 .name = "Master Playback Switch",
14160                 .subdevice = HDA_SUBDEV_AMP_FLAG,
14161                 .info = snd_hda_mixer_amp_switch_info,
14162                 .get = snd_hda_mixer_amp_switch_get,
14163                 .put = alc268_acer_master_sw_put,
14164                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14165         },
14166         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14167         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14168         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14169         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14170         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14171         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14172         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
14173         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
14174         HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x1b, 0, HDA_INPUT),
14175         { }
14176 };
14177
14178 static const struct snd_kcontrol_new alc269_laptop_mixer[] = {
14179         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14180         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14181         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14182         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14183         { } /* end */
14184 };
14185
14186 static const struct snd_kcontrol_new alc269vb_laptop_mixer[] = {
14187         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14188         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14189         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14190         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14191         { } /* end */
14192 };
14193
14194 static const struct snd_kcontrol_new alc269_asus_mixer[] = {
14195         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14196         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x0, HDA_INPUT),
14197         { } /* end */
14198 };
14199
14200 /* capture mixer elements */
14201 static const struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
14202         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
14203         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
14204         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14205         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14206         { } /* end */
14207 };
14208
14209 static const struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = {
14210         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
14211         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
14212         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14213         { } /* end */
14214 };
14215
14216 static const struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = {
14217         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14218         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14219         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14220         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14221         { } /* end */
14222 };
14223
14224 static const struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = {
14225         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14226         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14227         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14228         { } /* end */
14229 };
14230
14231 /* FSC amilo */
14232 #define alc269_fujitsu_mixer    alc269_laptop_mixer
14233
14234 static const struct hda_verb alc269_quanta_fl1_verbs[] = {
14235         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14236         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14237         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14238         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
14239         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14240         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14241         { }
14242 };
14243
14244 static const struct hda_verb alc269_lifebook_verbs[] = {
14245         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14246         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
14247         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14248         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14249         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
14250         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14251         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14252         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
14253         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14254         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14255         { }
14256 };
14257
14258 /* toggle speaker-output according to the hp-jack state */
14259 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
14260 {
14261         alc_hp_automute(codec);
14262
14263         snd_hda_codec_write(codec, 0x20, 0,
14264                         AC_VERB_SET_COEF_INDEX, 0x0c);
14265         snd_hda_codec_write(codec, 0x20, 0,
14266                         AC_VERB_SET_PROC_COEF, 0x680);
14267
14268         snd_hda_codec_write(codec, 0x20, 0,
14269                         AC_VERB_SET_COEF_INDEX, 0x0c);
14270         snd_hda_codec_write(codec, 0x20, 0,
14271                         AC_VERB_SET_PROC_COEF, 0x480);
14272 }
14273
14274 #define alc269_lifebook_speaker_automute \
14275         alc269_quanta_fl1_speaker_automute
14276
14277 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
14278 {
14279         unsigned int present_laptop;
14280         unsigned int present_dock;
14281
14282         present_laptop  = snd_hda_jack_detect(codec, 0x18);
14283         present_dock    = snd_hda_jack_detect(codec, 0x1b);
14284
14285         /* Laptop mic port overrides dock mic port, design decision */
14286         if (present_dock)
14287                 snd_hda_codec_write(codec, 0x23, 0,
14288                                 AC_VERB_SET_CONNECT_SEL, 0x3);
14289         if (present_laptop)
14290                 snd_hda_codec_write(codec, 0x23, 0,
14291                                 AC_VERB_SET_CONNECT_SEL, 0x0);
14292         if (!present_dock && !present_laptop)
14293                 snd_hda_codec_write(codec, 0x23, 0,
14294                                 AC_VERB_SET_CONNECT_SEL, 0x1);
14295 }
14296
14297 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
14298                                     unsigned int res)
14299 {
14300         switch (res >> 26) {
14301         case ALC880_HP_EVENT:
14302                 alc269_quanta_fl1_speaker_automute(codec);
14303                 break;
14304         case ALC880_MIC_EVENT:
14305                 alc_mic_automute(codec);
14306                 break;
14307         }
14308 }
14309
14310 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
14311                                         unsigned int res)
14312 {
14313         if ((res >> 26) == ALC880_HP_EVENT)
14314                 alc269_lifebook_speaker_automute(codec);
14315         if ((res >> 26) == ALC880_MIC_EVENT)
14316                 alc269_lifebook_mic_autoswitch(codec);
14317 }
14318
14319 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
14320 {
14321         struct alc_spec *spec = codec->spec;
14322         spec->autocfg.hp_pins[0] = 0x15;
14323         spec->autocfg.speaker_pins[0] = 0x14;
14324         spec->automute_mixer_nid[0] = 0x0c;
14325         spec->automute = 1;
14326         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14327         spec->ext_mic.pin = 0x18;
14328         spec->ext_mic.mux_idx = 0;
14329         spec->int_mic.pin = 0x19;
14330         spec->int_mic.mux_idx = 1;
14331         spec->auto_mic = 1;
14332 }
14333
14334 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
14335 {
14336         alc269_quanta_fl1_speaker_automute(codec);
14337         alc_mic_automute(codec);
14338 }
14339
14340 static void alc269_lifebook_setup(struct hda_codec *codec)
14341 {
14342         struct alc_spec *spec = codec->spec;
14343         spec->autocfg.hp_pins[0] = 0x15;
14344         spec->autocfg.hp_pins[1] = 0x1a;
14345         spec->autocfg.speaker_pins[0] = 0x14;
14346         spec->automute_mixer_nid[0] = 0x0c;
14347         spec->automute = 1;
14348         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14349 }
14350
14351 static void alc269_lifebook_init_hook(struct hda_codec *codec)
14352 {
14353         alc269_lifebook_speaker_automute(codec);
14354         alc269_lifebook_mic_autoswitch(codec);
14355 }
14356
14357 static const struct hda_verb alc269_laptop_dmic_init_verbs[] = {
14358         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14359         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
14360         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14361         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
14362         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14363         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14364         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14365         {}
14366 };
14367
14368 static const struct hda_verb alc269_laptop_amic_init_verbs[] = {
14369         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14370         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
14371         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14372         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
14373         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14374         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14375         {}
14376 };
14377
14378 static const struct hda_verb alc269vb_laptop_dmic_init_verbs[] = {
14379         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
14380         {0x22, AC_VERB_SET_CONNECT_SEL, 0x06},
14381         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14382         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
14383         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14384         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14385         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14386         {}
14387 };
14388
14389 static const struct hda_verb alc269vb_laptop_amic_init_verbs[] = {
14390         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
14391         {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
14392         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14393         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
14394         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14395         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14396         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14397         {}
14398 };
14399
14400 static const struct hda_verb alc271_acer_dmic_verbs[] = {
14401         {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
14402         {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
14403         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14404         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14405         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14406         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14407         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},
14408         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14409         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14410         {0x22, AC_VERB_SET_CONNECT_SEL, 6},
14411         { }
14412 };
14413
14414 static void alc269_laptop_amic_setup(struct hda_codec *codec)
14415 {
14416         struct alc_spec *spec = codec->spec;
14417         spec->autocfg.hp_pins[0] = 0x15;
14418         spec->autocfg.speaker_pins[0] = 0x14;
14419         spec->automute_mixer_nid[0] = 0x0c;
14420         spec->automute = 1;
14421         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14422         spec->ext_mic.pin = 0x18;
14423         spec->ext_mic.mux_idx = 0;
14424         spec->int_mic.pin = 0x19;
14425         spec->int_mic.mux_idx = 1;
14426         spec->auto_mic = 1;
14427 }
14428
14429 static void alc269_laptop_dmic_setup(struct hda_codec *codec)
14430 {
14431         struct alc_spec *spec = codec->spec;
14432         spec->autocfg.hp_pins[0] = 0x15;
14433         spec->autocfg.speaker_pins[0] = 0x14;
14434         spec->automute_mixer_nid[0] = 0x0c;
14435         spec->automute = 1;
14436         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14437         spec->ext_mic.pin = 0x18;
14438         spec->ext_mic.mux_idx = 0;
14439         spec->int_mic.pin = 0x12;
14440         spec->int_mic.mux_idx = 5;
14441         spec->auto_mic = 1;
14442 }
14443
14444 static void alc269vb_laptop_amic_setup(struct hda_codec *codec)
14445 {
14446         struct alc_spec *spec = codec->spec;
14447         spec->autocfg.hp_pins[0] = 0x21;
14448         spec->autocfg.speaker_pins[0] = 0x14;
14449         spec->automute_mixer_nid[0] = 0x0c;
14450         spec->automute = 1;
14451         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14452         spec->ext_mic.pin = 0x18;
14453         spec->ext_mic.mux_idx = 0;
14454         spec->int_mic.pin = 0x19;
14455         spec->int_mic.mux_idx = 1;
14456         spec->auto_mic = 1;
14457 }
14458
14459 static void alc269vb_laptop_dmic_setup(struct hda_codec *codec)
14460 {
14461         struct alc_spec *spec = codec->spec;
14462         spec->autocfg.hp_pins[0] = 0x21;
14463         spec->autocfg.speaker_pins[0] = 0x14;
14464         spec->automute_mixer_nid[0] = 0x0c;
14465         spec->automute = 1;
14466         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14467         spec->ext_mic.pin = 0x18;
14468         spec->ext_mic.mux_idx = 0;
14469         spec->int_mic.pin = 0x12;
14470         spec->int_mic.mux_idx = 6;
14471         spec->auto_mic = 1;
14472 }
14473
14474 /*
14475  * generic initialization of ADC, input mixers and output mixers
14476  */
14477 static const struct hda_verb alc269_init_verbs[] = {
14478         /*
14479          * Unmute ADC0 and set the default input to mic-in
14480          */
14481         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14482
14483         /*
14484          * Set up output mixers (0x02 - 0x03)
14485          */
14486         /* set vol=0 to output mixers */
14487         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14488         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14489
14490         /* set up input amps for analog loopback */
14491         /* Amp Indices: DAC = 0, mixer = 1 */
14492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14494         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14495         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14496         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14497         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14498
14499         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14500         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14501         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14502         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14503         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14504         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14505         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14506
14507         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14508         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14509
14510         /* FIXME: use Mux-type input source selection */
14511         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
14512         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
14513         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
14514
14515         /* set EAPD */
14516         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14517         { }
14518 };
14519
14520 static const struct hda_verb alc269vb_init_verbs[] = {
14521         /*
14522          * Unmute ADC0 and set the default input to mic-in
14523          */
14524         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14525
14526         /*
14527          * Set up output mixers (0x02 - 0x03)
14528          */
14529         /* set vol=0 to output mixers */
14530         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14531         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14532
14533         /* set up input amps for analog loopback */
14534         /* Amp Indices: DAC = 0, mixer = 1 */
14535         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14536         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14537         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14538         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14539         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14540         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14541
14542         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14543         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14544         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14545         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14546         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14547         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14548         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14549
14550         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14551         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14552
14553         /* FIXME: use Mux-type input source selection */
14554         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
14555         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
14556         {0x22, AC_VERB_SET_CONNECT_SEL, 0x00},
14557
14558         /* set EAPD */
14559         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14560         { }
14561 };
14562
14563 #define alc269_auto_create_multi_out_ctls \
14564         alc268_auto_create_multi_out_ctls
14565 #define alc269_auto_create_input_ctls \
14566         alc268_auto_create_input_ctls
14567
14568 #ifdef CONFIG_SND_HDA_POWER_SAVE
14569 #define alc269_loopbacks        alc880_loopbacks
14570 #endif
14571
14572 /* pcm configuration: identical with ALC880 */
14573 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
14574 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
14575 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
14576 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
14577
14578 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
14579         .substreams = 1,
14580         .channels_min = 2,
14581         .channels_max = 8,
14582         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
14583         /* NID is set in alc_build_pcms */
14584         .ops = {
14585                 .open = alc880_playback_pcm_open,
14586                 .prepare = alc880_playback_pcm_prepare,
14587                 .cleanup = alc880_playback_pcm_cleanup
14588         },
14589 };
14590
14591 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
14592         .substreams = 1,
14593         .channels_min = 2,
14594         .channels_max = 2,
14595         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
14596         /* NID is set in alc_build_pcms */
14597 };
14598
14599 #ifdef CONFIG_SND_HDA_POWER_SAVE
14600 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
14601 {
14602         switch (codec->subsystem_id) {
14603         case 0x103c1586:
14604                 return 1;
14605         }
14606         return 0;
14607 }
14608
14609 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
14610 {
14611         /* update mute-LED according to the speaker mute state */
14612         if (nid == 0x01 || nid == 0x14) {
14613                 int pinval;
14614                 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
14615                     HDA_AMP_MUTE)
14616                         pinval = 0x24;
14617                 else
14618                         pinval = 0x20;
14619                 /* mic2 vref pin is used for mute LED control */
14620                 snd_hda_codec_update_cache(codec, 0x19, 0,
14621                                            AC_VERB_SET_PIN_WIDGET_CONTROL,
14622                                            pinval);
14623         }
14624         return alc_check_power_status(codec, nid);
14625 }
14626 #endif /* CONFIG_SND_HDA_POWER_SAVE */
14627
14628 static int alc275_setup_dual_adc(struct hda_codec *codec)
14629 {
14630         struct alc_spec *spec = codec->spec;
14631
14632         if (codec->vendor_id != 0x10ec0275 || !spec->auto_mic)
14633                 return 0;
14634         if ((spec->ext_mic.pin >= 0x18 && spec->int_mic.pin <= 0x13) ||
14635             (spec->ext_mic.pin <= 0x12 && spec->int_mic.pin >= 0x18)) {
14636                 if (spec->ext_mic.pin <= 0x12) {
14637                         spec->private_adc_nids[0] = 0x08;
14638                         spec->private_adc_nids[1] = 0x11;
14639                         spec->private_capsrc_nids[0] = 0x23;
14640                         spec->private_capsrc_nids[1] = 0x22;
14641                 } else {
14642                         spec->private_adc_nids[0] = 0x11;
14643                         spec->private_adc_nids[1] = 0x08;
14644                         spec->private_capsrc_nids[0] = 0x22;
14645                         spec->private_capsrc_nids[1] = 0x23;
14646                 }
14647                 spec->adc_nids = spec->private_adc_nids;
14648                 spec->capsrc_nids = spec->private_capsrc_nids;
14649                 spec->num_adc_nids = 2;
14650                 spec->dual_adc_switch = 1;
14651                 snd_printdd("realtek: enabling dual ADC switchg (%02x:%02x)\n",
14652                             spec->adc_nids[0], spec->adc_nids[1]);
14653                 return 1;
14654         }
14655         return 0;
14656 }
14657
14658 /* different alc269-variants */
14659 enum {
14660         ALC269_TYPE_NORMAL,
14661         ALC269_TYPE_ALC258,
14662         ALC269_TYPE_ALC259,
14663         ALC269_TYPE_ALC269VB,
14664         ALC269_TYPE_ALC270,
14665         ALC269_TYPE_ALC271X,
14666 };
14667
14668 /*
14669  * BIOS auto configuration
14670  */
14671 static int alc269_parse_auto_config(struct hda_codec *codec)
14672 {
14673         struct alc_spec *spec = codec->spec;
14674         int err;
14675         static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
14676
14677         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14678                                            alc269_ignore);
14679         if (err < 0)
14680                 return err;
14681
14682         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
14683         if (err < 0)
14684                 return err;
14685         if (spec->codec_variant == ALC269_TYPE_NORMAL)
14686                 err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
14687         else
14688                 err = alc_auto_create_input_ctls(codec, &spec->autocfg, 0,
14689                                                  0x22, 0);
14690         if (err < 0)
14691                 return err;
14692
14693         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14694
14695         alc_auto_parse_digital(codec);
14696
14697         if (spec->kctls.list)
14698                 add_mixer(spec, spec->kctls.list);
14699
14700         if (spec->codec_variant != ALC269_TYPE_NORMAL)
14701                 alc_ssid_check(codec, 0, 0x1b, 0x14, 0x21);
14702         else
14703                 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
14704
14705         spec->num_mux_defs = 1;
14706         spec->input_mux = &spec->private_imux[0];
14707
14708         if (!alc275_setup_dual_adc(codec))
14709                 fillup_priv_adc_nids(codec, alc269_adc_candidates,
14710                                      sizeof(alc269_adc_candidates));
14711
14712         err = alc_auto_add_mic_boost(codec);
14713         if (err < 0)
14714                 return err;
14715
14716         if (!spec->cap_mixer && !spec->no_analog)
14717                 set_capture_mixer(codec);
14718
14719         return 1;
14720 }
14721
14722 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
14723 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
14724 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
14725 #define alc269_auto_init_input_src      alc882_auto_init_input_src
14726
14727
14728 /* init callback for auto-configuration model -- overriding the default init */
14729 static void alc269_auto_init(struct hda_codec *codec)
14730 {
14731         struct alc_spec *spec = codec->spec;
14732         alc269_auto_init_multi_out(codec);
14733         alc269_auto_init_hp_out(codec);
14734         alc269_auto_init_analog_input(codec);
14735         if (!spec->dual_adc_switch)
14736                 alc269_auto_init_input_src(codec);
14737         alc_auto_init_digital(codec);
14738         if (spec->unsol_event)
14739                 alc_inithook(codec);
14740 }
14741
14742 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
14743 {
14744         int val = alc_read_coef_idx(codec, 0x04);
14745         if (power_up)
14746                 val |= 1 << 11;
14747         else
14748                 val &= ~(1 << 11);
14749         alc_write_coef_idx(codec, 0x04, val);
14750 }
14751
14752 static void alc269_shutup(struct hda_codec *codec)
14753 {
14754         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
14755                 alc269_toggle_power_output(codec, 0);
14756         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
14757                 alc269_toggle_power_output(codec, 0);
14758                 msleep(150);
14759         }
14760 }
14761
14762 #ifdef SND_HDA_NEEDS_RESUME
14763 static int alc269_resume(struct hda_codec *codec)
14764 {
14765         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
14766                 alc269_toggle_power_output(codec, 0);
14767                 msleep(150);
14768         }
14769
14770         codec->patch_ops.init(codec);
14771
14772         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
14773                 alc269_toggle_power_output(codec, 1);
14774                 msleep(200);
14775         }
14776
14777         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
14778                 alc269_toggle_power_output(codec, 1);
14779
14780         snd_hda_codec_resume_amp(codec);
14781         snd_hda_codec_resume_cache(codec);
14782         hda_call_check_power_status(codec, 0x01);
14783         return 0;
14784 }
14785 #endif /* SND_HDA_NEEDS_RESUME */
14786
14787 static void alc269_fixup_hweq(struct hda_codec *codec,
14788                                const struct alc_fixup *fix, int action)
14789 {
14790         int coef;
14791
14792         if (action != ALC_FIXUP_ACT_INIT)
14793                 return;
14794         coef = alc_read_coef_idx(codec, 0x1e);
14795         alc_write_coef_idx(codec, 0x1e, coef | 0x80);
14796 }
14797
14798 static void alc271_fixup_dmic(struct hda_codec *codec,
14799                               const struct alc_fixup *fix, int action)
14800 {
14801         static const struct hda_verb verbs[] = {
14802                 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
14803                 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
14804                 {}
14805         };
14806         unsigned int cfg;
14807
14808         if (strcmp(codec->chip_name, "ALC271X"))
14809                 return;
14810         cfg = snd_hda_codec_get_pincfg(codec, 0x12);
14811         if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
14812                 snd_hda_sequence_write(codec, verbs);
14813 }
14814
14815 enum {
14816         ALC269_FIXUP_SONY_VAIO,
14817         ALC275_FIXUP_SONY_VAIO_GPIO2,
14818         ALC269_FIXUP_DELL_M101Z,
14819         ALC269_FIXUP_SKU_IGNORE,
14820         ALC269_FIXUP_ASUS_G73JW,
14821         ALC269_FIXUP_LENOVO_EAPD,
14822         ALC275_FIXUP_SONY_HWEQ,
14823         ALC271_FIXUP_DMIC,
14824 };
14825
14826 static const struct alc_fixup alc269_fixups[] = {
14827         [ALC269_FIXUP_SONY_VAIO] = {
14828                 .type = ALC_FIXUP_VERBS,
14829                 .v.verbs = (const struct hda_verb[]) {
14830                         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
14831                         {}
14832                 }
14833         },
14834         [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
14835                 .type = ALC_FIXUP_VERBS,
14836                 .v.verbs = (const struct hda_verb[]) {
14837                         {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
14838                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
14839                         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
14840                         { }
14841                 },
14842                 .chained = true,
14843                 .chain_id = ALC269_FIXUP_SONY_VAIO
14844         },
14845         [ALC269_FIXUP_DELL_M101Z] = {
14846                 .type = ALC_FIXUP_VERBS,
14847                 .v.verbs = (const struct hda_verb[]) {
14848                         /* Enables internal speaker */
14849                         {0x20, AC_VERB_SET_COEF_INDEX, 13},
14850                         {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
14851                         {}
14852                 }
14853         },
14854         [ALC269_FIXUP_SKU_IGNORE] = {
14855                 .type = ALC_FIXUP_SKU,
14856                 .v.sku = ALC_FIXUP_SKU_IGNORE,
14857         },
14858         [ALC269_FIXUP_ASUS_G73JW] = {
14859                 .type = ALC_FIXUP_PINS,
14860                 .v.pins = (const struct alc_pincfg[]) {
14861                         { 0x17, 0x99130111 }, /* subwoofer */
14862                         { }
14863                 }
14864         },
14865         [ALC269_FIXUP_LENOVO_EAPD] = {
14866                 .type = ALC_FIXUP_VERBS,
14867                 .v.verbs = (const struct hda_verb[]) {
14868                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
14869                         {}
14870                 }
14871         },
14872         [ALC275_FIXUP_SONY_HWEQ] = {
14873                 .type = ALC_FIXUP_FUNC,
14874                 .v.func = alc269_fixup_hweq,
14875                 .chained = true,
14876                 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
14877         },
14878         [ALC271_FIXUP_DMIC] = {
14879                 .type = ALC_FIXUP_FUNC,
14880                 .v.func = alc271_fixup_dmic,
14881         },
14882 };
14883
14884 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
14885         SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
14886         SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
14887         SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
14888         SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
14889         SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
14890         SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
14891         SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
14892         SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
14893         SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
14894         SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
14895         SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
14896         SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
14897         SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
14898         {}
14899 };
14900
14901
14902 /*
14903  * configuration and preset
14904  */
14905 static const char * const alc269_models[ALC269_MODEL_LAST] = {
14906         [ALC269_BASIC]                  = "basic",
14907         [ALC269_QUANTA_FL1]             = "quanta",
14908         [ALC269_AMIC]                   = "laptop-amic",
14909         [ALC269_DMIC]                   = "laptop-dmic",
14910         [ALC269_FUJITSU]                = "fujitsu",
14911         [ALC269_LIFEBOOK]               = "lifebook",
14912         [ALC269_AUTO]                   = "auto",
14913 };
14914
14915 static const struct snd_pci_quirk alc269_cfg_tbl[] = {
14916         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
14917         SND_PCI_QUIRK(0x1025, 0x047c, "ACER ZGA", ALC271_ACER),
14918         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
14919                       ALC269_AMIC),
14920         SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC),
14921         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269VB_AMIC),
14922         SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269VB_AMIC),
14923         SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_AMIC),
14924         SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269VB_AMIC),
14925         SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269VB_AMIC),
14926         SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269VB_AMIC),
14927         SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269VB_AMIC),
14928         SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_AMIC),
14929         SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269VB_AMIC),
14930         SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_AMIC),
14931         SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_AMIC),
14932         SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_AMIC),
14933         SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_AMIC),
14934         SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_AMIC),
14935         SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_AMIC),
14936         SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_AMIC),
14937         SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_AMIC),
14938         SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_AMIC),
14939         SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_AMIC),
14940         SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_AMIC),
14941         SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_AMIC),
14942         SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_AMIC),
14943         SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_AMIC),
14944         SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_AMIC),
14945         SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_AMIC),
14946         SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_AMIC),
14947         SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_AMIC),
14948         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_AMIC),
14949         SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_AMIC),
14950         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_AMIC),
14951         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_DMIC),
14952         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_AMIC),
14953         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_AMIC),
14954         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_AMIC),
14955         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_AMIC),
14956         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
14957                       ALC269_DMIC),
14958         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
14959                       ALC269_DMIC),
14960         SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005HA", ALC269_DMIC),
14961         SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005HA", ALC269_DMIC),
14962         SND_PCI_QUIRK(0x104d, 0x9071, "Sony VAIO", ALC269_AUTO),
14963         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
14964         SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_DMIC),
14965         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
14966         SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_AMIC),
14967         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_AMIC),
14968         SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_DMIC),
14969         SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_DMIC),
14970         {}
14971 };
14972
14973 static const struct alc_config_preset alc269_presets[] = {
14974         [ALC269_BASIC] = {
14975                 .mixers = { alc269_base_mixer },
14976                 .init_verbs = { alc269_init_verbs },
14977                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
14978                 .dac_nids = alc269_dac_nids,
14979                 .hp_nid = 0x03,
14980                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
14981                 .channel_mode = alc269_modes,
14982                 .input_mux = &alc269_capture_source,
14983         },
14984         [ALC269_QUANTA_FL1] = {
14985                 .mixers = { alc269_quanta_fl1_mixer },
14986                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
14987                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
14988                 .dac_nids = alc269_dac_nids,
14989                 .hp_nid = 0x03,
14990                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
14991                 .channel_mode = alc269_modes,
14992                 .input_mux = &alc269_capture_source,
14993                 .unsol_event = alc269_quanta_fl1_unsol_event,
14994                 .setup = alc269_quanta_fl1_setup,
14995                 .init_hook = alc269_quanta_fl1_init_hook,
14996         },
14997         [ALC269_AMIC] = {
14998                 .mixers = { alc269_laptop_mixer },
14999                 .cap_mixer = alc269_laptop_analog_capture_mixer,
15000                 .init_verbs = { alc269_init_verbs,
15001                                 alc269_laptop_amic_init_verbs },
15002                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15003                 .dac_nids = alc269_dac_nids,
15004                 .hp_nid = 0x03,
15005                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15006                 .channel_mode = alc269_modes,
15007                 .unsol_event = alc_sku_unsol_event,
15008                 .setup = alc269_laptop_amic_setup,
15009                 .init_hook = alc_inithook,
15010         },
15011         [ALC269_DMIC] = {
15012                 .mixers = { alc269_laptop_mixer },
15013                 .cap_mixer = alc269_laptop_digital_capture_mixer,
15014                 .init_verbs = { alc269_init_verbs,
15015                                 alc269_laptop_dmic_init_verbs },
15016                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15017                 .dac_nids = alc269_dac_nids,
15018                 .hp_nid = 0x03,
15019                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15020                 .channel_mode = alc269_modes,
15021                 .unsol_event = alc_sku_unsol_event,
15022                 .setup = alc269_laptop_dmic_setup,
15023                 .init_hook = alc_inithook,
15024         },
15025         [ALC269VB_AMIC] = {
15026                 .mixers = { alc269vb_laptop_mixer },
15027                 .cap_mixer = alc269vb_laptop_analog_capture_mixer,
15028                 .init_verbs = { alc269vb_init_verbs,
15029                                 alc269vb_laptop_amic_init_verbs },
15030                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15031                 .dac_nids = alc269_dac_nids,
15032                 .hp_nid = 0x03,
15033                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15034                 .channel_mode = alc269_modes,
15035                 .unsol_event = alc_sku_unsol_event,
15036                 .setup = alc269vb_laptop_amic_setup,
15037                 .init_hook = alc_inithook,
15038         },
15039         [ALC269VB_DMIC] = {
15040                 .mixers = { alc269vb_laptop_mixer },
15041                 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
15042                 .init_verbs = { alc269vb_init_verbs,
15043                                 alc269vb_laptop_dmic_init_verbs },
15044                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15045                 .dac_nids = alc269_dac_nids,
15046                 .hp_nid = 0x03,
15047                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15048                 .channel_mode = alc269_modes,
15049                 .unsol_event = alc_sku_unsol_event,
15050                 .setup = alc269vb_laptop_dmic_setup,
15051                 .init_hook = alc_inithook,
15052         },
15053         [ALC269_FUJITSU] = {
15054                 .mixers = { alc269_fujitsu_mixer },
15055                 .cap_mixer = alc269_laptop_digital_capture_mixer,
15056                 .init_verbs = { alc269_init_verbs,
15057                                 alc269_laptop_dmic_init_verbs },
15058                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15059                 .dac_nids = alc269_dac_nids,
15060                 .hp_nid = 0x03,
15061                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15062                 .channel_mode = alc269_modes,
15063                 .unsol_event = alc_sku_unsol_event,
15064                 .setup = alc269_laptop_dmic_setup,
15065                 .init_hook = alc_inithook,
15066         },
15067         [ALC269_LIFEBOOK] = {
15068                 .mixers = { alc269_lifebook_mixer },
15069                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
15070                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15071                 .dac_nids = alc269_dac_nids,
15072                 .hp_nid = 0x03,
15073                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15074                 .channel_mode = alc269_modes,
15075                 .input_mux = &alc269_capture_source,
15076                 .unsol_event = alc269_lifebook_unsol_event,
15077                 .setup = alc269_lifebook_setup,
15078                 .init_hook = alc269_lifebook_init_hook,
15079         },
15080         [ALC271_ACER] = {
15081                 .mixers = { alc269_asus_mixer },
15082                 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
15083                 .init_verbs = { alc269_init_verbs, alc271_acer_dmic_verbs },
15084                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15085                 .dac_nids = alc269_dac_nids,
15086                 .adc_nids = alc262_dmic_adc_nids,
15087                 .num_adc_nids = ARRAY_SIZE(alc262_dmic_adc_nids),
15088                 .capsrc_nids = alc262_dmic_capsrc_nids,
15089                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15090                 .channel_mode = alc269_modes,
15091                 .input_mux = &alc269_capture_source,
15092                 .dig_out_nid = ALC880_DIGOUT_NID,
15093                 .unsol_event = alc_sku_unsol_event,
15094                 .setup = alc269vb_laptop_dmic_setup,
15095                 .init_hook = alc_inithook,
15096         },
15097 };
15098
15099 static int alc269_fill_coef(struct hda_codec *codec)
15100 {
15101         int val;
15102
15103         if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
15104                 alc_write_coef_idx(codec, 0xf, 0x960b);
15105                 alc_write_coef_idx(codec, 0xe, 0x8817);
15106         }
15107
15108         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
15109                 alc_write_coef_idx(codec, 0xf, 0x960b);
15110                 alc_write_coef_idx(codec, 0xe, 0x8814);
15111         }
15112
15113         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
15114                 val = alc_read_coef_idx(codec, 0x04);
15115                 /* Power up output pin */
15116                 alc_write_coef_idx(codec, 0x04, val | (1<<11));
15117         }
15118
15119         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
15120                 val = alc_read_coef_idx(codec, 0xd);
15121                 if ((val & 0x0c00) >> 10 != 0x1) {
15122                         /* Capless ramp up clock control */
15123                         alc_write_coef_idx(codec, 0xd, val | (1<<10));
15124                 }
15125                 val = alc_read_coef_idx(codec, 0x17);
15126                 if ((val & 0x01c0) >> 6 != 0x4) {
15127                         /* Class D power on reset */
15128                         alc_write_coef_idx(codec, 0x17, val | (1<<7));
15129                 }
15130         }
15131
15132         val = alc_read_coef_idx(codec, 0xd); /* Class D */
15133         alc_write_coef_idx(codec, 0xd, val | (1<<14));
15134
15135         val = alc_read_coef_idx(codec, 0x4); /* HP */
15136         alc_write_coef_idx(codec, 0x4, val | (1<<11));
15137
15138         return 0;
15139 }
15140
15141 static int patch_alc269(struct hda_codec *codec)
15142 {
15143         struct alc_spec *spec;
15144         int board_config, coef;
15145         int err;
15146
15147         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15148         if (spec == NULL)
15149                 return -ENOMEM;
15150
15151         codec->spec = spec;
15152
15153         spec->mixer_nid = 0x0b;
15154
15155         alc_auto_parse_customize_define(codec);
15156
15157         if (codec->vendor_id == 0x10ec0269) {
15158                 coef = alc_read_coef_idx(codec, 0);
15159                 if ((coef & 0x00f0) == 0x0010) {
15160                         if (codec->bus->pci->subsystem_vendor == 0x1025 &&
15161                             spec->cdefine.platform_type == 1) {
15162                                 alc_codec_rename(codec, "ALC271X");
15163                                 spec->codec_variant = ALC269_TYPE_ALC271X;
15164                         } else if ((coef & 0xf000) == 0x1000) {
15165                                 spec->codec_variant = ALC269_TYPE_ALC270;
15166                         } else if ((coef & 0xf000) == 0x2000) {
15167                                 alc_codec_rename(codec, "ALC259");
15168                                 spec->codec_variant = ALC269_TYPE_ALC259;
15169                         } else if ((coef & 0xf000) == 0x3000) {
15170                                 alc_codec_rename(codec, "ALC258");
15171                                 spec->codec_variant = ALC269_TYPE_ALC258;
15172                         } else {
15173                                 alc_codec_rename(codec, "ALC269VB");
15174                                 spec->codec_variant = ALC269_TYPE_ALC269VB;
15175                         }
15176                 } else
15177                         alc_fix_pll_init(codec, 0x20, 0x04, 15);
15178                 alc269_fill_coef(codec);
15179         }
15180
15181         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
15182                                                   alc269_models,
15183                                                   alc269_cfg_tbl);
15184
15185         if (board_config < 0) {
15186                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15187                        codec->chip_name);
15188                 board_config = ALC269_AUTO;
15189         }
15190
15191         if (board_config == ALC269_AUTO) {
15192                 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
15193                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
15194         }
15195
15196         if (board_config == ALC269_AUTO) {
15197                 /* automatic parse from the BIOS config */
15198                 err = alc269_parse_auto_config(codec);
15199                 if (err < 0) {
15200                         alc_free(codec);
15201                         return err;
15202                 } else if (!err) {
15203                         printk(KERN_INFO
15204                                "hda_codec: Cannot set up configuration "
15205                                "from BIOS.  Using base mode...\n");
15206                         board_config = ALC269_BASIC;
15207                 }
15208         }
15209
15210         if (has_cdefine_beep(codec)) {
15211                 err = snd_hda_attach_beep_device(codec, 0x1);
15212                 if (err < 0) {
15213                         alc_free(codec);
15214                         return err;
15215                 }
15216         }
15217
15218         if (board_config != ALC269_AUTO)
15219                 setup_preset(codec, &alc269_presets[board_config]);
15220
15221         if (board_config == ALC269_QUANTA_FL1) {
15222                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
15223                  * fix the sample rate of analog I/O to 44.1kHz
15224                  */
15225                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
15226                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
15227         } else if (spec->dual_adc_switch) {
15228                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
15229                 /* switch ADC dynamically */
15230                 spec->stream_analog_capture = &dualmic_pcm_analog_capture;
15231         } else {
15232                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
15233                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
15234         }
15235         spec->stream_digital_playback = &alc269_pcm_digital_playback;
15236         spec->stream_digital_capture = &alc269_pcm_digital_capture;
15237
15238         if (!spec->adc_nids) { /* wasn't filled automatically? use default */
15239                 if (spec->codec_variant == ALC269_TYPE_NORMAL) {
15240                         spec->adc_nids = alc269_adc_nids;
15241                         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
15242                         spec->capsrc_nids = alc269_capsrc_nids;
15243                 } else {
15244                         spec->adc_nids = alc269vb_adc_nids;
15245                         spec->num_adc_nids = ARRAY_SIZE(alc269vb_adc_nids);
15246                         spec->capsrc_nids = alc269vb_capsrc_nids;
15247                 }
15248         }
15249
15250         if (!spec->cap_mixer)
15251                 set_capture_mixer(codec);
15252         if (has_cdefine_beep(codec))
15253                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
15254
15255         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
15256
15257         spec->vmaster_nid = 0x02;
15258
15259         codec->patch_ops = alc_patch_ops;
15260 #ifdef SND_HDA_NEEDS_RESUME
15261         codec->patch_ops.resume = alc269_resume;
15262 #endif
15263         if (board_config == ALC269_AUTO)
15264                 spec->init_hook = alc269_auto_init;
15265         spec->shutup = alc269_shutup;
15266
15267         alc_init_jacks(codec);
15268 #ifdef CONFIG_SND_HDA_POWER_SAVE
15269         if (!spec->loopback.amplist)
15270                 spec->loopback.amplist = alc269_loopbacks;
15271         if (alc269_mic2_for_mute_led(codec))
15272                 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
15273 #endif
15274
15275         return 0;
15276 }
15277
15278 /*
15279  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
15280  */
15281
15282 /*
15283  * set the path ways for 2 channel output
15284  * need to set the codec line out and mic 1 pin widgets to inputs
15285  */
15286 static const struct hda_verb alc861_threestack_ch2_init[] = {
15287         /* set pin widget 1Ah (line in) for input */
15288         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15289         /* set pin widget 18h (mic1/2) for input, for mic also enable
15290          * the vref
15291          */
15292         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15293
15294         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
15295 #if 0
15296         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
15297         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
15298 #endif
15299         { } /* end */
15300 };
15301 /*
15302  * 6ch mode
15303  * need to set the codec line out and mic 1 pin widgets to outputs
15304  */
15305 static const struct hda_verb alc861_threestack_ch6_init[] = {
15306         /* set pin widget 1Ah (line in) for output (Back Surround)*/
15307         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15308         /* set pin widget 18h (mic1) for output (CLFE)*/
15309         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15310
15311         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
15312         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
15313
15314         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
15315 #if 0
15316         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
15317         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
15318 #endif
15319         { } /* end */
15320 };
15321
15322 static const struct hda_channel_mode alc861_threestack_modes[2] = {
15323         { 2, alc861_threestack_ch2_init },
15324         { 6, alc861_threestack_ch6_init },
15325 };
15326 /* Set mic1 as input and unmute the mixer */
15327 static const struct hda_verb alc861_uniwill_m31_ch2_init[] = {
15328         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15329         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
15330         { } /* end */
15331 };
15332 /* Set mic1 as output and mute mixer */
15333 static const struct hda_verb alc861_uniwill_m31_ch4_init[] = {
15334         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15335         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
15336         { } /* end */
15337 };
15338
15339 static const struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
15340         { 2, alc861_uniwill_m31_ch2_init },
15341         { 4, alc861_uniwill_m31_ch4_init },
15342 };
15343
15344 /* Set mic1 and line-in as input and unmute the mixer */
15345 static const struct hda_verb alc861_asus_ch2_init[] = {
15346         /* set pin widget 1Ah (line in) for input */
15347         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15348         /* set pin widget 18h (mic1/2) for input, for mic also enable
15349          * the vref
15350          */
15351         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15352
15353         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
15354 #if 0
15355         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
15356         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
15357 #endif
15358         { } /* end */
15359 };
15360 /* Set mic1 nad line-in as output and mute mixer */
15361 static const struct hda_verb alc861_asus_ch6_init[] = {
15362         /* set pin widget 1Ah (line in) for output (Back Surround)*/
15363         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15364         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
15365         /* set pin widget 18h (mic1) for output (CLFE)*/
15366         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15367         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
15368         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
15369         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
15370
15371         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
15372 #if 0
15373         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
15374         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
15375 #endif
15376         { } /* end */
15377 };
15378
15379 static const struct hda_channel_mode alc861_asus_modes[2] = {
15380         { 2, alc861_asus_ch2_init },
15381         { 6, alc861_asus_ch6_init },
15382 };
15383
15384 /* patch-ALC861 */
15385
15386 static const struct snd_kcontrol_new alc861_base_mixer[] = {
15387         /* output mixer control */
15388         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15389         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15390         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15391         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15392         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
15393
15394         /*Input mixer control */
15395         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15396            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
15397         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15398         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15399         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15400         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15401         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15402         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15403         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15404         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
15405
15406         { } /* end */
15407 };
15408
15409 static const struct snd_kcontrol_new alc861_3ST_mixer[] = {
15410         /* output mixer control */
15411         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15412         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15413         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15414         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15415         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
15416
15417         /* Input mixer control */
15418         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15419            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
15420         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15421         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15422         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15423         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15424         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15425         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15426         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15427         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
15428
15429         {
15430                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15431                 .name = "Channel Mode",
15432                 .info = alc_ch_mode_info,
15433                 .get = alc_ch_mode_get,
15434                 .put = alc_ch_mode_put,
15435                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
15436         },
15437         { } /* end */
15438 };
15439
15440 static const struct snd_kcontrol_new alc861_toshiba_mixer[] = {
15441         /* output mixer control */
15442         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15443         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15444         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15445
15446         { } /* end */
15447 };
15448
15449 static const struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
15450         /* output mixer control */
15451         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15452         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15453         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15454         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15455         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
15456
15457         /* Input mixer control */
15458         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15459            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
15460         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15461         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15462         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15463         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15464         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15465         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15466         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15467         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
15468
15469         {
15470                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15471                 .name = "Channel Mode",
15472                 .info = alc_ch_mode_info,
15473                 .get = alc_ch_mode_get,
15474                 .put = alc_ch_mode_put,
15475                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
15476         },
15477         { } /* end */
15478 };
15479
15480 static const struct snd_kcontrol_new alc861_asus_mixer[] = {
15481         /* output mixer control */
15482         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15483         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15484         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15485         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15486         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
15487
15488         /* Input mixer control */
15489         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15490         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15491         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15492         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15493         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15494         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15495         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15496         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15497         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15498         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
15499
15500         {
15501                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15502                 .name = "Channel Mode",
15503                 .info = alc_ch_mode_info,
15504                 .get = alc_ch_mode_get,
15505                 .put = alc_ch_mode_put,
15506                 .private_value = ARRAY_SIZE(alc861_asus_modes),
15507         },
15508         { }
15509 };
15510
15511 /* additional mixer */
15512 static const struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
15513         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15514         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15515         { }
15516 };
15517
15518 /*
15519  * generic initialization of ADC, input mixers and output mixers
15520  */
15521 static const struct hda_verb alc861_base_init_verbs[] = {
15522         /*
15523          * Unmute ADC0 and set the default input to mic-in
15524          */
15525         /* port-A for surround (rear panel) */
15526         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15527         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
15528         /* port-B for mic-in (rear panel) with vref */
15529         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15530         /* port-C for line-in (rear panel) */
15531         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15532         /* port-D for Front */
15533         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15534         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15535         /* port-E for HP out (front panel) */
15536         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
15537         /* route front PCM to HP */
15538         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15539         /* port-F for mic-in (front panel) with vref */
15540         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15541         /* port-G for CLFE (rear panel) */
15542         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15543         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15544         /* port-H for side (rear panel) */
15545         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15546         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
15547         /* CD-in */
15548         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15549         /* route front mic to ADC1*/
15550         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15551         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15552
15553         /* Unmute DAC0~3 & spdif out*/
15554         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15555         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15556         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15557         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15558         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15559
15560         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15561         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15562         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15563         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15564         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15565
15566         /* Unmute Stereo Mixer 15 */
15567         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15568         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15569         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15570         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15571
15572         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15573         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15574         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15575         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15576         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15577         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15578         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15579         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15580         /* hp used DAC 3 (Front) */
15581         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15582         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15583
15584         { }
15585 };
15586
15587 static const struct hda_verb alc861_threestack_init_verbs[] = {
15588         /*
15589          * Unmute ADC0 and set the default input to mic-in
15590          */
15591         /* port-A for surround (rear panel) */
15592         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15593         /* port-B for mic-in (rear panel) with vref */
15594         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15595         /* port-C for line-in (rear panel) */
15596         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15597         /* port-D for Front */
15598         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15599         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15600         /* port-E for HP out (front panel) */
15601         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
15602         /* route front PCM to HP */
15603         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15604         /* port-F for mic-in (front panel) with vref */
15605         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15606         /* port-G for CLFE (rear panel) */
15607         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15608         /* port-H for side (rear panel) */
15609         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15610         /* CD-in */
15611         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15612         /* route front mic to ADC1*/
15613         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15614         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15615         /* Unmute DAC0~3 & spdif out*/
15616         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15617         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15618         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15619         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15620         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15621
15622         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15623         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15624         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15625         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15626         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15627
15628         /* Unmute Stereo Mixer 15 */
15629         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15630         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15631         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15632         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15633
15634         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15635         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15636         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15637         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15638         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15639         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15640         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15641         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15642         /* hp used DAC 3 (Front) */
15643         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15644         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15645         { }
15646 };
15647
15648 static const struct hda_verb alc861_uniwill_m31_init_verbs[] = {
15649         /*
15650          * Unmute ADC0 and set the default input to mic-in
15651          */
15652         /* port-A for surround (rear panel) */
15653         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15654         /* port-B for mic-in (rear panel) with vref */
15655         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15656         /* port-C for line-in (rear panel) */
15657         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15658         /* port-D for Front */
15659         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15660         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15661         /* port-E for HP out (front panel) */
15662         /* this has to be set to VREF80 */
15663         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15664         /* route front PCM to HP */
15665         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15666         /* port-F for mic-in (front panel) with vref */
15667         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15668         /* port-G for CLFE (rear panel) */
15669         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15670         /* port-H for side (rear panel) */
15671         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15672         /* CD-in */
15673         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15674         /* route front mic to ADC1*/
15675         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15676         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15677         /* Unmute DAC0~3 & spdif out*/
15678         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15679         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15680         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15681         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15682         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15683
15684         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15685         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15686         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15687         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15688         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15689
15690         /* Unmute Stereo Mixer 15 */
15691         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15692         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15693         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15694         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15695
15696         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15697         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15698         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15699         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15700         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15701         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15702         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15703         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15704         /* hp used DAC 3 (Front) */
15705         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15706         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15707         { }
15708 };
15709
15710 static const struct hda_verb alc861_asus_init_verbs[] = {
15711         /*
15712          * Unmute ADC0 and set the default input to mic-in
15713          */
15714         /* port-A for surround (rear panel)
15715          * according to codec#0 this is the HP jack
15716          */
15717         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
15718         /* route front PCM to HP */
15719         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
15720         /* port-B for mic-in (rear panel) with vref */
15721         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15722         /* port-C for line-in (rear panel) */
15723         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15724         /* port-D for Front */
15725         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15726         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15727         /* port-E for HP out (front panel) */
15728         /* this has to be set to VREF80 */
15729         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15730         /* route front PCM to HP */
15731         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15732         /* port-F for mic-in (front panel) with vref */
15733         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15734         /* port-G for CLFE (rear panel) */
15735         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15736         /* port-H for side (rear panel) */
15737         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15738         /* CD-in */
15739         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15740         /* route front mic to ADC1*/
15741         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15742         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15743         /* Unmute DAC0~3 & spdif out*/
15744         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15745         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15746         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15747         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15748         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15749         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15750         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15751         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15752         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15753         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15754
15755         /* Unmute Stereo Mixer 15 */
15756         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15757         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15758         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15759         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15760
15761         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15762         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15763         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15764         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15765         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15766         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15767         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15768         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15769         /* hp used DAC 3 (Front) */
15770         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15771         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15772         { }
15773 };
15774
15775 /* additional init verbs for ASUS laptops */
15776 static const struct hda_verb alc861_asus_laptop_init_verbs[] = {
15777         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
15778         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
15779         { }
15780 };
15781
15782 static const struct hda_verb alc861_toshiba_init_verbs[] = {
15783         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15784
15785         { }
15786 };
15787
15788 /* toggle speaker-output according to the hp-jack state */
15789 static void alc861_toshiba_automute(struct hda_codec *codec)
15790 {
15791         unsigned int present = snd_hda_jack_detect(codec, 0x0f);
15792
15793         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
15794                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
15795         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
15796                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
15797 }
15798
15799 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
15800                                        unsigned int res)
15801 {
15802         if ((res >> 26) == ALC880_HP_EVENT)
15803                 alc861_toshiba_automute(codec);
15804 }
15805
15806 /* pcm configuration: identical with ALC880 */
15807 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
15808 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
15809 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
15810 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
15811
15812
15813 #define ALC861_DIGOUT_NID       0x07
15814
15815 static const struct hda_channel_mode alc861_8ch_modes[1] = {
15816         { 8, NULL }
15817 };
15818
15819 static const hda_nid_t alc861_dac_nids[4] = {
15820         /* front, surround, clfe, side */
15821         0x03, 0x06, 0x05, 0x04
15822 };
15823
15824 static const hda_nid_t alc660_dac_nids[3] = {
15825         /* front, clfe, surround */
15826         0x03, 0x05, 0x06
15827 };
15828
15829 static const hda_nid_t alc861_adc_nids[1] = {
15830         /* ADC0-2 */
15831         0x08,
15832 };
15833
15834 static const struct hda_input_mux alc861_capture_source = {
15835         .num_items = 5,
15836         .items = {
15837                 { "Mic", 0x0 },
15838                 { "Front Mic", 0x3 },
15839                 { "Line", 0x1 },
15840                 { "CD", 0x4 },
15841                 { "Mixer", 0x5 },
15842         },
15843 };
15844
15845 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
15846 {
15847         struct alc_spec *spec = codec->spec;
15848         hda_nid_t mix, srcs[5];
15849         int i, num;
15850
15851         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
15852                 return 0;
15853         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
15854         if (num < 0)
15855                 return 0;
15856         for (i = 0; i < num; i++) {
15857                 unsigned int type;
15858                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
15859                 if (type != AC_WID_AUD_OUT)
15860                         continue;
15861                 if (!found_in_nid_list(srcs[i], spec->multiout.dac_nids,
15862                                        spec->multiout.num_dacs))
15863                         return srcs[i];
15864         }
15865         return 0;
15866 }
15867
15868 /* fill in the dac_nids table from the parsed pin configuration */
15869 static int alc861_auto_fill_dac_nids(struct hda_codec *codec)
15870 {
15871         struct alc_spec *spec = codec->spec;
15872         const struct auto_pin_cfg *cfg = &spec->autocfg;
15873         int i;
15874         hda_nid_t nid, dac;
15875
15876         spec->multiout.dac_nids = spec->private_dac_nids;
15877         for (i = 0; i < cfg->line_outs; i++) {
15878                 nid = cfg->line_out_pins[i];
15879                 dac = alc861_look_for_dac(codec, nid);
15880                 if (!dac)
15881                         continue;
15882                 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
15883         }
15884         return 0;
15885 }
15886
15887 static int __alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
15888                                   hda_nid_t nid, int idx, unsigned int chs)
15889 {
15890         return __add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx, idx,
15891                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
15892 }
15893
15894 #define alc861_create_out_sw(codec, pfx, nid, chs) \
15895         __alc861_create_out_sw(codec, pfx, nid, 0, chs)
15896
15897 /* add playback controls from the parsed DAC table */
15898 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
15899                                              const struct auto_pin_cfg *cfg)
15900 {
15901         struct alc_spec *spec = codec->spec;
15902         hda_nid_t nid;
15903         int i, err, noutputs;
15904
15905         noutputs = cfg->line_outs;
15906         if (spec->multi_ios > 0)
15907                 noutputs += spec->multi_ios;
15908
15909         for (i = 0; i < noutputs; i++) {
15910                 const char *name;
15911                 int index;
15912                 nid = spec->multiout.dac_nids[i];
15913                 if (!nid)
15914                         continue;
15915                 name = alc_get_line_out_pfx(spec, i, true, &index);
15916                 if (!name) {
15917                         /* Center/LFE */
15918                         err = alc861_create_out_sw(codec, "Center", nid, 1);
15919                         if (err < 0)
15920                                 return err;
15921                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
15922                         if (err < 0)
15923                                 return err;
15924                 } else {
15925                         err = __alc861_create_out_sw(codec, name, nid, index, 3);
15926                         if (err < 0)
15927                                 return err;
15928                 }
15929         }
15930         return 0;
15931 }
15932
15933 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
15934 {
15935         struct alc_spec *spec = codec->spec;
15936         int err;
15937         hda_nid_t nid;
15938
15939         if (!pin)
15940                 return 0;
15941
15942         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
15943                 nid = alc861_look_for_dac(codec, pin);
15944                 if (nid) {
15945                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
15946                         if (err < 0)
15947                                 return err;
15948                         spec->multiout.hp_nid = nid;
15949                 }
15950         }
15951         return 0;
15952 }
15953
15954 /* create playback/capture controls for input pins */
15955 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
15956                                                 const struct auto_pin_cfg *cfg)
15957 {
15958         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
15959 }
15960
15961 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
15962                                               hda_nid_t nid,
15963                                               int pin_type, hda_nid_t dac)
15964 {
15965         hda_nid_t mix, srcs[5];
15966         int i, num;
15967
15968         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
15969                             pin_type);
15970         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15971                             AMP_OUT_UNMUTE);
15972         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
15973                 return;
15974         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
15975         if (num < 0)
15976                 return;
15977         for (i = 0; i < num; i++) {
15978                 unsigned int mute;
15979                 if (srcs[i] == dac || srcs[i] == 0x15)
15980                         mute = AMP_IN_UNMUTE(i);
15981                 else
15982                         mute = AMP_IN_MUTE(i);
15983                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15984                                     mute);
15985         }
15986 }
15987
15988 static void alc861_auto_init_multi_out(struct hda_codec *codec)
15989 {
15990         struct alc_spec *spec = codec->spec;
15991         int i;
15992
15993         for (i = 0; i < spec->autocfg.line_outs + spec->multi_ios; i++) {
15994                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15995                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15996                 if (nid)
15997                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
15998                                                           spec->multiout.dac_nids[i]);
15999         }
16000 }
16001
16002 static void alc861_auto_init_hp_out(struct hda_codec *codec)
16003 {
16004         struct alc_spec *spec = codec->spec;
16005
16006         if (spec->autocfg.hp_outs)
16007                 alc861_auto_set_output_and_unmute(codec,
16008                                                   spec->autocfg.hp_pins[0],
16009                                                   PIN_HP,
16010                                                   spec->multiout.hp_nid);
16011         if (spec->autocfg.speaker_outs)
16012                 alc861_auto_set_output_and_unmute(codec,
16013                                                   spec->autocfg.speaker_pins[0],
16014                                                   PIN_OUT,
16015                                                   spec->multiout.dac_nids[0]);
16016 }
16017
16018 #define alc861_auto_init_analog_input   alc880_auto_init_analog_input
16019
16020 /* parse the BIOS configuration and set up the alc_spec */
16021 /* return 1 if successful, 0 if the proper config is not found,
16022  * or a negative error code
16023  */
16024 static int alc861_parse_auto_config(struct hda_codec *codec)
16025 {
16026         struct alc_spec *spec = codec->spec;
16027         int err;
16028         static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
16029
16030         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16031                                            alc861_ignore);
16032         if (err < 0)
16033                 return err;
16034         if (!spec->autocfg.line_outs)
16035                 return 0; /* can't find valid BIOS pin config */
16036
16037         err = alc861_auto_fill_dac_nids(codec);
16038         if (err < 0)
16039                 return err;
16040         err = alc_auto_add_multi_channel_mode(codec, alc861_auto_fill_dac_nids);
16041         if (err < 0)
16042                 return err;
16043         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
16044         if (err < 0)
16045                 return err;
16046         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
16047         if (err < 0)
16048                 return err;
16049         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
16050         if (err < 0)
16051                 return err;
16052
16053         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16054
16055         alc_auto_parse_digital(codec);
16056
16057         if (spec->kctls.list)
16058                 add_mixer(spec, spec->kctls.list);
16059
16060         spec->num_mux_defs = 1;
16061         spec->input_mux = &spec->private_imux[0];
16062
16063         spec->adc_nids = alc861_adc_nids;
16064         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
16065         set_capture_mixer(codec);
16066
16067         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b, 0);
16068
16069         return 1;
16070 }
16071
16072 /* additional initialization for auto-configuration model */
16073 static void alc861_auto_init(struct hda_codec *codec)
16074 {
16075         struct alc_spec *spec = codec->spec;
16076         alc861_auto_init_multi_out(codec);
16077         alc861_auto_init_hp_out(codec);
16078         alc861_auto_init_analog_input(codec);
16079         alc_auto_init_digital(codec);
16080         if (spec->unsol_event)
16081                 alc_inithook(codec);
16082 }
16083
16084 #ifdef CONFIG_SND_HDA_POWER_SAVE
16085 static const struct hda_amp_list alc861_loopbacks[] = {
16086         { 0x15, HDA_INPUT, 0 },
16087         { 0x15, HDA_INPUT, 1 },
16088         { 0x15, HDA_INPUT, 2 },
16089         { 0x15, HDA_INPUT, 3 },
16090         { } /* end */
16091 };
16092 #endif
16093
16094
16095 /*
16096  * configuration and preset
16097  */
16098 static const char * const alc861_models[ALC861_MODEL_LAST] = {
16099         [ALC861_3ST]            = "3stack",
16100         [ALC660_3ST]            = "3stack-660",
16101         [ALC861_3ST_DIG]        = "3stack-dig",
16102         [ALC861_6ST_DIG]        = "6stack-dig",
16103         [ALC861_UNIWILL_M31]    = "uniwill-m31",
16104         [ALC861_TOSHIBA]        = "toshiba",
16105         [ALC861_ASUS]           = "asus",
16106         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
16107         [ALC861_AUTO]           = "auto",
16108 };
16109
16110 static const struct snd_pci_quirk alc861_cfg_tbl[] = {
16111         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
16112         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
16113         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
16114         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
16115         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
16116         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
16117         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
16118         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
16119          *        Any other models that need this preset?
16120          */
16121         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
16122         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
16123         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
16124         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
16125         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
16126         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
16127         /* FIXME: the below seems conflict */
16128         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
16129         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
16130         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
16131         {}
16132 };
16133
16134 static const struct alc_config_preset alc861_presets[] = {
16135         [ALC861_3ST] = {
16136                 .mixers = { alc861_3ST_mixer },
16137                 .init_verbs = { alc861_threestack_init_verbs },
16138                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16139                 .dac_nids = alc861_dac_nids,
16140                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
16141                 .channel_mode = alc861_threestack_modes,
16142                 .need_dac_fix = 1,
16143                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16144                 .adc_nids = alc861_adc_nids,
16145                 .input_mux = &alc861_capture_source,
16146         },
16147         [ALC861_3ST_DIG] = {
16148                 .mixers = { alc861_base_mixer },
16149                 .init_verbs = { alc861_threestack_init_verbs },
16150                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16151                 .dac_nids = alc861_dac_nids,
16152                 .dig_out_nid = ALC861_DIGOUT_NID,
16153                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
16154                 .channel_mode = alc861_threestack_modes,
16155                 .need_dac_fix = 1,
16156                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16157                 .adc_nids = alc861_adc_nids,
16158                 .input_mux = &alc861_capture_source,
16159         },
16160         [ALC861_6ST_DIG] = {
16161                 .mixers = { alc861_base_mixer },
16162                 .init_verbs = { alc861_base_init_verbs },
16163                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16164                 .dac_nids = alc861_dac_nids,
16165                 .dig_out_nid = ALC861_DIGOUT_NID,
16166                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
16167                 .channel_mode = alc861_8ch_modes,
16168                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16169                 .adc_nids = alc861_adc_nids,
16170                 .input_mux = &alc861_capture_source,
16171         },
16172         [ALC660_3ST] = {
16173                 .mixers = { alc861_3ST_mixer },
16174                 .init_verbs = { alc861_threestack_init_verbs },
16175                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
16176                 .dac_nids = alc660_dac_nids,
16177                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
16178                 .channel_mode = alc861_threestack_modes,
16179                 .need_dac_fix = 1,
16180                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16181                 .adc_nids = alc861_adc_nids,
16182                 .input_mux = &alc861_capture_source,
16183         },
16184         [ALC861_UNIWILL_M31] = {
16185                 .mixers = { alc861_uniwill_m31_mixer },
16186                 .init_verbs = { alc861_uniwill_m31_init_verbs },
16187                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16188                 .dac_nids = alc861_dac_nids,
16189                 .dig_out_nid = ALC861_DIGOUT_NID,
16190                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
16191                 .channel_mode = alc861_uniwill_m31_modes,
16192                 .need_dac_fix = 1,
16193                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16194                 .adc_nids = alc861_adc_nids,
16195                 .input_mux = &alc861_capture_source,
16196         },
16197         [ALC861_TOSHIBA] = {
16198                 .mixers = { alc861_toshiba_mixer },
16199                 .init_verbs = { alc861_base_init_verbs,
16200                                 alc861_toshiba_init_verbs },
16201                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16202                 .dac_nids = alc861_dac_nids,
16203                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
16204                 .channel_mode = alc883_3ST_2ch_modes,
16205                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16206                 .adc_nids = alc861_adc_nids,
16207                 .input_mux = &alc861_capture_source,
16208                 .unsol_event = alc861_toshiba_unsol_event,
16209                 .init_hook = alc861_toshiba_automute,
16210         },
16211         [ALC861_ASUS] = {
16212                 .mixers = { alc861_asus_mixer },
16213                 .init_verbs = { alc861_asus_init_verbs },
16214                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16215                 .dac_nids = alc861_dac_nids,
16216                 .dig_out_nid = ALC861_DIGOUT_NID,
16217                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
16218                 .channel_mode = alc861_asus_modes,
16219                 .need_dac_fix = 1,
16220                 .hp_nid = 0x06,
16221                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16222                 .adc_nids = alc861_adc_nids,
16223                 .input_mux = &alc861_capture_source,
16224         },
16225         [ALC861_ASUS_LAPTOP] = {
16226                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
16227                 .init_verbs = { alc861_asus_init_verbs,
16228                                 alc861_asus_laptop_init_verbs },
16229                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16230                 .dac_nids = alc861_dac_nids,
16231                 .dig_out_nid = ALC861_DIGOUT_NID,
16232                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
16233                 .channel_mode = alc883_3ST_2ch_modes,
16234                 .need_dac_fix = 1,
16235                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16236                 .adc_nids = alc861_adc_nids,
16237                 .input_mux = &alc861_capture_source,
16238         },
16239 };
16240
16241 /* Pin config fixes */
16242 enum {
16243         PINFIX_FSC_AMILO_PI1505,
16244 };
16245
16246 static const struct alc_fixup alc861_fixups[] = {
16247         [PINFIX_FSC_AMILO_PI1505] = {
16248                 .type = ALC_FIXUP_PINS,
16249                 .v.pins = (const struct alc_pincfg[]) {
16250                         { 0x0b, 0x0221101f }, /* HP */
16251                         { 0x0f, 0x90170310 }, /* speaker */
16252                         { }
16253                 }
16254         },
16255 };
16256
16257 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
16258         SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
16259         {}
16260 };
16261
16262 static int patch_alc861(struct hda_codec *codec)
16263 {
16264         struct alc_spec *spec;
16265         int board_config;
16266         int err;
16267
16268         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16269         if (spec == NULL)
16270                 return -ENOMEM;
16271
16272         codec->spec = spec;
16273
16274         spec->mixer_nid = 0x15;
16275
16276         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
16277                                                   alc861_models,
16278                                                   alc861_cfg_tbl);
16279
16280         if (board_config < 0) {
16281                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
16282                        codec->chip_name);
16283                 board_config = ALC861_AUTO;
16284         }
16285
16286         if (board_config == ALC861_AUTO) {
16287                 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
16288                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
16289         }
16290
16291         if (board_config == ALC861_AUTO) {
16292                 /* automatic parse from the BIOS config */
16293                 err = alc861_parse_auto_config(codec);
16294                 if (err < 0) {
16295                         alc_free(codec);
16296                         return err;
16297                 } else if (!err) {
16298                         printk(KERN_INFO
16299                                "hda_codec: Cannot set up configuration "
16300                                "from BIOS.  Using base mode...\n");
16301                    board_config = ALC861_3ST_DIG;
16302                 }
16303         }
16304
16305         err = snd_hda_attach_beep_device(codec, 0x23);
16306         if (err < 0) {
16307                 alc_free(codec);
16308                 return err;
16309         }
16310
16311         if (board_config != ALC861_AUTO)
16312                 setup_preset(codec, &alc861_presets[board_config]);
16313
16314         spec->stream_analog_playback = &alc861_pcm_analog_playback;
16315         spec->stream_analog_capture = &alc861_pcm_analog_capture;
16316
16317         spec->stream_digital_playback = &alc861_pcm_digital_playback;
16318         spec->stream_digital_capture = &alc861_pcm_digital_capture;
16319
16320         if (!spec->cap_mixer)
16321                 set_capture_mixer(codec);
16322         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
16323
16324         spec->vmaster_nid = 0x03;
16325
16326         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
16327
16328         codec->patch_ops = alc_patch_ops;
16329         if (board_config == ALC861_AUTO) {
16330                 spec->init_hook = alc861_auto_init;
16331 #ifdef CONFIG_SND_HDA_POWER_SAVE
16332                 spec->power_hook = alc_power_eapd;
16333 #endif
16334         }
16335 #ifdef CONFIG_SND_HDA_POWER_SAVE
16336         if (!spec->loopback.amplist)
16337                 spec->loopback.amplist = alc861_loopbacks;
16338 #endif
16339
16340         return 0;
16341 }
16342
16343 /*
16344  * ALC861-VD support
16345  *
16346  * Based on ALC882
16347  *
16348  * In addition, an independent DAC
16349  */
16350 #define ALC861VD_DIGOUT_NID     0x06
16351
16352 static const hda_nid_t alc861vd_dac_nids[4] = {
16353         /* front, surr, clfe, side surr */
16354         0x02, 0x03, 0x04, 0x05
16355 };
16356
16357 /* dac_nids for ALC660vd are in a different order - according to
16358  * Realtek's driver.
16359  * This should probably result in a different mixer for 6stack models
16360  * of ALC660vd codecs, but for now there is only 3stack mixer
16361  * - and it is the same as in 861vd.
16362  * adc_nids in ALC660vd are (is) the same as in 861vd
16363  */
16364 static const hda_nid_t alc660vd_dac_nids[3] = {
16365         /* front, rear, clfe, rear_surr */
16366         0x02, 0x04, 0x03
16367 };
16368
16369 static const hda_nid_t alc861vd_adc_nids[1] = {
16370         /* ADC0 */
16371         0x09,
16372 };
16373
16374 static const hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
16375
16376 /* input MUX */
16377 /* FIXME: should be a matrix-type input source selection */
16378 static const struct hda_input_mux alc861vd_capture_source = {
16379         .num_items = 4,
16380         .items = {
16381                 { "Mic", 0x0 },
16382                 { "Front Mic", 0x1 },
16383                 { "Line", 0x2 },
16384                 { "CD", 0x4 },
16385         },
16386 };
16387
16388 static const struct hda_input_mux alc861vd_dallas_capture_source = {
16389         .num_items = 2,
16390         .items = {
16391                 { "Mic", 0x0 },
16392                 { "Internal Mic", 0x1 },
16393         },
16394 };
16395
16396 static const struct hda_input_mux alc861vd_hp_capture_source = {
16397         .num_items = 2,
16398         .items = {
16399                 { "Front Mic", 0x0 },
16400                 { "ATAPI Mic", 0x1 },
16401         },
16402 };
16403
16404 /*
16405  * 2ch mode
16406  */
16407 static const struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
16408         { 2, NULL }
16409 };
16410
16411 /*
16412  * 6ch mode
16413  */
16414 static const struct hda_verb alc861vd_6stack_ch6_init[] = {
16415         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
16416         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16417         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16418         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16419         { } /* end */
16420 };
16421
16422 /*
16423  * 8ch mode
16424  */
16425 static const struct hda_verb alc861vd_6stack_ch8_init[] = {
16426         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16427         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16428         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16429         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16430         { } /* end */
16431 };
16432
16433 static const struct hda_channel_mode alc861vd_6stack_modes[2] = {
16434         { 6, alc861vd_6stack_ch6_init },
16435         { 8, alc861vd_6stack_ch8_init },
16436 };
16437
16438 static const struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
16439         {
16440                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16441                 .name = "Channel Mode",
16442                 .info = alc_ch_mode_info,
16443                 .get = alc_ch_mode_get,
16444                 .put = alc_ch_mode_put,
16445         },
16446         { } /* end */
16447 };
16448
16449 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
16450  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
16451  */
16452 static const struct snd_kcontrol_new alc861vd_6st_mixer[] = {
16453         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16454         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16455
16456         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16457         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
16458
16459         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
16460                                 HDA_OUTPUT),
16461         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
16462                                 HDA_OUTPUT),
16463         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
16464         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
16465
16466         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
16467         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
16468
16469         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16470
16471         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16472         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16473         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16474
16475         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16476         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16477         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16478
16479         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16480         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16481
16482         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
16483         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
16484
16485         { } /* end */
16486 };
16487
16488 static const struct snd_kcontrol_new alc861vd_3st_mixer[] = {
16489         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16490         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16491
16492         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16493
16494         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16495         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16496         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16497
16498         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16499         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16500         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16501
16502         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16503         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16504
16505         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
16506         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
16507
16508         { } /* end */
16509 };
16510
16511 static const struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
16512         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16513         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
16514         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16515
16516         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16517
16518         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16519         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16520         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16521
16522         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16523         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16524         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16525
16526         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
16527         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
16528
16529         { } /* end */
16530 };
16531
16532 /* Pin assignment: Speaker=0x14, HP = 0x15,
16533  *                 Mic=0x18, Internal Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
16534  */
16535 static const struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
16536         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16537         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
16538         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16539         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
16540         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16541         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16542         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16543         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
16544         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16545         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16546         { } /* end */
16547 };
16548
16549 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
16550  *                 Front Mic=0x18, ATAPI Mic = 0x19,
16551  */
16552 static const struct snd_kcontrol_new alc861vd_hp_mixer[] = {
16553         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16554         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16555         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16556         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
16557         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16558         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16559         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16560         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16561
16562         { } /* end */
16563 };
16564
16565 /*
16566  * generic initialization of ADC, input mixers and output mixers
16567  */
16568 static const struct hda_verb alc861vd_volume_init_verbs[] = {
16569         /*
16570          * Unmute ADC0 and set the default input to mic-in
16571          */
16572         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16573         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16574
16575         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
16576          * the analog-loopback mixer widget
16577          */
16578         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16579         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16580         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16581         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16582         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16583         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16584
16585         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
16586         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16587         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16588         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
16589         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
16590
16591         /*
16592          * Set up output mixers (0x02 - 0x05)
16593          */
16594         /* set vol=0 to output mixers */
16595         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16596         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16597         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16598         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16599
16600         /* set up input amps for analog loopback */
16601         /* Amp Indices: DAC = 0, mixer = 1 */
16602         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16603         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16604         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16605         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16606         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16607         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16608         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16609         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16610
16611         { }
16612 };
16613
16614 /*
16615  * 3-stack pin configuration:
16616  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
16617  */
16618 static const struct hda_verb alc861vd_3stack_init_verbs[] = {
16619         /*
16620          * Set pin mode and muting
16621          */
16622         /* set front pin widgets 0x14 for output */
16623         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16624         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16625         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
16626
16627         /* Mic (rear) pin: input vref at 80% */
16628         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16629         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16630         /* Front Mic pin: input vref at 80% */
16631         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16632         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16633         /* Line In pin: input */
16634         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16635         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16636         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16637         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16638         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16639         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16640         /* CD pin widget for input */
16641         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16642
16643         { }
16644 };
16645
16646 /*
16647  * 6-stack pin configuration:
16648  */
16649 static const struct hda_verb alc861vd_6stack_init_verbs[] = {
16650         /*
16651          * Set pin mode and muting
16652          */
16653         /* set front pin widgets 0x14 for output */
16654         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16655         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16656         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
16657
16658         /* Rear Pin: output 1 (0x0d) */
16659         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16660         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16661         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
16662         /* CLFE Pin: output 2 (0x0e) */
16663         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16664         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16665         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
16666         /* Side Pin: output 3 (0x0f) */
16667         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16668         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16669         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
16670
16671         /* Mic (rear) pin: input vref at 80% */
16672         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16673         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16674         /* Front Mic pin: input vref at 80% */
16675         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16676         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16677         /* Line In pin: input */
16678         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16679         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16680         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16681         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16682         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16683         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16684         /* CD pin widget for input */
16685         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16686
16687         { }
16688 };
16689
16690 static const struct hda_verb alc861vd_eapd_verbs[] = {
16691         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16692         { }
16693 };
16694
16695 static const struct hda_verb alc660vd_eapd_verbs[] = {
16696         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16697         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16698         { }
16699 };
16700
16701 static const struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
16702         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16703         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16704         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
16705         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16706         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16707         {}
16708 };
16709
16710 static void alc861vd_lenovo_setup(struct hda_codec *codec)
16711 {
16712         struct alc_spec *spec = codec->spec;
16713         spec->autocfg.hp_pins[0] = 0x1b;
16714         spec->autocfg.speaker_pins[0] = 0x14;
16715         spec->automute = 1;
16716         spec->automute_mode = ALC_AUTOMUTE_AMP;
16717 }
16718
16719 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
16720 {
16721         alc_hp_automute(codec);
16722         alc88x_simple_mic_automute(codec);
16723 }
16724
16725 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
16726                                         unsigned int res)
16727 {
16728         switch (res >> 26) {
16729         case ALC880_MIC_EVENT:
16730                 alc88x_simple_mic_automute(codec);
16731                 break;
16732         default:
16733                 alc_sku_unsol_event(codec, res);
16734                 break;
16735         }
16736 }
16737
16738 static const struct hda_verb alc861vd_dallas_verbs[] = {
16739         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16740         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16741         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16742         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16743
16744         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16745         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16746         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16747         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16748         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16749         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16750         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16751         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16752
16753         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16754         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16755         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16756         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16757         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16758         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16759         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16760         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16761
16762         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
16763         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16764         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
16765         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16766         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16767         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16768         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16769         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16770
16771         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16772         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16773         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16774         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16775
16776         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16777         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16778         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16779
16780         { } /* end */
16781 };
16782
16783 /* toggle speaker-output according to the hp-jack state */
16784 static void alc861vd_dallas_setup(struct hda_codec *codec)
16785 {
16786         struct alc_spec *spec = codec->spec;
16787
16788         spec->autocfg.hp_pins[0] = 0x15;
16789         spec->autocfg.speaker_pins[0] = 0x14;
16790         spec->automute = 1;
16791         spec->automute_mode = ALC_AUTOMUTE_AMP;
16792 }
16793
16794 #ifdef CONFIG_SND_HDA_POWER_SAVE
16795 #define alc861vd_loopbacks      alc880_loopbacks
16796 #endif
16797
16798 /* pcm configuration: identical with ALC880 */
16799 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
16800 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
16801 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
16802 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
16803
16804 /*
16805  * configuration and preset
16806  */
16807 static const char * const alc861vd_models[ALC861VD_MODEL_LAST] = {
16808         [ALC660VD_3ST]          = "3stack-660",
16809         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
16810         [ALC660VD_ASUS_V1S]     = "asus-v1s",
16811         [ALC861VD_3ST]          = "3stack",
16812         [ALC861VD_3ST_DIG]      = "3stack-digout",
16813         [ALC861VD_6ST_DIG]      = "6stack-digout",
16814         [ALC861VD_LENOVO]       = "lenovo",
16815         [ALC861VD_DALLAS]       = "dallas",
16816         [ALC861VD_HP]           = "hp",
16817         [ALC861VD_AUTO]         = "auto",
16818 };
16819
16820 static const struct snd_pci_quirk alc861vd_cfg_tbl[] = {
16821         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
16822         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
16823         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
16824         /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
16825         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
16826         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
16827         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
16828         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
16829         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
16830         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
16831         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
16832         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
16833         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
16834         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
16835         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
16836         {}
16837 };
16838
16839 static const struct alc_config_preset alc861vd_presets[] = {
16840         [ALC660VD_3ST] = {
16841                 .mixers = { alc861vd_3st_mixer },
16842                 .init_verbs = { alc861vd_volume_init_verbs,
16843                                  alc861vd_3stack_init_verbs },
16844                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16845                 .dac_nids = alc660vd_dac_nids,
16846                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16847                 .channel_mode = alc861vd_3stack_2ch_modes,
16848                 .input_mux = &alc861vd_capture_source,
16849         },
16850         [ALC660VD_3ST_DIG] = {
16851                 .mixers = { alc861vd_3st_mixer },
16852                 .init_verbs = { alc861vd_volume_init_verbs,
16853                                  alc861vd_3stack_init_verbs },
16854                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16855                 .dac_nids = alc660vd_dac_nids,
16856                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16857                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16858                 .channel_mode = alc861vd_3stack_2ch_modes,
16859                 .input_mux = &alc861vd_capture_source,
16860         },
16861         [ALC861VD_3ST] = {
16862                 .mixers = { alc861vd_3st_mixer },
16863                 .init_verbs = { alc861vd_volume_init_verbs,
16864                                  alc861vd_3stack_init_verbs },
16865                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16866                 .dac_nids = alc861vd_dac_nids,
16867                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16868                 .channel_mode = alc861vd_3stack_2ch_modes,
16869                 .input_mux = &alc861vd_capture_source,
16870         },
16871         [ALC861VD_3ST_DIG] = {
16872                 .mixers = { alc861vd_3st_mixer },
16873                 .init_verbs = { alc861vd_volume_init_verbs,
16874                                  alc861vd_3stack_init_verbs },
16875                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16876                 .dac_nids = alc861vd_dac_nids,
16877                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16878                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16879                 .channel_mode = alc861vd_3stack_2ch_modes,
16880                 .input_mux = &alc861vd_capture_source,
16881         },
16882         [ALC861VD_6ST_DIG] = {
16883                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
16884                 .init_verbs = { alc861vd_volume_init_verbs,
16885                                 alc861vd_6stack_init_verbs },
16886                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16887                 .dac_nids = alc861vd_dac_nids,
16888                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16889                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
16890                 .channel_mode = alc861vd_6stack_modes,
16891                 .input_mux = &alc861vd_capture_source,
16892         },
16893         [ALC861VD_LENOVO] = {
16894                 .mixers = { alc861vd_lenovo_mixer },
16895                 .init_verbs = { alc861vd_volume_init_verbs,
16896                                 alc861vd_3stack_init_verbs,
16897                                 alc861vd_eapd_verbs,
16898                                 alc861vd_lenovo_unsol_verbs },
16899                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16900                 .dac_nids = alc660vd_dac_nids,
16901                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16902                 .channel_mode = alc861vd_3stack_2ch_modes,
16903                 .input_mux = &alc861vd_capture_source,
16904                 .unsol_event = alc861vd_lenovo_unsol_event,
16905                 .setup = alc861vd_lenovo_setup,
16906                 .init_hook = alc861vd_lenovo_init_hook,
16907         },
16908         [ALC861VD_DALLAS] = {
16909                 .mixers = { alc861vd_dallas_mixer },
16910                 .init_verbs = { alc861vd_dallas_verbs },
16911                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16912                 .dac_nids = alc861vd_dac_nids,
16913                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16914                 .channel_mode = alc861vd_3stack_2ch_modes,
16915                 .input_mux = &alc861vd_dallas_capture_source,
16916                 .unsol_event = alc_sku_unsol_event,
16917                 .setup = alc861vd_dallas_setup,
16918                 .init_hook = alc_hp_automute,
16919         },
16920         [ALC861VD_HP] = {
16921                 .mixers = { alc861vd_hp_mixer },
16922                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
16923                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16924                 .dac_nids = alc861vd_dac_nids,
16925                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16926                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16927                 .channel_mode = alc861vd_3stack_2ch_modes,
16928                 .input_mux = &alc861vd_hp_capture_source,
16929                 .unsol_event = alc_sku_unsol_event,
16930                 .setup = alc861vd_dallas_setup,
16931                 .init_hook = alc_hp_automute,
16932         },
16933         [ALC660VD_ASUS_V1S] = {
16934                 .mixers = { alc861vd_lenovo_mixer },
16935                 .init_verbs = { alc861vd_volume_init_verbs,
16936                                 alc861vd_3stack_init_verbs,
16937                                 alc861vd_eapd_verbs,
16938                                 alc861vd_lenovo_unsol_verbs },
16939                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16940                 .dac_nids = alc660vd_dac_nids,
16941                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16942                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16943                 .channel_mode = alc861vd_3stack_2ch_modes,
16944                 .input_mux = &alc861vd_capture_source,
16945                 .unsol_event = alc861vd_lenovo_unsol_event,
16946                 .setup = alc861vd_lenovo_setup,
16947                 .init_hook = alc861vd_lenovo_init_hook,
16948         },
16949 };
16950
16951 /*
16952  * BIOS auto configuration
16953  */
16954 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
16955                                                 const struct auto_pin_cfg *cfg)
16956 {
16957         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x22, 0);
16958 }
16959
16960
16961 #define alc861vd_auto_init_multi_out    alc882_auto_init_multi_out
16962 #define alc861vd_auto_init_hp_out       alc882_auto_init_hp_out
16963 #define alc861vd_auto_init_analog_input alc882_auto_init_analog_input
16964 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
16965
16966 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
16967 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
16968
16969 /* add playback controls from the parsed DAC table */
16970 /* Based on ALC880 version. But ALC861VD has separate,
16971  * different NIDs for mute/unmute switch and volume control */
16972 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
16973                                              const struct auto_pin_cfg *cfg)
16974 {
16975         hda_nid_t nid_v, nid_s;
16976         int i, err, noutputs;
16977
16978         noutputs = cfg->line_outs;
16979         if (spec->multi_ios > 0)
16980                 noutputs += spec->multi_ios;
16981
16982         for (i = 0; i < noutputs; i++) {
16983                 const char *name;
16984                 int index;
16985                 if (!spec->multiout.dac_nids[i])
16986                         continue;
16987                 nid_v = alc861vd_idx_to_mixer_vol(
16988                                 alc880_dac_to_idx(
16989                                         spec->multiout.dac_nids[i]));
16990                 nid_s = alc861vd_idx_to_mixer_switch(
16991                                 alc880_dac_to_idx(
16992                                         spec->multiout.dac_nids[i]));
16993
16994                 name = alc_get_line_out_pfx(spec, i, true, &index);
16995                 if (!name) {
16996                         /* Center/LFE */
16997                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
16998                                               "Center",
16999                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
17000                                                               HDA_OUTPUT));
17001                         if (err < 0)
17002                                 return err;
17003                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
17004                                               "LFE",
17005                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
17006                                                               HDA_OUTPUT));
17007                         if (err < 0)
17008                                 return err;
17009                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
17010                                              "Center",
17011                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
17012                                                               HDA_INPUT));
17013                         if (err < 0)
17014                                 return err;
17015                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
17016                                              "LFE",
17017                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
17018                                                               HDA_INPUT));
17019                         if (err < 0)
17020                                 return err;
17021                 } else {
17022                         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
17023                                                 name, index,
17024                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
17025                                                               HDA_OUTPUT));
17026                         if (err < 0)
17027                                 return err;
17028                         err = __add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
17029                                                name, index,
17030                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
17031                                                               HDA_INPUT));
17032                         if (err < 0)
17033                                 return err;
17034                 }
17035         }
17036         return 0;
17037 }
17038
17039 /* add playback controls for speaker and HP outputs */
17040 /* Based on ALC880 version. But ALC861VD has separate,
17041  * different NIDs for mute/unmute switch and volume control */
17042 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
17043                                         hda_nid_t pin, const char *pfx)
17044 {
17045         hda_nid_t nid_v, nid_s;
17046         int err;
17047
17048         if (!pin)
17049                 return 0;
17050
17051         if (alc880_is_fixed_pin(pin)) {
17052                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17053                 /* specify the DAC as the extra output */
17054                 if (!spec->multiout.hp_nid)
17055                         spec->multiout.hp_nid = nid_v;
17056                 else
17057                         spec->multiout.extra_out_nid[0] = nid_v;
17058                 /* control HP volume/switch on the output mixer amp */
17059                 nid_v = alc861vd_idx_to_mixer_vol(
17060                                 alc880_fixed_pin_idx(pin));
17061                 nid_s = alc861vd_idx_to_mixer_switch(
17062                                 alc880_fixed_pin_idx(pin));
17063
17064                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17065                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
17066                 if (err < 0)
17067                         return err;
17068                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
17069                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
17070                 if (err < 0)
17071                         return err;
17072         } else if (alc880_is_multi_pin(pin)) {
17073                 /* set manual connection */
17074                 /* we have only a switch on HP-out PIN */
17075                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17076                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17077                 if (err < 0)
17078                         return err;
17079         }
17080         return 0;
17081 }
17082
17083 /* parse the BIOS configuration and set up the alc_spec
17084  * return 1 if successful, 0 if the proper config is not found,
17085  * or a negative error code
17086  * Based on ALC880 version - had to change it to override
17087  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
17088 static int alc861vd_parse_auto_config(struct hda_codec *codec)
17089 {
17090         struct alc_spec *spec = codec->spec;
17091         int err;
17092         static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
17093
17094         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17095                                            alc861vd_ignore);
17096         if (err < 0)
17097                 return err;
17098         if (!spec->autocfg.line_outs)
17099                 return 0; /* can't find valid BIOS pin config */
17100
17101         err = alc880_auto_fill_dac_nids(codec);
17102         if (err < 0)
17103                 return err;
17104         err = alc_auto_add_multi_channel_mode(codec, alc880_auto_fill_dac_nids);
17105         if (err < 0)
17106                 return err;
17107         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
17108         if (err < 0)
17109                 return err;
17110         err = alc861vd_auto_create_extra_out(spec,
17111                                              spec->autocfg.speaker_pins[0],
17112                                              "Speaker");
17113         if (err < 0)
17114                 return err;
17115         err = alc861vd_auto_create_extra_out(spec,
17116                                              spec->autocfg.hp_pins[0],
17117                                              "Headphone");
17118         if (err < 0)
17119                 return err;
17120         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
17121         if (err < 0)
17122                 return err;
17123
17124         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17125
17126         alc_auto_parse_digital(codec);
17127
17128         if (spec->kctls.list)
17129                 add_mixer(spec, spec->kctls.list);
17130
17131         spec->num_mux_defs = 1;
17132         spec->input_mux = &spec->private_imux[0];
17133
17134         err = alc_auto_add_mic_boost(codec);
17135         if (err < 0)
17136                 return err;
17137
17138         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
17139
17140         return 1;
17141 }
17142
17143 /* additional initialization for auto-configuration model */
17144 static void alc861vd_auto_init(struct hda_codec *codec)
17145 {
17146         struct alc_spec *spec = codec->spec;
17147         alc861vd_auto_init_multi_out(codec);
17148         alc861vd_auto_init_hp_out(codec);
17149         alc861vd_auto_init_analog_input(codec);
17150         alc861vd_auto_init_input_src(codec);
17151         alc_auto_init_digital(codec);
17152         if (spec->unsol_event)
17153                 alc_inithook(codec);
17154 }
17155
17156 enum {
17157         ALC660VD_FIX_ASUS_GPIO1
17158 };
17159
17160 /* reset GPIO1 */
17161 static const struct alc_fixup alc861vd_fixups[] = {
17162         [ALC660VD_FIX_ASUS_GPIO1] = {
17163                 .type = ALC_FIXUP_VERBS,
17164                 .v.verbs = (const struct hda_verb[]) {
17165                         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
17166                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
17167                         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
17168                         { }
17169                 }
17170         },
17171 };
17172
17173 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
17174         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
17175         {}
17176 };
17177
17178 static int patch_alc861vd(struct hda_codec *codec)
17179 {
17180         struct alc_spec *spec;
17181         int err, board_config;
17182
17183         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17184         if (spec == NULL)
17185                 return -ENOMEM;
17186
17187         codec->spec = spec;
17188
17189         spec->mixer_nid = 0x0b;
17190
17191         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
17192                                                   alc861vd_models,
17193                                                   alc861vd_cfg_tbl);
17194
17195         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
17196                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17197                        codec->chip_name);
17198                 board_config = ALC861VD_AUTO;
17199         }
17200
17201         if (board_config == ALC861VD_AUTO) {
17202                 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
17203                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
17204         }
17205
17206         if (board_config == ALC861VD_AUTO) {
17207                 /* automatic parse from the BIOS config */
17208                 err = alc861vd_parse_auto_config(codec);
17209                 if (err < 0) {
17210                         alc_free(codec);
17211                         return err;
17212                 } else if (!err) {
17213                         printk(KERN_INFO
17214                                "hda_codec: Cannot set up configuration "
17215                                "from BIOS.  Using base mode...\n");
17216                         board_config = ALC861VD_3ST;
17217                 }
17218         }
17219
17220         err = snd_hda_attach_beep_device(codec, 0x23);
17221         if (err < 0) {
17222                 alc_free(codec);
17223                 return err;
17224         }
17225
17226         if (board_config != ALC861VD_AUTO)
17227                 setup_preset(codec, &alc861vd_presets[board_config]);
17228
17229         if (codec->vendor_id == 0x10ec0660) {
17230                 /* always turn on EAPD */
17231                 add_verb(spec, alc660vd_eapd_verbs);
17232         }
17233
17234         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
17235         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
17236
17237         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
17238         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
17239
17240         if (!spec->adc_nids) {
17241                 spec->adc_nids = alc861vd_adc_nids;
17242                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
17243         }
17244         if (!spec->capsrc_nids)
17245                 spec->capsrc_nids = alc861vd_capsrc_nids;
17246
17247         set_capture_mixer(codec);
17248         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17249
17250         spec->vmaster_nid = 0x02;
17251
17252         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
17253
17254         codec->patch_ops = alc_patch_ops;
17255
17256         if (board_config == ALC861VD_AUTO)
17257                 spec->init_hook = alc861vd_auto_init;
17258         spec->shutup = alc_eapd_shutup;
17259 #ifdef CONFIG_SND_HDA_POWER_SAVE
17260         if (!spec->loopback.amplist)
17261                 spec->loopback.amplist = alc861vd_loopbacks;
17262 #endif
17263
17264         return 0;
17265 }
17266
17267 /*
17268  * ALC662 support
17269  *
17270  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
17271  * configuration.  Each pin widget can choose any input DACs and a mixer.
17272  * Each ADC is connected from a mixer of all inputs.  This makes possible
17273  * 6-channel independent captures.
17274  *
17275  * In addition, an independent DAC for the multi-playback (not used in this
17276  * driver yet).
17277  */
17278 #define ALC662_DIGOUT_NID       0x06
17279 #define ALC662_DIGIN_NID        0x0a
17280
17281 static const hda_nid_t alc662_dac_nids[3] = {
17282         /* front, rear, clfe */
17283         0x02, 0x03, 0x04
17284 };
17285
17286 static const hda_nid_t alc272_dac_nids[2] = {
17287         0x02, 0x03
17288 };
17289
17290 static const hda_nid_t alc662_adc_nids[2] = {
17291         /* ADC1-2 */
17292         0x09, 0x08
17293 };
17294
17295 static const hda_nid_t alc272_adc_nids[1] = {
17296         /* ADC1-2 */
17297         0x08,
17298 };
17299
17300 static const hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
17301 static const hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
17302
17303
17304 /* input MUX */
17305 /* FIXME: should be a matrix-type input source selection */
17306 static const struct hda_input_mux alc662_capture_source = {
17307         .num_items = 4,
17308         .items = {
17309                 { "Mic", 0x0 },
17310                 { "Front Mic", 0x1 },
17311                 { "Line", 0x2 },
17312                 { "CD", 0x4 },
17313         },
17314 };
17315
17316 static const struct hda_input_mux alc662_lenovo_101e_capture_source = {
17317         .num_items = 2,
17318         .items = {
17319                 { "Mic", 0x1 },
17320                 { "Line", 0x2 },
17321         },
17322 };
17323
17324 static const struct hda_input_mux alc663_capture_source = {
17325         .num_items = 3,
17326         .items = {
17327                 { "Mic", 0x0 },
17328                 { "Front Mic", 0x1 },
17329                 { "Line", 0x2 },
17330         },
17331 };
17332
17333 #if 0 /* set to 1 for testing other input sources below */
17334 static const struct hda_input_mux alc272_nc10_capture_source = {
17335         .num_items = 16,
17336         .items = {
17337                 { "Autoselect Mic", 0x0 },
17338                 { "Internal Mic", 0x1 },
17339                 { "In-0x02", 0x2 },
17340                 { "In-0x03", 0x3 },
17341                 { "In-0x04", 0x4 },
17342                 { "In-0x05", 0x5 },
17343                 { "In-0x06", 0x6 },
17344                 { "In-0x07", 0x7 },
17345                 { "In-0x08", 0x8 },
17346                 { "In-0x09", 0x9 },
17347                 { "In-0x0a", 0x0a },
17348                 { "In-0x0b", 0x0b },
17349                 { "In-0x0c", 0x0c },
17350                 { "In-0x0d", 0x0d },
17351                 { "In-0x0e", 0x0e },
17352                 { "In-0x0f", 0x0f },
17353         },
17354 };
17355 #endif
17356
17357 /*
17358  * 2ch mode
17359  */
17360 static const struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
17361         { 2, NULL }
17362 };
17363
17364 /*
17365  * 2ch mode
17366  */
17367 static const struct hda_verb alc662_3ST_ch2_init[] = {
17368         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
17369         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
17370         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
17371         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
17372         { } /* end */
17373 };
17374
17375 /*
17376  * 6ch mode
17377  */
17378 static const struct hda_verb alc662_3ST_ch6_init[] = {
17379         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17380         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
17381         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
17382         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17383         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
17384         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
17385         { } /* end */
17386 };
17387
17388 static const struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
17389         { 2, alc662_3ST_ch2_init },
17390         { 6, alc662_3ST_ch6_init },
17391 };
17392
17393 /*
17394  * 2ch mode
17395  */
17396 static const struct hda_verb alc662_sixstack_ch6_init[] = {
17397         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
17398         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
17399         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17400         { } /* end */
17401 };
17402
17403 /*
17404  * 6ch mode
17405  */
17406 static const struct hda_verb alc662_sixstack_ch8_init[] = {
17407         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17408         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17409         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17410         { } /* end */
17411 };
17412
17413 static const struct hda_channel_mode alc662_5stack_modes[2] = {
17414         { 2, alc662_sixstack_ch6_init },
17415         { 6, alc662_sixstack_ch8_init },
17416 };
17417
17418 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
17419  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
17420  */
17421
17422 static const struct snd_kcontrol_new alc662_base_mixer[] = {
17423         /* output mixer control */
17424         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
17425         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
17426         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
17427         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
17428         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
17429         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
17430         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
17431         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
17432         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17433
17434         /*Input mixer control */
17435         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
17436         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
17437         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
17438         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
17439         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
17440         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
17441         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
17442         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
17443         { } /* end */
17444 };
17445
17446 static const struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
17447         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17448         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
17449         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17450         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
17451         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
17452         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17453         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17454         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17455         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17456         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17457         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17458         { } /* end */
17459 };
17460
17461 static const struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
17462         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17463         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
17464         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17465         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
17466         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
17467         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
17468         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
17469         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
17470         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17471         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
17472         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
17473         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17474         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17475         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17476         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17477         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17478         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17479         { } /* end */
17480 };
17481
17482 static const struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
17483         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17484         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
17485         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17486         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
17487         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17488         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17489         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17490         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17491         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17492         { } /* end */
17493 };
17494
17495 static const struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
17496         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17497         ALC262_HIPPO_MASTER_SWITCH,
17498
17499         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
17500         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17501         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17502
17503         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
17504         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17505         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17506         { } /* end */
17507 };
17508
17509 static const struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
17510         ALC262_HIPPO_MASTER_SWITCH,
17511         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17512         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17513         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
17514         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
17515         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
17516         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17517         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17518         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17519         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17520         { } /* end */
17521 };
17522
17523 static const struct hda_bind_ctls alc663_asus_bind_master_vol = {
17524         .ops = &snd_hda_bind_vol,
17525         .values = {
17526                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
17527                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
17528                 0
17529         },
17530 };
17531
17532 static const struct hda_bind_ctls alc663_asus_one_bind_switch = {
17533         .ops = &snd_hda_bind_sw,
17534         .values = {
17535                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17536                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
17537                 0
17538         },
17539 };
17540
17541 static const struct snd_kcontrol_new alc663_m51va_mixer[] = {
17542         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17543         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
17544         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17545         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17546         { } /* end */
17547 };
17548
17549 static const struct hda_bind_ctls alc663_asus_tree_bind_switch = {
17550         .ops = &snd_hda_bind_sw,
17551         .values = {
17552                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17553                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
17554                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
17555                 0
17556         },
17557 };
17558
17559 static const struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
17560         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17561         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
17562         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17563         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17564         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17565         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17566
17567         { } /* end */
17568 };
17569
17570 static const struct hda_bind_ctls alc663_asus_four_bind_switch = {
17571         .ops = &snd_hda_bind_sw,
17572         .values = {
17573                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17574                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
17575                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
17576                 0
17577         },
17578 };
17579
17580 static const struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
17581         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17582         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
17583         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17584         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17585         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17586         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17587         { } /* end */
17588 };
17589
17590 static const struct snd_kcontrol_new alc662_1bjd_mixer[] = {
17591         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17592         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
17593         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17594         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17595         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17596         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17597         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17598         { } /* end */
17599 };
17600
17601 static const struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
17602         .ops = &snd_hda_bind_vol,
17603         .values = {
17604                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
17605                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
17606                 0
17607         },
17608 };
17609
17610 static const struct hda_bind_ctls alc663_asus_two_bind_switch = {
17611         .ops = &snd_hda_bind_sw,
17612         .values = {
17613                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17614                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
17615                 0
17616         },
17617 };
17618
17619 static const struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
17620         HDA_BIND_VOL("Master Playback Volume",
17621                                 &alc663_asus_two_bind_master_vol),
17622         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
17623         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17624         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17625         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17626         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17627         { } /* end */
17628 };
17629
17630 static const struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
17631         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17632         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
17633         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17634         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
17635         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17636         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17637         { } /* end */
17638 };
17639
17640 static const struct snd_kcontrol_new alc663_g71v_mixer[] = {
17641         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17642         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
17643         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17644         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
17645         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17646
17647         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17648         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17649         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17650         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17651         { } /* end */
17652 };
17653
17654 static const struct snd_kcontrol_new alc663_g50v_mixer[] = {
17655         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17656         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
17657         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17658
17659         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17660         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17661         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17662         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17663         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17664         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17665         { } /* end */
17666 };
17667
17668 static const struct hda_bind_ctls alc663_asus_mode7_8_all_bind_switch = {
17669         .ops = &snd_hda_bind_sw,
17670         .values = {
17671                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17672                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
17673                 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
17674                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
17675                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
17676                 0
17677         },
17678 };
17679
17680 static const struct hda_bind_ctls alc663_asus_mode7_8_sp_bind_switch = {
17681         .ops = &snd_hda_bind_sw,
17682         .values = {
17683                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17684                 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
17685                 0
17686         },
17687 };
17688
17689 static const struct snd_kcontrol_new alc663_mode7_mixer[] = {
17690         HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
17691         HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
17692         HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
17693         HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17694         HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17695         HDA_CODEC_VOLUME("IntMic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17696         HDA_CODEC_MUTE("IntMic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17697         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17698         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17699         { } /* end */
17700 };
17701
17702 static const struct snd_kcontrol_new alc663_mode8_mixer[] = {
17703         HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
17704         HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
17705         HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
17706         HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x15, 0x0, HDA_OUTPUT),
17707         HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17708         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17709         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17710         { } /* end */
17711 };
17712
17713
17714 static const struct snd_kcontrol_new alc662_chmode_mixer[] = {
17715         {
17716                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
17717                 .name = "Channel Mode",
17718                 .info = alc_ch_mode_info,
17719                 .get = alc_ch_mode_get,
17720                 .put = alc_ch_mode_put,
17721         },
17722         { } /* end */
17723 };
17724
17725 static const struct hda_verb alc662_init_verbs[] = {
17726         /* ADC: mute amp left and right */
17727         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17728         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
17729
17730         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17731         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17732         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17733         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17734         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17735         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17736
17737         /* Front Pin: output 0 (0x0c) */
17738         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17739         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17740
17741         /* Rear Pin: output 1 (0x0d) */
17742         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17743         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17744
17745         /* CLFE Pin: output 2 (0x0e) */
17746         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17747         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17748
17749         /* Mic (rear) pin: input vref at 80% */
17750         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
17751         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
17752         /* Front Mic pin: input vref at 80% */
17753         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
17754         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
17755         /* Line In pin: input */
17756         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17757         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
17758         /* Line-2 In: Headphone output (output 0 - 0x0c) */
17759         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17760         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17761         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
17762         /* CD pin widget for input */
17763         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17764
17765         /* FIXME: use matrix-type input source selection */
17766         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
17767         /* Input mixer */
17768         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17769         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17770
17771         { }
17772 };
17773
17774 static const struct hda_verb alc662_eapd_init_verbs[] = {
17775         /* always trun on EAPD */
17776         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
17777         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
17778         { }
17779 };
17780
17781 static const struct hda_verb alc662_sue_init_verbs[] = {
17782         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
17783         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
17784         {}
17785 };
17786
17787 static const struct hda_verb alc662_eeepc_sue_init_verbs[] = {
17788         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17789         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17790         {}
17791 };
17792
17793 /* Set Unsolicited Event*/
17794 static const struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
17795         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17796         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17797         {}
17798 };
17799
17800 static const struct hda_verb alc663_m51va_init_verbs[] = {
17801         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17802         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17803         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17804         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17805         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17806         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17807         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17808         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17809         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17810         {}
17811 };
17812
17813 static const struct hda_verb alc663_21jd_amic_init_verbs[] = {
17814         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17815         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17816         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17817         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17818         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17819         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17820         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17821         {}
17822 };
17823
17824 static const struct hda_verb alc662_1bjd_amic_init_verbs[] = {
17825         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17826         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17827         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17828         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
17829         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17830         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17831         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17832         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17833         {}
17834 };
17835
17836 static const struct hda_verb alc663_15jd_amic_init_verbs[] = {
17837         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17838         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17839         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17840         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17841         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17842         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17843         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17844         {}
17845 };
17846
17847 static const struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
17848         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17849         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17850         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17851         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
17852         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17853         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17854         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
17855         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17856         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17857         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17858         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17859         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17860         {}
17861 };
17862
17863 static const struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
17864         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17865         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17866         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17867         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17868         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17869         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17870         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17871         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17872         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17873         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17874         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17875         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17876         {}
17877 };
17878
17879 static const struct hda_verb alc663_g71v_init_verbs[] = {
17880         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17881         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
17882         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
17883
17884         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17885         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17886         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
17887
17888         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
17889         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
17890         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
17891         {}
17892 };
17893
17894 static const struct hda_verb alc663_g50v_init_verbs[] = {
17895         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17896         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17897         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
17898
17899         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17900         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17901         {}
17902 };
17903
17904 static const struct hda_verb alc662_ecs_init_verbs[] = {
17905         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
17906         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17907         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17908         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17909         {}
17910 };
17911
17912 static const struct hda_verb alc272_dell_zm1_init_verbs[] = {
17913         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17914         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17915         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17916         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17917         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17918         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17919         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17920         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17921         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17922         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17923         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17924         {}
17925 };
17926
17927 static const struct hda_verb alc272_dell_init_verbs[] = {
17928         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17929         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17930         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17931         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17932         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17933         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17934         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17935         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17936         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17937         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17938         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17939         {}
17940 };
17941
17942 static const struct hda_verb alc663_mode7_init_verbs[] = {
17943         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17944         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17945         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17946         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17947         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17948         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17949         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
17950         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17951         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17952         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17953         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17954         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17955         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17956         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17957         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17958         {}
17959 };
17960
17961 static const struct hda_verb alc663_mode8_init_verbs[] = {
17962         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17963         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17964         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17965         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
17966         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17967         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17968         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17969         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17970         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17971         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17972         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17973         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17974         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17975         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17976         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17977         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17978         {}
17979 };
17980
17981 static const struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
17982         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
17983         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
17984         { } /* end */
17985 };
17986
17987 static const struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
17988         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
17989         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
17990         { } /* end */
17991 };
17992
17993 static void alc662_lenovo_101e_setup(struct hda_codec *codec)
17994 {
17995         struct alc_spec *spec = codec->spec;
17996
17997         spec->autocfg.hp_pins[0] = 0x1b;
17998         spec->autocfg.line_out_pins[0] = 0x14;
17999         spec->autocfg.speaker_pins[0] = 0x15;
18000         spec->automute = 1;
18001         spec->detect_line = 1;
18002         spec->automute_lines = 1;
18003         spec->automute_mode = ALC_AUTOMUTE_AMP;
18004 }
18005
18006 static void alc662_eeepc_setup(struct hda_codec *codec)
18007 {
18008         struct alc_spec *spec = codec->spec;
18009
18010         alc262_hippo1_setup(codec);
18011         spec->ext_mic.pin = 0x18;
18012         spec->ext_mic.mux_idx = 0;
18013         spec->int_mic.pin = 0x19;
18014         spec->int_mic.mux_idx = 1;
18015         spec->auto_mic = 1;
18016 }
18017
18018 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
18019 {
18020         struct alc_spec *spec = codec->spec;
18021
18022         spec->autocfg.hp_pins[0] = 0x14;
18023         spec->autocfg.speaker_pins[0] = 0x1b;
18024         spec->automute = 1;
18025         spec->automute_mode = ALC_AUTOMUTE_AMP;
18026 }
18027
18028 static void alc663_m51va_setup(struct hda_codec *codec)
18029 {
18030         struct alc_spec *spec = codec->spec;
18031         spec->autocfg.hp_pins[0] = 0x21;
18032         spec->autocfg.speaker_pins[0] = 0x14;
18033         spec->automute_mixer_nid[0] = 0x0c;
18034         spec->automute = 1;
18035         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18036         spec->ext_mic.pin = 0x18;
18037         spec->ext_mic.mux_idx = 0;
18038         spec->int_mic.pin = 0x12;
18039         spec->int_mic.mux_idx = 9;
18040         spec->auto_mic = 1;
18041 }
18042
18043 /* ***************** Mode1 ******************************/
18044 static void alc663_mode1_setup(struct hda_codec *codec)
18045 {
18046         struct alc_spec *spec = codec->spec;
18047         spec->autocfg.hp_pins[0] = 0x21;
18048         spec->autocfg.speaker_pins[0] = 0x14;
18049         spec->automute_mixer_nid[0] = 0x0c;
18050         spec->automute = 1;
18051         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18052         spec->ext_mic.pin = 0x18;
18053         spec->ext_mic.mux_idx = 0;
18054         spec->int_mic.pin = 0x19;
18055         spec->int_mic.mux_idx = 1;
18056         spec->auto_mic = 1;
18057 }
18058
18059 /* ***************** Mode2 ******************************/
18060 static void alc662_mode2_setup(struct hda_codec *codec)
18061 {
18062         struct alc_spec *spec = codec->spec;
18063         spec->autocfg.hp_pins[0] = 0x1b;
18064         spec->autocfg.speaker_pins[0] = 0x14;
18065         spec->automute = 1;
18066         spec->automute_mode = ALC_AUTOMUTE_PIN;
18067         spec->ext_mic.pin = 0x18;
18068         spec->ext_mic.mux_idx = 0;
18069         spec->int_mic.pin = 0x19;
18070         spec->int_mic.mux_idx = 1;
18071         spec->auto_mic = 1;
18072 }
18073
18074 /* ***************** Mode3 ******************************/
18075 static void alc663_mode3_setup(struct hda_codec *codec)
18076 {
18077         struct alc_spec *spec = codec->spec;
18078         spec->autocfg.hp_pins[0] = 0x21;
18079         spec->autocfg.hp_pins[0] = 0x15;
18080         spec->autocfg.speaker_pins[0] = 0x14;
18081         spec->automute = 1;
18082         spec->automute_mode = ALC_AUTOMUTE_PIN;
18083         spec->ext_mic.pin = 0x18;
18084         spec->ext_mic.mux_idx = 0;
18085         spec->int_mic.pin = 0x19;
18086         spec->int_mic.mux_idx = 1;
18087         spec->auto_mic = 1;
18088 }
18089
18090 /* ***************** Mode4 ******************************/
18091 static void alc663_mode4_setup(struct hda_codec *codec)
18092 {
18093         struct alc_spec *spec = codec->spec;
18094         spec->autocfg.hp_pins[0] = 0x21;
18095         spec->autocfg.speaker_pins[0] = 0x14;
18096         spec->autocfg.speaker_pins[1] = 0x16;
18097         spec->automute_mixer_nid[0] = 0x0c;
18098         spec->automute_mixer_nid[1] = 0x0e;
18099         spec->automute = 1;
18100         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18101         spec->ext_mic.pin = 0x18;
18102         spec->ext_mic.mux_idx = 0;
18103         spec->int_mic.pin = 0x19;
18104         spec->int_mic.mux_idx = 1;
18105         spec->auto_mic = 1;
18106 }
18107
18108 /* ***************** Mode5 ******************************/
18109 static void alc663_mode5_setup(struct hda_codec *codec)
18110 {
18111         struct alc_spec *spec = codec->spec;
18112         spec->autocfg.hp_pins[0] = 0x15;
18113         spec->autocfg.speaker_pins[0] = 0x14;
18114         spec->autocfg.speaker_pins[1] = 0x16;
18115         spec->automute_mixer_nid[0] = 0x0c;
18116         spec->automute_mixer_nid[1] = 0x0e;
18117         spec->automute = 1;
18118         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18119         spec->ext_mic.pin = 0x18;
18120         spec->ext_mic.mux_idx = 0;
18121         spec->int_mic.pin = 0x19;
18122         spec->int_mic.mux_idx = 1;
18123         spec->auto_mic = 1;
18124 }
18125
18126 /* ***************** Mode6 ******************************/
18127 static void alc663_mode6_setup(struct hda_codec *codec)
18128 {
18129         struct alc_spec *spec = codec->spec;
18130         spec->autocfg.hp_pins[0] = 0x1b;
18131         spec->autocfg.hp_pins[0] = 0x15;
18132         spec->autocfg.speaker_pins[0] = 0x14;
18133         spec->automute_mixer_nid[0] = 0x0c;
18134         spec->automute = 1;
18135         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18136         spec->ext_mic.pin = 0x18;
18137         spec->ext_mic.mux_idx = 0;
18138         spec->int_mic.pin = 0x19;
18139         spec->int_mic.mux_idx = 1;
18140         spec->auto_mic = 1;
18141 }
18142
18143 /* ***************** Mode7 ******************************/
18144 static void alc663_mode7_setup(struct hda_codec *codec)
18145 {
18146         struct alc_spec *spec = codec->spec;
18147         spec->autocfg.hp_pins[0] = 0x1b;
18148         spec->autocfg.hp_pins[0] = 0x21;
18149         spec->autocfg.speaker_pins[0] = 0x14;
18150         spec->autocfg.speaker_pins[0] = 0x17;
18151         spec->automute = 1;
18152         spec->automute_mode = ALC_AUTOMUTE_PIN;
18153         spec->ext_mic.pin = 0x18;
18154         spec->ext_mic.mux_idx = 0;
18155         spec->int_mic.pin = 0x19;
18156         spec->int_mic.mux_idx = 1;
18157         spec->auto_mic = 1;
18158 }
18159
18160 /* ***************** Mode8 ******************************/
18161 static void alc663_mode8_setup(struct hda_codec *codec)
18162 {
18163         struct alc_spec *spec = codec->spec;
18164         spec->autocfg.hp_pins[0] = 0x21;
18165         spec->autocfg.hp_pins[1] = 0x15;
18166         spec->autocfg.speaker_pins[0] = 0x14;
18167         spec->autocfg.speaker_pins[0] = 0x17;
18168         spec->automute = 1;
18169         spec->automute_mode = ALC_AUTOMUTE_PIN;
18170         spec->ext_mic.pin = 0x18;
18171         spec->ext_mic.mux_idx = 0;
18172         spec->int_mic.pin = 0x12;
18173         spec->int_mic.mux_idx = 9;
18174         spec->auto_mic = 1;
18175 }
18176
18177 static void alc663_g71v_setup(struct hda_codec *codec)
18178 {
18179         struct alc_spec *spec = codec->spec;
18180         spec->autocfg.hp_pins[0] = 0x21;
18181         spec->autocfg.line_out_pins[0] = 0x15;
18182         spec->autocfg.speaker_pins[0] = 0x14;
18183         spec->automute = 1;
18184         spec->automute_mode = ALC_AUTOMUTE_AMP;
18185         spec->detect_line = 1;
18186         spec->automute_lines = 1;
18187         spec->ext_mic.pin = 0x18;
18188         spec->ext_mic.mux_idx = 0;
18189         spec->int_mic.pin = 0x12;
18190         spec->int_mic.mux_idx = 9;
18191         spec->auto_mic = 1;
18192 }
18193
18194 #define alc663_g50v_setup       alc663_m51va_setup
18195
18196 static const struct snd_kcontrol_new alc662_ecs_mixer[] = {
18197         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
18198         ALC262_HIPPO_MASTER_SWITCH,
18199
18200         HDA_CODEC_VOLUME("Mic/LineIn Boost Volume", 0x18, 0, HDA_INPUT),
18201         HDA_CODEC_VOLUME("Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
18202         HDA_CODEC_MUTE("Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
18203
18204         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
18205         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
18206         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
18207         { } /* end */
18208 };
18209
18210 static const struct snd_kcontrol_new alc272_nc10_mixer[] = {
18211         /* Master Playback automatically created from Speaker and Headphone */
18212         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
18213         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
18214         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
18215         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
18216
18217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
18218         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
18219         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
18220
18221         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
18222         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
18223         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
18224         { } /* end */
18225 };
18226
18227 #ifdef CONFIG_SND_HDA_POWER_SAVE
18228 #define alc662_loopbacks        alc880_loopbacks
18229 #endif
18230
18231
18232 /* pcm configuration: identical with ALC880 */
18233 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
18234 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
18235 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
18236 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
18237
18238 /*
18239  * configuration and preset
18240  */
18241 static const char * const alc662_models[ALC662_MODEL_LAST] = {
18242         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
18243         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
18244         [ALC662_3ST_6ch]        = "3stack-6ch",
18245         [ALC662_5ST_DIG]        = "5stack-dig",
18246         [ALC662_LENOVO_101E]    = "lenovo-101e",
18247         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
18248         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
18249         [ALC662_ECS] = "ecs",
18250         [ALC663_ASUS_M51VA] = "m51va",
18251         [ALC663_ASUS_G71V] = "g71v",
18252         [ALC663_ASUS_H13] = "h13",
18253         [ALC663_ASUS_G50V] = "g50v",
18254         [ALC663_ASUS_MODE1] = "asus-mode1",
18255         [ALC662_ASUS_MODE2] = "asus-mode2",
18256         [ALC663_ASUS_MODE3] = "asus-mode3",
18257         [ALC663_ASUS_MODE4] = "asus-mode4",
18258         [ALC663_ASUS_MODE5] = "asus-mode5",
18259         [ALC663_ASUS_MODE6] = "asus-mode6",
18260         [ALC663_ASUS_MODE7] = "asus-mode7",
18261         [ALC663_ASUS_MODE8] = "asus-mode8",
18262         [ALC272_DELL]           = "dell",
18263         [ALC272_DELL_ZM1]       = "dell-zm1",
18264         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
18265         [ALC662_AUTO]           = "auto",
18266 };
18267
18268 static const struct snd_pci_quirk alc662_cfg_tbl[] = {
18269         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
18270         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
18271         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
18272         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
18273         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
18274         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC663_ASUS_MODE1),
18275         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
18276         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
18277         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
18278         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
18279         SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC663_ASUS_MODE1),
18280         SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC663_ASUS_MODE1),
18281         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
18282         SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC663_ASUS_MODE7),
18283         SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC663_ASUS_MODE7),
18284         SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC663_ASUS_MODE8),
18285         SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC663_ASUS_MODE3),
18286         SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC663_ASUS_MODE1),
18287         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
18288         SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_ASUS_MODE2),
18289         SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC663_ASUS_MODE1),
18290         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
18291         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
18292         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
18293         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
18294         SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC663_ASUS_MODE1),
18295         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
18296         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
18297         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
18298         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
18299         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
18300         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
18301         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
18302         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
18303         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
18304         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
18305         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
18306         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
18307         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
18308         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
18309         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
18310         SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC663_ASUS_MODE1),
18311         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
18312         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
18313         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
18314         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
18315         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
18316         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
18317         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
18318         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
18319         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
18320         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
18321         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
18322         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
18323         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
18324         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
18325         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
18326         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
18327         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
18328         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
18329         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
18330         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
18331         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
18332         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
18333                       ALC662_3ST_6ch_DIG),
18334         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB20x", ALC662_AUTO),
18335         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
18336         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
18337                       ALC662_3ST_6ch_DIG),
18338         SND_PCI_QUIRK(0x152d, 0x2304, "Quanta WH1", ALC663_ASUS_H13),
18339         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
18340         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
18341         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
18342         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
18343                                         ALC662_3ST_6ch_DIG),
18344         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
18345                            ALC663_ASUS_H13),
18346         SND_PCI_QUIRK(0x1991, 0x5628, "Ordissimo EVE", ALC662_LENOVO_101E),
18347         {}
18348 };
18349
18350 static const struct alc_config_preset alc662_presets[] = {
18351         [ALC662_3ST_2ch_DIG] = {
18352                 .mixers = { alc662_3ST_2ch_mixer },
18353                 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
18354                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18355                 .dac_nids = alc662_dac_nids,
18356                 .dig_out_nid = ALC662_DIGOUT_NID,
18357                 .dig_in_nid = ALC662_DIGIN_NID,
18358                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18359                 .channel_mode = alc662_3ST_2ch_modes,
18360                 .input_mux = &alc662_capture_source,
18361         },
18362         [ALC662_3ST_6ch_DIG] = {
18363                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
18364                 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
18365                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18366                 .dac_nids = alc662_dac_nids,
18367                 .dig_out_nid = ALC662_DIGOUT_NID,
18368                 .dig_in_nid = ALC662_DIGIN_NID,
18369                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18370                 .channel_mode = alc662_3ST_6ch_modes,
18371                 .need_dac_fix = 1,
18372                 .input_mux = &alc662_capture_source,
18373         },
18374         [ALC662_3ST_6ch] = {
18375                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
18376                 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
18377                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18378                 .dac_nids = alc662_dac_nids,
18379                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18380                 .channel_mode = alc662_3ST_6ch_modes,
18381                 .need_dac_fix = 1,
18382                 .input_mux = &alc662_capture_source,
18383         },
18384         [ALC662_5ST_DIG] = {
18385                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
18386                 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
18387                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18388                 .dac_nids = alc662_dac_nids,
18389                 .dig_out_nid = ALC662_DIGOUT_NID,
18390                 .dig_in_nid = ALC662_DIGIN_NID,
18391                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
18392                 .channel_mode = alc662_5stack_modes,
18393                 .input_mux = &alc662_capture_source,
18394         },
18395         [ALC662_LENOVO_101E] = {
18396                 .mixers = { alc662_lenovo_101e_mixer },
18397                 .init_verbs = { alc662_init_verbs,
18398                                 alc662_eapd_init_verbs,
18399                                 alc662_sue_init_verbs },
18400                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18401                 .dac_nids = alc662_dac_nids,
18402                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18403                 .channel_mode = alc662_3ST_2ch_modes,
18404                 .input_mux = &alc662_lenovo_101e_capture_source,
18405                 .unsol_event = alc_sku_unsol_event,
18406                 .setup = alc662_lenovo_101e_setup,
18407                 .init_hook = alc_inithook,
18408         },
18409         [ALC662_ASUS_EEEPC_P701] = {
18410                 .mixers = { alc662_eeepc_p701_mixer },
18411                 .init_verbs = { alc662_init_verbs,
18412                                 alc662_eapd_init_verbs,
18413                                 alc662_eeepc_sue_init_verbs },
18414                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18415                 .dac_nids = alc662_dac_nids,
18416                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18417                 .channel_mode = alc662_3ST_2ch_modes,
18418                 .unsol_event = alc_sku_unsol_event,
18419                 .setup = alc662_eeepc_setup,
18420                 .init_hook = alc_inithook,
18421         },
18422         [ALC662_ASUS_EEEPC_EP20] = {
18423                 .mixers = { alc662_eeepc_ep20_mixer,
18424                             alc662_chmode_mixer },
18425                 .init_verbs = { alc662_init_verbs,
18426                                 alc662_eapd_init_verbs,
18427                                 alc662_eeepc_ep20_sue_init_verbs },
18428                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18429                 .dac_nids = alc662_dac_nids,
18430                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18431                 .channel_mode = alc662_3ST_6ch_modes,
18432                 .input_mux = &alc662_lenovo_101e_capture_source,
18433                 .unsol_event = alc_sku_unsol_event,
18434                 .setup = alc662_eeepc_ep20_setup,
18435                 .init_hook = alc_inithook,
18436         },
18437         [ALC662_ECS] = {
18438                 .mixers = { alc662_ecs_mixer },
18439                 .init_verbs = { alc662_init_verbs,
18440                                 alc662_eapd_init_verbs,
18441                                 alc662_ecs_init_verbs },
18442                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18443                 .dac_nids = alc662_dac_nids,
18444                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18445                 .channel_mode = alc662_3ST_2ch_modes,
18446                 .unsol_event = alc_sku_unsol_event,
18447                 .setup = alc662_eeepc_setup,
18448                 .init_hook = alc_inithook,
18449         },
18450         [ALC663_ASUS_M51VA] = {
18451                 .mixers = { alc663_m51va_mixer },
18452                 .init_verbs = { alc662_init_verbs,
18453                                 alc662_eapd_init_verbs,
18454                                 alc663_m51va_init_verbs },
18455                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18456                 .dac_nids = alc662_dac_nids,
18457                 .dig_out_nid = ALC662_DIGOUT_NID,
18458                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18459                 .channel_mode = alc662_3ST_2ch_modes,
18460                 .unsol_event = alc_sku_unsol_event,
18461                 .setup = alc663_m51va_setup,
18462                 .init_hook = alc_inithook,
18463         },
18464         [ALC663_ASUS_G71V] = {
18465                 .mixers = { alc663_g71v_mixer },
18466                 .init_verbs = { alc662_init_verbs,
18467                                 alc662_eapd_init_verbs,
18468                                 alc663_g71v_init_verbs },
18469                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18470                 .dac_nids = alc662_dac_nids,
18471                 .dig_out_nid = ALC662_DIGOUT_NID,
18472                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18473                 .channel_mode = alc662_3ST_2ch_modes,
18474                 .unsol_event = alc_sku_unsol_event,
18475                 .setup = alc663_g71v_setup,
18476                 .init_hook = alc_inithook,
18477         },
18478         [ALC663_ASUS_H13] = {
18479                 .mixers = { alc663_m51va_mixer },
18480                 .init_verbs = { alc662_init_verbs,
18481                                 alc662_eapd_init_verbs,
18482                                 alc663_m51va_init_verbs },
18483                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18484                 .dac_nids = alc662_dac_nids,
18485                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18486                 .channel_mode = alc662_3ST_2ch_modes,
18487                 .setup = alc663_m51va_setup,
18488                 .unsol_event = alc_sku_unsol_event,
18489                 .init_hook = alc_inithook,
18490         },
18491         [ALC663_ASUS_G50V] = {
18492                 .mixers = { alc663_g50v_mixer },
18493                 .init_verbs = { alc662_init_verbs,
18494                                 alc662_eapd_init_verbs,
18495                                 alc663_g50v_init_verbs },
18496                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18497                 .dac_nids = alc662_dac_nids,
18498                 .dig_out_nid = ALC662_DIGOUT_NID,
18499                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18500                 .channel_mode = alc662_3ST_6ch_modes,
18501                 .input_mux = &alc663_capture_source,
18502                 .unsol_event = alc_sku_unsol_event,
18503                 .setup = alc663_g50v_setup,
18504                 .init_hook = alc_inithook,
18505         },
18506         [ALC663_ASUS_MODE1] = {
18507                 .mixers = { alc663_m51va_mixer },
18508                 .cap_mixer = alc662_auto_capture_mixer,
18509                 .init_verbs = { alc662_init_verbs,
18510                                 alc662_eapd_init_verbs,
18511                                 alc663_21jd_amic_init_verbs },
18512                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18513                 .hp_nid = 0x03,
18514                 .dac_nids = alc662_dac_nids,
18515                 .dig_out_nid = ALC662_DIGOUT_NID,
18516                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18517                 .channel_mode = alc662_3ST_2ch_modes,
18518                 .unsol_event = alc_sku_unsol_event,
18519                 .setup = alc663_mode1_setup,
18520                 .init_hook = alc_inithook,
18521         },
18522         [ALC662_ASUS_MODE2] = {
18523                 .mixers = { alc662_1bjd_mixer },
18524                 .cap_mixer = alc662_auto_capture_mixer,
18525                 .init_verbs = { alc662_init_verbs,
18526                                 alc662_eapd_init_verbs,
18527                                 alc662_1bjd_amic_init_verbs },
18528                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18529                 .dac_nids = alc662_dac_nids,
18530                 .dig_out_nid = ALC662_DIGOUT_NID,
18531                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18532                 .channel_mode = alc662_3ST_2ch_modes,
18533                 .unsol_event = alc_sku_unsol_event,
18534                 .setup = alc662_mode2_setup,
18535                 .init_hook = alc_inithook,
18536         },
18537         [ALC663_ASUS_MODE3] = {
18538                 .mixers = { alc663_two_hp_m1_mixer },
18539                 .cap_mixer = alc662_auto_capture_mixer,
18540                 .init_verbs = { alc662_init_verbs,
18541                                 alc662_eapd_init_verbs,
18542                                 alc663_two_hp_amic_m1_init_verbs },
18543                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18544                 .hp_nid = 0x03,
18545                 .dac_nids = alc662_dac_nids,
18546                 .dig_out_nid = ALC662_DIGOUT_NID,
18547                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18548                 .channel_mode = alc662_3ST_2ch_modes,
18549                 .unsol_event = alc_sku_unsol_event,
18550                 .setup = alc663_mode3_setup,
18551                 .init_hook = alc_inithook,
18552         },
18553         [ALC663_ASUS_MODE4] = {
18554                 .mixers = { alc663_asus_21jd_clfe_mixer },
18555                 .cap_mixer = alc662_auto_capture_mixer,
18556                 .init_verbs = { alc662_init_verbs,
18557                                 alc662_eapd_init_verbs,
18558                                 alc663_21jd_amic_init_verbs},
18559                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18560                 .hp_nid = 0x03,
18561                 .dac_nids = alc662_dac_nids,
18562                 .dig_out_nid = ALC662_DIGOUT_NID,
18563                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18564                 .channel_mode = alc662_3ST_2ch_modes,
18565                 .unsol_event = alc_sku_unsol_event,
18566                 .setup = alc663_mode4_setup,
18567                 .init_hook = alc_inithook,
18568         },
18569         [ALC663_ASUS_MODE5] = {
18570                 .mixers = { alc663_asus_15jd_clfe_mixer },
18571                 .cap_mixer = alc662_auto_capture_mixer,
18572                 .init_verbs = { alc662_init_verbs,
18573                                 alc662_eapd_init_verbs,
18574                                 alc663_15jd_amic_init_verbs },
18575                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18576                 .hp_nid = 0x03,
18577                 .dac_nids = alc662_dac_nids,
18578                 .dig_out_nid = ALC662_DIGOUT_NID,
18579                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18580                 .channel_mode = alc662_3ST_2ch_modes,
18581                 .unsol_event = alc_sku_unsol_event,
18582                 .setup = alc663_mode5_setup,
18583                 .init_hook = alc_inithook,
18584         },
18585         [ALC663_ASUS_MODE6] = {
18586                 .mixers = { alc663_two_hp_m2_mixer },
18587                 .cap_mixer = alc662_auto_capture_mixer,
18588                 .init_verbs = { alc662_init_verbs,
18589                                 alc662_eapd_init_verbs,
18590                                 alc663_two_hp_amic_m2_init_verbs },
18591                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18592                 .hp_nid = 0x03,
18593                 .dac_nids = alc662_dac_nids,
18594                 .dig_out_nid = ALC662_DIGOUT_NID,
18595                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18596                 .channel_mode = alc662_3ST_2ch_modes,
18597                 .unsol_event = alc_sku_unsol_event,
18598                 .setup = alc663_mode6_setup,
18599                 .init_hook = alc_inithook,
18600         },
18601         [ALC663_ASUS_MODE7] = {
18602                 .mixers = { alc663_mode7_mixer },
18603                 .cap_mixer = alc662_auto_capture_mixer,
18604                 .init_verbs = { alc662_init_verbs,
18605                                 alc662_eapd_init_verbs,
18606                                 alc663_mode7_init_verbs },
18607                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18608                 .hp_nid = 0x03,
18609                 .dac_nids = alc662_dac_nids,
18610                 .dig_out_nid = ALC662_DIGOUT_NID,
18611                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18612                 .channel_mode = alc662_3ST_2ch_modes,
18613                 .unsol_event = alc_sku_unsol_event,
18614                 .setup = alc663_mode7_setup,
18615                 .init_hook = alc_inithook,
18616         },
18617         [ALC663_ASUS_MODE8] = {
18618                 .mixers = { alc663_mode8_mixer },
18619                 .cap_mixer = alc662_auto_capture_mixer,
18620                 .init_verbs = { alc662_init_verbs,
18621                                 alc662_eapd_init_verbs,
18622                                 alc663_mode8_init_verbs },
18623                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18624                 .hp_nid = 0x03,
18625                 .dac_nids = alc662_dac_nids,
18626                 .dig_out_nid = ALC662_DIGOUT_NID,
18627                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18628                 .channel_mode = alc662_3ST_2ch_modes,
18629                 .unsol_event = alc_sku_unsol_event,
18630                 .setup = alc663_mode8_setup,
18631                 .init_hook = alc_inithook,
18632         },
18633         [ALC272_DELL] = {
18634                 .mixers = { alc663_m51va_mixer },
18635                 .cap_mixer = alc272_auto_capture_mixer,
18636                 .init_verbs = { alc662_init_verbs,
18637                                 alc662_eapd_init_verbs,
18638                                 alc272_dell_init_verbs },
18639                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
18640                 .dac_nids = alc272_dac_nids,
18641                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18642                 .adc_nids = alc272_adc_nids,
18643                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
18644                 .capsrc_nids = alc272_capsrc_nids,
18645                 .channel_mode = alc662_3ST_2ch_modes,
18646                 .unsol_event = alc_sku_unsol_event,
18647                 .setup = alc663_m51va_setup,
18648                 .init_hook = alc_inithook,
18649         },
18650         [ALC272_DELL_ZM1] = {
18651                 .mixers = { alc663_m51va_mixer },
18652                 .cap_mixer = alc662_auto_capture_mixer,
18653                 .init_verbs = { alc662_init_verbs,
18654                                 alc662_eapd_init_verbs,
18655                                 alc272_dell_zm1_init_verbs },
18656                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
18657                 .dac_nids = alc272_dac_nids,
18658                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18659                 .adc_nids = alc662_adc_nids,
18660                 .num_adc_nids = 1,
18661                 .capsrc_nids = alc662_capsrc_nids,
18662                 .channel_mode = alc662_3ST_2ch_modes,
18663                 .unsol_event = alc_sku_unsol_event,
18664                 .setup = alc663_m51va_setup,
18665                 .init_hook = alc_inithook,
18666         },
18667         [ALC272_SAMSUNG_NC10] = {
18668                 .mixers = { alc272_nc10_mixer },
18669                 .init_verbs = { alc662_init_verbs,
18670                                 alc662_eapd_init_verbs,
18671                                 alc663_21jd_amic_init_verbs },
18672                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
18673                 .dac_nids = alc272_dac_nids,
18674                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18675                 .channel_mode = alc662_3ST_2ch_modes,
18676                 /*.input_mux = &alc272_nc10_capture_source,*/
18677                 .unsol_event = alc_sku_unsol_event,
18678                 .setup = alc663_mode4_setup,
18679                 .init_hook = alc_inithook,
18680         },
18681 };
18682
18683
18684 /*
18685  * BIOS auto configuration
18686  */
18687
18688 /* convert from MIX nid to DAC */
18689 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
18690 {
18691         hda_nid_t list[5];
18692         int i, num;
18693
18694         num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
18695         for (i = 0; i < num; i++) {
18696                 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
18697                         return list[i];
18698         }
18699         return 0;
18700 }
18701
18702 /* go down to the selector widget before the mixer */
18703 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
18704 {
18705         hda_nid_t srcs[5];
18706         int num = snd_hda_get_connections(codec, pin, srcs,
18707                                           ARRAY_SIZE(srcs));
18708         if (num != 1 ||
18709             get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
18710                 return pin;
18711         return srcs[0];
18712 }
18713
18714 /* get MIX nid connected to the given pin targeted to DAC */
18715 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
18716                                    hda_nid_t dac)
18717 {
18718         hda_nid_t mix[5];
18719         int i, num;
18720
18721         pin = alc_go_down_to_selector(codec, pin);
18722         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
18723         for (i = 0; i < num; i++) {
18724                 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
18725                         return mix[i];
18726         }
18727         return 0;
18728 }
18729
18730 /* select the connection from pin to DAC if needed */
18731 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
18732                                hda_nid_t dac)
18733 {
18734         hda_nid_t mix[5];
18735         int i, num;
18736
18737         pin = alc_go_down_to_selector(codec, pin);
18738         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
18739         if (num < 2)
18740                 return 0;
18741         for (i = 0; i < num; i++) {
18742                 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
18743                         snd_hda_codec_update_cache(codec, pin, 0,
18744                                                    AC_VERB_SET_CONNECT_SEL, i);
18745                         return 0;
18746                 }
18747         }
18748         return 0;
18749 }
18750
18751 /* look for an empty DAC slot */
18752 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
18753 {
18754         struct alc_spec *spec = codec->spec;
18755         hda_nid_t srcs[5];
18756         int i, num;
18757
18758         pin = alc_go_down_to_selector(codec, pin);
18759         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
18760         for (i = 0; i < num; i++) {
18761                 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
18762                 if (!nid)
18763                         continue;
18764                 if (found_in_nid_list(nid, spec->multiout.dac_nids,
18765                                       spec->multiout.num_dacs))
18766                         continue;
18767                 if (spec->multiout.hp_nid == nid)
18768                         continue;
18769                 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
18770                                       ARRAY_SIZE(spec->multiout.extra_out_nid)))
18771                     continue;
18772                 return nid;
18773         }
18774         return 0;
18775 }
18776
18777 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
18778 {
18779         hda_nid_t sel = alc_go_down_to_selector(codec, pin);
18780         if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
18781                 return alc_auto_look_for_dac(codec, pin);
18782         return 0;
18783 }
18784
18785 /* fill in the dac_nids table from the parsed pin configuration */
18786 static int alc662_auto_fill_dac_nids(struct hda_codec *codec)
18787 {
18788         struct alc_spec *spec = codec->spec;
18789         const struct auto_pin_cfg *cfg = &spec->autocfg;
18790         bool redone;
18791         int i;
18792
18793  again:
18794         spec->multiout.num_dacs = 0;
18795         spec->multiout.hp_nid = 0;
18796         spec->multiout.extra_out_nid[0] = 0;
18797         memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
18798         spec->multiout.dac_nids = spec->private_dac_nids;
18799
18800         /* fill hard-wired DACs first */
18801         if (!redone) {
18802                 for (i = 0; i < cfg->line_outs; i++)
18803                         spec->private_dac_nids[i] =
18804                                 get_dac_if_single(codec, cfg->line_out_pins[i]);
18805                 if (cfg->hp_outs)
18806                         spec->multiout.hp_nid =
18807                                 get_dac_if_single(codec, cfg->hp_pins[0]);
18808                 if (cfg->speaker_outs)
18809                         spec->multiout.extra_out_nid[0] =
18810                                 get_dac_if_single(codec, cfg->speaker_pins[0]);
18811         }
18812
18813         for (i = 0; i < cfg->line_outs; i++) {
18814                 hda_nid_t pin = cfg->line_out_pins[i];
18815                 if (spec->private_dac_nids[i])
18816                         continue;
18817                 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
18818                 if (!spec->private_dac_nids[i] && !redone) {
18819                         /* if we can't find primary DACs, re-probe without
18820                          * checking the hard-wired DACs
18821                          */
18822                         redone = true;
18823                         goto again;
18824                 }
18825         }
18826
18827         for (i = 0; i < cfg->line_outs; i++) {
18828                 if (spec->private_dac_nids[i])
18829                         spec->multiout.num_dacs++;
18830                 else
18831                         memmove(spec->private_dac_nids + i,
18832                                 spec->private_dac_nids + i + 1,
18833                                 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
18834         }
18835
18836         return 0;
18837 }
18838
18839 static inline int __alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
18840                                        hda_nid_t nid, int idx, unsigned int chs)
18841 {
18842         return __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, idx,
18843                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
18844 }
18845
18846 static inline int __alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
18847                                       hda_nid_t nid, int idx, unsigned int chs)
18848 {
18849         return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, idx,
18850                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
18851 }
18852
18853 #define alc662_add_vol_ctl(spec, pfx, nid, chs) \
18854         __alc662_add_vol_ctl(spec, pfx, nid, 0, chs)
18855 #define alc662_add_sw_ctl(spec, pfx, nid, chs) \
18856         __alc662_add_sw_ctl(spec, pfx, nid, 0, chs)
18857 #define alc662_add_stereo_vol(spec, pfx, nid) \
18858         alc662_add_vol_ctl(spec, pfx, nid, 3)
18859 #define alc662_add_stereo_sw(spec, pfx, nid) \
18860         alc662_add_sw_ctl(spec, pfx, nid, 3)
18861
18862 /* add playback controls from the parsed DAC table */
18863 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
18864                                              const struct auto_pin_cfg *cfg)
18865 {
18866         struct alc_spec *spec = codec->spec;
18867         hda_nid_t nid, mix, pin;
18868         int i, err, noutputs;
18869
18870         noutputs = cfg->line_outs;
18871         if (spec->multi_ios > 0)
18872                 noutputs += spec->multi_ios;
18873
18874         for (i = 0; i < noutputs; i++) {
18875                 const char *name;
18876                 int index;
18877                 nid = spec->multiout.dac_nids[i];
18878                 if (!nid)
18879                         continue;
18880                 if (i >= cfg->line_outs)
18881                         pin = spec->multi_io[i - 1].pin;
18882                 else
18883                         pin = cfg->line_out_pins[i];
18884                 mix = alc_auto_dac_to_mix(codec, pin, nid);
18885                 if (!mix)
18886                         continue;
18887                 name = alc_get_line_out_pfx(spec, i, true, &index);
18888                 if (!name) {
18889                         /* Center/LFE */
18890                         err = alc662_add_vol_ctl(spec, "Center", nid, 1);
18891                         if (err < 0)
18892                                 return err;
18893                         err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
18894                         if (err < 0)
18895                                 return err;
18896                         err = alc662_add_sw_ctl(spec, "Center", mix, 1);
18897                         if (err < 0)
18898                                 return err;
18899                         err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
18900                         if (err < 0)
18901                                 return err;
18902                 } else {
18903                         err = __alc662_add_vol_ctl(spec, name, nid, index, 3);
18904                         if (err < 0)
18905                                 return err;
18906                         err = __alc662_add_sw_ctl(spec, name, mix, index, 3);
18907                         if (err < 0)
18908                                 return err;
18909                 }
18910         }
18911         return 0;
18912 }
18913
18914 /* add playback controls for speaker and HP outputs */
18915 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
18916                                         hda_nid_t dac, const char *pfx)
18917 {
18918         struct alc_spec *spec = codec->spec;
18919         hda_nid_t mix;
18920         int err;
18921
18922         if (!pin)
18923                 return 0;
18924         if (!dac) {
18925                 /* the corresponding DAC is already occupied */
18926                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
18927                         return 0; /* no way */
18928                 /* create a switch only */
18929                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
18930                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
18931         }
18932
18933         mix = alc_auto_dac_to_mix(codec, pin, dac);
18934         if (!mix)
18935                 return 0;
18936         err = alc662_add_vol_ctl(spec, pfx, dac, 3);
18937         if (err < 0)
18938                 return err;
18939         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
18940         if (err < 0)
18941                 return err;
18942         return 0;
18943 }
18944
18945 /* create playback/capture controls for input pins */
18946 #define alc662_auto_create_input_ctls \
18947         alc882_auto_create_input_ctls
18948
18949 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
18950                                               hda_nid_t nid, int pin_type,
18951                                               hda_nid_t dac)
18952 {
18953         int i, num;
18954         hda_nid_t srcs[HDA_MAX_CONNECTIONS];
18955
18956         alc_set_pin_output(codec, nid, pin_type);
18957         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
18958         for (i = 0; i < num; i++) {
18959                 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
18960                         continue;
18961                 /* need the manual connection? */
18962                 if (num > 1)
18963                         snd_hda_codec_write(codec, nid, 0,
18964                                             AC_VERB_SET_CONNECT_SEL, i);
18965                 /* unmute mixer widget inputs */
18966                 snd_hda_codec_write(codec, srcs[i], 0,
18967                                     AC_VERB_SET_AMP_GAIN_MUTE,
18968                                     AMP_IN_UNMUTE(0));
18969                 snd_hda_codec_write(codec, srcs[i], 0,
18970                                     AC_VERB_SET_AMP_GAIN_MUTE,
18971                                     AMP_IN_UNMUTE(1));
18972                 return;
18973         }
18974 }
18975
18976 static void alc662_auto_init_multi_out(struct hda_codec *codec)
18977 {
18978         struct alc_spec *spec = codec->spec;
18979         int pin_type = get_pin_type(spec->autocfg.line_out_type);
18980         int i;
18981
18982         for (i = 0; i <= HDA_SIDE; i++) {
18983                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
18984                 if (nid)
18985                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
18986                                         spec->multiout.dac_nids[i]);
18987         }
18988 }
18989
18990 static void alc662_auto_init_hp_out(struct hda_codec *codec)
18991 {
18992         struct alc_spec *spec = codec->spec;
18993         hda_nid_t pin;
18994
18995         pin = spec->autocfg.hp_pins[0];
18996         if (pin)
18997                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
18998                                                   spec->multiout.hp_nid);
18999         pin = spec->autocfg.speaker_pins[0];
19000         if (pin)
19001                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
19002                                         spec->multiout.extra_out_nid[0]);
19003 }
19004
19005 #define alc662_auto_init_analog_input   alc882_auto_init_analog_input
19006 #define alc662_auto_init_input_src      alc882_auto_init_input_src
19007
19008 /*
19009  * multi-io helper
19010  */
19011 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
19012                                    unsigned int location)
19013 {
19014         struct alc_spec *spec = codec->spec;
19015         struct auto_pin_cfg *cfg = &spec->autocfg;
19016         int type, i, num_pins = 0;
19017
19018         for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
19019                 for (i = 0; i < cfg->num_inputs; i++) {
19020                         hda_nid_t nid = cfg->inputs[i].pin;
19021                         hda_nid_t dac;
19022                         unsigned int defcfg, caps;
19023                         if (cfg->inputs[i].type != type)
19024                                 continue;
19025                         defcfg = snd_hda_codec_get_pincfg(codec, nid);
19026                         if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
19027                                 continue;
19028                         if (location && get_defcfg_location(defcfg) != location)
19029                                 continue;
19030                         caps = snd_hda_query_pin_caps(codec, nid);
19031                         if (!(caps & AC_PINCAP_OUT))
19032                                 continue;
19033                         dac = alc_auto_look_for_dac(codec, nid);
19034                         if (!dac)
19035                                 continue;
19036                         spec->multi_io[num_pins].pin = nid;
19037                         spec->multi_io[num_pins].dac = dac;
19038                         num_pins++;
19039                         spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
19040                 }
19041         }
19042         spec->multiout.num_dacs = 1;
19043         if (num_pins < 2)
19044                 return 0;
19045         return num_pins;
19046 }
19047
19048 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
19049                                  struct snd_ctl_elem_info *uinfo)
19050 {
19051         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19052         struct alc_spec *spec = codec->spec;
19053
19054         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
19055         uinfo->count = 1;
19056         uinfo->value.enumerated.items = spec->multi_ios + 1;
19057         if (uinfo->value.enumerated.item > spec->multi_ios)
19058                 uinfo->value.enumerated.item = spec->multi_ios;
19059         sprintf(uinfo->value.enumerated.name, "%dch",
19060                 (uinfo->value.enumerated.item + 1) * 2);
19061         return 0;
19062 }
19063
19064 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
19065                                 struct snd_ctl_elem_value *ucontrol)
19066 {
19067         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19068         struct alc_spec *spec = codec->spec;
19069         ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
19070         return 0;
19071 }
19072
19073 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
19074 {
19075         struct alc_spec *spec = codec->spec;
19076         hda_nid_t nid = spec->multi_io[idx].pin;
19077
19078         if (!spec->multi_io[idx].ctl_in)
19079                 spec->multi_io[idx].ctl_in =
19080                         snd_hda_codec_read(codec, nid, 0,
19081                                            AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
19082         if (output) {
19083                 snd_hda_codec_update_cache(codec, nid, 0,
19084                                            AC_VERB_SET_PIN_WIDGET_CONTROL,
19085                                            PIN_OUT);
19086                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
19087                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
19088                                                  HDA_AMP_MUTE, 0);
19089                 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
19090         } else {
19091                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
19092                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
19093                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
19094                 snd_hda_codec_update_cache(codec, nid, 0,
19095                                            AC_VERB_SET_PIN_WIDGET_CONTROL,
19096                                            spec->multi_io[idx].ctl_in);
19097         }
19098         return 0;
19099 }
19100
19101 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
19102                                 struct snd_ctl_elem_value *ucontrol)
19103 {
19104         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19105         struct alc_spec *spec = codec->spec;
19106         int i, ch;
19107
19108         ch = ucontrol->value.enumerated.item[0];
19109         if (ch < 0 || ch > spec->multi_ios)
19110                 return -EINVAL;
19111         if (ch == (spec->ext_channel_count - 1) / 2)
19112                 return 0;
19113         spec->ext_channel_count = (ch + 1) * 2;
19114         for (i = 0; i < spec->multi_ios; i++)
19115                 alc_set_multi_io(codec, i, i < ch);
19116         spec->multiout.max_channels = spec->ext_channel_count;
19117         return 1;
19118 }
19119
19120 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
19121         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
19122         .name = "Channel Mode",
19123         .info = alc_auto_ch_mode_info,
19124         .get = alc_auto_ch_mode_get,
19125         .put = alc_auto_ch_mode_put,
19126 };
19127
19128 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
19129                                            int (*fill_dac)(struct hda_codec *))
19130 {
19131         struct alc_spec *spec = codec->spec;
19132         struct auto_pin_cfg *cfg = &spec->autocfg;
19133         unsigned int location, defcfg;
19134         int num_pins;
19135
19136         if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) {
19137                 /* use HP as primary out */
19138                 cfg->speaker_outs = cfg->line_outs;
19139                 memcpy(cfg->speaker_pins, cfg->line_out_pins,
19140                        sizeof(cfg->speaker_pins));
19141                 cfg->line_outs = cfg->hp_outs;
19142                 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
19143                 cfg->hp_outs = 0;
19144                 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
19145                 cfg->line_out_type = AUTO_PIN_HP_OUT;
19146                 if (fill_dac)
19147                         fill_dac(codec);
19148         }
19149         if (cfg->line_outs != 1 ||
19150             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
19151                 return 0;
19152
19153         defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
19154         location = get_defcfg_location(defcfg);
19155
19156         num_pins = alc_auto_fill_multi_ios(codec, location);
19157         if (num_pins > 0) {
19158                 struct snd_kcontrol_new *knew;
19159
19160                 knew = alc_kcontrol_new(spec);
19161                 if (!knew)
19162                         return -ENOMEM;
19163                 *knew = alc_auto_channel_mode_enum;
19164                 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
19165                 if (!knew->name)
19166                         return -ENOMEM;
19167
19168                 spec->multi_ios = num_pins;
19169                 spec->ext_channel_count = 2;
19170                 spec->multiout.num_dacs = num_pins + 1;
19171         }
19172         return 0;
19173 }
19174
19175 static int alc662_parse_auto_config(struct hda_codec *codec)
19176 {
19177         struct alc_spec *spec = codec->spec;
19178         int err;
19179         static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
19180
19181         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
19182                                            alc662_ignore);
19183         if (err < 0)
19184                 return err;
19185         if (!spec->autocfg.line_outs)
19186                 return 0; /* can't find valid BIOS pin config */
19187
19188         err = alc662_auto_fill_dac_nids(codec);
19189         if (err < 0)
19190                 return err;
19191         err = alc_auto_add_multi_channel_mode(codec, alc662_auto_fill_dac_nids);
19192         if (err < 0)
19193                 return err;
19194         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
19195         if (err < 0)
19196                 return err;
19197         err = alc662_auto_create_extra_out(codec,
19198                                            spec->autocfg.speaker_pins[0],
19199                                            spec->multiout.extra_out_nid[0],
19200                                            "Speaker");
19201         if (err < 0)
19202                 return err;
19203         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
19204                                            spec->multiout.hp_nid,
19205                                            "Headphone");
19206         if (err < 0)
19207                 return err;
19208         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
19209         if (err < 0)
19210                 return err;
19211
19212         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
19213
19214         alc_auto_parse_digital(codec);
19215
19216         if (spec->kctls.list)
19217                 add_mixer(spec, spec->kctls.list);
19218
19219         spec->num_mux_defs = 1;
19220         spec->input_mux = &spec->private_imux[0];
19221
19222         err = alc_auto_add_mic_boost(codec);
19223         if (err < 0)
19224                 return err;
19225
19226         if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
19227             codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
19228             alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0x21);
19229         else
19230             alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
19231
19232         return 1;
19233 }
19234
19235 /* additional initialization for auto-configuration model */
19236 static void alc662_auto_init(struct hda_codec *codec)
19237 {
19238         struct alc_spec *spec = codec->spec;
19239         alc662_auto_init_multi_out(codec);
19240         alc662_auto_init_hp_out(codec);
19241         alc662_auto_init_analog_input(codec);
19242         alc662_auto_init_input_src(codec);
19243         alc_auto_init_digital(codec);
19244         if (spec->unsol_event)
19245                 alc_inithook(codec);
19246 }
19247
19248 static void alc272_fixup_mario(struct hda_codec *codec,
19249                                const struct alc_fixup *fix, int action)
19250 {
19251         if (action != ALC_FIXUP_ACT_PROBE)
19252                 return;
19253         if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
19254                                       (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
19255                                       (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
19256                                       (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
19257                                       (0 << AC_AMPCAP_MUTE_SHIFT)))
19258                 printk(KERN_WARNING
19259                        "hda_codec: failed to override amp caps for NID 0x2\n");
19260 }
19261
19262 enum {
19263         ALC662_FIXUP_ASPIRE,
19264         ALC662_FIXUP_IDEAPAD,
19265         ALC272_FIXUP_MARIO,
19266         ALC662_FIXUP_CZC_P10T,
19267         ALC662_FIXUP_SKU_IGNORE,
19268 };
19269
19270 static const struct alc_fixup alc662_fixups[] = {
19271         [ALC662_FIXUP_ASPIRE] = {
19272                 .type = ALC_FIXUP_PINS,
19273                 .v.pins = (const struct alc_pincfg[]) {
19274                         { 0x15, 0x99130112 }, /* subwoofer */
19275                         { }
19276                 }
19277         },
19278         [ALC662_FIXUP_IDEAPAD] = {
19279                 .type = ALC_FIXUP_PINS,
19280                 .v.pins = (const struct alc_pincfg[]) {
19281                         { 0x17, 0x99130112 }, /* subwoofer */
19282                         { }
19283                 }
19284         },
19285         [ALC272_FIXUP_MARIO] = {
19286                 .type = ALC_FIXUP_FUNC,
19287                 .v.func = alc272_fixup_mario,
19288         },
19289         [ALC662_FIXUP_CZC_P10T] = {
19290                 .type = ALC_FIXUP_VERBS,
19291                 .v.verbs = (const struct hda_verb[]) {
19292                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
19293                         {}
19294                 }
19295         },
19296         [ALC662_FIXUP_SKU_IGNORE] = {
19297                 .type = ALC_FIXUP_SKU,
19298                 .v.sku = ALC_FIXUP_SKU_IGNORE,
19299         },
19300 };
19301
19302 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
19303         SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
19304         SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
19305         SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
19306         SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
19307         SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
19308         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
19309         SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
19310         {}
19311 };
19312
19313 static const struct alc_model_fixup alc662_fixup_models[] = {
19314         {.id = ALC272_FIXUP_MARIO, .name = "mario"},
19315         {}
19316 };
19317
19318
19319 static int patch_alc662(struct hda_codec *codec)
19320 {
19321         struct alc_spec *spec;
19322         int err, board_config;
19323         int coef;
19324
19325         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
19326         if (!spec)
19327                 return -ENOMEM;
19328
19329         codec->spec = spec;
19330
19331         spec->mixer_nid = 0x0b;
19332
19333         alc_auto_parse_customize_define(codec);
19334
19335         alc_fix_pll_init(codec, 0x20, 0x04, 15);
19336
19337         coef = alc_read_coef_idx(codec, 0);
19338         if (coef == 0x8020 || coef == 0x8011)
19339                 alc_codec_rename(codec, "ALC661");
19340         else if (coef & (1 << 14) &&
19341                 codec->bus->pci->subsystem_vendor == 0x1025 &&
19342                 spec->cdefine.platform_type == 1)
19343                 alc_codec_rename(codec, "ALC272X");
19344         else if (coef == 0x4011)
19345                 alc_codec_rename(codec, "ALC656");
19346
19347         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
19348                                                   alc662_models,
19349                                                   alc662_cfg_tbl);
19350         if (board_config < 0) {
19351                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
19352                        codec->chip_name);
19353                 board_config = ALC662_AUTO;
19354         }
19355
19356         if (board_config == ALC662_AUTO) {
19357                 alc_pick_fixup(codec, alc662_fixup_models,
19358                                alc662_fixup_tbl, alc662_fixups);
19359                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
19360                 /* automatic parse from the BIOS config */
19361                 err = alc662_parse_auto_config(codec);
19362                 if (err < 0) {
19363                         alc_free(codec);
19364                         return err;
19365                 } else if (!err) {
19366                         printk(KERN_INFO
19367                                "hda_codec: Cannot set up configuration "
19368                                "from BIOS.  Using base mode...\n");
19369                         board_config = ALC662_3ST_2ch_DIG;
19370                 }
19371         }
19372
19373         if (has_cdefine_beep(codec)) {
19374                 err = snd_hda_attach_beep_device(codec, 0x1);
19375                 if (err < 0) {
19376                         alc_free(codec);
19377                         return err;
19378                 }
19379         }
19380
19381         if (board_config != ALC662_AUTO)
19382                 setup_preset(codec, &alc662_presets[board_config]);
19383
19384         spec->stream_analog_playback = &alc662_pcm_analog_playback;
19385         spec->stream_analog_capture = &alc662_pcm_analog_capture;
19386
19387         spec->stream_digital_playback = &alc662_pcm_digital_playback;
19388         spec->stream_digital_capture = &alc662_pcm_digital_capture;
19389
19390         if (!spec->adc_nids) {
19391                 spec->adc_nids = alc662_adc_nids;
19392                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
19393         }
19394         if (!spec->capsrc_nids)
19395                 spec->capsrc_nids = alc662_capsrc_nids;
19396
19397         if (!spec->cap_mixer)
19398                 set_capture_mixer(codec);
19399
19400         if (has_cdefine_beep(codec)) {
19401                 switch (codec->vendor_id) {
19402                 case 0x10ec0662:
19403                         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
19404                         break;
19405                 case 0x10ec0272:
19406                 case 0x10ec0663:
19407                 case 0x10ec0665:
19408                         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
19409                         break;
19410                 case 0x10ec0273:
19411                         set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
19412                         break;
19413                 }
19414         }
19415         spec->vmaster_nid = 0x02;
19416
19417         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
19418
19419         codec->patch_ops = alc_patch_ops;
19420         if (board_config == ALC662_AUTO)
19421                 spec->init_hook = alc662_auto_init;
19422         spec->shutup = alc_eapd_shutup;
19423
19424         alc_init_jacks(codec);
19425
19426 #ifdef CONFIG_SND_HDA_POWER_SAVE
19427         if (!spec->loopback.amplist)
19428                 spec->loopback.amplist = alc662_loopbacks;
19429 #endif
19430
19431         return 0;
19432 }
19433
19434 static int patch_alc888(struct hda_codec *codec)
19435 {
19436         if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
19437                 kfree(codec->chip_name);
19438                 if (codec->vendor_id == 0x10ec0887)
19439                         codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
19440                 else
19441                         codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
19442                 if (!codec->chip_name) {
19443                         alc_free(codec);
19444                         return -ENOMEM;
19445                 }
19446                 return patch_alc662(codec);
19447         }
19448         return patch_alc882(codec);
19449 }
19450
19451 static int patch_alc899(struct hda_codec *codec)
19452 {
19453         if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
19454                 kfree(codec->chip_name);
19455                 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
19456         }
19457         return patch_alc882(codec);
19458 }
19459
19460 /*
19461  * ALC680 support
19462  */
19463 #define ALC680_DIGIN_NID        ALC880_DIGIN_NID
19464 #define ALC680_DIGOUT_NID       ALC880_DIGOUT_NID
19465 #define alc680_modes            alc260_modes
19466
19467 static const hda_nid_t alc680_dac_nids[3] = {
19468         /* Lout1, Lout2, hp */
19469         0x02, 0x03, 0x04
19470 };
19471
19472 static const hda_nid_t alc680_adc_nids[3] = {
19473         /* ADC0-2 */
19474         /* DMIC, MIC, Line-in*/
19475         0x07, 0x08, 0x09
19476 };
19477
19478 /*
19479  * Analog capture ADC cgange
19480  */
19481 static void alc680_rec_autoswitch(struct hda_codec *codec)
19482 {
19483         struct alc_spec *spec = codec->spec;
19484         struct auto_pin_cfg *cfg = &spec->autocfg;
19485         int pin_found = 0;
19486         int type_found = AUTO_PIN_LAST;
19487         hda_nid_t nid;
19488         int i;
19489
19490         for (i = 0; i < cfg->num_inputs; i++) {
19491                 nid = cfg->inputs[i].pin;
19492                 if (!is_jack_detectable(codec, nid))
19493                         continue;
19494                 if (snd_hda_jack_detect(codec, nid)) {
19495                         if (cfg->inputs[i].type < type_found) {
19496                                 type_found = cfg->inputs[i].type;
19497                                 pin_found = nid;
19498                         }
19499                 }
19500         }
19501
19502         nid = 0x07;
19503         if (pin_found)
19504                 snd_hda_get_connections(codec, pin_found, &nid, 1);
19505
19506         if (nid != spec->cur_adc)
19507                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
19508         spec->cur_adc = nid;
19509         snd_hda_codec_setup_stream(codec, nid, spec->cur_adc_stream_tag, 0,
19510                                    spec->cur_adc_format);
19511 }
19512
19513 static int alc680_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
19514                                       struct hda_codec *codec,
19515                                       unsigned int stream_tag,
19516                                       unsigned int format,
19517                                       struct snd_pcm_substream *substream)
19518 {
19519         struct alc_spec *spec = codec->spec;
19520
19521         spec->cur_adc = 0x07;
19522         spec->cur_adc_stream_tag = stream_tag;
19523         spec->cur_adc_format = format;
19524
19525         alc680_rec_autoswitch(codec);
19526         return 0;
19527 }
19528
19529 static int alc680_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
19530                                       struct hda_codec *codec,
19531                                       struct snd_pcm_substream *substream)
19532 {
19533         snd_hda_codec_cleanup_stream(codec, 0x07);
19534         snd_hda_codec_cleanup_stream(codec, 0x08);
19535         snd_hda_codec_cleanup_stream(codec, 0x09);
19536         return 0;
19537 }
19538
19539 static const struct hda_pcm_stream alc680_pcm_analog_auto_capture = {
19540         .substreams = 1, /* can be overridden */
19541         .channels_min = 2,
19542         .channels_max = 2,
19543         /* NID is set in alc_build_pcms */
19544         .ops = {
19545                 .prepare = alc680_capture_pcm_prepare,
19546                 .cleanup = alc680_capture_pcm_cleanup
19547         },
19548 };
19549
19550 static const struct snd_kcontrol_new alc680_base_mixer[] = {
19551         /* output mixer control */
19552         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
19553         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
19554         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x4, 0x0, HDA_OUTPUT),
19555         HDA_CODEC_MUTE("Headphone Playback Switch", 0x16, 0x0, HDA_OUTPUT),
19556         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x12, 0, HDA_INPUT),
19557         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
19558         HDA_CODEC_VOLUME("Line In Boost Volume", 0x19, 0, HDA_INPUT),
19559         { }
19560 };
19561
19562 static const struct hda_bind_ctls alc680_bind_cap_vol = {
19563         .ops = &snd_hda_bind_vol,
19564         .values = {
19565                 HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
19566                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
19567                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
19568                 0
19569         },
19570 };
19571
19572 static const struct hda_bind_ctls alc680_bind_cap_switch = {
19573         .ops = &snd_hda_bind_sw,
19574         .values = {
19575                 HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
19576                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
19577                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
19578                 0
19579         },
19580 };
19581
19582 static const struct snd_kcontrol_new alc680_master_capture_mixer[] = {
19583         HDA_BIND_VOL("Capture Volume", &alc680_bind_cap_vol),
19584         HDA_BIND_SW("Capture Switch", &alc680_bind_cap_switch),
19585         { } /* end */
19586 };
19587
19588 /*
19589  * generic initialization of ADC, input mixers and output mixers
19590  */
19591 static const struct hda_verb alc680_init_verbs[] = {
19592         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
19593         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
19594         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
19595
19596         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
19597         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
19598         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
19599         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
19600         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
19601         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
19602
19603         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19604         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19605         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19606         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19607         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19608
19609         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT   | AC_USRSP_EN},
19610         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT  | AC_USRSP_EN},
19611         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT  | AC_USRSP_EN},
19612
19613         { }
19614 };
19615
19616 /* toggle speaker-output according to the hp-jack state */
19617 static void alc680_base_setup(struct hda_codec *codec)
19618 {
19619         struct alc_spec *spec = codec->spec;
19620
19621         spec->autocfg.hp_pins[0] = 0x16;
19622         spec->autocfg.speaker_pins[0] = 0x14;
19623         spec->autocfg.speaker_pins[1] = 0x15;
19624         spec->autocfg.num_inputs = 2;
19625         spec->autocfg.inputs[0].pin = 0x18;
19626         spec->autocfg.inputs[0].type = AUTO_PIN_MIC;
19627         spec->autocfg.inputs[1].pin = 0x19;
19628         spec->autocfg.inputs[1].type = AUTO_PIN_LINE_IN;
19629         spec->automute = 1;
19630         spec->automute_mode = ALC_AUTOMUTE_AMP;
19631 }
19632
19633 static void alc680_unsol_event(struct hda_codec *codec,
19634                                            unsigned int res)
19635 {
19636         if ((res >> 26) == ALC880_HP_EVENT)
19637                 alc_hp_automute(codec);
19638         if ((res >> 26) == ALC880_MIC_EVENT)
19639                 alc680_rec_autoswitch(codec);
19640 }
19641
19642 static void alc680_inithook(struct hda_codec *codec)
19643 {
19644         alc_hp_automute(codec);
19645         alc680_rec_autoswitch(codec);
19646 }
19647
19648 /* create input playback/capture controls for the given pin */
19649 static int alc680_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
19650                                     const char *ctlname, int idx)
19651 {
19652         hda_nid_t dac;
19653         int err;
19654
19655         switch (nid) {
19656         case 0x14:
19657                 dac = 0x02;
19658                 break;
19659         case 0x15:
19660                 dac = 0x03;
19661                 break;
19662         case 0x16:
19663                 dac = 0x04;
19664                 break;
19665         default:
19666                 return 0;
19667         }
19668         if (spec->multiout.dac_nids[0] != dac &&
19669             spec->multiout.dac_nids[1] != dac) {
19670                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
19671                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
19672                                                       HDA_OUTPUT));
19673                 if (err < 0)
19674                         return err;
19675
19676                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
19677                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
19678
19679                 if (err < 0)
19680                         return err;
19681                 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
19682         }
19683
19684         return 0;
19685 }
19686
19687 /* add playback controls from the parsed DAC table */
19688 static int alc680_auto_create_multi_out_ctls(struct alc_spec *spec,
19689                                              const struct auto_pin_cfg *cfg)
19690 {
19691         hda_nid_t nid;
19692         int err;
19693
19694         spec->multiout.dac_nids = spec->private_dac_nids;
19695
19696         nid = cfg->line_out_pins[0];
19697         if (nid) {
19698                 const char *name;
19699                 int index;
19700                 name = alc_get_line_out_pfx(spec, 0, true, &index);
19701                 err = alc680_new_analog_output(spec, nid, name, 0);
19702                 if (err < 0)
19703                         return err;
19704         }
19705
19706         nid = cfg->speaker_pins[0];
19707         if (nid) {
19708                 err = alc680_new_analog_output(spec, nid, "Speaker", 0);
19709                 if (err < 0)
19710                         return err;
19711         }
19712         nid = cfg->hp_pins[0];
19713         if (nid) {
19714                 err = alc680_new_analog_output(spec, nid, "Headphone", 0);
19715                 if (err < 0)
19716                         return err;
19717         }
19718
19719         return 0;
19720 }
19721
19722 static void alc680_auto_set_output_and_unmute(struct hda_codec *codec,
19723                                               hda_nid_t nid, int pin_type)
19724 {
19725         alc_set_pin_output(codec, nid, pin_type);
19726 }
19727
19728 static void alc680_auto_init_multi_out(struct hda_codec *codec)
19729 {
19730         struct alc_spec *spec = codec->spec;
19731         hda_nid_t nid = spec->autocfg.line_out_pins[0];
19732         if (nid) {
19733                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
19734                 alc680_auto_set_output_and_unmute(codec, nid, pin_type);
19735         }
19736 }
19737
19738 static void alc680_auto_init_hp_out(struct hda_codec *codec)
19739 {
19740         struct alc_spec *spec = codec->spec;
19741         hda_nid_t pin;
19742
19743         pin = spec->autocfg.hp_pins[0];
19744         if (pin)
19745                 alc680_auto_set_output_and_unmute(codec, pin, PIN_HP);
19746         pin = spec->autocfg.speaker_pins[0];
19747         if (pin)
19748                 alc680_auto_set_output_and_unmute(codec, pin, PIN_OUT);
19749 }
19750
19751 /* pcm configuration: identical with ALC880 */
19752 #define alc680_pcm_analog_playback      alc880_pcm_analog_playback
19753 #define alc680_pcm_analog_capture       alc880_pcm_analog_capture
19754 #define alc680_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
19755 #define alc680_pcm_digital_playback     alc880_pcm_digital_playback
19756 #define alc680_pcm_digital_capture      alc880_pcm_digital_capture
19757
19758 /*
19759  * BIOS auto configuration
19760  */
19761 static int alc680_parse_auto_config(struct hda_codec *codec)
19762 {
19763         struct alc_spec *spec = codec->spec;
19764         int err;
19765         static const hda_nid_t alc680_ignore[] = { 0 };
19766
19767         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
19768                                            alc680_ignore);
19769         if (err < 0)
19770                 return err;
19771
19772         if (!spec->autocfg.line_outs) {
19773                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
19774                         spec->multiout.max_channels = 2;
19775                         spec->no_analog = 1;
19776                         goto dig_only;
19777                 }
19778                 return 0; /* can't find valid BIOS pin config */
19779         }
19780         err = alc680_auto_create_multi_out_ctls(spec, &spec->autocfg);
19781         if (err < 0)
19782                 return err;
19783
19784         spec->multiout.max_channels = 2;
19785
19786  dig_only:
19787         /* digital only support output */
19788         alc_auto_parse_digital(codec);
19789         if (spec->kctls.list)
19790                 add_mixer(spec, spec->kctls.list);
19791
19792         err = alc_auto_add_mic_boost(codec);
19793         if (err < 0)
19794                 return err;
19795
19796         return 1;
19797 }
19798
19799 #define alc680_auto_init_analog_input   alc882_auto_init_analog_input
19800
19801 /* init callback for auto-configuration model -- overriding the default init */
19802 static void alc680_auto_init(struct hda_codec *codec)
19803 {
19804         struct alc_spec *spec = codec->spec;
19805         alc680_auto_init_multi_out(codec);
19806         alc680_auto_init_hp_out(codec);
19807         alc680_auto_init_analog_input(codec);
19808         alc_auto_init_digital(codec);
19809         if (spec->unsol_event)
19810                 alc_inithook(codec);
19811 }
19812
19813 /*
19814  * configuration and preset
19815  */
19816 static const char * const alc680_models[ALC680_MODEL_LAST] = {
19817         [ALC680_BASE]           = "base",
19818         [ALC680_AUTO]           = "auto",
19819 };
19820
19821 static const struct snd_pci_quirk alc680_cfg_tbl[] = {
19822         SND_PCI_QUIRK(0x1043, 0x12f3, "ASUS NX90", ALC680_BASE),
19823         {}
19824 };
19825
19826 static const struct alc_config_preset alc680_presets[] = {
19827         [ALC680_BASE] = {
19828                 .mixers = { alc680_base_mixer },
19829                 .cap_mixer =  alc680_master_capture_mixer,
19830                 .init_verbs = { alc680_init_verbs },
19831                 .num_dacs = ARRAY_SIZE(alc680_dac_nids),
19832                 .dac_nids = alc680_dac_nids,
19833                 .dig_out_nid = ALC680_DIGOUT_NID,
19834                 .num_channel_mode = ARRAY_SIZE(alc680_modes),
19835                 .channel_mode = alc680_modes,
19836                 .unsol_event = alc680_unsol_event,
19837                 .setup = alc680_base_setup,
19838                 .init_hook = alc680_inithook,
19839
19840         },
19841 };
19842
19843 static int patch_alc680(struct hda_codec *codec)
19844 {
19845         struct alc_spec *spec;
19846         int board_config;
19847         int err;
19848
19849         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
19850         if (spec == NULL)
19851                 return -ENOMEM;
19852
19853         codec->spec = spec;
19854
19855         /* ALC680 has no aa-loopback mixer */
19856
19857         board_config = snd_hda_check_board_config(codec, ALC680_MODEL_LAST,
19858                                                   alc680_models,
19859                                                   alc680_cfg_tbl);
19860
19861         if (board_config < 0 || board_config >= ALC680_MODEL_LAST) {
19862                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
19863                        codec->chip_name);
19864                 board_config = ALC680_AUTO;
19865         }
19866
19867         if (board_config == ALC680_AUTO) {
19868                 /* automatic parse from the BIOS config */
19869                 err = alc680_parse_auto_config(codec);
19870                 if (err < 0) {
19871                         alc_free(codec);
19872                         return err;
19873                 } else if (!err) {
19874                         printk(KERN_INFO
19875                                "hda_codec: Cannot set up configuration "
19876                                "from BIOS.  Using base mode...\n");
19877                         board_config = ALC680_BASE;
19878                 }
19879         }
19880
19881         if (board_config != ALC680_AUTO)
19882                 setup_preset(codec, &alc680_presets[board_config]);
19883
19884         spec->stream_analog_playback = &alc680_pcm_analog_playback;
19885         spec->stream_analog_capture = &alc680_pcm_analog_auto_capture;
19886         spec->stream_digital_playback = &alc680_pcm_digital_playback;
19887         spec->stream_digital_capture = &alc680_pcm_digital_capture;
19888
19889         if (!spec->adc_nids) {
19890                 spec->adc_nids = alc680_adc_nids;
19891                 spec->num_adc_nids = ARRAY_SIZE(alc680_adc_nids);
19892         }
19893
19894         if (!spec->cap_mixer)
19895                 set_capture_mixer(codec);
19896
19897         spec->vmaster_nid = 0x02;
19898
19899         codec->patch_ops = alc_patch_ops;
19900         if (board_config == ALC680_AUTO)
19901                 spec->init_hook = alc680_auto_init;
19902
19903         return 0;
19904 }
19905
19906 /*
19907  * patch entries
19908  */
19909 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
19910         { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
19911         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
19912         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
19913         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
19914         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
19915         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
19916         { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
19917         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
19918         { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
19919         { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
19920         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
19921           .patch = patch_alc861 },
19922         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
19923         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
19924         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
19925         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
19926           .patch = patch_alc882 },
19927         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
19928           .patch = patch_alc662 },
19929         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
19930         { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
19931         { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
19932         { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
19933         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
19934         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
19935         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
19936         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
19937           .patch = patch_alc882 },
19938         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
19939           .patch = patch_alc882 },
19940         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
19941         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
19942         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
19943           .patch = patch_alc882 },
19944         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
19945         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
19946         { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
19947         { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
19948         {} /* terminator */
19949 };
19950
19951 MODULE_ALIAS("snd-hda-codec-id:10ec*");
19952
19953 MODULE_LICENSE("GPL");
19954 MODULE_DESCRIPTION("Realtek HD-audio codec");
19955
19956 static struct hda_codec_preset_list realtek_list = {
19957         .preset = snd_hda_preset_realtek,
19958         .owner = THIS_MODULE,
19959 };
19960
19961 static int __init patch_realtek_init(void)
19962 {
19963         return snd_hda_add_codec_preset(&realtek_list);
19964 }
19965
19966 static void __exit patch_realtek_exit(void)
19967 {
19968         snd_hda_delete_codec_preset(&realtek_list);
19969 }
19970
19971 module_init(patch_realtek_init)
19972 module_exit(patch_realtek_exit)