236200963b02c1fbbd1d77049431c3fa770effec
[firefly-linux-kernel-4.4.55.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 #define get_connection_index(codec, mux, nid) \
1199         snd_hda_get_conn_index(codec, mux, nid, 0)
1200
1201 /* switch the current ADC according to the jack state */
1202 static void alc_dual_mic_adc_auto_switch(struct hda_codec *codec)
1203 {
1204         struct alc_spec *spec = codec->spec;
1205         unsigned int present;
1206         hda_nid_t new_adc;
1207
1208         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1209         if (present)
1210                 spec->cur_adc_idx = 1;
1211         else
1212                 spec->cur_adc_idx = 0;
1213         new_adc = spec->adc_nids[spec->cur_adc_idx];
1214         if (spec->cur_adc && spec->cur_adc != new_adc) {
1215                 /* stream is running, let's swap the current ADC */
1216                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1217                 spec->cur_adc = new_adc;
1218                 snd_hda_codec_setup_stream(codec, new_adc,
1219                                            spec->cur_adc_stream_tag, 0,
1220                                            spec->cur_adc_format);
1221         }
1222 }
1223
1224 static void alc_mic_automute(struct hda_codec *codec)
1225 {
1226         struct alc_spec *spec = codec->spec;
1227         struct alc_mic_route *dead1, *dead2, *alive;
1228         unsigned int present, type;
1229         hda_nid_t cap_nid;
1230
1231         if (!spec->auto_mic)
1232                 return;
1233         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1234                 return;
1235         if (snd_BUG_ON(!spec->adc_nids))
1236                 return;
1237
1238         if (spec->dual_adc_switch) {
1239                 alc_dual_mic_adc_auto_switch(codec);
1240                 return;
1241         }
1242
1243         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1244
1245         alive = &spec->int_mic;
1246         dead1 = &spec->ext_mic;
1247         dead2 = &spec->dock_mic;
1248
1249         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1250         if (present) {
1251                 alive = &spec->ext_mic;
1252                 dead1 = &spec->int_mic;
1253                 dead2 = &spec->dock_mic;
1254         }
1255         if (!present && spec->dock_mic.pin > 0) {
1256                 present = snd_hda_jack_detect(codec, spec->dock_mic.pin);
1257                 if (present) {
1258                         alive = &spec->dock_mic;
1259                         dead1 = &spec->int_mic;
1260                         dead2 = &spec->ext_mic;
1261                 }
1262                 snd_hda_input_jack_report(codec, spec->dock_mic.pin);
1263         }
1264
1265         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1266         if (type == AC_WID_AUD_MIX) {
1267                 /* Matrix-mixer style (e.g. ALC882) */
1268                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1269                                          alive->mux_idx,
1270                                          HDA_AMP_MUTE, 0);
1271                 if (dead1->pin > 0)
1272                         snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1273                                                  dead1->mux_idx,
1274                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
1275                 if (dead2->pin > 0)
1276                         snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1277                                                  dead2->mux_idx,
1278                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
1279         } else {
1280                 /* MUX style (e.g. ALC880) */
1281                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1282                                           AC_VERB_SET_CONNECT_SEL,
1283                                           alive->mux_idx);
1284         }
1285         snd_hda_input_jack_report(codec, spec->ext_mic.pin);
1286
1287         /* FIXME: analog mixer */
1288 }
1289
1290 /* unsolicited event for HP jack sensing */
1291 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1292 {
1293         if (codec->vendor_id == 0x10ec0880)
1294                 res >>= 28;
1295         else
1296                 res >>= 26;
1297         switch (res) {
1298         case ALC880_HP_EVENT:
1299                 alc_hp_automute(codec);
1300                 break;
1301         case ALC880_FRONT_EVENT:
1302                 alc_line_automute(codec);
1303                 break;
1304         case ALC880_MIC_EVENT:
1305                 alc_mic_automute(codec);
1306                 break;
1307         }
1308 }
1309
1310 static void alc_inithook(struct hda_codec *codec)
1311 {
1312         alc_hp_automute(codec);
1313         alc_line_automute(codec);
1314         alc_mic_automute(codec);
1315 }
1316
1317 /* additional initialization for ALC888 variants */
1318 static void alc888_coef_init(struct hda_codec *codec)
1319 {
1320         unsigned int tmp;
1321
1322         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1323         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1324         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1325         if ((tmp & 0xf0) == 0x20)
1326                 /* alc888S-VC */
1327                 snd_hda_codec_read(codec, 0x20, 0,
1328                                    AC_VERB_SET_PROC_COEF, 0x830);
1329          else
1330                  /* alc888-VB */
1331                  snd_hda_codec_read(codec, 0x20, 0,
1332                                     AC_VERB_SET_PROC_COEF, 0x3030);
1333 }
1334
1335 static void alc889_coef_init(struct hda_codec *codec)
1336 {
1337         unsigned int tmp;
1338
1339         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1340         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1341         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1342         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1343 }
1344
1345 /* turn on/off EAPD control (only if available) */
1346 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
1347 {
1348         if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
1349                 return;
1350         if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
1351                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1352                                     on ? 2 : 0);
1353 }
1354
1355 /* turn on/off EAPD controls of the codec */
1356 static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
1357 {
1358         /* We currently only handle front, HP */
1359         static hda_nid_t pins[] = {
1360                 0x0f, 0x10, 0x14, 0x15, 0
1361         };
1362         hda_nid_t *p;
1363         for (p = pins; *p; p++)
1364                 set_eapd(codec, *p, on);
1365 }
1366
1367 /* generic shutup callback;
1368  * just turning off EPAD and a little pause for avoiding pop-noise
1369  */
1370 static void alc_eapd_shutup(struct hda_codec *codec)
1371 {
1372         alc_auto_setup_eapd(codec, false);
1373         msleep(200);
1374 }
1375
1376 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1377 {
1378         unsigned int tmp;
1379
1380         alc_auto_setup_eapd(codec, true);
1381         switch (type) {
1382         case ALC_INIT_GPIO1:
1383                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1384                 break;
1385         case ALC_INIT_GPIO2:
1386                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1387                 break;
1388         case ALC_INIT_GPIO3:
1389                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1390                 break;
1391         case ALC_INIT_DEFAULT:
1392                 switch (codec->vendor_id) {
1393                 case 0x10ec0260:
1394                         snd_hda_codec_write(codec, 0x1a, 0,
1395                                             AC_VERB_SET_COEF_INDEX, 7);
1396                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1397                                                  AC_VERB_GET_PROC_COEF, 0);
1398                         snd_hda_codec_write(codec, 0x1a, 0,
1399                                             AC_VERB_SET_COEF_INDEX, 7);
1400                         snd_hda_codec_write(codec, 0x1a, 0,
1401                                             AC_VERB_SET_PROC_COEF,
1402                                             tmp | 0x2010);
1403                         break;
1404                 case 0x10ec0262:
1405                 case 0x10ec0880:
1406                 case 0x10ec0882:
1407                 case 0x10ec0883:
1408                 case 0x10ec0885:
1409                 case 0x10ec0887:
1410                 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
1411                         alc889_coef_init(codec);
1412                         break;
1413                 case 0x10ec0888:
1414                         alc888_coef_init(codec);
1415                         break;
1416 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
1417                 case 0x10ec0267:
1418                 case 0x10ec0268:
1419                         snd_hda_codec_write(codec, 0x20, 0,
1420                                             AC_VERB_SET_COEF_INDEX, 7);
1421                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1422                                                  AC_VERB_GET_PROC_COEF, 0);
1423                         snd_hda_codec_write(codec, 0x20, 0,
1424                                             AC_VERB_SET_COEF_INDEX, 7);
1425                         snd_hda_codec_write(codec, 0x20, 0,
1426                                             AC_VERB_SET_PROC_COEF,
1427                                             tmp | 0x3000);
1428                         break;
1429 #endif /* XXX */
1430                 }
1431                 break;
1432         }
1433 }
1434
1435 static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
1436                                   struct snd_ctl_elem_info *uinfo)
1437 {
1438         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1439         struct alc_spec *spec = codec->spec;
1440         static const char * const texts2[] = {
1441                 "Disabled", "Enabled"
1442         };
1443         static const char * const texts3[] = {
1444                 "Disabled", "Speaker Only", "Line-Out+Speaker"
1445         };
1446         const char * const *texts;
1447
1448         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1449         uinfo->count = 1;
1450         if (spec->automute_hp_lo) {
1451                 uinfo->value.enumerated.items = 3;
1452                 texts = texts3;
1453         } else {
1454                 uinfo->value.enumerated.items = 2;
1455                 texts = texts2;
1456         }
1457         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1458                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1459         strcpy(uinfo->value.enumerated.name,
1460                texts[uinfo->value.enumerated.item]);
1461         return 0;
1462 }
1463
1464 static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
1465                                  struct snd_ctl_elem_value *ucontrol)
1466 {
1467         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1468         struct alc_spec *spec = codec->spec;
1469         unsigned int val;
1470         if (!spec->automute)
1471                 val = 0;
1472         else if (!spec->automute_lines)
1473                 val = 1;
1474         else
1475                 val = 2;
1476         ucontrol->value.enumerated.item[0] = val;
1477         return 0;
1478 }
1479
1480 static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
1481                                  struct snd_ctl_elem_value *ucontrol)
1482 {
1483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1484         struct alc_spec *spec = codec->spec;
1485
1486         switch (ucontrol->value.enumerated.item[0]) {
1487         case 0:
1488                 if (!spec->automute)
1489                         return 0;
1490                 spec->automute = 0;
1491                 break;
1492         case 1:
1493                 if (spec->automute && !spec->automute_lines)
1494                         return 0;
1495                 spec->automute = 1;
1496                 spec->automute_lines = 0;
1497                 break;
1498         case 2:
1499                 if (!spec->automute_hp_lo)
1500                         return -EINVAL;
1501                 if (spec->automute && spec->automute_lines)
1502                         return 0;
1503                 spec->automute = 1;
1504                 spec->automute_lines = 1;
1505                 break;
1506         default:
1507                 return -EINVAL;
1508         }
1509         update_speakers(codec);
1510         return 1;
1511 }
1512
1513 static const struct snd_kcontrol_new alc_automute_mode_enum = {
1514         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1515         .name = "Auto-Mute Mode",
1516         .info = alc_automute_mode_info,
1517         .get = alc_automute_mode_get,
1518         .put = alc_automute_mode_put,
1519 };
1520
1521 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec);
1522
1523 static int alc_add_automute_mode_enum(struct hda_codec *codec)
1524 {
1525         struct alc_spec *spec = codec->spec;
1526         struct snd_kcontrol_new *knew;
1527
1528         knew = alc_kcontrol_new(spec);
1529         if (!knew)
1530                 return -ENOMEM;
1531         *knew = alc_automute_mode_enum;
1532         knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
1533         if (!knew->name)
1534                 return -ENOMEM;
1535         return 0;
1536 }
1537
1538 static void alc_init_auto_hp(struct hda_codec *codec)
1539 {
1540         struct alc_spec *spec = codec->spec;
1541         struct auto_pin_cfg *cfg = &spec->autocfg;
1542         int present = 0;
1543         int i;
1544
1545         if (cfg->hp_pins[0])
1546                 present++;
1547         if (cfg->line_out_pins[0])
1548                 present++;
1549         if (cfg->speaker_pins[0])
1550                 present++;
1551         if (present < 2) /* need two different output types */
1552                 return;
1553         if (present == 3)
1554                 spec->automute_hp_lo = 1; /* both HP and LO automute */
1555
1556         if (!cfg->speaker_pins[0]) {
1557                 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1558                        sizeof(cfg->speaker_pins));
1559                 cfg->speaker_outs = cfg->line_outs;
1560         }
1561
1562         if (!cfg->hp_pins[0]) {
1563                 memcpy(cfg->hp_pins, cfg->line_out_pins,
1564                        sizeof(cfg->hp_pins));
1565                 cfg->hp_outs = cfg->line_outs;
1566         }
1567
1568         for (i = 0; i < cfg->hp_outs; i++) {
1569                 hda_nid_t nid = cfg->hp_pins[i];
1570                 if (!is_jack_detectable(codec, nid))
1571                         continue;
1572                 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1573                             nid);
1574                 snd_hda_codec_write_cache(codec, nid, 0,
1575                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1576                                   AC_USRSP_EN | ALC880_HP_EVENT);
1577                 spec->automute = 1;
1578                 spec->automute_mode = ALC_AUTOMUTE_PIN;
1579         }
1580         if (spec->automute && cfg->line_out_pins[0] &&
1581             cfg->line_out_pins[0] != cfg->hp_pins[0] &&
1582             cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
1583                 for (i = 0; i < cfg->line_outs; i++) {
1584                         hda_nid_t nid = cfg->line_out_pins[i];
1585                         if (!is_jack_detectable(codec, nid))
1586                                 continue;
1587                         snd_printdd("realtek: Enable Line-Out auto-muting "
1588                                     "on NID 0x%x\n", nid);
1589                         snd_hda_codec_write_cache(codec, nid, 0,
1590                                         AC_VERB_SET_UNSOLICITED_ENABLE,
1591                                         AC_USRSP_EN | ALC880_FRONT_EVENT);
1592                         spec->detect_line = 1;
1593                 }
1594                 spec->automute_lines = spec->detect_line;
1595         }
1596
1597         if (spec->automute) {
1598                 /* create a control for automute mode */
1599                 alc_add_automute_mode_enum(codec);
1600                 spec->unsol_event = alc_sku_unsol_event;
1601         }
1602 }
1603
1604 static void alc_init_auto_mic(struct hda_codec *codec)
1605 {
1606         struct alc_spec *spec = codec->spec;
1607         struct auto_pin_cfg *cfg = &spec->autocfg;
1608         hda_nid_t fixed, ext, dock;
1609         int i;
1610
1611         fixed = ext = dock = 0;
1612         for (i = 0; i < cfg->num_inputs; i++) {
1613                 hda_nid_t nid = cfg->inputs[i].pin;
1614                 unsigned int defcfg;
1615                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1616                 switch (snd_hda_get_input_pin_attr(defcfg)) {
1617                 case INPUT_PIN_ATTR_INT:
1618                         if (fixed)
1619                                 return; /* already occupied */
1620                         if (cfg->inputs[i].type != AUTO_PIN_MIC)
1621                                 return; /* invalid type */
1622                         fixed = nid;
1623                         break;
1624                 case INPUT_PIN_ATTR_UNUSED:
1625                         return; /* invalid entry */
1626                 case INPUT_PIN_ATTR_DOCK:
1627                         if (dock)
1628                                 return; /* already occupied */
1629                         if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1630                                 return; /* invalid type */
1631                         dock = nid;
1632                         break;
1633                 default:
1634                         if (ext)
1635                                 return; /* already occupied */
1636                         if (cfg->inputs[i].type != AUTO_PIN_MIC)
1637                                 return; /* invalid type */
1638                         ext = nid;
1639                         break;
1640                 }
1641         }
1642         if (!ext && dock) {
1643                 ext = dock;
1644                 dock = 0;
1645         }
1646         if (!ext || !fixed)
1647                 return;
1648         if (!is_jack_detectable(codec, ext))
1649                 return; /* no unsol support */
1650         if (dock && !is_jack_detectable(codec, dock))
1651                 return; /* no unsol support */
1652         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1653                     ext, fixed, dock);
1654         spec->ext_mic.pin = ext;
1655         spec->dock_mic.pin = dock;
1656         spec->int_mic.pin = fixed;
1657         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1658         spec->dock_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1659         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1660         spec->auto_mic = 1;
1661         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1662                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1663                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1664         spec->unsol_event = alc_sku_unsol_event;
1665 }
1666
1667 /* Could be any non-zero and even value. When used as fixup, tells
1668  * the driver to ignore any present sku defines.
1669  */
1670 #define ALC_FIXUP_SKU_IGNORE (2)
1671
1672 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1673 {
1674         unsigned int ass, tmp, i;
1675         unsigned nid = 0;
1676         struct alc_spec *spec = codec->spec;
1677
1678         spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1679
1680         if (spec->cdefine.fixup) {
1681                 ass = spec->cdefine.sku_cfg;
1682                 if (ass == ALC_FIXUP_SKU_IGNORE)
1683                         return -1;
1684                 goto do_sku;
1685         }
1686
1687         ass = codec->subsystem_id & 0xffff;
1688         if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1689                 goto do_sku;
1690
1691         nid = 0x1d;
1692         if (codec->vendor_id == 0x10ec0260)
1693                 nid = 0x17;
1694         ass = snd_hda_codec_get_pincfg(codec, nid);
1695
1696         if (!(ass & 1)) {
1697                 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1698                        codec->chip_name, ass);
1699                 return -1;
1700         }
1701
1702         /* check sum */
1703         tmp = 0;
1704         for (i = 1; i < 16; i++) {
1705                 if ((ass >> i) & 1)
1706                         tmp++;
1707         }
1708         if (((ass >> 16) & 0xf) != tmp)
1709                 return -1;
1710
1711         spec->cdefine.port_connectivity = ass >> 30;
1712         spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1713         spec->cdefine.check_sum = (ass >> 16) & 0xf;
1714         spec->cdefine.customization = ass >> 8;
1715 do_sku:
1716         spec->cdefine.sku_cfg = ass;
1717         spec->cdefine.external_amp = (ass & 0x38) >> 3;
1718         spec->cdefine.platform_type = (ass & 0x4) >> 2;
1719         spec->cdefine.swap = (ass & 0x2) >> 1;
1720         spec->cdefine.override = ass & 0x1;
1721
1722         snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1723                    nid, spec->cdefine.sku_cfg);
1724         snd_printd("SKU: port_connectivity=0x%x\n",
1725                    spec->cdefine.port_connectivity);
1726         snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1727         snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1728         snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1729         snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1730         snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1731         snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1732         snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1733
1734         return 0;
1735 }
1736
1737 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1738 {
1739         int i;
1740         for (i = 0; i < nums; i++)
1741                 if (list[i] == nid)
1742                         return true;
1743         return false;
1744 }
1745
1746 /* check subsystem ID and set up device-specific initialization;
1747  * return 1 if initialized, 0 if invalid SSID
1748  */
1749 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1750  *      31 ~ 16 :       Manufacture ID
1751  *      15 ~ 8  :       SKU ID
1752  *      7  ~ 0  :       Assembly ID
1753  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1754  */
1755 static int alc_subsystem_id(struct hda_codec *codec,
1756                             hda_nid_t porta, hda_nid_t porte,
1757                             hda_nid_t portd, hda_nid_t porti)
1758 {
1759         unsigned int ass, tmp, i;
1760         unsigned nid;
1761         struct alc_spec *spec = codec->spec;
1762
1763         if (spec->cdefine.fixup) {
1764                 ass = spec->cdefine.sku_cfg;
1765                 if (ass == ALC_FIXUP_SKU_IGNORE)
1766                         return 0;
1767                 goto do_sku;
1768         }
1769
1770         ass = codec->subsystem_id & 0xffff;
1771         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1772                 goto do_sku;
1773
1774         /* invalid SSID, check the special NID pin defcfg instead */
1775         /*
1776          * 31~30        : port connectivity
1777          * 29~21        : reserve
1778          * 20           : PCBEEP input
1779          * 19~16        : Check sum (15:1)
1780          * 15~1         : Custom
1781          * 0            : override
1782         */
1783         nid = 0x1d;
1784         if (codec->vendor_id == 0x10ec0260)
1785                 nid = 0x17;
1786         ass = snd_hda_codec_get_pincfg(codec, nid);
1787         snd_printd("realtek: No valid SSID, "
1788                    "checking pincfg 0x%08x for NID 0x%x\n",
1789                    ass, nid);
1790         if (!(ass & 1))
1791                 return 0;
1792         if ((ass >> 30) != 1)   /* no physical connection */
1793                 return 0;
1794
1795         /* check sum */
1796         tmp = 0;
1797         for (i = 1; i < 16; i++) {
1798                 if ((ass >> i) & 1)
1799                         tmp++;
1800         }
1801         if (((ass >> 16) & 0xf) != tmp)
1802                 return 0;
1803 do_sku:
1804         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1805                    ass & 0xffff, codec->vendor_id);
1806         /*
1807          * 0 : override
1808          * 1 :  Swap Jack
1809          * 2 : 0 --> Desktop, 1 --> Laptop
1810          * 3~5 : External Amplifier control
1811          * 7~6 : Reserved
1812         */
1813         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1814         switch (tmp) {
1815         case 1:
1816                 spec->init_amp = ALC_INIT_GPIO1;
1817                 break;
1818         case 3:
1819                 spec->init_amp = ALC_INIT_GPIO2;
1820                 break;
1821         case 7:
1822                 spec->init_amp = ALC_INIT_GPIO3;
1823                 break;
1824         case 5:
1825         default:
1826                 spec->init_amp = ALC_INIT_DEFAULT;
1827                 break;
1828         }
1829
1830         /* is laptop or Desktop and enable the function "Mute internal speaker
1831          * when the external headphone out jack is plugged"
1832          */
1833         if (!(ass & 0x8000))
1834                 return 1;
1835         /*
1836          * 10~8 : Jack location
1837          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1838          * 14~13: Resvered
1839          * 15   : 1 --> enable the function "Mute internal speaker
1840          *              when the external headphone out jack is plugged"
1841          */
1842         if (!spec->autocfg.hp_pins[0]) {
1843                 hda_nid_t nid;
1844                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1845                 if (tmp == 0)
1846                         nid = porta;
1847                 else if (tmp == 1)
1848                         nid = porte;
1849                 else if (tmp == 2)
1850                         nid = portd;
1851                 else if (tmp == 3)
1852                         nid = porti;
1853                 else
1854                         return 1;
1855                 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1856                                       spec->autocfg.line_outs))
1857                         return 1;
1858                 spec->autocfg.hp_pins[0] = nid;
1859         }
1860         return 1;
1861 }
1862
1863 static void alc_ssid_check(struct hda_codec *codec,
1864                            hda_nid_t porta, hda_nid_t porte,
1865                            hda_nid_t portd, hda_nid_t porti)
1866 {
1867         if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1868                 struct alc_spec *spec = codec->spec;
1869                 snd_printd("realtek: "
1870                            "Enable default setup for auto mode as fallback\n");
1871                 spec->init_amp = ALC_INIT_DEFAULT;
1872         }
1873
1874         alc_init_auto_hp(codec);
1875         alc_init_auto_mic(codec);
1876 }
1877
1878 /*
1879  * Fix-up pin default configurations and add default verbs
1880  */
1881
1882 struct alc_pincfg {
1883         hda_nid_t nid;
1884         u32 val;
1885 };
1886
1887 struct alc_model_fixup {
1888         const int id;
1889         const char *name;
1890 };
1891
1892 struct alc_fixup {
1893         int type;
1894         bool chained;
1895         int chain_id;
1896         union {
1897                 unsigned int sku;
1898                 const struct alc_pincfg *pins;
1899                 const struct hda_verb *verbs;
1900                 void (*func)(struct hda_codec *codec,
1901                              const struct alc_fixup *fix,
1902                              int action);
1903         } v;
1904 };
1905
1906 enum {
1907         ALC_FIXUP_INVALID,
1908         ALC_FIXUP_SKU,
1909         ALC_FIXUP_PINS,
1910         ALC_FIXUP_VERBS,
1911         ALC_FIXUP_FUNC,
1912 };
1913
1914 enum {
1915         ALC_FIXUP_ACT_PRE_PROBE,
1916         ALC_FIXUP_ACT_PROBE,
1917         ALC_FIXUP_ACT_INIT,
1918 };
1919
1920 static void alc_apply_fixup(struct hda_codec *codec, int action)
1921 {
1922         struct alc_spec *spec = codec->spec;
1923         int id = spec->fixup_id;
1924 #ifdef CONFIG_SND_DEBUG_VERBOSE
1925         const char *modelname = spec->fixup_name;
1926 #endif
1927         int depth = 0;
1928
1929         if (!spec->fixup_list)
1930                 return;
1931
1932         while (id >= 0) {
1933                 const struct alc_fixup *fix = spec->fixup_list + id;
1934                 const struct alc_pincfg *cfg;
1935
1936                 switch (fix->type) {
1937                 case ALC_FIXUP_SKU:
1938                         if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1939                                 break;;
1940                         snd_printdd(KERN_INFO "hda_codec: %s: "
1941                                     "Apply sku override for %s\n",
1942                                     codec->chip_name, modelname);
1943                         spec->cdefine.sku_cfg = fix->v.sku;
1944                         spec->cdefine.fixup = 1;
1945                         break;
1946                 case ALC_FIXUP_PINS:
1947                         cfg = fix->v.pins;
1948                         if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1949                                 break;
1950                         snd_printdd(KERN_INFO "hda_codec: %s: "
1951                                     "Apply pincfg for %s\n",
1952                                     codec->chip_name, modelname);
1953                         for (; cfg->nid; cfg++)
1954                                 snd_hda_codec_set_pincfg(codec, cfg->nid,
1955                                                          cfg->val);
1956                         break;
1957                 case ALC_FIXUP_VERBS:
1958                         if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1959                                 break;
1960                         snd_printdd(KERN_INFO "hda_codec: %s: "
1961                                     "Apply fix-verbs for %s\n",
1962                                     codec->chip_name, modelname);
1963                         add_verb(codec->spec, fix->v.verbs);
1964                         break;
1965                 case ALC_FIXUP_FUNC:
1966                         if (!fix->v.func)
1967                                 break;
1968                         snd_printdd(KERN_INFO "hda_codec: %s: "
1969                                     "Apply fix-func for %s\n",
1970                                     codec->chip_name, modelname);
1971                         fix->v.func(codec, fix, action);
1972                         break;
1973                 default:
1974                         snd_printk(KERN_ERR "hda_codec: %s: "
1975                                    "Invalid fixup type %d\n",
1976                                    codec->chip_name, fix->type);
1977                         break;
1978                 }
1979                 if (!fix->chained)
1980                         break;
1981                 if (++depth > 10)
1982                         break;
1983                 id = fix->chain_id;
1984         }
1985 }
1986
1987 static void alc_pick_fixup(struct hda_codec *codec,
1988                            const struct alc_model_fixup *models,
1989                            const struct snd_pci_quirk *quirk,
1990                            const struct alc_fixup *fixlist)
1991 {
1992         struct alc_spec *spec = codec->spec;
1993         int id = -1;
1994         const char *name = NULL;
1995
1996         if (codec->modelname && models) {
1997                 while (models->name) {
1998                         if (!strcmp(codec->modelname, models->name)) {
1999                                 id = models->id;
2000                                 name = models->name;
2001                                 break;
2002                         }
2003                         models++;
2004                 }
2005         }
2006         if (id < 0) {
2007                 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
2008                 if (quirk) {
2009                         id = quirk->value;
2010 #ifdef CONFIG_SND_DEBUG_VERBOSE
2011                         name = quirk->name;
2012 #endif
2013                 }
2014         }
2015
2016         spec->fixup_id = id;
2017         if (id >= 0) {
2018                 spec->fixup_list = fixlist;
2019                 spec->fixup_name = name;
2020         }
2021 }
2022
2023 static int alc_read_coef_idx(struct hda_codec *codec,
2024                         unsigned int coef_idx)
2025 {
2026         unsigned int val;
2027         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
2028                                 coef_idx);
2029         val = snd_hda_codec_read(codec, 0x20, 0,
2030                                 AC_VERB_GET_PROC_COEF, 0);
2031         return val;
2032 }
2033
2034 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
2035                                                         unsigned int coef_val)
2036 {
2037         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
2038                             coef_idx);
2039         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
2040                             coef_val);
2041 }
2042
2043 /* set right pin controls for digital I/O */
2044 static void alc_auto_init_digital(struct hda_codec *codec)
2045 {
2046         struct alc_spec *spec = codec->spec;
2047         int i;
2048         hda_nid_t pin, dac;
2049
2050         for (i = 0; i < spec->autocfg.dig_outs; i++) {
2051                 pin = spec->autocfg.dig_out_pins[i];
2052                 if (!pin)
2053                         continue;
2054                 snd_hda_codec_write(codec, pin, 0,
2055                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2056                 if (!i)
2057                         dac = spec->multiout.dig_out_nid;
2058                 else
2059                         dac = spec->slave_dig_outs[i - 1];
2060                 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
2061                         continue;
2062                 snd_hda_codec_write(codec, dac, 0,
2063                                     AC_VERB_SET_AMP_GAIN_MUTE,
2064                                     AMP_OUT_UNMUTE);
2065         }
2066         pin = spec->autocfg.dig_in_pin;
2067         if (pin)
2068                 snd_hda_codec_write(codec, pin, 0,
2069                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
2070                                     PIN_IN);
2071 }
2072
2073 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
2074 static void alc_auto_parse_digital(struct hda_codec *codec)
2075 {
2076         struct alc_spec *spec = codec->spec;
2077         int i, err;
2078         hda_nid_t dig_nid;
2079
2080         /* support multiple SPDIFs; the secondary is set up as a slave */
2081         for (i = 0; i < spec->autocfg.dig_outs; i++) {
2082                 err = snd_hda_get_connections(codec,
2083                                               spec->autocfg.dig_out_pins[i],
2084                                               &dig_nid, 1);
2085                 if (err < 0)
2086                         continue;
2087                 if (!i) {
2088                         spec->multiout.dig_out_nid = dig_nid;
2089                         spec->dig_out_type = spec->autocfg.dig_out_type[0];
2090                 } else {
2091                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
2092                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
2093                                 break;
2094                         spec->slave_dig_outs[i - 1] = dig_nid;
2095                 }
2096         }
2097
2098         if (spec->autocfg.dig_in_pin) {
2099                 dig_nid = codec->start_nid;
2100                 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2101                         unsigned int wcaps = get_wcaps(codec, dig_nid);
2102                         if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2103                                 continue;
2104                         if (!(wcaps & AC_WCAP_DIGITAL))
2105                                 continue;
2106                         if (!(wcaps & AC_WCAP_CONN_LIST))
2107                                 continue;
2108                         err = get_connection_index(codec, dig_nid,
2109                                                    spec->autocfg.dig_in_pin);
2110                         if (err >= 0) {
2111                                 spec->dig_in_nid = dig_nid;
2112                                 break;
2113                         }
2114                 }
2115         }
2116 }
2117
2118 /*
2119  * ALC888
2120  */
2121
2122 /*
2123  * 2ch mode
2124  */
2125 static const struct hda_verb alc888_4ST_ch2_intel_init[] = {
2126 /* Mic-in jack as mic in */
2127         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2128         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2129 /* Line-in jack as Line in */
2130         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2131         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2132 /* Line-Out as Front */
2133         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
2134         { } /* end */
2135 };
2136
2137 /*
2138  * 4ch mode
2139  */
2140 static const struct hda_verb alc888_4ST_ch4_intel_init[] = {
2141 /* Mic-in jack as mic in */
2142         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2143         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2144 /* Line-in jack as Surround */
2145         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2146         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2147 /* Line-Out as Front */
2148         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
2149         { } /* end */
2150 };
2151
2152 /*
2153  * 6ch mode
2154  */
2155 static const struct hda_verb alc888_4ST_ch6_intel_init[] = {
2156 /* Mic-in jack as CLFE */
2157         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2158         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2159 /* Line-in jack as Surround */
2160         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2161         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2162 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
2163         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
2164         { } /* end */
2165 };
2166
2167 /*
2168  * 8ch mode
2169  */
2170 static const struct hda_verb alc888_4ST_ch8_intel_init[] = {
2171 /* Mic-in jack as CLFE */
2172         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2173         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2174 /* Line-in jack as Surround */
2175         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2176         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2177 /* Line-Out as Side */
2178         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
2179         { } /* end */
2180 };
2181
2182 static const struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
2183         { 2, alc888_4ST_ch2_intel_init },
2184         { 4, alc888_4ST_ch4_intel_init },
2185         { 6, alc888_4ST_ch6_intel_init },
2186         { 8, alc888_4ST_ch8_intel_init },
2187 };
2188
2189 /*
2190  * ALC888 Fujitsu Siemens Amillo xa3530
2191  */
2192
2193 static const struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
2194 /* Front Mic: set to PIN_IN (empty by default) */
2195         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2196 /* Connect Internal HP to Front */
2197         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2198         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2199         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2200 /* Connect Bass HP to Front */
2201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2202         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2203         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2204 /* Connect Line-Out side jack (SPDIF) to Side */
2205         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2206         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2207         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
2208 /* Connect Mic jack to CLFE */
2209         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2210         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2211         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
2212 /* Connect Line-in jack to Surround */
2213         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2214         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2215         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
2216 /* Connect HP out jack to Front */
2217         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2218         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2220 /* Enable unsolicited event for HP jack and Line-out jack */
2221         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2222         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2223         {}
2224 };
2225
2226 static void alc889_automute_setup(struct hda_codec *codec)
2227 {
2228         struct alc_spec *spec = codec->spec;
2229
2230         spec->autocfg.hp_pins[0] = 0x15;
2231         spec->autocfg.speaker_pins[0] = 0x14;
2232         spec->autocfg.speaker_pins[1] = 0x16;
2233         spec->autocfg.speaker_pins[2] = 0x17;
2234         spec->autocfg.speaker_pins[3] = 0x19;
2235         spec->autocfg.speaker_pins[4] = 0x1a;
2236         spec->automute = 1;
2237         spec->automute_mode = ALC_AUTOMUTE_AMP;
2238 }
2239
2240 static void alc889_intel_init_hook(struct hda_codec *codec)
2241 {
2242         alc889_coef_init(codec);
2243         alc_hp_automute(codec);
2244 }
2245
2246 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
2247 {
2248         struct alc_spec *spec = codec->spec;
2249
2250         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
2251         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
2252         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
2253         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
2254         spec->automute = 1;
2255         spec->automute_mode = ALC_AUTOMUTE_AMP;
2256 }
2257
2258 /*
2259  * ALC888 Acer Aspire 4930G model
2260  */
2261
2262 static const struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
2263 /* Front Mic: set to PIN_IN (empty by default) */
2264         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2265 /* Unselect Front Mic by default in input mixer 3 */
2266         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2267 /* Enable unsolicited event for HP jack */
2268         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2269 /* Connect Internal HP to front */
2270         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2271         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2272         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2273 /* Connect HP out to front */
2274         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2275         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2276         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2277         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2278         { }
2279 };
2280
2281 /*
2282  * ALC888 Acer Aspire 6530G model
2283  */
2284
2285 static const struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
2286 /* Route to built-in subwoofer as well as speakers */
2287         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2288         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2289         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2290         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2291 /* Bias voltage on for external mic port */
2292         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2293 /* Front Mic: set to PIN_IN (empty by default) */
2294         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2295 /* Unselect Front Mic by default in input mixer 3 */
2296         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2297 /* Enable unsolicited event for HP jack */
2298         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2299 /* Enable speaker output */
2300         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2301         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2302         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2303 /* Enable headphone output */
2304         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2305         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2306         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2307         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2308         { }
2309 };
2310
2311 /*
2312  *ALC888 Acer Aspire 7730G model
2313  */
2314
2315 static const struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
2316 /* Bias voltage on for external mic port */
2317         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2318 /* Front Mic: set to PIN_IN (empty by default) */
2319         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2320 /* Unselect Front Mic by default in input mixer 3 */
2321         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2322 /* Enable unsolicited event for HP jack */
2323         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2324 /* Enable speaker output */
2325         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2326         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2327         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2328 /* Enable headphone output */
2329         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2330         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2331         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2332         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2333 /*Enable internal subwoofer */
2334         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2335         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2336         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
2337         {0x17, AC_VERB_SET_EAPD_BTLENABLE, 2},
2338         { }
2339 };
2340
2341 /*
2342  * ALC889 Acer Aspire 8930G model
2343  */
2344
2345 static const struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
2346 /* Front Mic: set to PIN_IN (empty by default) */
2347         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2348 /* Unselect Front Mic by default in input mixer 3 */
2349         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2350 /* Enable unsolicited event for HP jack */
2351         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2352 /* Connect Internal Front to Front */
2353         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2354         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2355         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2356 /* Connect Internal Rear to Rear */
2357         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2358         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2359         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
2360 /* Connect Internal CLFE to CLFE */
2361         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2362         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2363         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
2364 /* Connect HP out to Front */
2365         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2366         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2367         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2368 /* Enable all DACs */
2369 /*  DAC DISABLE/MUTE 1? */
2370 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
2371         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
2372         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2373 /*  DAC DISABLE/MUTE 2? */
2374 /*  some bit here disables the other DACs. Init=0x4900 */
2375         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
2376         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2377 /* DMIC fix
2378  * This laptop has a stereo digital microphone. The mics are only 1cm apart
2379  * which makes the stereo useless. However, either the mic or the ALC889
2380  * makes the signal become a difference/sum signal instead of standard
2381  * stereo, which is annoying. So instead we flip this bit which makes the
2382  * codec replicate the sum signal to both channels, turning it into a
2383  * normal mono mic.
2384  */
2385 /*  DMIC_CONTROL? Init value = 0x0001 */
2386         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
2387         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
2388         { }
2389 };
2390
2391 static const struct hda_input_mux alc888_2_capture_sources[2] = {
2392         /* Front mic only available on one ADC */
2393         {
2394                 .num_items = 4,
2395                 .items = {
2396                         { "Mic", 0x0 },
2397                         { "Line", 0x2 },
2398                         { "CD", 0x4 },
2399                         { "Front Mic", 0xb },
2400                 },
2401         },
2402         {
2403                 .num_items = 3,
2404                 .items = {
2405                         { "Mic", 0x0 },
2406                         { "Line", 0x2 },
2407                         { "CD", 0x4 },
2408                 },
2409         }
2410 };
2411
2412 static const struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
2413         /* Interal mic only available on one ADC */
2414         {
2415                 .num_items = 5,
2416                 .items = {
2417                         { "Mic", 0x0 },
2418                         { "Line In", 0x2 },
2419                         { "CD", 0x4 },
2420                         { "Input Mix", 0xa },
2421                         { "Internal Mic", 0xb },
2422                 },
2423         },
2424         {
2425                 .num_items = 4,
2426                 .items = {
2427                         { "Mic", 0x0 },
2428                         { "Line In", 0x2 },
2429                         { "CD", 0x4 },
2430                         { "Input Mix", 0xa },
2431                 },
2432         }
2433 };
2434
2435 static const struct hda_input_mux alc889_capture_sources[3] = {
2436         /* Digital mic only available on first "ADC" */
2437         {
2438                 .num_items = 5,
2439                 .items = {
2440                         { "Mic", 0x0 },
2441                         { "Line", 0x2 },
2442                         { "CD", 0x4 },
2443                         { "Front Mic", 0xb },
2444                         { "Input Mix", 0xa },
2445                 },
2446         },
2447         {
2448                 .num_items = 4,
2449                 .items = {
2450                         { "Mic", 0x0 },
2451                         { "Line", 0x2 },
2452                         { "CD", 0x4 },
2453                         { "Input Mix", 0xa },
2454                 },
2455         },
2456         {
2457                 .num_items = 4,
2458                 .items = {
2459                         { "Mic", 0x0 },
2460                         { "Line", 0x2 },
2461                         { "CD", 0x4 },
2462                         { "Input Mix", 0xa },
2463                 },
2464         }
2465 };
2466
2467 static const struct snd_kcontrol_new alc888_base_mixer[] = {
2468         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2469         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2470         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2471         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2472         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2473                 HDA_OUTPUT),
2474         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2475         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2476         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2477         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2478         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2479         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2480         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2481         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2482         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2483         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2484         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2485         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2486         { } /* end */
2487 };
2488
2489 static const struct snd_kcontrol_new alc888_acer_aspire_4930g_mixer[] = {
2490         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2491         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2492         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2493         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2494         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2495                 HDA_OUTPUT),
2496         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2497         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2498         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2499         HDA_CODEC_VOLUME_MONO("Internal LFE Playback Volume", 0x0f, 1, 0x0, HDA_OUTPUT),
2500         HDA_BIND_MUTE_MONO("Internal LFE Playback Switch", 0x0f, 1, 2, HDA_INPUT),
2501         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2502         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2503         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2504         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2505         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2506         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2507         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2508         { } /* end */
2509 };
2510
2511 static const struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
2512         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2513         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2514         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2515         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2516         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2517                 HDA_OUTPUT),
2518         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2519         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2520         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2521         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2522         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2523         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2524         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2525         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2526         { } /* end */
2527 };
2528
2529
2530 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
2531 {
2532         struct alc_spec *spec = codec->spec;
2533
2534         spec->autocfg.hp_pins[0] = 0x15;
2535         spec->autocfg.speaker_pins[0] = 0x14;
2536         spec->autocfg.speaker_pins[1] = 0x16;
2537         spec->autocfg.speaker_pins[2] = 0x17;
2538         spec->automute = 1;
2539         spec->automute_mode = ALC_AUTOMUTE_AMP;
2540 }
2541
2542 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
2543 {
2544         struct alc_spec *spec = codec->spec;
2545
2546         spec->autocfg.hp_pins[0] = 0x15;
2547         spec->autocfg.speaker_pins[0] = 0x14;
2548         spec->autocfg.speaker_pins[1] = 0x16;
2549         spec->autocfg.speaker_pins[2] = 0x17;
2550         spec->automute = 1;
2551         spec->automute_mode = ALC_AUTOMUTE_AMP;
2552 }
2553
2554 static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
2555 {
2556         struct alc_spec *spec = codec->spec;
2557
2558         spec->autocfg.hp_pins[0] = 0x15;
2559         spec->autocfg.speaker_pins[0] = 0x14;
2560         spec->autocfg.speaker_pins[1] = 0x16;
2561         spec->autocfg.speaker_pins[2] = 0x17;
2562         spec->automute = 1;
2563         spec->automute_mode = ALC_AUTOMUTE_AMP;
2564 }
2565
2566 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
2567 {
2568         struct alc_spec *spec = codec->spec;
2569
2570         spec->autocfg.hp_pins[0] = 0x15;
2571         spec->autocfg.speaker_pins[0] = 0x14;
2572         spec->autocfg.speaker_pins[1] = 0x16;
2573         spec->autocfg.speaker_pins[2] = 0x1b;
2574         spec->automute = 1;
2575         spec->automute_mode = ALC_AUTOMUTE_AMP;
2576 }
2577
2578 /*
2579  * ALC880 3-stack model
2580  *
2581  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
2582  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
2583  *                 F-Mic = 0x1b, HP = 0x19
2584  */
2585
2586 static const hda_nid_t alc880_dac_nids[4] = {
2587         /* front, rear, clfe, rear_surr */
2588         0x02, 0x05, 0x04, 0x03
2589 };
2590
2591 static const hda_nid_t alc880_adc_nids[3] = {
2592         /* ADC0-2 */
2593         0x07, 0x08, 0x09,
2594 };
2595
2596 /* The datasheet says the node 0x07 is connected from inputs,
2597  * but it shows zero connection in the real implementation on some devices.
2598  * Note: this is a 915GAV bug, fixed on 915GLV
2599  */
2600 static const hda_nid_t alc880_adc_nids_alt[2] = {
2601         /* ADC1-2 */
2602         0x08, 0x09,
2603 };
2604
2605 #define ALC880_DIGOUT_NID       0x06
2606 #define ALC880_DIGIN_NID        0x0a
2607
2608 static const struct hda_input_mux alc880_capture_source = {
2609         .num_items = 4,
2610         .items = {
2611                 { "Mic", 0x0 },
2612                 { "Front Mic", 0x3 },
2613                 { "Line", 0x2 },
2614                 { "CD", 0x4 },
2615         },
2616 };
2617
2618 /* channel source setting (2/6 channel selection for 3-stack) */
2619 /* 2ch mode */
2620 static const struct hda_verb alc880_threestack_ch2_init[] = {
2621         /* set line-in to input, mute it */
2622         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2623         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2624         /* set mic-in to input vref 80%, mute it */
2625         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2626         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2627         { } /* end */
2628 };
2629
2630 /* 6ch mode */
2631 static const struct hda_verb alc880_threestack_ch6_init[] = {
2632         /* set line-in to output, unmute it */
2633         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2634         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2635         /* set mic-in to output, unmute it */
2636         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2637         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2638         { } /* end */
2639 };
2640
2641 static const struct hda_channel_mode alc880_threestack_modes[2] = {
2642         { 2, alc880_threestack_ch2_init },
2643         { 6, alc880_threestack_ch6_init },
2644 };
2645
2646 static const struct snd_kcontrol_new alc880_three_stack_mixer[] = {
2647         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2648         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2649         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2650         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2651         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2652         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2653         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2654         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2655         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2656         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2657         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2658         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2659         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2660         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2661         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
2662         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
2663         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
2664         {
2665                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2666                 .name = "Channel Mode",
2667                 .info = alc_ch_mode_info,
2668                 .get = alc_ch_mode_get,
2669                 .put = alc_ch_mode_put,
2670         },
2671         { } /* end */
2672 };
2673
2674 /* capture mixer elements */
2675 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
2676                             struct snd_ctl_elem_info *uinfo)
2677 {
2678         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2679         struct alc_spec *spec = codec->spec;
2680         int err;
2681
2682         mutex_lock(&codec->control_mutex);
2683         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2684                                                       HDA_INPUT);
2685         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
2686         mutex_unlock(&codec->control_mutex);
2687         return err;
2688 }
2689
2690 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2691                            unsigned int size, unsigned int __user *tlv)
2692 {
2693         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2694         struct alc_spec *spec = codec->spec;
2695         int err;
2696
2697         mutex_lock(&codec->control_mutex);
2698         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2699                                                       HDA_INPUT);
2700         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
2701         mutex_unlock(&codec->control_mutex);
2702         return err;
2703 }
2704
2705 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
2706                              struct snd_ctl_elem_value *ucontrol);
2707
2708 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
2709                                  struct snd_ctl_elem_value *ucontrol,
2710                                  getput_call_t func, bool check_adc_switch)
2711 {
2712         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2713         struct alc_spec *spec = codec->spec;
2714         int i, err;
2715
2716         mutex_lock(&codec->control_mutex);
2717         if (check_adc_switch && spec->dual_adc_switch) {
2718                 for (i = 0; i < spec->num_adc_nids; i++) {
2719                         kcontrol->private_value =
2720                                 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
2721                                                     3, 0, HDA_INPUT);
2722                         err = func(kcontrol, ucontrol);
2723                         if (err < 0)
2724                                 goto error;
2725                 }
2726         } else {
2727                 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2728                 kcontrol->private_value =
2729                         HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
2730                                             3, 0, HDA_INPUT);
2731                 err = func(kcontrol, ucontrol);
2732         }
2733  error:
2734         mutex_unlock(&codec->control_mutex);
2735         return err;
2736 }
2737
2738 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
2739                            struct snd_ctl_elem_value *ucontrol)
2740 {
2741         return alc_cap_getput_caller(kcontrol, ucontrol,
2742                                      snd_hda_mixer_amp_volume_get, false);
2743 }
2744
2745 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
2746                            struct snd_ctl_elem_value *ucontrol)
2747 {
2748         return alc_cap_getput_caller(kcontrol, ucontrol,
2749                                      snd_hda_mixer_amp_volume_put, true);
2750 }
2751
2752 /* capture mixer elements */
2753 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
2754
2755 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
2756                           struct snd_ctl_elem_value *ucontrol)
2757 {
2758         return alc_cap_getput_caller(kcontrol, ucontrol,
2759                                      snd_hda_mixer_amp_switch_get, false);
2760 }
2761
2762 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
2763                           struct snd_ctl_elem_value *ucontrol)
2764 {
2765         return alc_cap_getput_caller(kcontrol, ucontrol,
2766                                      snd_hda_mixer_amp_switch_put, true);
2767 }
2768
2769 #define _DEFINE_CAPMIX(num) \
2770         { \
2771                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2772                 .name = "Capture Switch", \
2773                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
2774                 .count = num, \
2775                 .info = alc_cap_sw_info, \
2776                 .get = alc_cap_sw_get, \
2777                 .put = alc_cap_sw_put, \
2778         }, \
2779         { \
2780                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2781                 .name = "Capture Volume", \
2782                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2783                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2784                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2785                 .count = num, \
2786                 .info = alc_cap_vol_info, \
2787                 .get = alc_cap_vol_get, \
2788                 .put = alc_cap_vol_put, \
2789                 .tlv = { .c = alc_cap_vol_tlv }, \
2790         }
2791
2792 #define _DEFINE_CAPSRC(num) \
2793         { \
2794                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2795                 /* .name = "Capture Source", */ \
2796                 .name = "Input Source", \
2797                 .count = num, \
2798                 .info = alc_mux_enum_info, \
2799                 .get = alc_mux_enum_get, \
2800                 .put = alc_mux_enum_put, \
2801         }
2802
2803 #define DEFINE_CAPMIX(num) \
2804 static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2805         _DEFINE_CAPMIX(num),                                  \
2806         _DEFINE_CAPSRC(num),                                  \
2807         { } /* end */                                         \
2808 }
2809
2810 #define DEFINE_CAPMIX_NOSRC(num) \
2811 static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2812         _DEFINE_CAPMIX(num),                                        \
2813         { } /* end */                                               \
2814 }
2815
2816 /* up to three ADCs */
2817 DEFINE_CAPMIX(1);
2818 DEFINE_CAPMIX(2);
2819 DEFINE_CAPMIX(3);
2820 DEFINE_CAPMIX_NOSRC(1);
2821 DEFINE_CAPMIX_NOSRC(2);
2822 DEFINE_CAPMIX_NOSRC(3);
2823
2824 /*
2825  * ALC880 5-stack model
2826  *
2827  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2828  *      Side = 0x02 (0xd)
2829  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2830  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2831  */
2832
2833 /* additional mixers to alc880_three_stack_mixer */
2834 static const struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2835         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2836         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2837         { } /* end */
2838 };
2839
2840 /* channel source setting (6/8 channel selection for 5-stack) */
2841 /* 6ch mode */
2842 static const struct hda_verb alc880_fivestack_ch6_init[] = {
2843         /* set line-in to input, mute it */
2844         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2845         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2846         { } /* end */
2847 };
2848
2849 /* 8ch mode */
2850 static const struct hda_verb alc880_fivestack_ch8_init[] = {
2851         /* set line-in to output, unmute it */
2852         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2853         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2854         { } /* end */
2855 };
2856
2857 static const struct hda_channel_mode alc880_fivestack_modes[2] = {
2858         { 6, alc880_fivestack_ch6_init },
2859         { 8, alc880_fivestack_ch8_init },
2860 };
2861
2862
2863 /*
2864  * ALC880 6-stack model
2865  *
2866  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2867  *      Side = 0x05 (0x0f)
2868  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2869  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2870  */
2871
2872 static const hda_nid_t alc880_6st_dac_nids[4] = {
2873         /* front, rear, clfe, rear_surr */
2874         0x02, 0x03, 0x04, 0x05
2875 };
2876
2877 static const struct hda_input_mux alc880_6stack_capture_source = {
2878         .num_items = 4,
2879         .items = {
2880                 { "Mic", 0x0 },
2881                 { "Front Mic", 0x1 },
2882                 { "Line", 0x2 },
2883                 { "CD", 0x4 },
2884         },
2885 };
2886
2887 /* fixed 8-channels */
2888 static const struct hda_channel_mode alc880_sixstack_modes[1] = {
2889         { 8, NULL },
2890 };
2891
2892 static const struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2893         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2894         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2895         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2896         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2897         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2898         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2899         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2900         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2901         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2902         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2903         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2904         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2905         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2906         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2907         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2908         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2909         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2910         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2911         {
2912                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2913                 .name = "Channel Mode",
2914                 .info = alc_ch_mode_info,
2915                 .get = alc_ch_mode_get,
2916                 .put = alc_ch_mode_put,
2917         },
2918         { } /* end */
2919 };
2920
2921
2922 /*
2923  * ALC880 W810 model
2924  *
2925  * W810 has rear IO for:
2926  * Front (DAC 02)
2927  * Surround (DAC 03)
2928  * Center/LFE (DAC 04)
2929  * Digital out (06)
2930  *
2931  * The system also has a pair of internal speakers, and a headphone jack.
2932  * These are both connected to Line2 on the codec, hence to DAC 02.
2933  *
2934  * There is a variable resistor to control the speaker or headphone
2935  * volume. This is a hardware-only device without a software API.
2936  *
2937  * Plugging headphones in will disable the internal speakers. This is
2938  * implemented in hardware, not via the driver using jack sense. In
2939  * a similar fashion, plugging into the rear socket marked "front" will
2940  * disable both the speakers and headphones.
2941  *
2942  * For input, there's a microphone jack, and an "audio in" jack.
2943  * These may not do anything useful with this driver yet, because I
2944  * haven't setup any initialization verbs for these yet...
2945  */
2946
2947 static const hda_nid_t alc880_w810_dac_nids[3] = {
2948         /* front, rear/surround, clfe */
2949         0x02, 0x03, 0x04
2950 };
2951
2952 /* fixed 6 channels */
2953 static const struct hda_channel_mode alc880_w810_modes[1] = {
2954         { 6, NULL }
2955 };
2956
2957 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2958 static const struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2959         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2960         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2961         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2962         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2963         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2964         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2965         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2966         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2967         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2968         { } /* end */
2969 };
2970
2971
2972 /*
2973  * Z710V model
2974  *
2975  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2976  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2977  *                 Line = 0x1a
2978  */
2979
2980 static const hda_nid_t alc880_z71v_dac_nids[1] = {
2981         0x02
2982 };
2983 #define ALC880_Z71V_HP_DAC      0x03
2984
2985 /* fixed 2 channels */
2986 static const struct hda_channel_mode alc880_2_jack_modes[1] = {
2987         { 2, NULL }
2988 };
2989
2990 static const struct snd_kcontrol_new alc880_z71v_mixer[] = {
2991         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2992         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2993         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2994         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2995         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2996         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2997         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2998         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2999         { } /* end */
3000 };
3001
3002
3003 /*
3004  * ALC880 F1734 model
3005  *
3006  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
3007  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
3008  */
3009
3010 static const hda_nid_t alc880_f1734_dac_nids[1] = {
3011         0x03
3012 };
3013 #define ALC880_F1734_HP_DAC     0x02
3014
3015 static const struct snd_kcontrol_new alc880_f1734_mixer[] = {
3016         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3017         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3018         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3019         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3020         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3021         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3022         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3023         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3024         { } /* end */
3025 };
3026
3027 static const struct hda_input_mux alc880_f1734_capture_source = {
3028         .num_items = 2,
3029         .items = {
3030                 { "Mic", 0x1 },
3031                 { "CD", 0x4 },
3032         },
3033 };
3034
3035
3036 /*
3037  * ALC880 ASUS model
3038  *
3039  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
3040  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
3041  *  Mic = 0x18, Line = 0x1a
3042  */
3043
3044 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
3045 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
3046
3047 static const struct snd_kcontrol_new alc880_asus_mixer[] = {
3048         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3049         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3050         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3051         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3052         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3053         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3054         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3055         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3056         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3057         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3058         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3059         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3060         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3061         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3062         {
3063                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3064                 .name = "Channel Mode",
3065                 .info = alc_ch_mode_info,
3066                 .get = alc_ch_mode_get,
3067                 .put = alc_ch_mode_put,
3068         },
3069         { } /* end */
3070 };
3071
3072 /*
3073  * ALC880 ASUS W1V model
3074  *
3075  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
3076  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
3077  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
3078  */
3079
3080 /* additional mixers to alc880_asus_mixer */
3081 static const struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
3082         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
3083         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
3084         { } /* end */
3085 };
3086
3087 /* TCL S700 */
3088 static const struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
3089         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3090         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
3091         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
3092         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
3093         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
3094         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
3095         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
3096         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
3097         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
3098         { } /* end */
3099 };
3100
3101 /* Uniwill */
3102 static const struct snd_kcontrol_new alc880_uniwill_mixer[] = {
3103         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3104         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3105         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3106         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3107         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3108         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3109         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3110         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3111         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3112         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3113         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3114         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3115         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3116         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3117         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3118         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3119         {
3120                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3121                 .name = "Channel Mode",
3122                 .info = alc_ch_mode_info,
3123                 .get = alc_ch_mode_get,
3124                 .put = alc_ch_mode_put,
3125         },
3126         { } /* end */
3127 };
3128
3129 static const struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
3130         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3131         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3132         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3133         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3134         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
3135         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
3136         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3137         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3138         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3139         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3140         { } /* end */
3141 };
3142
3143 static const struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
3144         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3145         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
3146         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3147         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
3148         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3149         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3150         { } /* end */
3151 };
3152
3153 /*
3154  * virtual master controls
3155  */
3156
3157 /*
3158  * slave controls for virtual master
3159  */
3160 static const char * const alc_slave_vols[] = {
3161         "Front Playback Volume",
3162         "Surround Playback Volume",
3163         "Center Playback Volume",
3164         "LFE Playback Volume",
3165         "Side Playback Volume",
3166         "Headphone Playback Volume",
3167         "Speaker Playback Volume",
3168         "Mono Playback Volume",
3169         "Line-Out Playback Volume",
3170         NULL,
3171 };
3172
3173 static const char * const alc_slave_sws[] = {
3174         "Front Playback Switch",
3175         "Surround Playback Switch",
3176         "Center Playback Switch",
3177         "LFE Playback Switch",
3178         "Side Playback Switch",
3179         "Headphone Playback Switch",
3180         "Speaker Playback Switch",
3181         "Mono Playback Switch",
3182         "IEC958 Playback Switch",
3183         "Line-Out Playback Switch",
3184         NULL,
3185 };
3186
3187 /*
3188  * build control elements
3189  */
3190
3191 #define NID_MAPPING             (-1)
3192
3193 #define SUBDEV_SPEAKER_         (0 << 6)
3194 #define SUBDEV_HP_              (1 << 6)
3195 #define SUBDEV_LINE_            (2 << 6)
3196 #define SUBDEV_SPEAKER(x)       (SUBDEV_SPEAKER_ | ((x) & 0x3f))
3197 #define SUBDEV_HP(x)            (SUBDEV_HP_ | ((x) & 0x3f))
3198 #define SUBDEV_LINE(x)          (SUBDEV_LINE_ | ((x) & 0x3f))
3199
3200 static void alc_free_kctls(struct hda_codec *codec);
3201
3202 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3203 /* additional beep mixers; the actual parameters are overwritten at build */
3204 static const struct snd_kcontrol_new alc_beep_mixer[] = {
3205         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
3206         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
3207         { } /* end */
3208 };
3209 #endif
3210
3211 static int alc_build_controls(struct hda_codec *codec)
3212 {
3213         struct alc_spec *spec = codec->spec;
3214         struct snd_kcontrol *kctl = NULL;
3215         const struct snd_kcontrol_new *knew;
3216         int i, j, err;
3217         unsigned int u;
3218         hda_nid_t nid;
3219
3220         for (i = 0; i < spec->num_mixers; i++) {
3221                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
3222                 if (err < 0)
3223                         return err;
3224         }
3225         if (spec->cap_mixer) {
3226                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
3227                 if (err < 0)
3228                         return err;
3229         }
3230         if (spec->multiout.dig_out_nid) {
3231                 err = snd_hda_create_spdif_out_ctls(codec,
3232                                                     spec->multiout.dig_out_nid,
3233                                                     spec->multiout.dig_out_nid);
3234                 if (err < 0)
3235                         return err;
3236                 if (!spec->no_analog) {
3237                         err = snd_hda_create_spdif_share_sw(codec,
3238                                                             &spec->multiout);
3239                         if (err < 0)
3240                                 return err;
3241                         spec->multiout.share_spdif = 1;
3242                 }
3243         }
3244         if (spec->dig_in_nid) {
3245                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
3246                 if (err < 0)
3247                         return err;
3248         }
3249
3250 #ifdef CONFIG_SND_HDA_INPUT_BEEP
3251         /* create beep controls if needed */
3252         if (spec->beep_amp) {
3253                 const struct snd_kcontrol_new *knew;
3254                 for (knew = alc_beep_mixer; knew->name; knew++) {
3255                         struct snd_kcontrol *kctl;
3256                         kctl = snd_ctl_new1(knew, codec);
3257                         if (!kctl)
3258                                 return -ENOMEM;
3259                         kctl->private_value = spec->beep_amp;
3260                         err = snd_hda_ctl_add(codec, 0, kctl);
3261                         if (err < 0)
3262                                 return err;
3263                 }
3264         }
3265 #endif
3266
3267         /* if we have no master control, let's create it */
3268         if (!spec->no_analog &&
3269             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
3270                 unsigned int vmaster_tlv[4];
3271                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
3272                                         HDA_OUTPUT, vmaster_tlv);
3273                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
3274                                           vmaster_tlv, alc_slave_vols);
3275                 if (err < 0)
3276                         return err;
3277         }
3278         if (!spec->no_analog &&
3279             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
3280                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
3281                                           NULL, alc_slave_sws);
3282                 if (err < 0)
3283                         return err;
3284         }
3285
3286         /* assign Capture Source enums to NID */
3287         if (spec->capsrc_nids || spec->adc_nids) {
3288                 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
3289                 if (!kctl)
3290                         kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
3291                 for (i = 0; kctl && i < kctl->count; i++) {
3292                         const hda_nid_t *nids = spec->capsrc_nids;
3293                         if (!nids)
3294                                 nids = spec->adc_nids;
3295                         err = snd_hda_add_nid(codec, kctl, i, nids[i]);
3296                         if (err < 0)
3297                                 return err;
3298                 }
3299         }
3300         if (spec->cap_mixer) {
3301                 const char *kname = kctl ? kctl->id.name : NULL;
3302                 for (knew = spec->cap_mixer; knew->name; knew++) {
3303                         if (kname && strcmp(knew->name, kname) == 0)
3304                                 continue;
3305                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3306                         for (i = 0; kctl && i < kctl->count; i++) {
3307                                 err = snd_hda_add_nid(codec, kctl, i,
3308                                                       spec->adc_nids[i]);
3309                                 if (err < 0)
3310                                         return err;
3311                         }
3312                 }
3313         }
3314
3315         /* other nid->control mapping */
3316         for (i = 0; i < spec->num_mixers; i++) {
3317                 for (knew = spec->mixers[i]; knew->name; knew++) {
3318                         if (knew->iface != NID_MAPPING)
3319                                 continue;
3320                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3321                         if (kctl == NULL)
3322                                 continue;
3323                         u = knew->subdevice;
3324                         for (j = 0; j < 4; j++, u >>= 8) {
3325                                 nid = u & 0x3f;
3326                                 if (nid == 0)
3327                                         continue;
3328                                 switch (u & 0xc0) {
3329                                 case SUBDEV_SPEAKER_:
3330                                         nid = spec->autocfg.speaker_pins[nid];
3331                                         break;
3332                                 case SUBDEV_LINE_:
3333                                         nid = spec->autocfg.line_out_pins[nid];
3334                                         break;
3335                                 case SUBDEV_HP_:
3336                                         nid = spec->autocfg.hp_pins[nid];
3337                                         break;
3338                                 default:
3339                                         continue;
3340                                 }
3341                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
3342                                 if (err < 0)
3343                                         return err;
3344                         }
3345                         u = knew->private_value;
3346                         for (j = 0; j < 4; j++, u >>= 8) {
3347                                 nid = u & 0xff;
3348                                 if (nid == 0)
3349                                         continue;
3350                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
3351                                 if (err < 0)
3352                                         return err;
3353                         }
3354                 }
3355         }
3356
3357         alc_free_kctls(codec); /* no longer needed */
3358
3359         return 0;
3360 }
3361
3362
3363 /*
3364  * initialize the codec volumes, etc
3365  */
3366
3367 /*
3368  * generic initialization of ADC, input mixers and output mixers
3369  */
3370 static const struct hda_verb alc880_volume_init_verbs[] = {
3371         /*
3372          * Unmute ADC0-2 and set the default input to mic-in
3373          */
3374         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3376         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3377         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3378         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3379         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3380
3381         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3382          * mixer widget
3383          * Note: PASD motherboards uses the Line In 2 as the input for front
3384          * panel mic (mic 2)
3385          */
3386         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
3387         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3388         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3389         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3390         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3391         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3392         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3393         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3394
3395         /*
3396          * Set up output mixers (0x0c - 0x0f)
3397          */
3398         /* set vol=0 to output mixers */
3399         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3400         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3401         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3402         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3403         /* set up input amps for analog loopback */
3404         /* Amp Indices: DAC = 0, mixer = 1 */
3405         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3406         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3407         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3408         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3409         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3410         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3411         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3412         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3413
3414         { }
3415 };
3416
3417 /*
3418  * 3-stack pin configuration:
3419  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
3420  */
3421 static const struct hda_verb alc880_pin_3stack_init_verbs[] = {
3422         /*
3423          * preset connection lists of input pins
3424          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3425          */
3426         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3427         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3428         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3429
3430         /*
3431          * Set pin mode and muting
3432          */
3433         /* set front pin widgets 0x14 for output */
3434         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3435         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3436         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3437         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3438         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3439         /* Mic2 (as headphone out) for HP output */
3440         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3441         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3442         /* Line In pin widget for input */
3443         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3444         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3445         /* Line2 (as front mic) pin widget for input and vref at 80% */
3446         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3447         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3448         /* CD pin widget for input */
3449         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3450
3451         { }
3452 };
3453
3454 /*
3455  * 5-stack pin configuration:
3456  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
3457  * line-in/side = 0x1a, f-mic = 0x1b
3458  */
3459 static const struct hda_verb alc880_pin_5stack_init_verbs[] = {
3460         /*
3461          * preset connection lists of input pins
3462          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3463          */
3464         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3465         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
3466
3467         /*
3468          * Set pin mode and muting
3469          */
3470         /* set pin widgets 0x14-0x17 for output */
3471         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3472         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3473         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3474         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3475         /* unmute pins for output (no gain on this amp) */
3476         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3477         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3478         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3479         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3480
3481         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3482         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3483         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3484         /* Mic2 (as headphone out) for HP output */
3485         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3486         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3487         /* Line In pin widget for input */
3488         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3489         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3490         /* Line2 (as front mic) pin widget for input and vref at 80% */
3491         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3492         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3493         /* CD pin widget for input */
3494         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3495
3496         { }
3497 };
3498
3499 /*
3500  * W810 pin configuration:
3501  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
3502  */
3503 static const struct hda_verb alc880_pin_w810_init_verbs[] = {
3504         /* hphone/speaker input selector: front DAC */
3505         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
3506
3507         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3508         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3509         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3510         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3511         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3512         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3513
3514         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3515         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3516
3517         { }
3518 };
3519
3520 /*
3521  * Z71V pin configuration:
3522  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
3523  */
3524 static const struct hda_verb alc880_pin_z71v_init_verbs[] = {
3525         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3526         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3527         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3528         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3529
3530         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3531         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3532         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3533         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3534
3535         { }
3536 };
3537
3538 /*
3539  * 6-stack pin configuration:
3540  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
3541  * f-mic = 0x19, line = 0x1a, HP = 0x1b
3542  */
3543 static const struct hda_verb alc880_pin_6stack_init_verbs[] = {
3544         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3545
3546         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3547         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3548         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3549         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3550         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3551         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3552         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3553         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3554
3555         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3556         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3557         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3558         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3559         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3560         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3561         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3562         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3563         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3564
3565         { }
3566 };
3567
3568 /*
3569  * Uniwill pin configuration:
3570  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
3571  * line = 0x1a
3572  */
3573 static const struct hda_verb alc880_uniwill_init_verbs[] = {
3574         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3575
3576         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3577         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3578         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3579         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3580         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3581         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3582         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3583         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3584         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3585         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3586         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3587         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3588         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3589         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3590
3591         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3592         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3593         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3594         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3595         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3596         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3597         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
3598         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
3599         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3600
3601         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3602         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
3603
3604         { }
3605 };
3606
3607 /*
3608 * Uniwill P53
3609 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
3610  */
3611 static const struct hda_verb alc880_uniwill_p53_init_verbs[] = {
3612         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3613
3614         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3615         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3616         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3617         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3618         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3619         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3620         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3621         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3622         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3623         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3624         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3625         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3626
3627         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3628         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3629         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3630         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3631         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3632         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3633
3634         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3635         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
3636
3637         { }
3638 };
3639
3640 static const struct hda_verb alc880_beep_init_verbs[] = {
3641         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
3642         { }
3643 };
3644
3645 /* auto-toggle front mic */
3646 static void alc88x_simple_mic_automute(struct hda_codec *codec)
3647 {
3648         unsigned int present;
3649         unsigned char bits;
3650
3651         present = snd_hda_jack_detect(codec, 0x18);
3652         bits = present ? HDA_AMP_MUTE : 0;
3653         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
3654 }
3655
3656 static void alc880_uniwill_setup(struct hda_codec *codec)
3657 {
3658         struct alc_spec *spec = codec->spec;
3659
3660         spec->autocfg.hp_pins[0] = 0x14;
3661         spec->autocfg.speaker_pins[0] = 0x15;
3662         spec->autocfg.speaker_pins[0] = 0x16;
3663         spec->automute = 1;
3664         spec->automute_mode = ALC_AUTOMUTE_AMP;
3665 }
3666
3667 static void alc880_uniwill_init_hook(struct hda_codec *codec)
3668 {
3669         alc_hp_automute(codec);
3670         alc88x_simple_mic_automute(codec);
3671 }
3672
3673 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
3674                                        unsigned int res)
3675 {
3676         /* Looks like the unsol event is incompatible with the standard
3677          * definition.  4bit tag is placed at 28 bit!
3678          */
3679         switch (res >> 28) {
3680         case ALC880_MIC_EVENT:
3681                 alc88x_simple_mic_automute(codec);
3682                 break;
3683         default:
3684                 alc_sku_unsol_event(codec, res);
3685                 break;
3686         }
3687 }
3688
3689 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
3690 {
3691         struct alc_spec *spec = codec->spec;
3692
3693         spec->autocfg.hp_pins[0] = 0x14;
3694         spec->autocfg.speaker_pins[0] = 0x15;
3695         spec->automute = 1;
3696         spec->automute_mode = ALC_AUTOMUTE_AMP;
3697 }
3698
3699 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
3700 {
3701         unsigned int present;
3702
3703         present = snd_hda_codec_read(codec, 0x21, 0,
3704                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
3705         present &= HDA_AMP_VOLMASK;
3706         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
3707                                  HDA_AMP_VOLMASK, present);
3708         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
3709                                  HDA_AMP_VOLMASK, present);
3710 }
3711
3712 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
3713                                            unsigned int res)
3714 {
3715         /* Looks like the unsol event is incompatible with the standard
3716          * definition.  4bit tag is placed at 28 bit!
3717          */
3718         if ((res >> 28) == ALC880_DCVOL_EVENT)
3719                 alc880_uniwill_p53_dcvol_automute(codec);
3720         else
3721                 alc_sku_unsol_event(codec, res);
3722 }
3723
3724 /*
3725  * F1734 pin configuration:
3726  * HP = 0x14, speaker-out = 0x15, mic = 0x18
3727  */
3728 static const struct hda_verb alc880_pin_f1734_init_verbs[] = {
3729         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
3730         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3731         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3732         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3733         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3734
3735         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3736         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3737         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3738         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3739
3740         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3741         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3742         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3743         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3744         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3745         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3746         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3747         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3748         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3749
3750         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
3751         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
3752
3753         { }
3754 };
3755
3756 /*
3757  * ASUS pin configuration:
3758  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
3759  */
3760 static const struct hda_verb alc880_pin_asus_init_verbs[] = {
3761         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3762         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3763         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3764         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3765
3766         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3767         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3768         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3769         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3770         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3771         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3772         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3773         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3774
3775         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3776         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3777         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3778         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3779         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3780         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3781         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3782         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3783         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3784
3785         { }
3786 };
3787
3788 /* Enable GPIO mask and set output */
3789 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
3790 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
3791 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
3792
3793 /* Clevo m520g init */
3794 static const struct hda_verb alc880_pin_clevo_init_verbs[] = {
3795         /* headphone output */
3796         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3797         /* line-out */
3798         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3799         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3800         /* Line-in */
3801         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3802         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3803         /* CD */
3804         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3805         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3806         /* Mic1 (rear panel) */
3807         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3808         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3809         /* Mic2 (front panel) */
3810         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3811         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3812         /* headphone */
3813         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3814         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3815         /* change to EAPD mode */
3816         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3817         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3818
3819         { }
3820 };
3821
3822 static const struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
3823         /* change to EAPD mode */
3824         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3825         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3826
3827         /* Headphone output */
3828         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3829         /* Front output*/
3830         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3831         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
3832
3833         /* Line In pin widget for input */
3834         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3835         /* CD pin widget for input */
3836         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3837         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3838         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3839
3840         /* change to EAPD mode */
3841         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3842         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
3843
3844         { }
3845 };
3846
3847 /*
3848  * LG m1 express dual
3849  *
3850  * Pin assignment:
3851  *   Rear Line-In/Out (blue): 0x14
3852  *   Build-in Mic-In: 0x15
3853  *   Speaker-out: 0x17
3854  *   HP-Out (green): 0x1b
3855  *   Mic-In/Out (red): 0x19
3856  *   SPDIF-Out: 0x1e
3857  */
3858
3859 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
3860 static const hda_nid_t alc880_lg_dac_nids[3] = {
3861         0x05, 0x02, 0x03
3862 };
3863
3864 /* seems analog CD is not working */
3865 static const struct hda_input_mux alc880_lg_capture_source = {
3866         .num_items = 3,
3867         .items = {
3868                 { "Mic", 0x1 },
3869                 { "Line", 0x5 },
3870                 { "Internal Mic", 0x6 },
3871         },
3872 };
3873
3874 /* 2,4,6 channel modes */
3875 static const struct hda_verb alc880_lg_ch2_init[] = {
3876         /* set line-in and mic-in to input */
3877         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3878         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3879         { }
3880 };
3881
3882 static const struct hda_verb alc880_lg_ch4_init[] = {
3883         /* set line-in to out and mic-in to input */
3884         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3885         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3886         { }
3887 };
3888
3889 static const struct hda_verb alc880_lg_ch6_init[] = {
3890         /* set line-in and mic-in to output */
3891         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3892         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3893         { }
3894 };
3895
3896 static const struct hda_channel_mode alc880_lg_ch_modes[3] = {
3897         { 2, alc880_lg_ch2_init },
3898         { 4, alc880_lg_ch4_init },
3899         { 6, alc880_lg_ch6_init },
3900 };
3901
3902 static const struct snd_kcontrol_new alc880_lg_mixer[] = {
3903         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3904         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3905         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3906         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3907         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3908         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3909         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3910         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3911         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3912         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3913         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3914         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3915         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3916         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3917         {
3918                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3919                 .name = "Channel Mode",
3920                 .info = alc_ch_mode_info,
3921                 .get = alc_ch_mode_get,
3922                 .put = alc_ch_mode_put,
3923         },
3924         { } /* end */
3925 };
3926
3927 static const struct hda_verb alc880_lg_init_verbs[] = {
3928         /* set capture source to mic-in */
3929         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3930         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3931         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3932         /* mute all amp mixer inputs */
3933         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3934         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3935         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3936         /* line-in to input */
3937         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3938         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3939         /* built-in mic */
3940         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3941         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3942         /* speaker-out */
3943         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3944         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3945         /* mic-in to input */
3946         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3947         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3948         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3949         /* HP-out */
3950         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3951         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3952         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3953         /* jack sense */
3954         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3955         { }
3956 };
3957
3958 /* toggle speaker-output according to the hp-jack state */
3959 static void alc880_lg_setup(struct hda_codec *codec)
3960 {
3961         struct alc_spec *spec = codec->spec;
3962
3963         spec->autocfg.hp_pins[0] = 0x1b;
3964         spec->autocfg.speaker_pins[0] = 0x17;
3965         spec->automute = 1;
3966         spec->automute_mode = ALC_AUTOMUTE_AMP;
3967 }
3968
3969 /*
3970  * LG LW20
3971  *
3972  * Pin assignment:
3973  *   Speaker-out: 0x14
3974  *   Mic-In: 0x18
3975  *   Built-in Mic-In: 0x19
3976  *   Line-In: 0x1b
3977  *   HP-Out: 0x1a
3978  *   SPDIF-Out: 0x1e
3979  */
3980
3981 static const struct hda_input_mux alc880_lg_lw_capture_source = {
3982         .num_items = 3,
3983         .items = {
3984                 { "Mic", 0x0 },
3985                 { "Internal Mic", 0x1 },
3986                 { "Line In", 0x2 },
3987         },
3988 };
3989
3990 #define alc880_lg_lw_modes alc880_threestack_modes
3991
3992 static const struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3993         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3994         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3995         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3996         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3997         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3998         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3999         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4000         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4001         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4002         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4003         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4004         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4005         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
4006         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
4007         {
4008                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4009                 .name = "Channel Mode",
4010                 .info = alc_ch_mode_info,
4011                 .get = alc_ch_mode_get,
4012                 .put = alc_ch_mode_put,
4013         },
4014         { } /* end */
4015 };
4016
4017 static const struct hda_verb alc880_lg_lw_init_verbs[] = {
4018         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
4019         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
4020         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
4021
4022         /* set capture source to mic-in */
4023         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4024         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4025         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4026         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4027         /* speaker-out */
4028         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4029         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4030         /* HP-out */
4031         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4032         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4033         /* mic-in to input */
4034         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4035         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4036         /* built-in mic */
4037         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4038         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4039         /* jack sense */
4040         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4041         { }
4042 };
4043
4044 /* toggle speaker-output according to the hp-jack state */
4045 static void alc880_lg_lw_setup(struct hda_codec *codec)
4046 {
4047         struct alc_spec *spec = codec->spec;
4048
4049         spec->autocfg.hp_pins[0] = 0x1b;
4050         spec->autocfg.speaker_pins[0] = 0x14;
4051         spec->automute = 1;
4052         spec->automute_mode = ALC_AUTOMUTE_AMP;
4053 }
4054
4055 static const struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
4056         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4057         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
4058         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4059         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4060         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4061         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
4062         { } /* end */
4063 };
4064
4065 static const struct hda_input_mux alc880_medion_rim_capture_source = {
4066         .num_items = 2,
4067         .items = {
4068                 { "Mic", 0x0 },
4069                 { "Internal Mic", 0x1 },
4070         },
4071 };
4072
4073 static const struct hda_verb alc880_medion_rim_init_verbs[] = {
4074         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
4075
4076         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4077         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4078
4079         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4080         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4081         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4082         /* Mic2 (as headphone out) for HP output */
4083         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4084         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4085         /* Internal Speaker */
4086         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4087         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4088
4089         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
4090         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
4091
4092         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4093         { }
4094 };
4095
4096 /* toggle speaker-output according to the hp-jack state */
4097 static void alc880_medion_rim_automute(struct hda_codec *codec)
4098 {
4099         struct alc_spec *spec = codec->spec;
4100         alc_hp_automute(codec);
4101         /* toggle EAPD */
4102         if (spec->jack_present)
4103                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
4104         else
4105                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
4106 }
4107
4108 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
4109                                           unsigned int res)
4110 {
4111         /* Looks like the unsol event is incompatible with the standard
4112          * definition.  4bit tag is placed at 28 bit!
4113          */
4114         if ((res >> 28) == ALC880_HP_EVENT)
4115                 alc880_medion_rim_automute(codec);
4116 }
4117
4118 static void alc880_medion_rim_setup(struct hda_codec *codec)
4119 {
4120         struct alc_spec *spec = codec->spec;
4121
4122         spec->autocfg.hp_pins[0] = 0x14;
4123         spec->autocfg.speaker_pins[0] = 0x1b;
4124         spec->automute = 1;
4125         spec->automute_mode = ALC_AUTOMUTE_AMP;
4126 }
4127
4128 #ifdef CONFIG_SND_HDA_POWER_SAVE
4129 static const struct hda_amp_list alc880_loopbacks[] = {
4130         { 0x0b, HDA_INPUT, 0 },
4131         { 0x0b, HDA_INPUT, 1 },
4132         { 0x0b, HDA_INPUT, 2 },
4133         { 0x0b, HDA_INPUT, 3 },
4134         { 0x0b, HDA_INPUT, 4 },
4135         { } /* end */
4136 };
4137
4138 static const struct hda_amp_list alc880_lg_loopbacks[] = {
4139         { 0x0b, HDA_INPUT, 1 },
4140         { 0x0b, HDA_INPUT, 6 },
4141         { 0x0b, HDA_INPUT, 7 },
4142         { } /* end */
4143 };
4144 #endif
4145
4146 /*
4147  * Common callbacks
4148  */
4149
4150 static void alc_init_special_input_src(struct hda_codec *codec);
4151
4152 static int alc_init(struct hda_codec *codec)
4153 {
4154         struct alc_spec *spec = codec->spec;
4155         unsigned int i;
4156
4157         alc_fix_pll(codec);
4158         alc_auto_init_amp(codec, spec->init_amp);
4159
4160         for (i = 0; i < spec->num_init_verbs; i++)
4161                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
4162         alc_init_special_input_src(codec);
4163
4164         if (spec->init_hook)
4165                 spec->init_hook(codec);
4166
4167         alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
4168
4169         hda_call_check_power_status(codec, 0x01);
4170         return 0;
4171 }
4172
4173 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
4174 {
4175         struct alc_spec *spec = codec->spec;
4176
4177         if (spec->unsol_event)
4178                 spec->unsol_event(codec, res);
4179 }
4180
4181 #ifdef CONFIG_SND_HDA_POWER_SAVE
4182 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
4183 {
4184         struct alc_spec *spec = codec->spec;
4185         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
4186 }
4187 #endif
4188
4189 /*
4190  * Analog playback callbacks
4191  */
4192 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
4193                                     struct hda_codec *codec,
4194                                     struct snd_pcm_substream *substream)
4195 {
4196         struct alc_spec *spec = codec->spec;
4197         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
4198                                              hinfo);
4199 }
4200
4201 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4202                                        struct hda_codec *codec,
4203                                        unsigned int stream_tag,
4204                                        unsigned int format,
4205                                        struct snd_pcm_substream *substream)
4206 {
4207         struct alc_spec *spec = codec->spec;
4208         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
4209                                                 stream_tag, format, substream);
4210 }
4211
4212 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4213                                        struct hda_codec *codec,
4214                                        struct snd_pcm_substream *substream)
4215 {
4216         struct alc_spec *spec = codec->spec;
4217         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
4218 }
4219
4220 /*
4221  * Digital out
4222  */
4223 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
4224                                         struct hda_codec *codec,
4225                                         struct snd_pcm_substream *substream)
4226 {
4227         struct alc_spec *spec = codec->spec;
4228         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
4229 }
4230
4231 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
4232                                            struct hda_codec *codec,
4233                                            unsigned int stream_tag,
4234                                            unsigned int format,
4235                                            struct snd_pcm_substream *substream)
4236 {
4237         struct alc_spec *spec = codec->spec;
4238         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
4239                                              stream_tag, format, substream);
4240 }
4241
4242 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
4243                                            struct hda_codec *codec,
4244                                            struct snd_pcm_substream *substream)
4245 {
4246         struct alc_spec *spec = codec->spec;
4247         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
4248 }
4249
4250 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
4251                                          struct hda_codec *codec,
4252                                          struct snd_pcm_substream *substream)
4253 {
4254         struct alc_spec *spec = codec->spec;
4255         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
4256 }
4257
4258 /*
4259  * Analog capture
4260  */
4261 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4262                                       struct hda_codec *codec,
4263                                       unsigned int stream_tag,
4264                                       unsigned int format,
4265                                       struct snd_pcm_substream *substream)
4266 {
4267         struct alc_spec *spec = codec->spec;
4268
4269         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
4270                                    stream_tag, 0, format);
4271         return 0;
4272 }
4273
4274 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4275                                       struct hda_codec *codec,
4276                                       struct snd_pcm_substream *substream)
4277 {
4278         struct alc_spec *spec = codec->spec;
4279
4280         snd_hda_codec_cleanup_stream(codec,
4281                                      spec->adc_nids[substream->number + 1]);
4282         return 0;
4283 }
4284
4285 /* analog capture with dynamic dual-adc changes */
4286 static int dualmic_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
4287                                        struct hda_codec *codec,
4288                                        unsigned int stream_tag,
4289                                        unsigned int format,
4290                                        struct snd_pcm_substream *substream)
4291 {
4292         struct alc_spec *spec = codec->spec;
4293         spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
4294         spec->cur_adc_stream_tag = stream_tag;
4295         spec->cur_adc_format = format;
4296         snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
4297         return 0;
4298 }
4299
4300 static int dualmic_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4301                                        struct hda_codec *codec,
4302                                        struct snd_pcm_substream *substream)
4303 {
4304         struct alc_spec *spec = codec->spec;
4305         snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4306         spec->cur_adc = 0;
4307         return 0;
4308 }
4309
4310 static const struct hda_pcm_stream dualmic_pcm_analog_capture = {
4311         .substreams = 1,
4312         .channels_min = 2,
4313         .channels_max = 2,
4314         .nid = 0, /* fill later */
4315         .ops = {
4316                 .prepare = dualmic_capture_pcm_prepare,
4317                 .cleanup = dualmic_capture_pcm_cleanup
4318         },
4319 };
4320
4321 /*
4322  */
4323 static const struct hda_pcm_stream alc880_pcm_analog_playback = {
4324         .substreams = 1,
4325         .channels_min = 2,
4326         .channels_max = 8,
4327         /* NID is set in alc_build_pcms */
4328         .ops = {
4329                 .open = alc880_playback_pcm_open,
4330                 .prepare = alc880_playback_pcm_prepare,
4331                 .cleanup = alc880_playback_pcm_cleanup
4332         },
4333 };
4334
4335 static const struct hda_pcm_stream alc880_pcm_analog_capture = {
4336         .substreams = 1,
4337         .channels_min = 2,
4338         .channels_max = 2,
4339         /* NID is set in alc_build_pcms */
4340 };
4341
4342 static const struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
4343         .substreams = 1,
4344         .channels_min = 2,
4345         .channels_max = 2,
4346         /* NID is set in alc_build_pcms */
4347 };
4348
4349 static const struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
4350         .substreams = 2, /* can be overridden */
4351         .channels_min = 2,
4352         .channels_max = 2,
4353         /* NID is set in alc_build_pcms */
4354         .ops = {
4355                 .prepare = alc880_alt_capture_pcm_prepare,
4356                 .cleanup = alc880_alt_capture_pcm_cleanup
4357         },
4358 };
4359
4360 static const struct hda_pcm_stream alc880_pcm_digital_playback = {
4361         .substreams = 1,
4362         .channels_min = 2,
4363         .channels_max = 2,
4364         /* NID is set in alc_build_pcms */
4365         .ops = {
4366                 .open = alc880_dig_playback_pcm_open,
4367                 .close = alc880_dig_playback_pcm_close,
4368                 .prepare = alc880_dig_playback_pcm_prepare,
4369                 .cleanup = alc880_dig_playback_pcm_cleanup
4370         },
4371 };
4372
4373 static const struct hda_pcm_stream alc880_pcm_digital_capture = {
4374         .substreams = 1,
4375         .channels_min = 2,
4376         .channels_max = 2,
4377         /* NID is set in alc_build_pcms */
4378 };
4379
4380 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
4381 static const struct hda_pcm_stream alc_pcm_null_stream = {
4382         .substreams = 0,
4383         .channels_min = 0,
4384         .channels_max = 0,
4385 };
4386
4387 static int alc_build_pcms(struct hda_codec *codec)
4388 {
4389         struct alc_spec *spec = codec->spec;
4390         struct hda_pcm *info = spec->pcm_rec;
4391         int i;
4392
4393         codec->num_pcms = 1;
4394         codec->pcm_info = info;
4395
4396         if (spec->no_analog)
4397                 goto skip_analog;
4398
4399         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
4400                  "%s Analog", codec->chip_name);
4401         info->name = spec->stream_name_analog;
4402
4403         if (spec->stream_analog_playback) {
4404                 if (snd_BUG_ON(!spec->multiout.dac_nids))
4405                         return -EINVAL;
4406                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
4407                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
4408         }
4409         if (spec->stream_analog_capture) {
4410                 if (snd_BUG_ON(!spec->adc_nids))
4411                         return -EINVAL;
4412                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
4413                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4414         }
4415
4416         if (spec->channel_mode) {
4417                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
4418                 for (i = 0; i < spec->num_channel_mode; i++) {
4419                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
4420                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
4421                         }
4422                 }
4423         }
4424
4425  skip_analog:
4426         /* SPDIF for stream index #1 */
4427         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
4428                 snprintf(spec->stream_name_digital,
4429                          sizeof(spec->stream_name_digital),
4430                          "%s Digital", codec->chip_name);
4431                 codec->num_pcms = 2;
4432                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
4433                 info = spec->pcm_rec + 1;
4434                 info->name = spec->stream_name_digital;
4435                 if (spec->dig_out_type)
4436                         info->pcm_type = spec->dig_out_type;
4437                 else
4438                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
4439                 if (spec->multiout.dig_out_nid &&
4440                     spec->stream_digital_playback) {
4441                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
4442                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
4443                 }
4444                 if (spec->dig_in_nid &&
4445                     spec->stream_digital_capture) {
4446                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
4447                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
4448                 }
4449                 /* FIXME: do we need this for all Realtek codec models? */
4450                 codec->spdif_status_reset = 1;
4451         }
4452
4453         if (spec->no_analog)
4454                 return 0;
4455
4456         /* If the use of more than one ADC is requested for the current
4457          * model, configure a second analog capture-only PCM.
4458          */
4459         /* Additional Analaog capture for index #2 */
4460         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
4461             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
4462                 codec->num_pcms = 3;
4463                 info = spec->pcm_rec + 2;
4464                 info->name = spec->stream_name_analog;
4465                 if (spec->alt_dac_nid) {
4466                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4467                                 *spec->stream_analog_alt_playback;
4468                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
4469                                 spec->alt_dac_nid;
4470                 } else {
4471                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4472                                 alc_pcm_null_stream;
4473                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
4474                 }
4475                 if (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture) {
4476                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4477                                 *spec->stream_analog_alt_capture;
4478                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
4479                                 spec->adc_nids[1];
4480                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
4481                                 spec->num_adc_nids - 1;
4482                 } else {
4483                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4484                                 alc_pcm_null_stream;
4485                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
4486                 }
4487         }
4488
4489         return 0;
4490 }
4491
4492 static inline void alc_shutup(struct hda_codec *codec)
4493 {
4494         struct alc_spec *spec = codec->spec;
4495
4496         if (spec && spec->shutup)
4497                 spec->shutup(codec);
4498         snd_hda_shutup_pins(codec);
4499 }
4500
4501 static void alc_free_kctls(struct hda_codec *codec)
4502 {
4503         struct alc_spec *spec = codec->spec;
4504
4505         if (spec->kctls.list) {
4506                 struct snd_kcontrol_new *kctl = spec->kctls.list;
4507                 int i;
4508                 for (i = 0; i < spec->kctls.used; i++)
4509                         kfree(kctl[i].name);
4510         }
4511         snd_array_free(&spec->kctls);
4512 }
4513
4514 static void alc_free(struct hda_codec *codec)
4515 {
4516         struct alc_spec *spec = codec->spec;
4517
4518         if (!spec)
4519                 return;
4520
4521         alc_shutup(codec);
4522         snd_hda_input_jack_free(codec);
4523         alc_free_kctls(codec);
4524         kfree(spec);
4525         snd_hda_detach_beep_device(codec);
4526 }
4527
4528 #ifdef CONFIG_SND_HDA_POWER_SAVE
4529 static void alc_power_eapd(struct hda_codec *codec)
4530 {
4531         alc_auto_setup_eapd(codec, false);
4532 }
4533
4534 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
4535 {
4536         struct alc_spec *spec = codec->spec;
4537         alc_shutup(codec);
4538         if (spec && spec->power_hook)
4539                 spec->power_hook(codec);
4540         return 0;
4541 }
4542 #endif
4543
4544 #ifdef SND_HDA_NEEDS_RESUME
4545 static int alc_resume(struct hda_codec *codec)
4546 {
4547         msleep(150); /* to avoid pop noise */
4548         codec->patch_ops.init(codec);
4549         snd_hda_codec_resume_amp(codec);
4550         snd_hda_codec_resume_cache(codec);
4551         hda_call_check_power_status(codec, 0x01);
4552         return 0;
4553 }
4554 #endif
4555
4556 /*
4557  */
4558 static const struct hda_codec_ops alc_patch_ops = {
4559         .build_controls = alc_build_controls,
4560         .build_pcms = alc_build_pcms,
4561         .init = alc_init,
4562         .free = alc_free,
4563         .unsol_event = alc_unsol_event,
4564 #ifdef SND_HDA_NEEDS_RESUME
4565         .resume = alc_resume,
4566 #endif
4567 #ifdef CONFIG_SND_HDA_POWER_SAVE
4568         .suspend = alc_suspend,
4569         .check_power_status = alc_check_power_status,
4570 #endif
4571         .reboot_notify = alc_shutup,
4572 };
4573
4574 /* replace the codec chip_name with the given string */
4575 static int alc_codec_rename(struct hda_codec *codec, const char *name)
4576 {
4577         kfree(codec->chip_name);
4578         codec->chip_name = kstrdup(name, GFP_KERNEL);
4579         if (!codec->chip_name) {
4580                 alc_free(codec);
4581                 return -ENOMEM;
4582         }
4583         return 0;
4584 }
4585
4586 /*
4587  * Test configuration for debugging
4588  *
4589  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
4590  * enum controls.
4591  */
4592 #ifdef CONFIG_SND_DEBUG
4593 static const hda_nid_t alc880_test_dac_nids[4] = {
4594         0x02, 0x03, 0x04, 0x05
4595 };
4596
4597 static const struct hda_input_mux alc880_test_capture_source = {
4598         .num_items = 7,
4599         .items = {
4600                 { "In-1", 0x0 },
4601                 { "In-2", 0x1 },
4602                 { "In-3", 0x2 },
4603                 { "In-4", 0x3 },
4604                 { "CD", 0x4 },
4605                 { "Front", 0x5 },
4606                 { "Surround", 0x6 },
4607         },
4608 };
4609
4610 static const struct hda_channel_mode alc880_test_modes[4] = {
4611         { 2, NULL },
4612         { 4, NULL },
4613         { 6, NULL },
4614         { 8, NULL },
4615 };
4616
4617 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
4618                                  struct snd_ctl_elem_info *uinfo)
4619 {
4620         static const char * const texts[] = {
4621                 "N/A", "Line Out", "HP Out",
4622                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
4623         };
4624         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4625         uinfo->count = 1;
4626         uinfo->value.enumerated.items = 8;
4627         if (uinfo->value.enumerated.item >= 8)
4628                 uinfo->value.enumerated.item = 7;
4629         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4630         return 0;
4631 }
4632
4633 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
4634                                 struct snd_ctl_elem_value *ucontrol)
4635 {
4636         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4637         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4638         unsigned int pin_ctl, item = 0;
4639
4640         pin_ctl = snd_hda_codec_read(codec, nid, 0,
4641                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4642         if (pin_ctl & AC_PINCTL_OUT_EN) {
4643                 if (pin_ctl & AC_PINCTL_HP_EN)
4644                         item = 2;
4645                 else
4646                         item = 1;
4647         } else if (pin_ctl & AC_PINCTL_IN_EN) {
4648                 switch (pin_ctl & AC_PINCTL_VREFEN) {
4649                 case AC_PINCTL_VREF_HIZ: item = 3; break;
4650                 case AC_PINCTL_VREF_50:  item = 4; break;
4651                 case AC_PINCTL_VREF_GRD: item = 5; break;
4652                 case AC_PINCTL_VREF_80:  item = 6; break;
4653                 case AC_PINCTL_VREF_100: item = 7; break;
4654                 }
4655         }
4656         ucontrol->value.enumerated.item[0] = item;
4657         return 0;
4658 }
4659
4660 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
4661                                 struct snd_ctl_elem_value *ucontrol)
4662 {
4663         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4664         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4665         static const unsigned int ctls[] = {
4666                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
4667                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
4668                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
4669                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
4670                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
4671                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
4672         };
4673         unsigned int old_ctl, new_ctl;
4674
4675         old_ctl = snd_hda_codec_read(codec, nid, 0,
4676                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4677         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
4678         if (old_ctl != new_ctl) {
4679                 int val;
4680                 snd_hda_codec_write_cache(codec, nid, 0,
4681                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4682                                           new_ctl);
4683                 val = ucontrol->value.enumerated.item[0] >= 3 ?
4684                         HDA_AMP_MUTE : 0;
4685                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4686                                          HDA_AMP_MUTE, val);
4687                 return 1;
4688         }
4689         return 0;
4690 }
4691
4692 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
4693                                  struct snd_ctl_elem_info *uinfo)
4694 {
4695         static const char * const texts[] = {
4696                 "Front", "Surround", "CLFE", "Side"
4697         };
4698         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4699         uinfo->count = 1;
4700         uinfo->value.enumerated.items = 4;
4701         if (uinfo->value.enumerated.item >= 4)
4702                 uinfo->value.enumerated.item = 3;
4703         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4704         return 0;
4705 }
4706
4707 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
4708                                 struct snd_ctl_elem_value *ucontrol)
4709 {
4710         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4711         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4712         unsigned int sel;
4713
4714         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
4715         ucontrol->value.enumerated.item[0] = sel & 3;
4716         return 0;
4717 }
4718
4719 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
4720                                 struct snd_ctl_elem_value *ucontrol)
4721 {
4722         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4723         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4724         unsigned int sel;
4725
4726         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
4727         if (ucontrol->value.enumerated.item[0] != sel) {
4728                 sel = ucontrol->value.enumerated.item[0] & 3;
4729                 snd_hda_codec_write_cache(codec, nid, 0,
4730                                           AC_VERB_SET_CONNECT_SEL, sel);
4731                 return 1;
4732         }
4733         return 0;
4734 }
4735
4736 #define PIN_CTL_TEST(xname,nid) {                       \
4737                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4738                         .name = xname,                 \
4739                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4740                         .info = alc_test_pin_ctl_info, \
4741                         .get = alc_test_pin_ctl_get,   \
4742                         .put = alc_test_pin_ctl_put,   \
4743                         .private_value = nid           \
4744                         }
4745
4746 #define PIN_SRC_TEST(xname,nid) {                       \
4747                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4748                         .name = xname,                 \
4749                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4750                         .info = alc_test_pin_src_info, \
4751                         .get = alc_test_pin_src_get,   \
4752                         .put = alc_test_pin_src_put,   \
4753                         .private_value = nid           \
4754                         }
4755
4756 static const struct snd_kcontrol_new alc880_test_mixer[] = {
4757         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4758         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4759         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
4760         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4761         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4762         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4763         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
4764         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4765         PIN_CTL_TEST("Front Pin Mode", 0x14),
4766         PIN_CTL_TEST("Surround Pin Mode", 0x15),
4767         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
4768         PIN_CTL_TEST("Side Pin Mode", 0x17),
4769         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
4770         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
4771         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
4772         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
4773         PIN_SRC_TEST("In-1 Pin Source", 0x18),
4774         PIN_SRC_TEST("In-2 Pin Source", 0x19),
4775         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
4776         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
4777         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
4778         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
4779         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
4780         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
4781         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
4782         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
4783         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
4784         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
4785         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
4786         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
4787         {
4788                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4789                 .name = "Channel Mode",
4790                 .info = alc_ch_mode_info,
4791                 .get = alc_ch_mode_get,
4792                 .put = alc_ch_mode_put,
4793         },
4794         { } /* end */
4795 };
4796
4797 static const struct hda_verb alc880_test_init_verbs[] = {
4798         /* Unmute inputs of 0x0c - 0x0f */
4799         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4800         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4801         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4802         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4803         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4804         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4805         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4806         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4807         /* Vol output for 0x0c-0x0f */
4808         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4809         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4810         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4811         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4812         /* Set output pins 0x14-0x17 */
4813         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4814         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4815         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4816         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4817         /* Unmute output pins 0x14-0x17 */
4818         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4819         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4820         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4821         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4822         /* Set input pins 0x18-0x1c */
4823         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4824         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4825         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4826         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4827         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4828         /* Mute input pins 0x18-0x1b */
4829         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4830         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4831         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4832         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4833         /* ADC set up */
4834         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4835         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4836         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4837         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4838         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4839         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4840         /* Analog input/passthru */
4841         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4842         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4843         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4844         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4845         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4846         { }
4847 };
4848 #endif
4849
4850 /*
4851  */
4852
4853 static const char * const alc880_models[ALC880_MODEL_LAST] = {
4854         [ALC880_3ST]            = "3stack",
4855         [ALC880_TCL_S700]       = "tcl",
4856         [ALC880_3ST_DIG]        = "3stack-digout",
4857         [ALC880_CLEVO]          = "clevo",
4858         [ALC880_5ST]            = "5stack",
4859         [ALC880_5ST_DIG]        = "5stack-digout",
4860         [ALC880_W810]           = "w810",
4861         [ALC880_Z71V]           = "z71v",
4862         [ALC880_6ST]            = "6stack",
4863         [ALC880_6ST_DIG]        = "6stack-digout",
4864         [ALC880_ASUS]           = "asus",
4865         [ALC880_ASUS_W1V]       = "asus-w1v",
4866         [ALC880_ASUS_DIG]       = "asus-dig",
4867         [ALC880_ASUS_DIG2]      = "asus-dig2",
4868         [ALC880_UNIWILL_DIG]    = "uniwill",
4869         [ALC880_UNIWILL_P53]    = "uniwill-p53",
4870         [ALC880_FUJITSU]        = "fujitsu",
4871         [ALC880_F1734]          = "F1734",
4872         [ALC880_LG]             = "lg",
4873         [ALC880_LG_LW]          = "lg-lw",
4874         [ALC880_MEDION_RIM]     = "medion",
4875 #ifdef CONFIG_SND_DEBUG
4876         [ALC880_TEST]           = "test",
4877 #endif
4878         [ALC880_AUTO]           = "auto",
4879 };
4880
4881 static const struct snd_pci_quirk alc880_cfg_tbl[] = {
4882         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
4883         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
4884         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
4885         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
4886         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
4887         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
4888         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
4889         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
4890         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
4891         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
4892         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
4893         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
4894         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
4895         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
4896         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
4897         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
4898         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
4899         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
4900         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
4901         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
4902         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
4903         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
4904         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
4905         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
4906         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
4907         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
4908         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
4909         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
4910         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
4911         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
4912         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
4913         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
4914         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
4915         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
4916         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
4917         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
4918         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
4919         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
4920         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
4921         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_F1734),
4922         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
4923         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
4924         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
4925         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
4926         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
4927         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
4928         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
4929         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
4930         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_F1734),
4931         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
4932         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
4933         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
4934         SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_LG),
4935         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
4936         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
4937         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
4938         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
4939         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
4940         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
4941         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
4942         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
4943         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
4944         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
4945         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
4946         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
4947         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
4948         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
4949         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
4950         /* default Intel */
4951         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
4952         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
4953         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
4954         {}
4955 };
4956
4957 /*
4958  * ALC880 codec presets
4959  */
4960 static const struct alc_config_preset alc880_presets[] = {
4961         [ALC880_3ST] = {
4962                 .mixers = { alc880_three_stack_mixer },
4963                 .init_verbs = { alc880_volume_init_verbs,
4964                                 alc880_pin_3stack_init_verbs },
4965                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4966                 .dac_nids = alc880_dac_nids,
4967                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4968                 .channel_mode = alc880_threestack_modes,
4969                 .need_dac_fix = 1,
4970                 .input_mux = &alc880_capture_source,
4971         },
4972         [ALC880_3ST_DIG] = {
4973                 .mixers = { alc880_three_stack_mixer },
4974                 .init_verbs = { alc880_volume_init_verbs,
4975                                 alc880_pin_3stack_init_verbs },
4976                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4977                 .dac_nids = alc880_dac_nids,
4978                 .dig_out_nid = ALC880_DIGOUT_NID,
4979                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4980                 .channel_mode = alc880_threestack_modes,
4981                 .need_dac_fix = 1,
4982                 .input_mux = &alc880_capture_source,
4983         },
4984         [ALC880_TCL_S700] = {
4985                 .mixers = { alc880_tcl_s700_mixer },
4986                 .init_verbs = { alc880_volume_init_verbs,
4987                                 alc880_pin_tcl_S700_init_verbs,
4988                                 alc880_gpio2_init_verbs },
4989                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4990                 .dac_nids = alc880_dac_nids,
4991                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4992                 .num_adc_nids = 1, /* single ADC */
4993                 .hp_nid = 0x03,
4994                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4995                 .channel_mode = alc880_2_jack_modes,
4996                 .input_mux = &alc880_capture_source,
4997         },
4998         [ALC880_5ST] = {
4999                 .mixers = { alc880_three_stack_mixer,
5000                             alc880_five_stack_mixer},
5001                 .init_verbs = { alc880_volume_init_verbs,
5002                                 alc880_pin_5stack_init_verbs },
5003                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5004                 .dac_nids = alc880_dac_nids,
5005                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
5006                 .channel_mode = alc880_fivestack_modes,
5007                 .input_mux = &alc880_capture_source,
5008         },
5009         [ALC880_5ST_DIG] = {
5010                 .mixers = { alc880_three_stack_mixer,
5011                             alc880_five_stack_mixer },
5012                 .init_verbs = { alc880_volume_init_verbs,
5013                                 alc880_pin_5stack_init_verbs },
5014                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5015                 .dac_nids = alc880_dac_nids,
5016                 .dig_out_nid = ALC880_DIGOUT_NID,
5017                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
5018                 .channel_mode = alc880_fivestack_modes,
5019                 .input_mux = &alc880_capture_source,
5020         },
5021         [ALC880_6ST] = {
5022                 .mixers = { alc880_six_stack_mixer },
5023                 .init_verbs = { alc880_volume_init_verbs,
5024                                 alc880_pin_6stack_init_verbs },
5025                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
5026                 .dac_nids = alc880_6st_dac_nids,
5027                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
5028                 .channel_mode = alc880_sixstack_modes,
5029                 .input_mux = &alc880_6stack_capture_source,
5030         },
5031         [ALC880_6ST_DIG] = {
5032                 .mixers = { alc880_six_stack_mixer },
5033                 .init_verbs = { alc880_volume_init_verbs,
5034                                 alc880_pin_6stack_init_verbs },
5035                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
5036                 .dac_nids = alc880_6st_dac_nids,
5037                 .dig_out_nid = ALC880_DIGOUT_NID,
5038                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
5039                 .channel_mode = alc880_sixstack_modes,
5040                 .input_mux = &alc880_6stack_capture_source,
5041         },
5042         [ALC880_W810] = {
5043                 .mixers = { alc880_w810_base_mixer },
5044                 .init_verbs = { alc880_volume_init_verbs,
5045                                 alc880_pin_w810_init_verbs,
5046                                 alc880_gpio2_init_verbs },
5047                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
5048                 .dac_nids = alc880_w810_dac_nids,
5049                 .dig_out_nid = ALC880_DIGOUT_NID,
5050                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
5051                 .channel_mode = alc880_w810_modes,
5052                 .input_mux = &alc880_capture_source,
5053         },
5054         [ALC880_Z71V] = {
5055                 .mixers = { alc880_z71v_mixer },
5056                 .init_verbs = { alc880_volume_init_verbs,
5057                                 alc880_pin_z71v_init_verbs },
5058                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
5059                 .dac_nids = alc880_z71v_dac_nids,
5060                 .dig_out_nid = ALC880_DIGOUT_NID,
5061                 .hp_nid = 0x03,
5062                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5063                 .channel_mode = alc880_2_jack_modes,
5064                 .input_mux = &alc880_capture_source,
5065         },
5066         [ALC880_F1734] = {
5067                 .mixers = { alc880_f1734_mixer },
5068                 .init_verbs = { alc880_volume_init_verbs,
5069                                 alc880_pin_f1734_init_verbs },
5070                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
5071                 .dac_nids = alc880_f1734_dac_nids,
5072                 .hp_nid = 0x02,
5073                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5074                 .channel_mode = alc880_2_jack_modes,
5075                 .input_mux = &alc880_f1734_capture_source,
5076                 .unsol_event = alc880_uniwill_p53_unsol_event,
5077                 .setup = alc880_uniwill_p53_setup,
5078                 .init_hook = alc_hp_automute,
5079         },
5080         [ALC880_ASUS] = {
5081                 .mixers = { alc880_asus_mixer },
5082                 .init_verbs = { alc880_volume_init_verbs,
5083                                 alc880_pin_asus_init_verbs,
5084                                 alc880_gpio1_init_verbs },
5085                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5086                 .dac_nids = alc880_asus_dac_nids,
5087                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
5088                 .channel_mode = alc880_asus_modes,
5089                 .need_dac_fix = 1,
5090                 .input_mux = &alc880_capture_source,
5091         },
5092         [ALC880_ASUS_DIG] = {
5093                 .mixers = { alc880_asus_mixer },
5094                 .init_verbs = { alc880_volume_init_verbs,
5095                                 alc880_pin_asus_init_verbs,
5096                                 alc880_gpio1_init_verbs },
5097                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5098                 .dac_nids = alc880_asus_dac_nids,
5099                 .dig_out_nid = ALC880_DIGOUT_NID,
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_DIG2] = {
5106                 .mixers = { alc880_asus_mixer },
5107                 .init_verbs = { alc880_volume_init_verbs,
5108                                 alc880_pin_asus_init_verbs,
5109                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
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_W1V] = {
5119                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
5120                 .init_verbs = { alc880_volume_init_verbs,
5121                                 alc880_pin_asus_init_verbs,
5122                                 alc880_gpio1_init_verbs },
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_UNIWILL_DIG] = {
5132                 .mixers = { alc880_asus_mixer },
5133                 .init_verbs = { alc880_volume_init_verbs,
5134                                 alc880_pin_asus_init_verbs },
5135                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5136                 .dac_nids = alc880_asus_dac_nids,
5137                 .dig_out_nid = ALC880_DIGOUT_NID,
5138                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
5139                 .channel_mode = alc880_asus_modes,
5140                 .need_dac_fix = 1,
5141                 .input_mux = &alc880_capture_source,
5142         },
5143         [ALC880_UNIWILL] = {
5144                 .mixers = { alc880_uniwill_mixer },
5145                 .init_verbs = { alc880_volume_init_verbs,
5146                                 alc880_uniwill_init_verbs },
5147                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5148                 .dac_nids = alc880_asus_dac_nids,
5149                 .dig_out_nid = ALC880_DIGOUT_NID,
5150                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5151                 .channel_mode = alc880_threestack_modes,
5152                 .need_dac_fix = 1,
5153                 .input_mux = &alc880_capture_source,
5154                 .unsol_event = alc880_uniwill_unsol_event,
5155                 .setup = alc880_uniwill_setup,
5156                 .init_hook = alc880_uniwill_init_hook,
5157         },
5158         [ALC880_UNIWILL_P53] = {
5159                 .mixers = { alc880_uniwill_p53_mixer },
5160                 .init_verbs = { alc880_volume_init_verbs,
5161                                 alc880_uniwill_p53_init_verbs },
5162                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
5163                 .dac_nids = alc880_asus_dac_nids,
5164                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
5165                 .channel_mode = alc880_threestack_modes,
5166                 .input_mux = &alc880_capture_source,
5167                 .unsol_event = alc880_uniwill_p53_unsol_event,
5168                 .setup = alc880_uniwill_p53_setup,
5169                 .init_hook = alc_hp_automute,
5170         },
5171         [ALC880_FUJITSU] = {
5172                 .mixers = { alc880_fujitsu_mixer },
5173                 .init_verbs = { alc880_volume_init_verbs,
5174                                 alc880_uniwill_p53_init_verbs,
5175                                 alc880_beep_init_verbs },
5176                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5177                 .dac_nids = alc880_dac_nids,
5178                 .dig_out_nid = ALC880_DIGOUT_NID,
5179                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5180                 .channel_mode = alc880_2_jack_modes,
5181                 .input_mux = &alc880_capture_source,
5182                 .unsol_event = alc880_uniwill_p53_unsol_event,
5183                 .setup = alc880_uniwill_p53_setup,
5184                 .init_hook = alc_hp_automute,
5185         },
5186         [ALC880_CLEVO] = {
5187                 .mixers = { alc880_three_stack_mixer },
5188                 .init_verbs = { alc880_volume_init_verbs,
5189                                 alc880_pin_clevo_init_verbs },
5190                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5191                 .dac_nids = alc880_dac_nids,
5192                 .hp_nid = 0x03,
5193                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5194                 .channel_mode = alc880_threestack_modes,
5195                 .need_dac_fix = 1,
5196                 .input_mux = &alc880_capture_source,
5197         },
5198         [ALC880_LG] = {
5199                 .mixers = { alc880_lg_mixer },
5200                 .init_verbs = { alc880_volume_init_verbs,
5201                                 alc880_lg_init_verbs },
5202                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
5203                 .dac_nids = alc880_lg_dac_nids,
5204                 .dig_out_nid = ALC880_DIGOUT_NID,
5205                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
5206                 .channel_mode = alc880_lg_ch_modes,
5207                 .need_dac_fix = 1,
5208                 .input_mux = &alc880_lg_capture_source,
5209                 .unsol_event = alc_sku_unsol_event,
5210                 .setup = alc880_lg_setup,
5211                 .init_hook = alc_hp_automute,
5212 #ifdef CONFIG_SND_HDA_POWER_SAVE
5213                 .loopbacks = alc880_lg_loopbacks,
5214 #endif
5215         },
5216         [ALC880_LG_LW] = {
5217                 .mixers = { alc880_lg_lw_mixer },
5218                 .init_verbs = { alc880_volume_init_verbs,
5219                                 alc880_lg_lw_init_verbs },
5220                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5221                 .dac_nids = alc880_dac_nids,
5222                 .dig_out_nid = ALC880_DIGOUT_NID,
5223                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
5224                 .channel_mode = alc880_lg_lw_modes,
5225                 .input_mux = &alc880_lg_lw_capture_source,
5226                 .unsol_event = alc_sku_unsol_event,
5227                 .setup = alc880_lg_lw_setup,
5228                 .init_hook = alc_hp_automute,
5229         },
5230         [ALC880_MEDION_RIM] = {
5231                 .mixers = { alc880_medion_rim_mixer },
5232                 .init_verbs = { alc880_volume_init_verbs,
5233                                 alc880_medion_rim_init_verbs,
5234                                 alc_gpio2_init_verbs },
5235                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
5236                 .dac_nids = alc880_dac_nids,
5237                 .dig_out_nid = ALC880_DIGOUT_NID,
5238                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
5239                 .channel_mode = alc880_2_jack_modes,
5240                 .input_mux = &alc880_medion_rim_capture_source,
5241                 .unsol_event = alc880_medion_rim_unsol_event,
5242                 .setup = alc880_medion_rim_setup,
5243                 .init_hook = alc880_medion_rim_automute,
5244         },
5245 #ifdef CONFIG_SND_DEBUG
5246         [ALC880_TEST] = {
5247                 .mixers = { alc880_test_mixer },
5248                 .init_verbs = { alc880_test_init_verbs },
5249                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
5250                 .dac_nids = alc880_test_dac_nids,
5251                 .dig_out_nid = ALC880_DIGOUT_NID,
5252                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
5253                 .channel_mode = alc880_test_modes,
5254                 .input_mux = &alc880_test_capture_source,
5255         },
5256 #endif
5257 };
5258
5259 /*
5260  * Automatic parse of I/O pins from the BIOS configuration
5261  */
5262
5263 enum {
5264         ALC_CTL_WIDGET_VOL,
5265         ALC_CTL_WIDGET_MUTE,
5266         ALC_CTL_BIND_MUTE,
5267 };
5268 static const struct snd_kcontrol_new alc880_control_templates[] = {
5269         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
5270         HDA_CODEC_MUTE(NULL, 0, 0, 0),
5271         HDA_BIND_MUTE(NULL, 0, 0, 0),
5272 };
5273
5274 static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
5275 {
5276         snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
5277         return snd_array_new(&spec->kctls);
5278 }
5279
5280 /* add dynamic controls */
5281 static int add_control(struct alc_spec *spec, int type, const char *name,
5282                        int cidx, unsigned long val)
5283 {
5284         struct snd_kcontrol_new *knew;
5285
5286         knew = alc_kcontrol_new(spec);
5287         if (!knew)
5288                 return -ENOMEM;
5289         *knew = alc880_control_templates[type];
5290         knew->name = kstrdup(name, GFP_KERNEL);
5291         if (!knew->name)
5292                 return -ENOMEM;
5293         knew->index = cidx;
5294         if (get_amp_nid_(val))
5295                 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
5296         knew->private_value = val;
5297         return 0;
5298 }
5299
5300 static int add_control_with_pfx(struct alc_spec *spec, int type,
5301                                 const char *pfx, const char *dir,
5302                                 const char *sfx, int cidx, unsigned long val)
5303 {
5304         char name[32];
5305         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
5306         return add_control(spec, type, name, cidx, val);
5307 }
5308
5309 #define add_pb_vol_ctrl(spec, type, pfx, val)                   \
5310         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
5311 #define add_pb_sw_ctrl(spec, type, pfx, val)                    \
5312         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
5313 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val)                   \
5314         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
5315 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val)                    \
5316         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
5317
5318 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
5319 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
5320 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
5321 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
5322 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
5323 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
5324 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
5325 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
5326 #define ALC880_PIN_CD_NID               0x1c
5327
5328 /* fill in the dac_nids table from the parsed pin configuration */
5329 static int alc880_auto_fill_dac_nids(struct hda_codec *codec)
5330 {
5331         struct alc_spec *spec = codec->spec;
5332         const struct auto_pin_cfg *cfg = &spec->autocfg;
5333         hda_nid_t nid;
5334         int assigned[4];
5335         int i, j;
5336
5337         memset(assigned, 0, sizeof(assigned));
5338         spec->multiout.dac_nids = spec->private_dac_nids;
5339
5340         /* check the pins hardwired to audio widget */
5341         for (i = 0; i < cfg->line_outs; i++) {
5342                 nid = cfg->line_out_pins[i];
5343                 if (alc880_is_fixed_pin(nid)) {
5344                         int idx = alc880_fixed_pin_idx(nid);
5345                         spec->private_dac_nids[i] = alc880_idx_to_dac(idx);
5346                         assigned[idx] = 1;
5347                 }
5348         }
5349         /* left pins can be connect to any audio widget */
5350         for (i = 0; i < cfg->line_outs; i++) {
5351                 nid = cfg->line_out_pins[i];
5352                 if (alc880_is_fixed_pin(nid))
5353                         continue;
5354                 /* search for an empty channel */
5355                 for (j = 0; j < cfg->line_outs; j++) {
5356                         if (!assigned[j]) {
5357                                 spec->private_dac_nids[i] =
5358                                         alc880_idx_to_dac(j);
5359                                 assigned[j] = 1;
5360                                 break;
5361                         }
5362                 }
5363         }
5364         spec->multiout.num_dacs = cfg->line_outs;
5365         return 0;
5366 }
5367
5368 static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
5369                                         bool can_be_master, int *index)
5370 {
5371         struct auto_pin_cfg *cfg = &spec->autocfg;
5372         static const char * const chname[4] = {
5373                 "Front", "Surround", NULL /*CLFE*/, "Side"
5374         };
5375
5376         *index = 0;
5377         if (cfg->line_outs == 1 && !spec->multi_ios &&
5378             !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
5379                 return "Master";
5380
5381         switch (cfg->line_out_type) {
5382         case AUTO_PIN_SPEAKER_OUT:
5383                 if (cfg->line_outs == 1)
5384                         return "Speaker";
5385                 break;
5386         case AUTO_PIN_HP_OUT:
5387                 /* for multi-io case, only the primary out */
5388                 if (ch && spec->multi_ios)
5389                         break;
5390                 *index = ch;
5391                 return "Headphone";
5392         default:
5393                 if (cfg->line_outs == 1 && !spec->multi_ios)
5394                         return "PCM";
5395                 break;
5396         }
5397         return chname[ch];
5398 }
5399
5400 /* add playback controls from the parsed DAC table */
5401 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
5402                                              const struct auto_pin_cfg *cfg)
5403 {
5404         hda_nid_t nid;
5405         int i, err, noutputs;
5406
5407         noutputs = cfg->line_outs;
5408         if (spec->multi_ios > 0)
5409                 noutputs += spec->multi_ios;
5410
5411         for (i = 0; i < noutputs; i++) {
5412                 const char *name;
5413                 int index;
5414                 if (!spec->multiout.dac_nids[i])
5415                         continue;
5416                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
5417                 name = alc_get_line_out_pfx(spec, i, false, &index);
5418                 if (!name) {
5419                         /* Center/LFE */
5420                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5421                                               "Center",
5422                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
5423                                                               HDA_OUTPUT));
5424                         if (err < 0)
5425                                 return err;
5426                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5427                                               "LFE",
5428                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
5429                                                               HDA_OUTPUT));
5430                         if (err < 0)
5431                                 return err;
5432                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5433                                              "Center",
5434                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
5435                                                               HDA_INPUT));
5436                         if (err < 0)
5437                                 return err;
5438                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5439                                              "LFE",
5440                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
5441                                                               HDA_INPUT));
5442                         if (err < 0)
5443                                 return err;
5444                 } else {
5445                         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5446                                                 name, index,
5447                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
5448                                                               HDA_OUTPUT));
5449                         if (err < 0)
5450                                 return err;
5451                         err = __add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5452                                                name, index,
5453                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
5454                                                               HDA_INPUT));
5455                         if (err < 0)
5456                                 return err;
5457                 }
5458         }
5459         return 0;
5460 }
5461
5462 /* add playback controls for speaker and HP outputs */
5463 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
5464                                         const char *pfx)
5465 {
5466         hda_nid_t nid;
5467         int err;
5468
5469         if (!pin)
5470                 return 0;
5471
5472         if (alc880_is_fixed_pin(pin)) {
5473                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
5474                 /* specify the DAC as the extra output */
5475                 if (!spec->multiout.hp_nid)
5476                         spec->multiout.hp_nid = nid;
5477                 else
5478                         spec->multiout.extra_out_nid[0] = nid;
5479                 /* control HP volume/switch on the output mixer amp */
5480                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
5481                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
5482                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
5483                 if (err < 0)
5484                         return err;
5485                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
5486                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
5487                 if (err < 0)
5488                         return err;
5489         } else if (alc880_is_multi_pin(pin)) {
5490                 /* set manual connection */
5491                 /* we have only a switch on HP-out PIN */
5492                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
5493                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5494                 if (err < 0)
5495                         return err;
5496         }
5497         return 0;
5498 }
5499
5500 /* create input playback/capture controls for the given pin */
5501 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
5502                             const char *ctlname, int ctlidx,
5503                             int idx, hda_nid_t mix_nid)
5504 {
5505         int err;
5506
5507         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
5508                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5509         if (err < 0)
5510                 return err;
5511         err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
5512                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5513         if (err < 0)
5514                 return err;
5515         return 0;
5516 }
5517
5518 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
5519 {
5520         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
5521         return (pincap & AC_PINCAP_IN) != 0;
5522 }
5523
5524 /* create playback/capture controls for input pins */
5525 static int alc_auto_create_input_ctls(struct hda_codec *codec,
5526                                       const struct auto_pin_cfg *cfg,
5527                                       hda_nid_t mixer,
5528                                       hda_nid_t cap1, hda_nid_t cap2)
5529 {
5530         struct alc_spec *spec = codec->spec;
5531         struct hda_input_mux *imux = &spec->private_imux[0];
5532         int i, err, idx, type_idx = 0;
5533         const char *prev_label = NULL;
5534
5535         for (i = 0; i < cfg->num_inputs; i++) {
5536                 hda_nid_t pin;
5537                 const char *label;
5538
5539                 pin = cfg->inputs[i].pin;
5540                 if (!alc_is_input_pin(codec, pin))
5541                         continue;
5542
5543                 label = hda_get_autocfg_input_label(codec, cfg, i);
5544                 if (prev_label && !strcmp(label, prev_label))
5545                         type_idx++;
5546                 else
5547                         type_idx = 0;
5548                 prev_label = label;
5549
5550                 if (mixer) {
5551                         idx = get_connection_index(codec, mixer, pin);
5552                         if (idx >= 0) {
5553                                 err = new_analog_input(spec, pin,
5554                                                        label, type_idx,
5555                                                        idx, mixer);
5556                                 if (err < 0)
5557                                         return err;
5558                         }
5559                 }
5560
5561                 if (!cap1)
5562                         continue;
5563                 idx = get_connection_index(codec, cap1, pin);
5564                 if (idx < 0 && cap2)
5565                         idx = get_connection_index(codec, cap2, pin);
5566                 if (idx >= 0)
5567                         snd_hda_add_imux_item(imux, label, idx, NULL);
5568         }
5569         return 0;
5570 }
5571
5572 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
5573                                                 const struct auto_pin_cfg *cfg)
5574 {
5575         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
5576 }
5577
5578 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
5579                                unsigned int pin_type)
5580 {
5581         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5582                             pin_type);
5583         /* unmute pin */
5584         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5585                             AMP_OUT_UNMUTE);
5586 }
5587
5588 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
5589                                               hda_nid_t nid, int pin_type,
5590                                               int dac_idx)
5591 {
5592         alc_set_pin_output(codec, nid, pin_type);
5593         /* need the manual connection? */
5594         if (alc880_is_multi_pin(nid)) {
5595                 struct alc_spec *spec = codec->spec;
5596                 int idx = alc880_multi_pin_idx(nid);
5597                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
5598                                     AC_VERB_SET_CONNECT_SEL,
5599                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
5600         }
5601 }
5602
5603 static int get_pin_type(int line_out_type)
5604 {
5605         if (line_out_type == AUTO_PIN_HP_OUT)
5606                 return PIN_HP;
5607         else
5608                 return PIN_OUT;
5609 }
5610
5611 static void alc880_auto_init_dac(struct hda_codec *codec, hda_nid_t dac)
5612 {
5613         hda_nid_t nid, mix;
5614
5615         if (!dac)
5616                 return;
5617         mix = alc880_idx_to_mixer(alc880_dac_to_idx(dac));
5618         if (query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
5619                 nid = dac;
5620         else if (query_amp_caps(codec, mix, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
5621                 nid = mix;
5622         else
5623                 nid = 0;
5624         if (nid)
5625                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5626                                     AMP_OUT_ZERO);
5627         if (query_amp_caps(codec, mix, HDA_INPUT) & AC_AMPCAP_MUTE) {
5628                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5629                                     AMP_IN_UNMUTE(0));
5630                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5631                                     AMP_IN_UNMUTE(1));
5632         }
5633 }
5634
5635 static void alc880_auto_init_multi_out(struct hda_codec *codec)
5636 {
5637         struct alc_spec *spec = codec->spec;
5638         int i;
5639
5640         for (i = 0; i < spec->autocfg.line_outs; i++) {
5641                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5642                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5643                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
5644         }
5645         /* mute DACs */
5646         for (i = 0; i < spec->multiout.num_dacs; i++)
5647                 alc880_auto_init_dac(codec, spec->multiout.dac_nids[i]);
5648 }
5649
5650 static void alc880_auto_init_extra_out(struct hda_codec *codec)
5651 {
5652         struct alc_spec *spec = codec->spec;
5653         hda_nid_t pin;
5654         int i;
5655
5656         pin = spec->autocfg.speaker_pins[0];
5657         if (pin) /* connect to front */
5658                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
5659         pin = spec->autocfg.hp_pins[0];
5660         if (pin) /* connect to front */
5661                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5662         /* mute DACs */
5663         alc880_auto_init_dac(codec, spec->multiout.hp_nid);
5664         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
5665                 alc880_auto_init_dac(codec, spec->multiout.extra_out_nid[i]);
5666 }
5667
5668 static void alc880_auto_init_analog_input(struct hda_codec *codec)
5669 {
5670         struct alc_spec *spec = codec->spec;
5671         struct auto_pin_cfg *cfg = &spec->autocfg;
5672         int i;
5673
5674         for (i = 0; i < cfg->num_inputs; i++) {
5675                 hda_nid_t nid = cfg->inputs[i].pin;
5676                 if (alc_is_input_pin(codec, nid)) {
5677                         alc_set_input_pin(codec, nid, cfg->inputs[i].type);
5678                         if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
5679                                 snd_hda_codec_write(codec, nid, 0,
5680                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5681                                                     AMP_OUT_MUTE);
5682                 }
5683         }
5684
5685         /* mute all loopback inputs */
5686         if (spec->mixer_nid) {
5687                 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
5688                 for (i = 0; i < nums; i++)
5689                         snd_hda_codec_write(codec, spec->mixer_nid, 0,
5690                                             AC_VERB_SET_AMP_GAIN_MUTE,
5691                                             AMP_IN_MUTE(i));
5692         }
5693 }
5694
5695 static void alc880_auto_init_input_src(struct hda_codec *codec)
5696 {
5697         struct alc_spec *spec = codec->spec;
5698         int c;
5699
5700         for (c = 0; c < spec->num_adc_nids; c++) {
5701                 unsigned int mux_idx;
5702                 const struct hda_input_mux *imux;
5703                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
5704                 imux = &spec->input_mux[mux_idx];
5705                 if (!imux->num_items && mux_idx > 0)
5706                         imux = &spec->input_mux[0];
5707                 if (imux)
5708                         snd_hda_codec_write(codec, spec->adc_nids[c], 0,
5709                                             AC_VERB_SET_CONNECT_SEL,
5710                                             imux->items[0].index);
5711                 snd_hda_codec_write(codec, spec->adc_nids[c], 0,
5712                                     AC_VERB_SET_AMP_GAIN_MUTE,
5713                                     AMP_IN_MUTE(0));
5714         }
5715 }
5716
5717 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
5718                                            int (*fill_dac)(struct hda_codec *));
5719
5720 /* parse the BIOS configuration and set up the alc_spec */
5721 /* return 1 if successful, 0 if the proper config is not found,
5722  * or a negative error code
5723  */
5724 static int alc880_parse_auto_config(struct hda_codec *codec)
5725 {
5726         struct alc_spec *spec = codec->spec;
5727         int err;
5728         static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
5729
5730         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5731                                            alc880_ignore);
5732         if (err < 0)
5733                 return err;
5734         if (!spec->autocfg.line_outs)
5735                 return 0; /* can't find valid BIOS pin config */
5736
5737         err = alc880_auto_fill_dac_nids(codec);
5738         if (err < 0)
5739                 return err;
5740         err = alc_auto_add_multi_channel_mode(codec, alc880_auto_fill_dac_nids);
5741         if (err < 0)
5742                 return err;
5743         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
5744         if (err < 0)
5745                 return err;
5746         err = alc880_auto_create_extra_out(spec,
5747                                            spec->autocfg.speaker_pins[0],
5748                                            "Speaker");
5749         if (err < 0)
5750                 return err;
5751         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
5752                                            "Headphone");
5753         if (err < 0)
5754                 return err;
5755         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
5756         if (err < 0)
5757                 return err;
5758
5759         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5760
5761         alc_auto_parse_digital(codec);
5762
5763         if (spec->kctls.list)
5764                 add_mixer(spec, spec->kctls.list);
5765
5766         spec->num_mux_defs = 1;
5767         spec->input_mux = &spec->private_imux[0];
5768
5769         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
5770
5771         return 1;
5772 }
5773
5774 /* additional initialization for auto-configuration model */
5775 static void alc880_auto_init(struct hda_codec *codec)
5776 {
5777         struct alc_spec *spec = codec->spec;
5778         alc880_auto_init_multi_out(codec);
5779         alc880_auto_init_extra_out(codec);
5780         alc880_auto_init_analog_input(codec);
5781         alc880_auto_init_input_src(codec);
5782         alc_auto_init_digital(codec);
5783         if (spec->unsol_event)
5784                 alc_inithook(codec);
5785 }
5786
5787 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
5788  * one of two digital mic pins, e.g. on ALC272
5789  */
5790 static void fixup_automic_adc(struct hda_codec *codec)
5791 {
5792         struct alc_spec *spec = codec->spec;
5793         int i;
5794
5795         for (i = 0; i < spec->num_adc_nids; i++) {
5796                 hda_nid_t cap = spec->capsrc_nids ?
5797                         spec->capsrc_nids[i] : spec->adc_nids[i];
5798                 int iidx, eidx;
5799
5800                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
5801                 if (iidx < 0)
5802                         continue;
5803                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
5804                 if (eidx < 0)
5805                         continue;
5806                 spec->int_mic.mux_idx = iidx;
5807                 spec->ext_mic.mux_idx = eidx;
5808                 if (spec->capsrc_nids)
5809                         spec->capsrc_nids += i;
5810                 spec->adc_nids += i;
5811                 spec->num_adc_nids = 1;
5812                 /* optional dock-mic */
5813                 eidx = get_connection_index(codec, cap, spec->dock_mic.pin);
5814                 if (eidx < 0)
5815                         spec->dock_mic.pin = 0;
5816                 else
5817                         spec->dock_mic.mux_idx = eidx;
5818                 return;
5819         }
5820         snd_printd(KERN_INFO "hda_codec: %s: "
5821                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
5822                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
5823         spec->auto_mic = 0; /* disable auto-mic to be sure */
5824 }
5825
5826 /* select or unmute the given capsrc route */
5827 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
5828                                     int idx)
5829 {
5830         if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
5831                 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
5832                                          HDA_AMP_MUTE, 0);
5833         } else {
5834                 snd_hda_codec_write_cache(codec, cap, 0,
5835                                           AC_VERB_SET_CONNECT_SEL, idx);
5836         }
5837 }
5838
5839 /* set the default connection to that pin */
5840 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
5841 {
5842         struct alc_spec *spec = codec->spec;
5843         int i;
5844
5845         if (!pin)
5846                 return 0;
5847         for (i = 0; i < spec->num_adc_nids; i++) {
5848                 hda_nid_t cap = spec->capsrc_nids ?
5849                         spec->capsrc_nids[i] : spec->adc_nids[i];
5850                 int idx;
5851
5852                 idx = get_connection_index(codec, cap, pin);
5853                 if (idx < 0)
5854                         continue;
5855                 select_or_unmute_capsrc(codec, cap, idx);
5856                 return i; /* return the found index */
5857         }
5858         return -1; /* not found */
5859 }
5860
5861 /* choose the ADC/MUX containing the input pin and initialize the setup */
5862 static void fixup_single_adc(struct hda_codec *codec)
5863 {
5864         struct alc_spec *spec = codec->spec;
5865         struct auto_pin_cfg *cfg = &spec->autocfg;
5866         int i;
5867
5868         /* search for the input pin; there must be only one */
5869         if (cfg->num_inputs != 1)
5870                 return;
5871         i = init_capsrc_for_pin(codec, cfg->inputs[0].pin);
5872         if (i >= 0) {
5873                 /* use only this ADC */
5874                 if (spec->capsrc_nids)
5875                         spec->capsrc_nids += i;
5876                 spec->adc_nids += i;
5877                 spec->num_adc_nids = 1;
5878                 spec->single_input_src = 1;
5879         }
5880 }
5881
5882 /* initialize dual adcs */
5883 static void fixup_dual_adc_switch(struct hda_codec *codec)
5884 {
5885         struct alc_spec *spec = codec->spec;
5886         init_capsrc_for_pin(codec, spec->ext_mic.pin);
5887         init_capsrc_for_pin(codec, spec->dock_mic.pin);
5888         init_capsrc_for_pin(codec, spec->int_mic.pin);
5889 }
5890
5891 /* initialize some special cases for input sources */
5892 static void alc_init_special_input_src(struct hda_codec *codec)
5893 {
5894         struct alc_spec *spec = codec->spec;
5895         if (spec->dual_adc_switch)
5896                 fixup_dual_adc_switch(codec);
5897         else if (spec->single_input_src)
5898                 init_capsrc_for_pin(codec, spec->autocfg.inputs[0].pin);
5899 }
5900
5901 static void set_capture_mixer(struct hda_codec *codec)
5902 {
5903         struct alc_spec *spec = codec->spec;
5904         static const struct snd_kcontrol_new *caps[2][3] = {
5905                 { alc_capture_mixer_nosrc1,
5906                   alc_capture_mixer_nosrc2,
5907                   alc_capture_mixer_nosrc3 },
5908                 { alc_capture_mixer1,
5909                   alc_capture_mixer2,
5910                   alc_capture_mixer3 },
5911         };
5912         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
5913                 int mux = 0;
5914                 int num_adcs = spec->num_adc_nids;
5915                 if (spec->dual_adc_switch)
5916                         num_adcs = 1;
5917                 else if (spec->auto_mic)
5918                         fixup_automic_adc(codec);
5919                 else if (spec->input_mux) {
5920                         if (spec->input_mux->num_items > 1)
5921                                 mux = 1;
5922                         else if (spec->input_mux->num_items == 1)
5923                                 fixup_single_adc(codec);
5924                 }
5925                 spec->cap_mixer = caps[mux][num_adcs - 1];
5926         }
5927 }
5928
5929 /* fill adc_nids (and capsrc_nids) containing all active input pins */
5930 static void fillup_priv_adc_nids(struct hda_codec *codec, const hda_nid_t *nids,
5931                                  int num_nids)
5932 {
5933         struct alc_spec *spec = codec->spec;
5934         struct auto_pin_cfg *cfg = &spec->autocfg;
5935         int n;
5936         hda_nid_t fallback_adc = 0, fallback_cap = 0;
5937
5938         for (n = 0; n < num_nids; n++) {
5939                 hda_nid_t adc, cap;
5940                 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
5941                 int nconns, i, j;
5942
5943                 adc = nids[n];
5944                 if (get_wcaps_type(get_wcaps(codec, adc)) != AC_WID_AUD_IN)
5945                         continue;
5946                 cap = adc;
5947                 nconns = snd_hda_get_connections(codec, cap, conn,
5948                                                  ARRAY_SIZE(conn));
5949                 if (nconns == 1) {
5950                         cap = conn[0];
5951                         nconns = snd_hda_get_connections(codec, cap, conn,
5952                                                          ARRAY_SIZE(conn));
5953                 }
5954                 if (nconns <= 0)
5955                         continue;
5956                 if (!fallback_adc) {
5957                         fallback_adc = adc;
5958                         fallback_cap = cap;
5959                 }
5960                 for (i = 0; i < cfg->num_inputs; i++) {
5961                         hda_nid_t nid = cfg->inputs[i].pin;
5962                         for (j = 0; j < nconns; j++) {
5963                                 if (conn[j] == nid)
5964                                         break;
5965                         }
5966                         if (j >= nconns)
5967                                 break;
5968                 }
5969                 if (i >= cfg->num_inputs) {
5970                         int num_adcs = spec->num_adc_nids;
5971                         spec->private_adc_nids[num_adcs] = adc;
5972                         spec->private_capsrc_nids[num_adcs] = cap;
5973                         spec->num_adc_nids++;
5974                         spec->adc_nids = spec->private_adc_nids;
5975                         if (adc != cap)
5976                                 spec->capsrc_nids = spec->private_capsrc_nids;
5977                 }
5978         }
5979         if (!spec->num_adc_nids) {
5980                 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
5981                        " using fallback 0x%x\n",
5982                        codec->chip_name, fallback_adc);
5983                 spec->private_adc_nids[0] = fallback_adc;
5984                 spec->adc_nids = spec->private_adc_nids;
5985                 if (fallback_adc != fallback_cap) {
5986                         spec->private_capsrc_nids[0] = fallback_cap;
5987                         spec->capsrc_nids = spec->private_adc_nids;
5988                 }
5989         }
5990 }
5991
5992 #ifdef CONFIG_SND_HDA_INPUT_BEEP
5993 #define set_beep_amp(spec, nid, idx, dir) \
5994         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
5995
5996 static const struct snd_pci_quirk beep_white_list[] = {
5997         SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
5998         SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
5999         SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
6000         SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
6001         SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
6002         {}
6003 };
6004
6005 static inline int has_cdefine_beep(struct hda_codec *codec)
6006 {
6007         struct alc_spec *spec = codec->spec;
6008         const struct snd_pci_quirk *q;
6009         q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
6010         if (q)
6011                 return q->value;
6012         return spec->cdefine.enable_pcbeep;
6013 }
6014 #else
6015 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
6016 #define has_cdefine_beep(codec)         0
6017 #endif
6018
6019 /*
6020  * OK, here we have finally the patch for ALC880
6021  */
6022
6023 static int patch_alc880(struct hda_codec *codec)
6024 {
6025         struct alc_spec *spec;
6026         int board_config;
6027         int err;
6028
6029         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6030         if (spec == NULL)
6031                 return -ENOMEM;
6032
6033         codec->spec = spec;
6034
6035         spec->mixer_nid = 0x0b;
6036
6037         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
6038                                                   alc880_models,
6039                                                   alc880_cfg_tbl);
6040         if (board_config < 0) {
6041                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6042                        codec->chip_name);
6043                 board_config = ALC880_AUTO;
6044         }
6045
6046         if (board_config == ALC880_AUTO) {
6047                 /* automatic parse from the BIOS config */
6048                 err = alc880_parse_auto_config(codec);
6049                 if (err < 0) {
6050                         alc_free(codec);
6051                         return err;
6052                 } else if (!err) {
6053                         printk(KERN_INFO
6054                                "hda_codec: Cannot set up configuration "
6055                                "from BIOS.  Using 3-stack mode...\n");
6056                         board_config = ALC880_3ST;
6057                 }
6058         }
6059
6060         err = snd_hda_attach_beep_device(codec, 0x1);
6061         if (err < 0) {
6062                 alc_free(codec);
6063                 return err;
6064         }
6065
6066         if (board_config != ALC880_AUTO)
6067                 setup_preset(codec, &alc880_presets[board_config]);
6068
6069         spec->stream_analog_playback = &alc880_pcm_analog_playback;
6070         spec->stream_analog_capture = &alc880_pcm_analog_capture;
6071         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6072
6073         spec->stream_digital_playback = &alc880_pcm_digital_playback;
6074         spec->stream_digital_capture = &alc880_pcm_digital_capture;
6075
6076         if (!spec->adc_nids && spec->input_mux) {
6077                 /* check whether NID 0x07 is valid */
6078                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
6079                 /* get type */
6080                 wcap = get_wcaps_type(wcap);
6081                 if (wcap != AC_WID_AUD_IN) {
6082                         spec->adc_nids = alc880_adc_nids_alt;
6083                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
6084                 } else {
6085                         spec->adc_nids = alc880_adc_nids;
6086                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
6087                 }
6088         }
6089         set_capture_mixer(codec);
6090         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6091
6092         spec->vmaster_nid = 0x0c;
6093
6094         codec->patch_ops = alc_patch_ops;
6095         if (board_config == ALC880_AUTO)
6096                 spec->init_hook = alc880_auto_init;
6097 #ifdef CONFIG_SND_HDA_POWER_SAVE
6098         if (!spec->loopback.amplist)
6099                 spec->loopback.amplist = alc880_loopbacks;
6100 #endif
6101
6102         return 0;
6103 }
6104
6105
6106 /*
6107  * ALC260 support
6108  */
6109
6110 static const hda_nid_t alc260_dac_nids[1] = {
6111         /* front */
6112         0x02,
6113 };
6114
6115 static const hda_nid_t alc260_adc_nids[1] = {
6116         /* ADC0 */
6117         0x04,
6118 };
6119
6120 static const hda_nid_t alc260_adc_nids_alt[1] = {
6121         /* ADC1 */
6122         0x05,
6123 };
6124
6125 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
6126  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
6127  */
6128 static const hda_nid_t alc260_dual_adc_nids[2] = {
6129         /* ADC0, ADC1 */
6130         0x04, 0x05
6131 };
6132
6133 #define ALC260_DIGOUT_NID       0x03
6134 #define ALC260_DIGIN_NID        0x06
6135
6136 static const struct hda_input_mux alc260_capture_source = {
6137         .num_items = 4,
6138         .items = {
6139                 { "Mic", 0x0 },
6140                 { "Front Mic", 0x1 },
6141                 { "Line", 0x2 },
6142                 { "CD", 0x4 },
6143         },
6144 };
6145
6146 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
6147  * headphone jack and the internal CD lines since these are the only pins at
6148  * which audio can appear.  For flexibility, also allow the option of
6149  * recording the mixer output on the second ADC (ADC0 doesn't have a
6150  * connection to the mixer output).
6151  */
6152 static const struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
6153         {
6154                 .num_items = 3,
6155                 .items = {
6156                         { "Mic/Line", 0x0 },
6157                         { "CD", 0x4 },
6158                         { "Headphone", 0x2 },
6159                 },
6160         },
6161         {
6162                 .num_items = 4,
6163                 .items = {
6164                         { "Mic/Line", 0x0 },
6165                         { "CD", 0x4 },
6166                         { "Headphone", 0x2 },
6167                         { "Mixer", 0x5 },
6168                 },
6169         },
6170
6171 };
6172
6173 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
6174  * the Fujitsu S702x, but jacks are marked differently.
6175  */
6176 static const struct hda_input_mux alc260_acer_capture_sources[2] = {
6177         {
6178                 .num_items = 4,
6179                 .items = {
6180                         { "Mic", 0x0 },
6181                         { "Line", 0x2 },
6182                         { "CD", 0x4 },
6183                         { "Headphone", 0x5 },
6184                 },
6185         },
6186         {
6187                 .num_items = 5,
6188                 .items = {
6189                         { "Mic", 0x0 },
6190                         { "Line", 0x2 },
6191                         { "CD", 0x4 },
6192                         { "Headphone", 0x6 },
6193                         { "Mixer", 0x5 },
6194                 },
6195         },
6196 };
6197
6198 /* Maxdata Favorit 100XS */
6199 static const struct hda_input_mux alc260_favorit100_capture_sources[2] = {
6200         {
6201                 .num_items = 2,
6202                 .items = {
6203                         { "Line/Mic", 0x0 },
6204                         { "CD", 0x4 },
6205                 },
6206         },
6207         {
6208                 .num_items = 3,
6209                 .items = {
6210                         { "Line/Mic", 0x0 },
6211                         { "CD", 0x4 },
6212                         { "Mixer", 0x5 },
6213                 },
6214         },
6215 };
6216
6217 /*
6218  * This is just place-holder, so there's something for alc_build_pcms to look
6219  * at when it calculates the maximum number of channels. ALC260 has no mixer
6220  * element which allows changing the channel mode, so the verb list is
6221  * never used.
6222  */
6223 static const struct hda_channel_mode alc260_modes[1] = {
6224         { 2, NULL },
6225 };
6226
6227
6228 /* Mixer combinations
6229  *
6230  * basic: base_output + input + pc_beep + capture
6231  * HP: base_output + input + capture_alt
6232  * HP_3013: hp_3013 + input + capture
6233  * fujitsu: fujitsu + capture
6234  * acer: acer + capture
6235  */
6236
6237 static const struct snd_kcontrol_new alc260_base_output_mixer[] = {
6238         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6239         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
6240         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6241         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
6242         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
6243         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
6244         { } /* end */
6245 };
6246
6247 static const struct snd_kcontrol_new alc260_input_mixer[] = {
6248         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6249         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6250         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6251         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6252         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6253         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6254         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
6255         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
6256         { } /* end */
6257 };
6258
6259 /* update HP, line and mono out pins according to the master switch */
6260 static void alc260_hp_master_update(struct hda_codec *codec)
6261 {
6262         update_speakers(codec);
6263 }
6264
6265 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
6266                                    struct snd_ctl_elem_value *ucontrol)
6267 {
6268         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6269         struct alc_spec *spec = codec->spec;
6270         *ucontrol->value.integer.value = !spec->master_mute;
6271         return 0;
6272 }
6273
6274 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
6275                                    struct snd_ctl_elem_value *ucontrol)
6276 {
6277         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6278         struct alc_spec *spec = codec->spec;
6279         int val = !*ucontrol->value.integer.value;
6280
6281         if (val == spec->master_mute)
6282                 return 0;
6283         spec->master_mute = val;
6284         alc260_hp_master_update(codec);
6285         return 1;
6286 }
6287
6288 static const struct snd_kcontrol_new alc260_hp_output_mixer[] = {
6289         {
6290                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6291                 .name = "Master Playback Switch",
6292                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
6293                 .info = snd_ctl_boolean_mono_info,
6294                 .get = alc260_hp_master_sw_get,
6295                 .put = alc260_hp_master_sw_put,
6296         },
6297         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6298         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
6299         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6300         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
6301         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
6302                               HDA_OUTPUT),
6303         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
6304         { } /* end */
6305 };
6306
6307 static const struct hda_verb alc260_hp_unsol_verbs[] = {
6308         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6309         {},
6310 };
6311
6312 static void alc260_hp_setup(struct hda_codec *codec)
6313 {
6314         struct alc_spec *spec = codec->spec;
6315
6316         spec->autocfg.hp_pins[0] = 0x0f;
6317         spec->autocfg.speaker_pins[0] = 0x10;
6318         spec->autocfg.speaker_pins[1] = 0x11;
6319         spec->automute = 1;
6320         spec->automute_mode = ALC_AUTOMUTE_PIN;
6321 }
6322
6323 static const struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
6324         {
6325                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6326                 .name = "Master Playback Switch",
6327                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
6328                 .info = snd_ctl_boolean_mono_info,
6329                 .get = alc260_hp_master_sw_get,
6330                 .put = alc260_hp_master_sw_put,
6331         },
6332         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6333         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
6334         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
6335         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
6336         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6337         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6338         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
6339         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
6340         { } /* end */
6341 };
6342
6343 static void alc260_hp_3013_setup(struct hda_codec *codec)
6344 {
6345         struct alc_spec *spec = codec->spec;
6346
6347         spec->autocfg.hp_pins[0] = 0x15;
6348         spec->autocfg.speaker_pins[0] = 0x10;
6349         spec->autocfg.speaker_pins[1] = 0x11;
6350         spec->automute = 1;
6351         spec->automute_mode = ALC_AUTOMUTE_PIN;
6352 }
6353
6354 static const struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
6355         .ops = &snd_hda_bind_vol,
6356         .values = {
6357                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
6358                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
6359                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
6360                 0
6361         },
6362 };
6363
6364 static const struct hda_bind_ctls alc260_dc7600_bind_switch = {
6365         .ops = &snd_hda_bind_sw,
6366         .values = {
6367                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
6368                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
6369                 0
6370         },
6371 };
6372
6373 static const struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
6374         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
6375         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
6376         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
6377         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
6378         { } /* end */
6379 };
6380
6381 static const struct hda_verb alc260_hp_3013_unsol_verbs[] = {
6382         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6383         {},
6384 };
6385
6386 static void alc260_hp_3012_setup(struct hda_codec *codec)
6387 {
6388         struct alc_spec *spec = codec->spec;
6389
6390         spec->autocfg.hp_pins[0] = 0x10;
6391         spec->autocfg.speaker_pins[0] = 0x0f;
6392         spec->autocfg.speaker_pins[1] = 0x11;
6393         spec->autocfg.speaker_pins[2] = 0x15;
6394         spec->automute = 1;
6395         spec->automute_mode = ALC_AUTOMUTE_PIN;
6396 }
6397
6398 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
6399  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
6400  */
6401 static const struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
6402         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6403         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
6404         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6405         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6406         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6407         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
6408         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
6409         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
6410         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
6411         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
6412         { } /* end */
6413 };
6414
6415 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
6416  * versions of the ALC260 don't act on requests to enable mic bias from NID
6417  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
6418  * datasheet doesn't mention this restriction.  At this stage it's not clear
6419  * whether this behaviour is intentional or is a hardware bug in chip
6420  * revisions available in early 2006.  Therefore for now allow the
6421  * "Headphone Jack Mode" control to span all choices, but if it turns out
6422  * that the lack of mic bias for this NID is intentional we could change the
6423  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
6424  *
6425  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
6426  * don't appear to make the mic bias available from the "line" jack, even
6427  * though the NID used for this jack (0x14) can supply it.  The theory is
6428  * that perhaps Acer have included blocking capacitors between the ALC260
6429  * and the output jack.  If this turns out to be the case for all such
6430  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
6431  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
6432  *
6433  * The C20x Tablet series have a mono internal speaker which is controlled
6434  * via the chip's Mono sum widget and pin complex, so include the necessary
6435  * controls for such models.  On models without a "mono speaker" the control
6436  * won't do anything.
6437  */
6438 static const struct snd_kcontrol_new alc260_acer_mixer[] = {
6439         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6440         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
6441         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
6442         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
6443                               HDA_OUTPUT),
6444         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
6445                            HDA_INPUT),
6446         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6447         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6448         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6449         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6450         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6451         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6452         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6453         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6454         { } /* end */
6455 };
6456
6457 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
6458  */
6459 static const struct snd_kcontrol_new alc260_favorit100_mixer[] = {
6460         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6461         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
6462         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
6463         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6464         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6465         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6466         { } /* end */
6467 };
6468
6469 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
6470  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
6471  */
6472 static const struct snd_kcontrol_new alc260_will_mixer[] = {
6473         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6474         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
6475         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6476         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6477         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6478         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6479         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6480         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6481         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
6482         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
6483         { } /* end */
6484 };
6485
6486 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
6487  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
6488  */
6489 static const struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
6490         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
6491         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
6492         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
6493         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
6494         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
6495         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
6496         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
6497         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
6498         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
6499         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
6500         { } /* end */
6501 };
6502
6503 /*
6504  * initialization verbs
6505  */
6506 static const struct hda_verb alc260_init_verbs[] = {
6507         /* Line In pin widget for input */
6508         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6509         /* CD pin widget for input */
6510         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6511         /* Mic1 (rear panel) pin widget for input and vref at 80% */
6512         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6513         /* Mic2 (front panel) pin widget for input and vref at 80% */
6514         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6515         /* LINE-2 is used for line-out in rear */
6516         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6517         /* select line-out */
6518         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
6519         /* LINE-OUT pin */
6520         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6521         /* enable HP */
6522         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6523         /* enable Mono */
6524         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6525         /* mute capture amp left and right */
6526         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6527         /* set connection select to line in (default select for this ADC) */
6528         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
6529         /* mute capture amp left and right */
6530         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6531         /* set connection select to line in (default select for this ADC) */
6532         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
6533         /* set vol=0 Line-Out mixer amp left and right */
6534         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6535         /* unmute pin widget amp left and right (no gain on this amp) */
6536         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6537         /* set vol=0 HP mixer amp left and right */
6538         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6539         /* unmute pin widget amp left and right (no gain on this amp) */
6540         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6541         /* set vol=0 Mono mixer amp left and right */
6542         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6543         /* unmute pin widget amp left and right (no gain on this amp) */
6544         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6545         /* unmute LINE-2 out pin */
6546         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6547         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
6548          * Line In 2 = 0x03
6549          */
6550         /* mute analog inputs */
6551         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6552         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6553         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6554         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6555         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6556         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
6557         /* mute Front out path */
6558         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6559         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6560         /* mute Headphone out path */
6561         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6562         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6563         /* mute Mono out path */
6564         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6565         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6566         { }
6567 };
6568
6569 #if 0 /* should be identical with alc260_init_verbs? */
6570 static const struct hda_verb alc260_hp_init_verbs[] = {
6571         /* Headphone and output */
6572         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6573         /* mono output */
6574         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6575         /* Mic1 (rear panel) pin widget for input and vref at 80% */
6576         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6577         /* Mic2 (front panel) pin widget for input and vref at 80% */
6578         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6579         /* Line In pin widget for input */
6580         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6581         /* Line-2 pin widget for output */
6582         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6583         /* CD pin widget for input */
6584         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6585         /* unmute amp left and right */
6586         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
6587         /* set connection select to line in (default select for this ADC) */
6588         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
6589         /* unmute Line-Out mixer amp left and right (volume = 0) */
6590         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6591         /* mute pin widget amp left and right (no gain on this amp) */
6592         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6593         /* unmute HP mixer amp left and right (volume = 0) */
6594         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6595         /* mute pin widget amp left and right (no gain on this amp) */
6596         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6597         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
6598          * Line In 2 = 0x03
6599          */
6600         /* mute analog inputs */
6601         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6602         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6603         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6604         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6605         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6606         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
6607         /* Unmute Front out path */
6608         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6609         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6610         /* Unmute Headphone out path */
6611         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6612         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6613         /* Unmute Mono out path */
6614         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6615         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6616         { }
6617 };
6618 #endif
6619
6620 static const struct hda_verb alc260_hp_3013_init_verbs[] = {
6621         /* Line out and output */
6622         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6623         /* mono output */
6624         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6625         /* Mic1 (rear panel) pin widget for input and vref at 80% */
6626         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6627         /* Mic2 (front panel) pin widget for input and vref at 80% */
6628         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6629         /* Line In pin widget for input */
6630         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6631         /* Headphone pin widget for output */
6632         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6633         /* CD pin widget for input */
6634         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6635         /* unmute amp left and right */
6636         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
6637         /* set connection select to line in (default select for this ADC) */
6638         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
6639         /* unmute Line-Out mixer amp left and right (volume = 0) */
6640         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6641         /* mute pin widget amp left and right (no gain on this amp) */
6642         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6643         /* unmute HP mixer amp left and right (volume = 0) */
6644         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
6645         /* mute pin widget amp left and right (no gain on this amp) */
6646         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6647         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
6648          * Line In 2 = 0x03
6649          */
6650         /* mute analog inputs */
6651         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6652         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6653         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6654         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6655         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6656         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
6657         /* Unmute Front out path */
6658         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6659         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6660         /* Unmute Headphone out path */
6661         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6662         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6663         /* Unmute Mono out path */
6664         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6665         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
6666         { }
6667 };
6668
6669 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
6670  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
6671  * audio = 0x16, internal speaker = 0x10.
6672  */
6673 static const struct hda_verb alc260_fujitsu_init_verbs[] = {
6674         /* Disable all GPIOs */
6675         {0x01, AC_VERB_SET_GPIO_MASK, 0},
6676         /* Internal speaker is connected to headphone pin */
6677         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6678         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
6679         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6680         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
6681         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6682         /* Ensure all other unused pins are disabled and muted. */
6683         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6684         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6685         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6686         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6687         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6688         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6689         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6690         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6691
6692         /* Disable digital (SPDIF) pins */
6693         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
6694         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
6695
6696         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
6697          * when acting as an output.
6698          */
6699         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
6700
6701         /* Start with output sum widgets muted and their output gains at min */
6702         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6703         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6704         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6705         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6706         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6707         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6708         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6709         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6710         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6711
6712         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
6713         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6714         /* Unmute Line1 pin widget output buffer since it starts as an output.
6715          * If the pin mode is changed by the user the pin mode control will
6716          * take care of enabling the pin's input/output buffers as needed.
6717          * Therefore there's no need to enable the input buffer at this
6718          * stage.
6719          */
6720         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6721         /* Unmute input buffer of pin widget used for Line-in (no equiv
6722          * mixer ctrl)
6723          */
6724         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6725
6726         /* Mute capture amp left and right */
6727         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6728         /* Set ADC connection select to match default mixer setting - line
6729          * in (on mic1 pin)
6730          */
6731         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6732
6733         /* Do the same for the second ADC: mute capture input amp and
6734          * set ADC connection to line in (on mic1 pin)
6735          */
6736         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6737         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6738
6739         /* Mute all inputs to mixer widget (even unconnected ones) */
6740         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
6741         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
6742         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
6743         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
6744         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
6745         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
6746         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
6747         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
6748
6749         { }
6750 };
6751
6752 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
6753  * similar laptops (adapted from Fujitsu init verbs).
6754  */
6755 static const struct hda_verb alc260_acer_init_verbs[] = {
6756         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
6757          * the headphone jack.  Turn this on and rely on the standard mute
6758          * methods whenever the user wants to turn these outputs off.
6759          */
6760         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
6761         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6762         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6763         /* Internal speaker/Headphone jack is connected to Line-out pin */
6764         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6765         /* Internal microphone/Mic jack is connected to Mic1 pin */
6766         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
6767         /* Line In jack is connected to Line1 pin */
6768         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6769         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
6770         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6771         /* Ensure all other unused pins are disabled and muted. */
6772         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6773         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6774         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6775         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6776         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6777         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6778         /* Disable digital (SPDIF) pins */
6779         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
6780         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
6781
6782         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
6783          * bus when acting as outputs.
6784          */
6785         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
6786         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
6787
6788         /* Start with output sum widgets muted and their output gains at min */
6789         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6790         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6791         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6792         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6793         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6794         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6795         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6796         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6797         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6798
6799         /* Unmute Line-out pin widget amp left and right
6800          * (no equiv mixer ctrl)
6801          */
6802         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6803         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
6804         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6805         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
6806          * inputs. If the pin mode is changed by the user the pin mode control
6807          * will take care of enabling the pin's input/output buffers as needed.
6808          * Therefore there's no need to enable the input buffer at this
6809          * stage.
6810          */
6811         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6813
6814         /* Mute capture amp left and right */
6815         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6816         /* Set ADC connection select to match default mixer setting - mic
6817          * (on mic1 pin)
6818          */
6819         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6820
6821         /* Do similar with the second ADC: mute capture input amp and
6822          * set ADC connection to mic to match ALSA's default state.
6823          */
6824         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6825         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6826
6827         /* Mute all inputs to mixer widget (even unconnected ones) */
6828         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
6829         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
6830         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
6831         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
6832         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
6833         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
6834         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
6835         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
6836
6837         { }
6838 };
6839
6840 /* Initialisation sequence for Maxdata Favorit 100XS
6841  * (adapted from Acer init verbs).
6842  */
6843 static const struct hda_verb alc260_favorit100_init_verbs[] = {
6844         /* GPIO 0 enables the output jack.
6845          * Turn this on and rely on the standard mute
6846          * methods whenever the user wants to turn these outputs off.
6847          */
6848         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
6849         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6850         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6851         /* Line/Mic input jack is connected to Mic1 pin */
6852         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
6853         /* Ensure all other unused pins are disabled and muted. */
6854         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6855         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6856         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6857         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6858         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6859         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6860         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6861         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6862         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
6863         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6864         /* Disable digital (SPDIF) pins */
6865         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
6866         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
6867
6868         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
6869          * bus when acting as outputs.
6870          */
6871         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
6872         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
6873
6874         /* Start with output sum widgets muted and their output gains at min */
6875         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6876         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6877         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6878         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6879         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6880         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6881         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6882         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6883         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6884
6885         /* Unmute Line-out pin widget amp left and right
6886          * (no equiv mixer ctrl)
6887          */
6888         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6889         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
6890          * inputs. If the pin mode is changed by the user the pin mode control
6891          * will take care of enabling the pin's input/output buffers as needed.
6892          * Therefore there's no need to enable the input buffer at this
6893          * stage.
6894          */
6895         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6896
6897         /* Mute capture amp left and right */
6898         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6899         /* Set ADC connection select to match default mixer setting - mic
6900          * (on mic1 pin)
6901          */
6902         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6903
6904         /* Do similar with the second ADC: mute capture input amp and
6905          * set ADC connection to mic to match ALSA's default state.
6906          */
6907         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6908         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6909
6910         /* Mute all inputs to mixer widget (even unconnected ones) */
6911         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
6912         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
6913         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
6914         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
6915         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
6916         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
6917         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
6918         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
6919
6920         { }
6921 };
6922
6923 static const struct hda_verb alc260_will_verbs[] = {
6924         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6925         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
6926         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
6927         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
6928         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
6929         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
6930         {}
6931 };
6932
6933 static const struct hda_verb alc260_replacer_672v_verbs[] = {
6934         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
6935         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
6936         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
6937
6938         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
6939         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6940         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6941
6942         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6943         {}
6944 };
6945
6946 /* toggle speaker-output according to the hp-jack state */
6947 static void alc260_replacer_672v_automute(struct hda_codec *codec)
6948 {
6949         unsigned int present;
6950
6951         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
6952         present = snd_hda_jack_detect(codec, 0x0f);
6953         if (present) {
6954                 snd_hda_codec_write_cache(codec, 0x01, 0,
6955                                           AC_VERB_SET_GPIO_DATA, 1);
6956                 snd_hda_codec_write_cache(codec, 0x0f, 0,
6957                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
6958                                           PIN_HP);
6959         } else {
6960                 snd_hda_codec_write_cache(codec, 0x01, 0,
6961                                           AC_VERB_SET_GPIO_DATA, 0);
6962                 snd_hda_codec_write_cache(codec, 0x0f, 0,
6963                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
6964                                           PIN_OUT);
6965         }
6966 }
6967
6968 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
6969                                        unsigned int res)
6970 {
6971         if ((res >> 26) == ALC880_HP_EVENT)
6972                 alc260_replacer_672v_automute(codec);
6973 }
6974
6975 static const struct hda_verb alc260_hp_dc7600_verbs[] = {
6976         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
6977         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6978         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6979         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6980         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6981         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6982         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6983         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6984         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6985         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6986         {}
6987 };
6988
6989 /* Test configuration for debugging, modelled after the ALC880 test
6990  * configuration.
6991  */
6992 #ifdef CONFIG_SND_DEBUG
6993 static const hda_nid_t alc260_test_dac_nids[1] = {
6994         0x02,
6995 };
6996 static const hda_nid_t alc260_test_adc_nids[2] = {
6997         0x04, 0x05,
6998 };
6999 /* For testing the ALC260, each input MUX needs its own definition since
7000  * the signal assignments are different.  This assumes that the first ADC
7001  * is NID 0x04.
7002  */
7003 static const struct hda_input_mux alc260_test_capture_sources[2] = {
7004         {
7005                 .num_items = 7,
7006                 .items = {
7007                         { "MIC1 pin", 0x0 },
7008                         { "MIC2 pin", 0x1 },
7009                         { "LINE1 pin", 0x2 },
7010                         { "LINE2 pin", 0x3 },
7011                         { "CD pin", 0x4 },
7012                         { "LINE-OUT pin", 0x5 },
7013                         { "HP-OUT pin", 0x6 },
7014                 },
7015         },
7016         {
7017                 .num_items = 8,
7018                 .items = {
7019                         { "MIC1 pin", 0x0 },
7020                         { "MIC2 pin", 0x1 },
7021                         { "LINE1 pin", 0x2 },
7022                         { "LINE2 pin", 0x3 },
7023                         { "CD pin", 0x4 },
7024                         { "Mixer", 0x5 },
7025                         { "LINE-OUT pin", 0x6 },
7026                         { "HP-OUT pin", 0x7 },
7027                 },
7028         },
7029 };
7030 static const struct snd_kcontrol_new alc260_test_mixer[] = {
7031         /* Output driver widgets */
7032         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
7033         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
7034         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
7035         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
7036         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
7037         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
7038
7039         /* Modes for retasking pin widgets
7040          * Note: the ALC260 doesn't seem to act on requests to enable mic
7041          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
7042          * mention this restriction.  At this stage it's not clear whether
7043          * this behaviour is intentional or is a hardware bug in chip
7044          * revisions available at least up until early 2006.  Therefore for
7045          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
7046          * choices, but if it turns out that the lack of mic bias for these
7047          * NIDs is intentional we could change their modes from
7048          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
7049          */
7050         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
7051         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
7052         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
7053         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
7054         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
7055         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
7056
7057         /* Loopback mixer controls */
7058         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
7059         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
7060         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
7061         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
7062         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
7063         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
7064         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
7065         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
7066         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
7067         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
7068         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
7069         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
7070         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
7071         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
7072
7073         /* Controls for GPIO pins, assuming they are configured as outputs */
7074         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
7075         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
7076         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
7077         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
7078
7079         /* Switches to allow the digital IO pins to be enabled.  The datasheet
7080          * is ambigious as to which NID is which; testing on laptops which
7081          * make this output available should provide clarification.
7082          */
7083         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
7084         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
7085
7086         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
7087          * this output to turn on an external amplifier.
7088          */
7089         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
7090         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
7091
7092         { } /* end */
7093 };
7094 static const struct hda_verb alc260_test_init_verbs[] = {
7095         /* Enable all GPIOs as outputs with an initial value of 0 */
7096         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
7097         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
7098         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
7099
7100         /* Enable retasking pins as output, initially without power amp */
7101         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7102         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7103         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7104         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7105         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7106         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7107
7108         /* Disable digital (SPDIF) pins initially, but users can enable
7109          * them via a mixer switch.  In the case of SPDIF-out, this initverb
7110          * payload also sets the generation to 0, output to be in "consumer"
7111          * PCM format, copyright asserted, no pre-emphasis and no validity
7112          * control.
7113          */
7114         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
7115         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
7116
7117         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
7118          * OUT1 sum bus when acting as an output.
7119          */
7120         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
7121         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
7122         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
7123         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
7124
7125         /* Start with output sum widgets muted and their output gains at min */
7126         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7127         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7128         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7129         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7130         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7131         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7132         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7133         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7134         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7135
7136         /* Unmute retasking pin widget output buffers since the default
7137          * state appears to be output.  As the pin mode is changed by the
7138          * user the pin mode control will take care of enabling the pin's
7139          * input/output buffers as needed.
7140          */
7141         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7142         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7143         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7144         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7145         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7146         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7147         /* Also unmute the mono-out pin widget */
7148         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7149
7150         /* Mute capture amp left and right */
7151         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7152         /* Set ADC connection select to match default mixer setting (mic1
7153          * pin)
7154          */
7155         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
7156
7157         /* Do the same for the second ADC: mute capture input amp and
7158          * set ADC connection to mic1 pin
7159          */
7160         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7161         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
7162
7163         /* Mute all inputs to mixer widget (even unconnected ones) */
7164         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
7165         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
7166         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
7167         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
7168         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
7169         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
7170         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
7171         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
7172
7173         { }
7174 };
7175 #endif
7176
7177 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
7178 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
7179
7180 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
7181 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
7182
7183 /*
7184  * for BIOS auto-configuration
7185  */
7186
7187 /* convert from pin to volume-mixer widget */
7188 static hda_nid_t alc260_pin_to_vol_mix(hda_nid_t nid)
7189 {
7190         if (nid >= 0x0f && nid <= 0x11)
7191                 return nid - 0x7;
7192         else if (nid >= 0x12 && nid <= 0x15)
7193                 return 0x08;
7194         else
7195                 return 0;
7196 }
7197
7198 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
7199                                         const char *pfx, int *vol_bits)
7200 {
7201         hda_nid_t nid_vol;
7202         unsigned long vol_val, sw_val;
7203         int chs, err;
7204
7205         nid_vol = alc260_pin_to_vol_mix(nid);
7206         if (!nid_vol)
7207                 return 0; /* N/A */
7208         if (nid == 0x11)
7209                 chs = 2;
7210         else
7211                 chs = 3;
7212         vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, chs, 0, HDA_OUTPUT);
7213         sw_val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
7214
7215         if (!(*vol_bits & (1 << nid_vol))) {
7216                 /* first control for the volume widget */
7217                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
7218                 if (err < 0)
7219                         return err;
7220                 *vol_bits |= (1 << nid_vol);
7221         }
7222         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
7223         if (err < 0)
7224                 return err;
7225         return 1;
7226 }
7227
7228 /* add playback controls from the parsed DAC table */
7229 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
7230                                              const struct auto_pin_cfg *cfg)
7231 {
7232         hda_nid_t nid;
7233         int err;
7234         int vols = 0;
7235
7236         spec->multiout.num_dacs = 1;
7237         spec->multiout.dac_nids = spec->private_dac_nids;
7238         spec->private_dac_nids[0] = 0x02;
7239
7240         nid = cfg->line_out_pins[0];
7241         if (nid) {
7242                 const char *pfx;
7243                 int index;
7244                 pfx = alc_get_line_out_pfx(spec, 0, true, &index);
7245                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
7246                 if (err < 0)
7247                         return err;
7248         }
7249
7250         nid = cfg->speaker_pins[0];
7251         if (nid) {
7252                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
7253                 if (err < 0)
7254                         return err;
7255         }
7256
7257         nid = cfg->hp_pins[0];
7258         if (nid) {
7259                 err = alc260_add_playback_controls(spec, nid, "Headphone",
7260                                                    &vols);
7261                 if (err < 0)
7262                         return err;
7263         }
7264         return 0;
7265 }
7266
7267 /* create playback/capture controls for input pins */
7268 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
7269                                                 const struct auto_pin_cfg *cfg)
7270 {
7271         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
7272 }
7273
7274 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
7275                                               hda_nid_t nid, int pin_type,
7276                                               int sel_idx)
7277 {
7278         hda_nid_t mix;
7279
7280         alc_set_pin_output(codec, nid, pin_type);
7281         /* need the manual connection? */
7282         if (nid >= 0x12) {
7283                 int idx = nid - 0x12;
7284                 snd_hda_codec_write(codec, idx + 0x0b, 0,
7285                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
7286         }
7287
7288         mix = alc260_pin_to_vol_mix(nid);
7289         if (!mix)
7290                 return;
7291         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7292                             AMP_OUT_ZERO);
7293         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7294                             AMP_IN_UNMUTE(0));
7295         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7296                             AMP_IN_UNMUTE(1));
7297 }
7298
7299 static void alc260_auto_init_multi_out(struct hda_codec *codec)
7300 {
7301         struct alc_spec *spec = codec->spec;
7302         hda_nid_t nid;
7303
7304         nid = spec->autocfg.line_out_pins[0];
7305         if (nid) {
7306                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7307                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
7308         }
7309
7310         nid = spec->autocfg.speaker_pins[0];
7311         if (nid)
7312                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
7313
7314         nid = spec->autocfg.hp_pins[0];
7315         if (nid)
7316                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
7317 }
7318
7319 #define alc260_auto_init_analog_input   alc880_auto_init_analog_input
7320 #define alc260_auto_init_input_src      alc880_auto_init_input_src
7321
7322 static int alc260_parse_auto_config(struct hda_codec *codec)
7323 {
7324         struct alc_spec *spec = codec->spec;
7325         int err;
7326         static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
7327
7328         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
7329                                            alc260_ignore);
7330         if (err < 0)
7331                 return err;
7332         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
7333         if (err < 0)
7334                 return err;
7335         if (!spec->kctls.list)
7336                 return 0; /* can't find valid BIOS pin config */
7337         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
7338         if (err < 0)
7339                 return err;
7340
7341         spec->multiout.max_channels = 2;
7342
7343         if (spec->autocfg.dig_outs)
7344                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
7345         if (spec->kctls.list)
7346                 add_mixer(spec, spec->kctls.list);
7347
7348         spec->num_mux_defs = 1;
7349         spec->input_mux = &spec->private_imux[0];
7350
7351         alc_ssid_check(codec, 0x10, 0x15, 0x0f, 0);
7352
7353         return 1;
7354 }
7355
7356 /* additional initialization for auto-configuration model */
7357 static void alc260_auto_init(struct hda_codec *codec)
7358 {
7359         struct alc_spec *spec = codec->spec;
7360         alc260_auto_init_multi_out(codec);
7361         alc260_auto_init_analog_input(codec);
7362         alc260_auto_init_input_src(codec);
7363         alc_auto_init_digital(codec);
7364         if (spec->unsol_event)
7365                 alc_inithook(codec);
7366 }
7367
7368 #ifdef CONFIG_SND_HDA_POWER_SAVE
7369 static const struct hda_amp_list alc260_loopbacks[] = {
7370         { 0x07, HDA_INPUT, 0 },
7371         { 0x07, HDA_INPUT, 1 },
7372         { 0x07, HDA_INPUT, 2 },
7373         { 0x07, HDA_INPUT, 3 },
7374         { 0x07, HDA_INPUT, 4 },
7375         { } /* end */
7376 };
7377 #endif
7378
7379 /*
7380  * Pin config fixes
7381  */
7382 enum {
7383         PINFIX_HP_DC5750,
7384 };
7385
7386 static const struct alc_fixup alc260_fixups[] = {
7387         [PINFIX_HP_DC5750] = {
7388                 .type = ALC_FIXUP_PINS,
7389                 .v.pins = (const struct alc_pincfg[]) {
7390                         { 0x11, 0x90130110 }, /* speaker */
7391                         { }
7392                 }
7393         },
7394 };
7395
7396 static const struct snd_pci_quirk alc260_fixup_tbl[] = {
7397         SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
7398         {}
7399 };
7400
7401 /*
7402  * ALC260 configurations
7403  */
7404 static const char * const alc260_models[ALC260_MODEL_LAST] = {
7405         [ALC260_BASIC]          = "basic",
7406         [ALC260_HP]             = "hp",
7407         [ALC260_HP_3013]        = "hp-3013",
7408         [ALC260_HP_DC7600]      = "hp-dc7600",
7409         [ALC260_FUJITSU_S702X]  = "fujitsu",
7410         [ALC260_ACER]           = "acer",
7411         [ALC260_WILL]           = "will",
7412         [ALC260_REPLACER_672V]  = "replacer",
7413         [ALC260_FAVORIT100]     = "favorit100",
7414 #ifdef CONFIG_SND_DEBUG
7415         [ALC260_TEST]           = "test",
7416 #endif
7417         [ALC260_AUTO]           = "auto",
7418 };
7419
7420 static const struct snd_pci_quirk alc260_cfg_tbl[] = {
7421         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
7422         SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL),
7423         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
7424         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
7425         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
7426         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
7427         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
7428         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
7429         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
7430         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
7431         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
7432         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
7433         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
7434         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
7435         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
7436         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
7437         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
7438         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
7439         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
7440         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
7441         {}
7442 };
7443
7444 static const struct alc_config_preset alc260_presets[] = {
7445         [ALC260_BASIC] = {
7446                 .mixers = { alc260_base_output_mixer,
7447                             alc260_input_mixer },
7448                 .init_verbs = { alc260_init_verbs },
7449                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7450                 .dac_nids = alc260_dac_nids,
7451                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7452                 .adc_nids = alc260_dual_adc_nids,
7453                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7454                 .channel_mode = alc260_modes,
7455                 .input_mux = &alc260_capture_source,
7456         },
7457         [ALC260_HP] = {
7458                 .mixers = { alc260_hp_output_mixer,
7459                             alc260_input_mixer },
7460                 .init_verbs = { alc260_init_verbs,
7461                                 alc260_hp_unsol_verbs },
7462                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7463                 .dac_nids = alc260_dac_nids,
7464                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
7465                 .adc_nids = alc260_adc_nids_alt,
7466                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7467                 .channel_mode = alc260_modes,
7468                 .input_mux = &alc260_capture_source,
7469                 .unsol_event = alc_sku_unsol_event,
7470                 .setup = alc260_hp_setup,
7471                 .init_hook = alc_inithook,
7472         },
7473         [ALC260_HP_DC7600] = {
7474                 .mixers = { alc260_hp_dc7600_mixer,
7475                             alc260_input_mixer },
7476                 .init_verbs = { alc260_init_verbs,
7477                                 alc260_hp_dc7600_verbs },
7478                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7479                 .dac_nids = alc260_dac_nids,
7480                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
7481                 .adc_nids = alc260_adc_nids_alt,
7482                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7483                 .channel_mode = alc260_modes,
7484                 .input_mux = &alc260_capture_source,
7485                 .unsol_event = alc_sku_unsol_event,
7486                 .setup = alc260_hp_3012_setup,
7487                 .init_hook = alc_inithook,
7488         },
7489         [ALC260_HP_3013] = {
7490                 .mixers = { alc260_hp_3013_mixer,
7491                             alc260_input_mixer },
7492                 .init_verbs = { alc260_hp_3013_init_verbs,
7493                                 alc260_hp_3013_unsol_verbs },
7494                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7495                 .dac_nids = alc260_dac_nids,
7496                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
7497                 .adc_nids = alc260_adc_nids_alt,
7498                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7499                 .channel_mode = alc260_modes,
7500                 .input_mux = &alc260_capture_source,
7501                 .unsol_event = alc_sku_unsol_event,
7502                 .setup = alc260_hp_3013_setup,
7503                 .init_hook = alc_inithook,
7504         },
7505         [ALC260_FUJITSU_S702X] = {
7506                 .mixers = { alc260_fujitsu_mixer },
7507                 .init_verbs = { alc260_fujitsu_init_verbs },
7508                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7509                 .dac_nids = alc260_dac_nids,
7510                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7511                 .adc_nids = alc260_dual_adc_nids,
7512                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7513                 .channel_mode = alc260_modes,
7514                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
7515                 .input_mux = alc260_fujitsu_capture_sources,
7516         },
7517         [ALC260_ACER] = {
7518                 .mixers = { alc260_acer_mixer },
7519                 .init_verbs = { alc260_acer_init_verbs },
7520                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7521                 .dac_nids = alc260_dac_nids,
7522                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7523                 .adc_nids = alc260_dual_adc_nids,
7524                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7525                 .channel_mode = alc260_modes,
7526                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
7527                 .input_mux = alc260_acer_capture_sources,
7528         },
7529         [ALC260_FAVORIT100] = {
7530                 .mixers = { alc260_favorit100_mixer },
7531                 .init_verbs = { alc260_favorit100_init_verbs },
7532                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7533                 .dac_nids = alc260_dac_nids,
7534                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
7535                 .adc_nids = alc260_dual_adc_nids,
7536                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7537                 .channel_mode = alc260_modes,
7538                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
7539                 .input_mux = alc260_favorit100_capture_sources,
7540         },
7541         [ALC260_WILL] = {
7542                 .mixers = { alc260_will_mixer },
7543                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
7544                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7545                 .dac_nids = alc260_dac_nids,
7546                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
7547                 .adc_nids = alc260_adc_nids,
7548                 .dig_out_nid = ALC260_DIGOUT_NID,
7549                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7550                 .channel_mode = alc260_modes,
7551                 .input_mux = &alc260_capture_source,
7552         },
7553         [ALC260_REPLACER_672V] = {
7554                 .mixers = { alc260_replacer_672v_mixer },
7555                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
7556                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
7557                 .dac_nids = alc260_dac_nids,
7558                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
7559                 .adc_nids = alc260_adc_nids,
7560                 .dig_out_nid = ALC260_DIGOUT_NID,
7561                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7562                 .channel_mode = alc260_modes,
7563                 .input_mux = &alc260_capture_source,
7564                 .unsol_event = alc260_replacer_672v_unsol_event,
7565                 .init_hook = alc260_replacer_672v_automute,
7566         },
7567 #ifdef CONFIG_SND_DEBUG
7568         [ALC260_TEST] = {
7569                 .mixers = { alc260_test_mixer },
7570                 .init_verbs = { alc260_test_init_verbs },
7571                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
7572                 .dac_nids = alc260_test_dac_nids,
7573                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
7574                 .adc_nids = alc260_test_adc_nids,
7575                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
7576                 .channel_mode = alc260_modes,
7577                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
7578                 .input_mux = alc260_test_capture_sources,
7579         },
7580 #endif
7581 };
7582
7583 static int patch_alc260(struct hda_codec *codec)
7584 {
7585         struct alc_spec *spec;
7586         int err, board_config;
7587
7588         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7589         if (spec == NULL)
7590                 return -ENOMEM;
7591
7592         codec->spec = spec;
7593
7594         spec->mixer_nid = 0x07;
7595
7596         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
7597                                                   alc260_models,
7598                                                   alc260_cfg_tbl);
7599         if (board_config < 0) {
7600                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
7601                            codec->chip_name);
7602                 board_config = ALC260_AUTO;
7603         }
7604
7605         if (board_config == ALC260_AUTO) {
7606                 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
7607                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7608         }
7609
7610         if (board_config == ALC260_AUTO) {
7611                 /* automatic parse from the BIOS config */
7612                 err = alc260_parse_auto_config(codec);
7613                 if (err < 0) {
7614                         alc_free(codec);
7615                         return err;
7616                 } else if (!err) {
7617                         printk(KERN_INFO
7618                                "hda_codec: Cannot set up configuration "
7619                                "from BIOS.  Using base mode...\n");
7620                         board_config = ALC260_BASIC;
7621                 }
7622         }
7623
7624         err = snd_hda_attach_beep_device(codec, 0x1);
7625         if (err < 0) {
7626                 alc_free(codec);
7627                 return err;
7628         }
7629
7630         if (board_config != ALC260_AUTO)
7631                 setup_preset(codec, &alc260_presets[board_config]);
7632
7633         spec->stream_analog_playback = &alc260_pcm_analog_playback;
7634         spec->stream_analog_capture = &alc260_pcm_analog_capture;
7635         spec->stream_analog_alt_capture = &alc260_pcm_analog_capture;
7636
7637         spec->stream_digital_playback = &alc260_pcm_digital_playback;
7638         spec->stream_digital_capture = &alc260_pcm_digital_capture;
7639
7640         if (!spec->adc_nids && spec->input_mux) {
7641                 /* check whether NID 0x04 is valid */
7642                 unsigned int wcap = get_wcaps(codec, 0x04);
7643                 wcap = get_wcaps_type(wcap);
7644                 /* get type */
7645                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
7646                         spec->adc_nids = alc260_adc_nids_alt;
7647                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
7648                 } else {
7649                         spec->adc_nids = alc260_adc_nids;
7650                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
7651                 }
7652         }
7653         set_capture_mixer(codec);
7654         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
7655
7656         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7657
7658         spec->vmaster_nid = 0x08;
7659
7660         codec->patch_ops = alc_patch_ops;
7661         if (board_config == ALC260_AUTO)
7662                 spec->init_hook = alc260_auto_init;
7663         spec->shutup = alc_eapd_shutup;
7664 #ifdef CONFIG_SND_HDA_POWER_SAVE
7665         if (!spec->loopback.amplist)
7666                 spec->loopback.amplist = alc260_loopbacks;
7667 #endif
7668
7669         return 0;
7670 }
7671
7672
7673 /*
7674  * ALC882/883/885/888/889 support
7675  *
7676  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
7677  * configuration.  Each pin widget can choose any input DACs and a mixer.
7678  * Each ADC is connected from a mixer of all inputs.  This makes possible
7679  * 6-channel independent captures.
7680  *
7681  * In addition, an independent DAC for the multi-playback (not used in this
7682  * driver yet).
7683  */
7684 #define ALC882_DIGOUT_NID       0x06
7685 #define ALC882_DIGIN_NID        0x0a
7686 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
7687 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
7688 #define ALC1200_DIGOUT_NID      0x10
7689
7690
7691 static const struct hda_channel_mode alc882_ch_modes[1] = {
7692         { 8, NULL }
7693 };
7694
7695 /* DACs */
7696 static const hda_nid_t alc882_dac_nids[4] = {
7697         /* front, rear, clfe, rear_surr */
7698         0x02, 0x03, 0x04, 0x05
7699 };
7700 #define alc883_dac_nids         alc882_dac_nids
7701
7702 /* ADCs */
7703 #define alc882_adc_nids         alc880_adc_nids
7704 #define alc882_adc_nids_alt     alc880_adc_nids_alt
7705 #define alc883_adc_nids         alc882_adc_nids_alt
7706 static const hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
7707 static const hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
7708 #define alc889_adc_nids         alc880_adc_nids
7709
7710 static const hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
7711 static const hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
7712 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
7713 static const hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7714 #define alc889_capsrc_nids      alc882_capsrc_nids
7715
7716 /* input MUX */
7717 /* FIXME: should be a matrix-type input source selection */
7718
7719 static const struct hda_input_mux alc882_capture_source = {
7720         .num_items = 4,
7721         .items = {
7722                 { "Mic", 0x0 },
7723                 { "Front Mic", 0x1 },
7724                 { "Line", 0x2 },
7725                 { "CD", 0x4 },
7726         },
7727 };
7728
7729 #define alc883_capture_source   alc882_capture_source
7730
7731 static const struct hda_input_mux alc889_capture_source = {
7732         .num_items = 3,
7733         .items = {
7734                 { "Front Mic", 0x0 },
7735                 { "Mic", 0x3 },
7736                 { "Line", 0x2 },
7737         },
7738 };
7739
7740 static const struct hda_input_mux mb5_capture_source = {
7741         .num_items = 3,
7742         .items = {
7743                 { "Mic", 0x1 },
7744                 { "Line", 0x7 },
7745                 { "CD", 0x4 },
7746         },
7747 };
7748
7749 static const struct hda_input_mux macmini3_capture_source = {
7750         .num_items = 2,
7751         .items = {
7752                 { "Line", 0x2 },
7753                 { "CD", 0x4 },
7754         },
7755 };
7756
7757 static const struct hda_input_mux alc883_3stack_6ch_intel = {
7758         .num_items = 4,
7759         .items = {
7760                 { "Mic", 0x1 },
7761                 { "Front Mic", 0x0 },
7762                 { "Line", 0x2 },
7763                 { "CD", 0x4 },
7764         },
7765 };
7766
7767 static const struct hda_input_mux alc883_lenovo_101e_capture_source = {
7768         .num_items = 2,
7769         .items = {
7770                 { "Mic", 0x1 },
7771                 { "Line", 0x2 },
7772         },
7773 };
7774
7775 static const struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7776         .num_items = 4,
7777         .items = {
7778                 { "Mic", 0x0 },
7779                 { "Internal Mic", 0x1 },
7780                 { "Line", 0x2 },
7781                 { "CD", 0x4 },
7782         },
7783 };
7784
7785 static const struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7786         .num_items = 2,
7787         .items = {
7788                 { "Mic", 0x0 },
7789                 { "Internal Mic", 0x1 },
7790         },
7791 };
7792
7793 static const struct hda_input_mux alc883_lenovo_sky_capture_source = {
7794         .num_items = 3,
7795         .items = {
7796                 { "Mic", 0x0 },
7797                 { "Front Mic", 0x1 },
7798                 { "Line", 0x4 },
7799         },
7800 };
7801
7802 static const struct hda_input_mux alc883_asus_eee1601_capture_source = {
7803         .num_items = 2,
7804         .items = {
7805                 { "Mic", 0x0 },
7806                 { "Line", 0x2 },
7807         },
7808 };
7809
7810 static const struct hda_input_mux alc889A_mb31_capture_source = {
7811         .num_items = 2,
7812         .items = {
7813                 { "Mic", 0x0 },
7814                 /* Front Mic (0x01) unused */
7815                 { "Line", 0x2 },
7816                 /* Line 2 (0x03) unused */
7817                 /* CD (0x04) unused? */
7818         },
7819 };
7820
7821 static const struct hda_input_mux alc889A_imac91_capture_source = {
7822         .num_items = 2,
7823         .items = {
7824                 { "Mic", 0x01 },
7825                 { "Line", 0x2 }, /* Not sure! */
7826         },
7827 };
7828
7829 /*
7830  * 2ch mode
7831  */
7832 static const struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7833         { 2, NULL }
7834 };
7835
7836 /*
7837  * 2ch mode
7838  */
7839 static const struct hda_verb alc882_3ST_ch2_init[] = {
7840         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7841         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7842         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7843         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7844         { } /* end */
7845 };
7846
7847 /*
7848  * 4ch mode
7849  */
7850 static const struct hda_verb alc882_3ST_ch4_init[] = {
7851         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7852         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7853         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7854         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7855         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7856         { } /* end */
7857 };
7858
7859 /*
7860  * 6ch mode
7861  */
7862 static const struct hda_verb alc882_3ST_ch6_init[] = {
7863         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7864         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7865         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7866         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7867         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7868         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7869         { } /* end */
7870 };
7871
7872 static const struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
7873         { 2, alc882_3ST_ch2_init },
7874         { 4, alc882_3ST_ch4_init },
7875         { 6, alc882_3ST_ch6_init },
7876 };
7877
7878 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
7879
7880 /*
7881  * 2ch mode
7882  */
7883 static const struct hda_verb alc883_3ST_ch2_clevo_init[] = {
7884         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
7885         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7886         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7887         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7888         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7889         { } /* end */
7890 };
7891
7892 /*
7893  * 4ch mode
7894  */
7895 static const struct hda_verb alc883_3ST_ch4_clevo_init[] = {
7896         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7897         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7898         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7899         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7900         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7901         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7902         { } /* end */
7903 };
7904
7905 /*
7906  * 6ch mode
7907  */
7908 static const struct hda_verb alc883_3ST_ch6_clevo_init[] = {
7909         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7910         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7911         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7912         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7913         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7914         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7915         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7916         { } /* end */
7917 };
7918
7919 static const struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
7920         { 2, alc883_3ST_ch2_clevo_init },
7921         { 4, alc883_3ST_ch4_clevo_init },
7922         { 6, alc883_3ST_ch6_clevo_init },
7923 };
7924
7925
7926 /*
7927  * 6ch mode
7928  */
7929 static const struct hda_verb alc882_sixstack_ch6_init[] = {
7930         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7931         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7932         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7933         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7934         { } /* end */
7935 };
7936
7937 /*
7938  * 8ch mode
7939  */
7940 static const struct hda_verb alc882_sixstack_ch8_init[] = {
7941         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7942         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7943         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7944         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7945         { } /* end */
7946 };
7947
7948 static const struct hda_channel_mode alc882_sixstack_modes[2] = {
7949         { 6, alc882_sixstack_ch6_init },
7950         { 8, alc882_sixstack_ch8_init },
7951 };
7952
7953
7954 /* Macbook Air 2,1 */
7955
7956 static const struct hda_channel_mode alc885_mba21_ch_modes[1] = {
7957       { 2, NULL },
7958 };
7959
7960 /*
7961  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
7962  */
7963
7964 /*
7965  * 2ch mode
7966  */
7967 static const struct hda_verb alc885_mbp_ch2_init[] = {
7968         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7969         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7970         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7971         { } /* end */
7972 };
7973
7974 /*
7975  * 4ch mode
7976  */
7977 static const struct hda_verb alc885_mbp_ch4_init[] = {
7978         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7979         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7980         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7981         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7982         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7983         { } /* end */
7984 };
7985
7986 static const struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
7987         { 2, alc885_mbp_ch2_init },
7988         { 4, alc885_mbp_ch4_init },
7989 };
7990
7991 /*
7992  * 2ch
7993  * Speakers/Woofer/HP = Front
7994  * LineIn = Input
7995  */
7996 static const struct hda_verb alc885_mb5_ch2_init[] = {
7997         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7998         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7999         { } /* end */
8000 };
8001
8002 /*
8003  * 6ch mode
8004  * Speakers/HP = Front
8005  * Woofer = LFE
8006  * LineIn = Surround
8007  */
8008 static const struct hda_verb alc885_mb5_ch6_init[] = {
8009         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8010         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8011         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8012         { } /* end */
8013 };
8014
8015 static const struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
8016         { 2, alc885_mb5_ch2_init },
8017         { 6, alc885_mb5_ch6_init },
8018 };
8019
8020 #define alc885_macmini3_6ch_modes       alc885_mb5_6ch_modes
8021
8022 /*
8023  * 2ch mode
8024  */
8025 static const struct hda_verb alc883_4ST_ch2_init[] = {
8026         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8027         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8028         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8029         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8030         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8031         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8032         { } /* end */
8033 };
8034
8035 /*
8036  * 4ch mode
8037  */
8038 static const struct hda_verb alc883_4ST_ch4_init[] = {
8039         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8040         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8041         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8042         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8043         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8044         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8045         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8046         { } /* end */
8047 };
8048
8049 /*
8050  * 6ch mode
8051  */
8052 static const struct hda_verb alc883_4ST_ch6_init[] = {
8053         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8054         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8055         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8056         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8057         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8058         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8059         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8060         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8061         { } /* end */
8062 };
8063
8064 /*
8065  * 8ch mode
8066  */
8067 static const struct hda_verb alc883_4ST_ch8_init[] = {
8068         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8069         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8070         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
8071         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8072         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8073         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8074         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8075         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8076         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8077         { } /* end */
8078 };
8079
8080 static const struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
8081         { 2, alc883_4ST_ch2_init },
8082         { 4, alc883_4ST_ch4_init },
8083         { 6, alc883_4ST_ch6_init },
8084         { 8, alc883_4ST_ch8_init },
8085 };
8086
8087
8088 /*
8089  * 2ch mode
8090  */
8091 static const struct hda_verb alc883_3ST_ch2_intel_init[] = {
8092         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8093         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8094         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8095         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8096         { } /* end */
8097 };
8098
8099 /*
8100  * 4ch mode
8101  */
8102 static const struct hda_verb alc883_3ST_ch4_intel_init[] = {
8103         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8104         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8105         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8106         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8107         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8108         { } /* end */
8109 };
8110
8111 /*
8112  * 6ch mode
8113  */
8114 static const struct hda_verb alc883_3ST_ch6_intel_init[] = {
8115         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8116         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8117         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
8118         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8119         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8120         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
8121         { } /* end */
8122 };
8123
8124 static const struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
8125         { 2, alc883_3ST_ch2_intel_init },
8126         { 4, alc883_3ST_ch4_intel_init },
8127         { 6, alc883_3ST_ch6_intel_init },
8128 };
8129
8130 /*
8131  * 2ch mode
8132  */
8133 static const struct hda_verb alc889_ch2_intel_init[] = {
8134         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
8135         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
8136         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
8137         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
8138         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8139         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8140         { } /* end */
8141 };
8142
8143 /*
8144  * 6ch mode
8145  */
8146 static const struct hda_verb alc889_ch6_intel_init[] = {
8147         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
8148         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
8149         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
8150         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
8151         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8152         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8153         { } /* end */
8154 };
8155
8156 /*
8157  * 8ch mode
8158  */
8159 static const struct hda_verb alc889_ch8_intel_init[] = {
8160         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
8161         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
8162         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
8163         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
8164         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
8165         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8166         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8167         { } /* end */
8168 };
8169
8170 static const struct hda_channel_mode alc889_8ch_intel_modes[3] = {
8171         { 2, alc889_ch2_intel_init },
8172         { 6, alc889_ch6_intel_init },
8173         { 8, alc889_ch8_intel_init },
8174 };
8175
8176 /*
8177  * 6ch mode
8178  */
8179 static const struct hda_verb alc883_sixstack_ch6_init[] = {
8180         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8181         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8182         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8183         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8184         { } /* end */
8185 };
8186
8187 /*
8188  * 8ch mode
8189  */
8190 static const struct hda_verb alc883_sixstack_ch8_init[] = {
8191         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8192         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8193         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8194         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8195         { } /* end */
8196 };
8197
8198 static const struct hda_channel_mode alc883_sixstack_modes[2] = {
8199         { 6, alc883_sixstack_ch6_init },
8200         { 8, alc883_sixstack_ch8_init },
8201 };
8202
8203
8204 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
8205  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
8206  */
8207 static const struct snd_kcontrol_new alc882_base_mixer[] = {
8208         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8209         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8210         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8211         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8212         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8213         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8214         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8215         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8216         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8217         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8218         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8219         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8220         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8221         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8222         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8223         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8224         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8225         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8226         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8227         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8228         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8229         { } /* end */
8230 };
8231
8232 /* Macbook Air 2,1 same control for HP and internal Speaker */
8233
8234 static const struct snd_kcontrol_new alc885_mba21_mixer[] = {
8235       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8236       HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 0x02, HDA_OUTPUT),
8237      { }
8238 };
8239
8240
8241 static const struct snd_kcontrol_new alc885_mbp3_mixer[] = {
8242         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8243         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
8244         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
8245         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
8246         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8247         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8248         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8249         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8250         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8251         HDA_CODEC_VOLUME("Line Boost Volume", 0x1a, 0x00, HDA_INPUT),
8252         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x00, HDA_INPUT),
8253         { } /* end */
8254 };
8255
8256 static const struct snd_kcontrol_new alc885_mb5_mixer[] = {
8257         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8258         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8259         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8260         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8261         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
8262         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
8263         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
8264         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
8265         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
8266         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
8267         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8268         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8269         HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x00, HDA_INPUT),
8270         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0x00, HDA_INPUT),
8271         { } /* end */
8272 };
8273
8274 static const struct snd_kcontrol_new alc885_macmini3_mixer[] = {
8275         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8276         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8277         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8278         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8279         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
8280         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
8281         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
8282         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0f, 0x02, HDA_INPUT),
8283         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x07, HDA_INPUT),
8284         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x07, HDA_INPUT),
8285         HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x00, HDA_INPUT),
8286         { } /* end */
8287 };
8288
8289 static const struct snd_kcontrol_new alc885_imac91_mixer[] = {
8290         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8291         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
8292         { } /* end */
8293 };
8294
8295
8296 static const struct snd_kcontrol_new alc882_w2jc_mixer[] = {
8297         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8298         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8299         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8300         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8301         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8302         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8303         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8304         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8305         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8306         { } /* end */
8307 };
8308
8309 static const struct snd_kcontrol_new alc882_targa_mixer[] = {
8310         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8311         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8312         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8313         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8314         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8315         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8316         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8317         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8318         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8319         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8320         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8321         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8322         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
8323         { } /* end */
8324 };
8325
8326 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
8327  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
8328  */
8329 static const struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
8330         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8331         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8332         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8333         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8334         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8335         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8336         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8337         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8338         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
8339         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
8340         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8341         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8342         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8343         { } /* end */
8344 };
8345
8346 static const struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
8347         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8348         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8349         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8350         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8351         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8352         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8353         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8354         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8355         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
8356         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8357         { } /* end */
8358 };
8359
8360 static const struct snd_kcontrol_new alc882_chmode_mixer[] = {
8361         {
8362                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8363                 .name = "Channel Mode",
8364                 .info = alc_ch_mode_info,
8365                 .get = alc_ch_mode_get,
8366                 .put = alc_ch_mode_put,
8367         },
8368         { } /* end */
8369 };
8370
8371 static const struct hda_verb alc882_base_init_verbs[] = {
8372         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8373         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8374         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8375         /* Rear mixer */
8376         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8377         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8378         /* CLFE mixer */
8379         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8380         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8381         /* Side mixer */
8382         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8383         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8384
8385         /* Front Pin: output 0 (0x0c) */
8386         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8387         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8388         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8389         /* Rear Pin: output 1 (0x0d) */
8390         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8391         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8392         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8393         /* CLFE Pin: output 2 (0x0e) */
8394         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8395         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8396         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8397         /* Side Pin: output 3 (0x0f) */
8398         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8399         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8400         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8401         /* Mic (rear) pin: input vref at 80% */
8402         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8403         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8404         /* Front Mic pin: input vref at 80% */
8405         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8406         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8407         /* Line In pin: input */
8408         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8409         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8410         /* Line-2 In: Headphone output (output 0 - 0x0c) */
8411         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8412         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8413         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8414         /* CD pin widget for input */
8415         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8416
8417         /* FIXME: use matrix-type input source selection */
8418         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8419         /* Input mixer2 */
8420         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8421         /* Input mixer3 */
8422         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8423         /* ADC2: mute amp left and right */
8424         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8425         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8426         /* ADC3: mute amp left and right */
8427         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8428         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8429
8430         { }
8431 };
8432
8433 static const struct hda_verb alc882_adc1_init_verbs[] = {
8434         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8435         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8436         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8437         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8438         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8439         /* ADC1: mute amp left and right */
8440         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8441         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8442         { }
8443 };
8444
8445 static const struct hda_verb alc882_eapd_verbs[] = {
8446         /* change to EAPD mode */
8447         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8448         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
8449         { }
8450 };
8451
8452 static const struct hda_verb alc889_eapd_verbs[] = {
8453         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
8454         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
8455         { }
8456 };
8457
8458 static const struct hda_verb alc_hp15_unsol_verbs[] = {
8459         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8460         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8461         {}
8462 };
8463
8464 static const struct hda_verb alc885_init_verbs[] = {
8465         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8466         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8467         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8468         /* Rear mixer */
8469         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8470         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8471         /* CLFE mixer */
8472         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8473         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8474         /* Side mixer */
8475         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8476         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8477
8478         /* Front HP Pin: output 0 (0x0c) */
8479         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8480         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8481         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8482         /* Front Pin: output 0 (0x0c) */
8483         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8484         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8485         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8486         /* Rear Pin: output 1 (0x0d) */
8487         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8488         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8489         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
8490         /* CLFE Pin: output 2 (0x0e) */
8491         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8492         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8493         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8494         /* Side Pin: output 3 (0x0f) */
8495         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8496         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8497         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8498         /* Mic (rear) pin: input vref at 80% */
8499         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8500         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8501         /* Front Mic pin: input vref at 80% */
8502         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8503         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8504         /* Line In pin: input */
8505         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8506         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8507
8508         /* Mixer elements: 0x18, , 0x1a, 0x1b */
8509         /* Input mixer1 */
8510         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8511         /* Input mixer2 */
8512         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8513         /* Input mixer3 */
8514         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8515         /* ADC2: mute amp left and right */
8516         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8517         /* ADC3: mute amp left and right */
8518         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8519
8520         { }
8521 };
8522
8523 static const struct hda_verb alc885_init_input_verbs[] = {
8524         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8525         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8526         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8527         { }
8528 };
8529
8530
8531 /* Unmute Selector 24h and set the default input to front mic */
8532 static const struct hda_verb alc889_init_input_verbs[] = {
8533         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
8534         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8535         { }
8536 };
8537
8538
8539 #define alc883_init_verbs       alc882_base_init_verbs
8540
8541 /* Mac Pro test */
8542 static const struct snd_kcontrol_new alc882_macpro_mixer[] = {
8543         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8544         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8545         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
8546         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8547         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8548         /* FIXME: this looks suspicious...
8549         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
8550         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
8551         */
8552         { } /* end */
8553 };
8554
8555 static const struct hda_verb alc882_macpro_init_verbs[] = {
8556         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8557         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8558         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8559         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8560         /* Front Pin: output 0 (0x0c) */
8561         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8562         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8563         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8564         /* Front Mic pin: input vref at 80% */
8565         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8566         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8567         /* Speaker:  output */
8568         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8569         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8570         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
8571         /* Headphone output (output 0 - 0x0c) */
8572         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8573         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8574         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8575
8576         /* FIXME: use matrix-type input source selection */
8577         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8578         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8579         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8580         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8581         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8582         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8583         /* Input mixer2 */
8584         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8585         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8586         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8587         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8588         /* Input mixer3 */
8589         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8590         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8591         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8592         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8593         /* ADC1: mute amp left and right */
8594         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8595         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8596         /* ADC2: mute amp left and right */
8597         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8598         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8599         /* ADC3: mute amp left and right */
8600         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8601         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8602
8603         { }
8604 };
8605
8606 /* Macbook 5,1 */
8607 static const struct hda_verb alc885_mb5_init_verbs[] = {
8608         /* DACs */
8609         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8610         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8611         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8612         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8613         /* Front mixer */
8614         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8615         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8616         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8617         /* Surround mixer */
8618         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8619         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8620         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8621         /* LFE mixer */
8622         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8623         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8624         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8625         /* HP mixer */
8626         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8627         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8628         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8629         /* Front Pin (0x0c) */
8630         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8631         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8632         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8633         /* LFE Pin (0x0e) */
8634         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8635         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8636         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
8637         /* HP Pin (0x0f) */
8638         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8639         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8640         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
8641         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8642         /* Front Mic pin: input vref at 80% */
8643         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8644         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8645         /* Line In pin */
8646         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8647         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8648
8649         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0x1)},
8650         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x7)},
8651         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0x4)},
8652         { }
8653 };
8654
8655 /* Macmini 3,1 */
8656 static const struct hda_verb alc885_macmini3_init_verbs[] = {
8657         /* DACs */
8658         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8659         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8660         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8661         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8662         /* Front mixer */
8663         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8664         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8665         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8666         /* Surround mixer */
8667         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8668         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8669         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8670         /* LFE mixer */
8671         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8672         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8673         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8674         /* HP mixer */
8675         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8676         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8677         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8678         /* Front Pin (0x0c) */
8679         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8680         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8681         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8682         /* LFE Pin (0x0e) */
8683         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
8684         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8685         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
8686         /* HP Pin (0x0f) */
8687         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8688         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8689         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
8690         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8691         /* Line In pin */
8692         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8693         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8694
8695         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8696         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8697         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8698         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8699         { }
8700 };
8701
8702
8703 static const struct hda_verb alc885_mba21_init_verbs[] = {
8704         /*Internal and HP Speaker Mixer*/
8705         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8706         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8707         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8708         /*Internal Speaker Pin (0x0c)*/
8709         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
8710         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8711         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8712         /* HP Pin: output 0 (0x0e) */
8713         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
8714         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8715         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8716         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, (ALC880_HP_EVENT | AC_USRSP_EN)},
8717         /* Line in (is hp when jack connected)*/
8718         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_VREF_50},
8719         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8720
8721         { }
8722  };
8723
8724
8725 /* Macbook Pro rev3 */
8726 static const struct hda_verb alc885_mbp3_init_verbs[] = {
8727         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8728         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8729         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8730         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8731         /* Rear mixer */
8732         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8733         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8734         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8735         /* HP mixer */
8736         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8737         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8738         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8739         /* Front Pin: output 0 (0x0c) */
8740         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8741         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8742         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8743         /* HP Pin: output 0 (0x0e) */
8744         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
8745         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8746         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
8747         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8748         /* Mic (rear) pin: input vref at 80% */
8749         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8750         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8751         /* Front Mic pin: input vref at 80% */
8752         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8753         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8754         /* Line In pin: use output 1 when in LineOut mode */
8755         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8756         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8757         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8758
8759         /* FIXME: use matrix-type input source selection */
8760         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8761         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8762         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8763         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8764         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8765         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8766         /* Input mixer2 */
8767         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8768         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8769         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8770         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8771         /* Input mixer3 */
8772         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8773         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8774         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8775         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8776         /* ADC1: mute amp left and right */
8777         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8778         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8779         /* ADC2: mute amp left and right */
8780         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8781         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8782         /* ADC3: mute amp left and right */
8783         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8784         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8785
8786         { }
8787 };
8788
8789 /* iMac 9,1 */
8790 static const struct hda_verb alc885_imac91_init_verbs[] = {
8791         /* Internal Speaker Pin (0x0c) */
8792         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
8793         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8794         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8795         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, (PIN_OUT | AC_PINCTL_VREF_50) },
8796         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8797         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8798         /* HP Pin: Rear */
8799         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8800         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8801         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8802         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, (ALC880_HP_EVENT | AC_USRSP_EN)},
8803         /* Line in Rear */
8804         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_VREF_50},
8805         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8806         /* Front Mic pin: input vref at 80% */
8807         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8808         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8809         /* Rear mixer */
8810         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8811         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8812         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8813         /* Line-Out mixer: unmute input/output amp left and right (volume = 0) */
8814         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8815         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8816         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8817         /* 0x24 [Audio Mixer] wcaps 0x20010b: Stereo Amp-In */
8818         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8819         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8820         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8821         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8822         /* 0x23 [Audio Mixer] wcaps 0x20010b: Stereo Amp-In */
8823         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8824         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8825         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8826         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8827         /* 0x22 [Audio Mixer] wcaps 0x20010b: Stereo Amp-In */
8828         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8829         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8830         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8831         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8832         /* 0x07 [Audio Input] wcaps 0x10011b: Stereo Amp-In */
8833         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8834         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8835         /* 0x08 [Audio Input] wcaps 0x10011b: Stereo Amp-In */
8836         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8837         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8838         /* 0x09 [Audio Input] wcaps 0x10011b: Stereo Amp-In */
8839         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8840         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8841         { }
8842 };
8843
8844 /* iMac 24 mixer. */
8845 static const struct snd_kcontrol_new alc885_imac24_mixer[] = {
8846         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8847         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
8848         { } /* end */
8849 };
8850
8851 /* iMac 24 init verbs. */
8852 static const struct hda_verb alc885_imac24_init_verbs[] = {
8853         /* Internal speakers: output 0 (0x0c) */
8854         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8855         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8856         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
8857         /* Internal speakers: output 0 (0x0c) */
8858         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8859         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8860         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8861         /* Headphone: output 0 (0x0c) */
8862         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8863         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8864         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8865         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8866         /* Front Mic: input vref at 80% */
8867         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8868         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8869         { }
8870 };
8871
8872 /* Toggle speaker-output according to the hp-jack state */
8873 static void alc885_imac24_setup(struct hda_codec *codec)
8874 {
8875         struct alc_spec *spec = codec->spec;
8876
8877         spec->autocfg.hp_pins[0] = 0x14;
8878         spec->autocfg.speaker_pins[0] = 0x18;
8879         spec->autocfg.speaker_pins[1] = 0x1a;
8880         spec->automute = 1;
8881         spec->automute_mode = ALC_AUTOMUTE_AMP;
8882 }
8883
8884 #define alc885_mb5_setup        alc885_imac24_setup
8885 #define alc885_macmini3_setup   alc885_imac24_setup
8886
8887 /* Macbook Air 2,1 */
8888 static void alc885_mba21_setup(struct hda_codec *codec)
8889 {
8890        struct alc_spec *spec = codec->spec;
8891
8892        spec->autocfg.hp_pins[0] = 0x14;
8893        spec->autocfg.speaker_pins[0] = 0x18;
8894         spec->automute = 1;
8895         spec->automute_mode = ALC_AUTOMUTE_AMP;
8896 }
8897
8898
8899
8900 static void alc885_mbp3_setup(struct hda_codec *codec)
8901 {
8902         struct alc_spec *spec = codec->spec;
8903
8904         spec->autocfg.hp_pins[0] = 0x15;
8905         spec->autocfg.speaker_pins[0] = 0x14;
8906         spec->automute = 1;
8907         spec->automute_mode = ALC_AUTOMUTE_AMP;
8908 }
8909
8910 static void alc885_imac91_setup(struct hda_codec *codec)
8911 {
8912         struct alc_spec *spec = codec->spec;
8913
8914         spec->autocfg.hp_pins[0] = 0x14;
8915         spec->autocfg.speaker_pins[0] = 0x18;
8916         spec->autocfg.speaker_pins[1] = 0x1a;
8917         spec->automute = 1;
8918         spec->automute_mode = ALC_AUTOMUTE_AMP;
8919 }
8920
8921 static const struct hda_verb alc882_targa_verbs[] = {
8922         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8923         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8924
8925         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8926         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8927
8928         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8929         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8930         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8931
8932         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8933         { } /* end */
8934 };
8935
8936 /* toggle speaker-output according to the hp-jack state */
8937 static void alc882_targa_automute(struct hda_codec *codec)
8938 {
8939         struct alc_spec *spec = codec->spec;
8940         alc_hp_automute(codec);
8941         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8942                                   spec->jack_present ? 1 : 3);
8943 }
8944
8945 static void alc882_targa_setup(struct hda_codec *codec)
8946 {
8947         struct alc_spec *spec = codec->spec;
8948
8949         spec->autocfg.hp_pins[0] = 0x14;
8950         spec->autocfg.speaker_pins[0] = 0x1b;
8951         spec->automute = 1;
8952         spec->automute_mode = ALC_AUTOMUTE_AMP;
8953 }
8954
8955 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
8956 {
8957         if ((res >> 26) == ALC880_HP_EVENT)
8958                 alc882_targa_automute(codec);
8959 }
8960
8961 static const struct hda_verb alc882_asus_a7j_verbs[] = {
8962         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8963         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8964
8965         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8966         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8967         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8968
8969         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8970         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8971         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8972
8973         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8974         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8975         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8976         { } /* end */
8977 };
8978
8979 static const struct hda_verb alc882_asus_a7m_verbs[] = {
8980         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8981         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8982
8983         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8984         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8985         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8986
8987         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8988         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8989         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
8990
8991         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8992         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8993         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8994         { } /* end */
8995 };
8996
8997 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
8998 {
8999         unsigned int gpiostate, gpiomask, gpiodir;
9000
9001         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
9002                                        AC_VERB_GET_GPIO_DATA, 0);
9003
9004         if (!muted)
9005                 gpiostate |= (1 << pin);
9006         else
9007                 gpiostate &= ~(1 << pin);
9008
9009         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
9010                                       AC_VERB_GET_GPIO_MASK, 0);
9011         gpiomask |= (1 << pin);
9012
9013         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
9014                                      AC_VERB_GET_GPIO_DIRECTION, 0);
9015         gpiodir |= (1 << pin);
9016
9017
9018         snd_hda_codec_write(codec, codec->afg, 0,
9019                             AC_VERB_SET_GPIO_MASK, gpiomask);
9020         snd_hda_codec_write(codec, codec->afg, 0,
9021                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
9022
9023         msleep(1);
9024
9025         snd_hda_codec_write(codec, codec->afg, 0,
9026                             AC_VERB_SET_GPIO_DATA, gpiostate);
9027 }
9028
9029 /* set up GPIO at initialization */
9030 static void alc885_macpro_init_hook(struct hda_codec *codec)
9031 {
9032         alc882_gpio_mute(codec, 0, 0);
9033         alc882_gpio_mute(codec, 1, 0);
9034 }
9035
9036 /* set up GPIO and update auto-muting at initialization */
9037 static void alc885_imac24_init_hook(struct hda_codec *codec)
9038 {
9039         alc885_macpro_init_hook(codec);
9040         alc_hp_automute(codec);
9041 }
9042
9043 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
9044 static const struct hda_verb alc889A_mb31_ch2_init[] = {
9045         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
9046         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
9047         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
9048         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
9049         { } /* end */
9050 };
9051
9052 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
9053 static const struct hda_verb alc889A_mb31_ch4_init[] = {
9054         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
9055         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
9056         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
9057         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
9058         { } /* end */
9059 };
9060
9061 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
9062 static const struct hda_verb alc889A_mb31_ch5_init[] = {
9063         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
9064         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
9065         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
9066         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
9067         { } /* end */
9068 };
9069
9070 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
9071 static const struct hda_verb alc889A_mb31_ch6_init[] = {
9072         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
9073         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
9074         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
9075         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
9076         { } /* end */
9077 };
9078
9079 static const struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
9080         { 2, alc889A_mb31_ch2_init },
9081         { 4, alc889A_mb31_ch4_init },
9082         { 5, alc889A_mb31_ch5_init },
9083         { 6, alc889A_mb31_ch6_init },
9084 };
9085
9086 static const struct hda_verb alc883_medion_eapd_verbs[] = {
9087         /* eanable EAPD on medion laptop */
9088         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9089         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
9090         { }
9091 };
9092
9093 #define alc883_base_mixer       alc882_base_mixer
9094
9095 static const struct snd_kcontrol_new alc883_mitac_mixer[] = {
9096         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9097         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9098         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9099         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9100         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9101         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9102         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9103         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9104         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9105         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9106         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9107         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9108         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9109         { } /* end */
9110 };
9111
9112 static const struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
9113         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9114         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
9115         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9116         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
9117         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9118         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9119         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9120         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9121         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9122         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9123         { } /* end */
9124 };
9125
9126 static const struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
9127         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9128         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
9129         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9130         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
9131         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9132         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9133         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9134         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9135         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9136         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9137         { } /* end */
9138 };
9139
9140 static const struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
9141         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9142         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9143         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9144         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9145         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9146         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9147         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9148         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9149         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9150         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9151         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9152         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9153         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9154         { } /* end */
9155 };
9156
9157 static const struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
9158         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9159         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9160         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9161         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9162         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9163         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9164         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9165         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9166         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9167         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9168         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9169         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9170         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9171         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9172         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9173         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9174         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9175         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9176         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9177         { } /* end */
9178 };
9179
9180 static const struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
9181         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9182         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9183         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9184         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9185         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
9186                               HDA_OUTPUT),
9187         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9188         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9189         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9190         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9191         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9192         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9193         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9194         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9195         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9196         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
9197         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9198         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9199         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x18, 0, HDA_INPUT),
9200         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9201         { } /* end */
9202 };
9203
9204 static const struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
9205         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9206         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9207         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9208         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9209         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
9210                               HDA_OUTPUT),
9211         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9212         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9213         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9214         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9215         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
9216         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9217         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9218         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9219         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
9220         HDA_CODEC_VOLUME("Mic Boost Volume", 0x1b, 0, HDA_INPUT),
9221         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
9222         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9223         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x18, 0, HDA_INPUT),
9224         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9225         { } /* end */
9226 };
9227
9228 static const struct snd_kcontrol_new alc883_fivestack_mixer[] = {
9229         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9230         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9231         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9232         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9233         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9234         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9235         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9236         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9237         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9238         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9239         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9240         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9241         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9242         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9243         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9244         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9245         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9246         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9247         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9248         { } /* end */
9249 };
9250
9251 static const struct snd_kcontrol_new alc883_targa_mixer[] = {
9252         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9253         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9254         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9255         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9256         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9257         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9258         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9259         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9260         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9261         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9262         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9263         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9264         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9265         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9266         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9267         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9268         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9269         { } /* end */
9270 };
9271
9272 static const struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
9273         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9274         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9275         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9276         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9277         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9278         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9279         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9280         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9281         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9282         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9283         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9284         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9285         { } /* end */
9286 };
9287
9288 static const struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
9289         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9290         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
9291         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9292         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
9293         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9294         { } /* end */
9295 };
9296
9297 static const struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
9298         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9299         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9300         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9301         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
9302         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9303         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9304         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9305         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9306         { } /* end */
9307 };
9308
9309 static const struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
9310         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9311         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
9312         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9313         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9314         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9315         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9316         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9317         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9318         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9319         { } /* end */
9320 };
9321
9322 static const struct snd_kcontrol_new alc883_medion_wim2160_mixer[] = {
9323         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9324         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9325         HDA_CODEC_MUTE("Speaker Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9326         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
9327         HDA_CODEC_VOLUME("Line Playback Volume", 0x08, 0x0, HDA_INPUT),
9328         HDA_CODEC_MUTE("Line Playback Switch", 0x08, 0x0, HDA_INPUT),
9329         { } /* end */
9330 };
9331
9332 static const struct hda_verb alc883_medion_wim2160_verbs[] = {
9333         /* Unmute front mixer */
9334         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9335         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9336
9337         /* Set speaker pin to front mixer */
9338         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9339
9340         /* Init headphone pin */
9341         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9342         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9343         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
9344         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9345
9346         { } /* end */
9347 };
9348
9349 /* toggle speaker-output according to the hp-jack state */
9350 static void alc883_medion_wim2160_setup(struct hda_codec *codec)
9351 {
9352         struct alc_spec *spec = codec->spec;
9353
9354         spec->autocfg.hp_pins[0] = 0x1a;
9355         spec->autocfg.speaker_pins[0] = 0x15;
9356         spec->automute = 1;
9357         spec->automute_mode = ALC_AUTOMUTE_AMP;
9358 }
9359
9360 static const struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
9361         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9362         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9363         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9364         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9365         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9366         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9367         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9368         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9369         { } /* end */
9370 };
9371
9372 static const struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
9373         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9374         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9375         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9376         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9377         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9378         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9379         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9380         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9381         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9382         { } /* end */
9383 };
9384
9385 static const struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
9386         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9387         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9388         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9389         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
9390         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
9391                                                 0x0d, 1, 0x0, HDA_OUTPUT),
9392         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
9393         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
9394         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
9395         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
9396         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
9397         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9398         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9399         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9400         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9401         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9402         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9403         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9404         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9405         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
9406         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9407         { } /* end */
9408 };
9409
9410 static const struct snd_kcontrol_new alc889A_mb31_mixer[] = {
9411         /* Output mixers */
9412         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
9413         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
9414         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
9415         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
9416         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
9417                 HDA_OUTPUT),
9418         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
9419         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
9420         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
9421         /* Output switches */
9422         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
9423         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
9424         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
9425         /* Boost mixers */
9426         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x00, HDA_INPUT),
9427         HDA_CODEC_VOLUME("Line Boost Volume", 0x1a, 0x00, HDA_INPUT),
9428         /* Input mixers */
9429         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
9430         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
9431         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9432         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9433         { } /* end */
9434 };
9435
9436 static const struct snd_kcontrol_new alc883_vaiott_mixer[] = {
9437         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9438         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9439         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9440         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9441         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
9442         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9443         { } /* end */
9444 };
9445
9446 static const struct hda_bind_ctls alc883_bind_cap_vol = {
9447         .ops = &snd_hda_bind_vol,
9448         .values = {
9449                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
9450                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
9451                 0
9452         },
9453 };
9454
9455 static const struct hda_bind_ctls alc883_bind_cap_switch = {
9456         .ops = &snd_hda_bind_sw,
9457         .values = {
9458                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
9459                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
9460                 0
9461         },
9462 };
9463
9464 static const struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
9465         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9466         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9467         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9468         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9469         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9470         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9471         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
9472         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9473         { } /* end */
9474 };
9475
9476 static const struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
9477         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
9478         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
9479         {
9480                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9481                 /* .name = "Capture Source", */
9482                 .name = "Input Source",
9483                 .count = 1,
9484                 .info = alc_mux_enum_info,
9485                 .get = alc_mux_enum_get,
9486                 .put = alc_mux_enum_put,
9487         },
9488         { } /* end */
9489 };
9490
9491 static const struct snd_kcontrol_new alc883_chmode_mixer[] = {
9492         {
9493                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9494                 .name = "Channel Mode",
9495                 .info = alc_ch_mode_info,
9496                 .get = alc_ch_mode_get,
9497                 .put = alc_ch_mode_put,
9498         },
9499         { } /* end */
9500 };
9501
9502 /* toggle speaker-output according to the hp-jack state */
9503 static void alc883_mitac_setup(struct hda_codec *codec)
9504 {
9505         struct alc_spec *spec = codec->spec;
9506
9507         spec->autocfg.hp_pins[0] = 0x15;
9508         spec->autocfg.speaker_pins[0] = 0x14;
9509         spec->autocfg.speaker_pins[1] = 0x17;
9510         spec->automute = 1;
9511         spec->automute_mode = ALC_AUTOMUTE_AMP;
9512 }
9513
9514 static const struct hda_verb alc883_mitac_verbs[] = {
9515         /* HP */
9516         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9517         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9518         /* Subwoofer */
9519         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
9520         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9521
9522         /* enable unsolicited event */
9523         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9524         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
9525
9526         { } /* end */
9527 };
9528
9529 static const struct hda_verb alc883_clevo_m540r_verbs[] = {
9530         /* HP */
9531         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9532         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9533         /* Int speaker */
9534         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
9535
9536         /* enable unsolicited event */
9537         /*
9538         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9539         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9540         */
9541
9542         { } /* end */
9543 };
9544
9545 static const struct hda_verb alc883_clevo_m720_verbs[] = {
9546         /* HP */
9547         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9548         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9549         /* Int speaker */
9550         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
9551         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9552
9553         /* enable unsolicited event */
9554         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9555         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9556
9557         { } /* end */
9558 };
9559
9560 static const struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
9561         /* HP */
9562         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9563         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9564         /* Subwoofer */
9565         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9566         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9567
9568         /* enable unsolicited event */
9569         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9570
9571         { } /* end */
9572 };
9573
9574 static const struct hda_verb alc883_targa_verbs[] = {
9575         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9576         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9577
9578         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9579         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9580
9581 /* Connect Line-Out side jack (SPDIF) to Side */
9582         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9583         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9584         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
9585 /* Connect Mic jack to CLFE */
9586         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9587         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9588         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
9589 /* Connect Line-in jack to Surround */
9590         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9591         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9592         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
9593 /* Connect HP out jack to Front */
9594         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9595         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9596         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9597
9598         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9599
9600         { } /* end */
9601 };
9602
9603 static const struct hda_verb alc883_lenovo_101e_verbs[] = {
9604         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9605         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
9606         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
9607         { } /* end */
9608 };
9609
9610 static const struct hda_verb alc883_lenovo_nb0763_verbs[] = {
9611         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9612         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9613         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9614         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9615         { } /* end */
9616 };
9617
9618 static const struct hda_verb alc888_lenovo_ms7195_verbs[] = {
9619         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9620         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9621         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9622         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
9623         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
9624         { } /* end */
9625 };
9626
9627 static const struct hda_verb alc883_haier_w66_verbs[] = {
9628         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9629         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9630
9631         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9632
9633         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9634         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9635         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9636         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9637         { } /* end */
9638 };
9639
9640 static const struct hda_verb alc888_lenovo_sky_verbs[] = {
9641         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9642         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9643         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9644         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9645         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9646         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9647         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
9648         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9649         { } /* end */
9650 };
9651
9652 static const struct hda_verb alc888_6st_dell_verbs[] = {
9653         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9654         { }
9655 };
9656
9657 static const struct hda_verb alc883_vaiott_verbs[] = {
9658         /* HP */
9659         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9660         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9661
9662         /* enable unsolicited event */
9663         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9664
9665         { } /* end */
9666 };
9667
9668 static void alc888_3st_hp_setup(struct hda_codec *codec)
9669 {
9670         struct alc_spec *spec = codec->spec;
9671
9672         spec->autocfg.hp_pins[0] = 0x1b;
9673         spec->autocfg.speaker_pins[0] = 0x14;
9674         spec->autocfg.speaker_pins[1] = 0x16;
9675         spec->autocfg.speaker_pins[2] = 0x18;
9676         spec->automute = 1;
9677         spec->automute_mode = ALC_AUTOMUTE_AMP;
9678 }
9679
9680 static const struct hda_verb alc888_3st_hp_verbs[] = {
9681         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
9682         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
9683         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
9684         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9685         { } /* end */
9686 };
9687
9688 /*
9689  * 2ch mode
9690  */
9691 static const struct hda_verb alc888_3st_hp_2ch_init[] = {
9692         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
9693         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
9694         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
9695         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
9696         { } /* end */
9697 };
9698
9699 /*
9700  * 4ch mode
9701  */
9702 static const struct hda_verb alc888_3st_hp_4ch_init[] = {
9703         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
9704         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
9705         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9706         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9707         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
9708         { } /* end */
9709 };
9710
9711 /*
9712  * 6ch mode
9713  */
9714 static const struct hda_verb alc888_3st_hp_6ch_init[] = {
9715         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9716         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9717         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
9718         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9719         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9720         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
9721         { } /* end */
9722 };
9723
9724 static const struct hda_channel_mode alc888_3st_hp_modes[3] = {
9725         { 2, alc888_3st_hp_2ch_init },
9726         { 4, alc888_3st_hp_4ch_init },
9727         { 6, alc888_3st_hp_6ch_init },
9728 };
9729
9730 static void alc888_lenovo_ms7195_setup(struct hda_codec *codec)
9731 {
9732         struct alc_spec *spec = codec->spec;
9733
9734         spec->autocfg.hp_pins[0] = 0x1b;
9735         spec->autocfg.line_out_pins[0] = 0x14;
9736         spec->autocfg.speaker_pins[0] = 0x15;
9737         spec->automute = 1;
9738         spec->automute_mode = ALC_AUTOMUTE_AMP;
9739 }
9740
9741 /* toggle speaker-output according to the hp-jack state */
9742 static void alc883_lenovo_nb0763_setup(struct hda_codec *codec)
9743 {
9744         struct alc_spec *spec = codec->spec;
9745
9746         spec->autocfg.hp_pins[0] = 0x14;
9747         spec->autocfg.speaker_pins[0] = 0x15;
9748         spec->automute = 1;
9749         spec->automute_mode = ALC_AUTOMUTE_AMP;
9750 }
9751
9752 /* toggle speaker-output according to the hp-jack state */
9753 #define alc883_targa_init_hook          alc882_targa_init_hook
9754 #define alc883_targa_unsol_event        alc882_targa_unsol_event
9755
9756 static void alc883_clevo_m720_setup(struct hda_codec *codec)
9757 {
9758         struct alc_spec *spec = codec->spec;
9759
9760         spec->autocfg.hp_pins[0] = 0x15;
9761         spec->autocfg.speaker_pins[0] = 0x14;
9762         spec->automute = 1;
9763         spec->automute_mode = ALC_AUTOMUTE_AMP;
9764 }
9765
9766 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
9767 {
9768         alc_hp_automute(codec);
9769         alc88x_simple_mic_automute(codec);
9770 }
9771
9772 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
9773                                            unsigned int res)
9774 {
9775         switch (res >> 26) {
9776         case ALC880_MIC_EVENT:
9777                 alc88x_simple_mic_automute(codec);
9778                 break;
9779         default:
9780                 alc_sku_unsol_event(codec, res);
9781                 break;
9782         }
9783 }
9784
9785 /* toggle speaker-output according to the hp-jack state */
9786 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
9787 {
9788         struct alc_spec *spec = codec->spec;
9789
9790         spec->autocfg.hp_pins[0] = 0x14;
9791         spec->autocfg.speaker_pins[0] = 0x15;
9792         spec->automute = 1;
9793         spec->automute_mode = ALC_AUTOMUTE_AMP;
9794 }
9795
9796 static void alc883_haier_w66_setup(struct hda_codec *codec)
9797 {
9798         struct alc_spec *spec = codec->spec;
9799
9800         spec->autocfg.hp_pins[0] = 0x1b;
9801         spec->autocfg.speaker_pins[0] = 0x14;
9802         spec->automute = 1;
9803         spec->automute_mode = ALC_AUTOMUTE_AMP;
9804 }
9805
9806 static void alc883_lenovo_101e_setup(struct hda_codec *codec)
9807 {
9808         struct alc_spec *spec = codec->spec;
9809
9810         spec->autocfg.hp_pins[0] = 0x1b;
9811         spec->autocfg.line_out_pins[0] = 0x14;
9812         spec->autocfg.speaker_pins[0] = 0x15;
9813         spec->automute = 1;
9814         spec->detect_line = 1;
9815         spec->automute_lines = 1;
9816         spec->automute_mode = ALC_AUTOMUTE_AMP;
9817 }
9818
9819 /* toggle speaker-output according to the hp-jack state */
9820 static void alc883_acer_aspire_setup(struct hda_codec *codec)
9821 {
9822         struct alc_spec *spec = codec->spec;
9823
9824         spec->autocfg.hp_pins[0] = 0x14;
9825         spec->autocfg.speaker_pins[0] = 0x15;
9826         spec->autocfg.speaker_pins[1] = 0x16;
9827         spec->automute = 1;
9828         spec->automute_mode = ALC_AUTOMUTE_AMP;
9829 }
9830
9831 static const struct hda_verb alc883_acer_eapd_verbs[] = {
9832         /* HP Pin: output 0 (0x0c) */
9833         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9834         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9835         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9836         /* Front Pin: output 0 (0x0c) */
9837         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9838         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9839         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9840         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
9841         /* eanable EAPD on medion laptop */
9842         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9843         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
9844         /* enable unsolicited event */
9845         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9846         { }
9847 };
9848
9849 static void alc888_6st_dell_setup(struct hda_codec *codec)
9850 {
9851         struct alc_spec *spec = codec->spec;
9852
9853         spec->autocfg.hp_pins[0] = 0x1b;
9854         spec->autocfg.speaker_pins[0] = 0x14;
9855         spec->autocfg.speaker_pins[1] = 0x15;
9856         spec->autocfg.speaker_pins[2] = 0x16;
9857         spec->autocfg.speaker_pins[3] = 0x17;
9858         spec->automute = 1;
9859         spec->automute_mode = ALC_AUTOMUTE_AMP;
9860 }
9861
9862 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
9863 {
9864         struct alc_spec *spec = codec->spec;
9865
9866         spec->autocfg.hp_pins[0] = 0x1b;
9867         spec->autocfg.speaker_pins[0] = 0x14;
9868         spec->autocfg.speaker_pins[1] = 0x15;
9869         spec->autocfg.speaker_pins[2] = 0x16;
9870         spec->autocfg.speaker_pins[3] = 0x17;
9871         spec->autocfg.speaker_pins[4] = 0x1a;
9872         spec->automute = 1;
9873         spec->automute_mode = ALC_AUTOMUTE_AMP;
9874 }
9875
9876 static void alc883_vaiott_setup(struct hda_codec *codec)
9877 {
9878         struct alc_spec *spec = codec->spec;
9879
9880         spec->autocfg.hp_pins[0] = 0x15;
9881         spec->autocfg.speaker_pins[0] = 0x14;
9882         spec->autocfg.speaker_pins[1] = 0x17;
9883         spec->automute = 1;
9884         spec->automute_mode = ALC_AUTOMUTE_AMP;
9885 }
9886
9887 static const struct hda_verb alc888_asus_m90v_verbs[] = {
9888         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9889         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9890         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9891         /* enable unsolicited event */
9892         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9893         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9894         { } /* end */
9895 };
9896
9897 static void alc883_mode2_setup(struct hda_codec *codec)
9898 {
9899         struct alc_spec *spec = codec->spec;
9900
9901         spec->autocfg.hp_pins[0] = 0x1b;
9902         spec->autocfg.speaker_pins[0] = 0x14;
9903         spec->autocfg.speaker_pins[1] = 0x15;
9904         spec->autocfg.speaker_pins[2] = 0x16;
9905         spec->ext_mic.pin = 0x18;
9906         spec->int_mic.pin = 0x19;
9907         spec->ext_mic.mux_idx = 0;
9908         spec->int_mic.mux_idx = 1;
9909         spec->auto_mic = 1;
9910         spec->automute = 1;
9911         spec->automute_mode = ALC_AUTOMUTE_AMP;
9912 }
9913
9914 static const struct hda_verb alc888_asus_eee1601_verbs[] = {
9915         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9916         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9917         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9918         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9919         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9920         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
9921         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
9922         /* enable unsolicited event */
9923         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9924         { } /* end */
9925 };
9926
9927 static void alc883_eee1601_inithook(struct hda_codec *codec)
9928 {
9929         struct alc_spec *spec = codec->spec;
9930
9931         spec->autocfg.hp_pins[0] = 0x14;
9932         spec->autocfg.speaker_pins[0] = 0x1b;
9933         alc_hp_automute(codec);
9934 }
9935
9936 static const struct hda_verb alc889A_mb31_verbs[] = {
9937         /* Init rear pin (used as headphone output) */
9938         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
9939         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
9940         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9941         /* Init line pin (used as output in 4ch and 6ch mode) */
9942         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
9943         /* Init line 2 pin (used as headphone out by default) */
9944         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
9945         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
9946         { } /* end */
9947 };
9948
9949 /* Mute speakers according to the headphone jack state */
9950 static void alc889A_mb31_automute(struct hda_codec *codec)
9951 {
9952         unsigned int present;
9953
9954         /* Mute only in 2ch or 4ch mode */
9955         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
9956             == 0x00) {
9957                 present = snd_hda_jack_detect(codec, 0x15);
9958                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
9959                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9960                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9961                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9962         }
9963 }
9964
9965 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
9966 {
9967         if ((res >> 26) == ALC880_HP_EVENT)
9968                 alc889A_mb31_automute(codec);
9969 }
9970
9971
9972 #ifdef CONFIG_SND_HDA_POWER_SAVE
9973 #define alc882_loopbacks        alc880_loopbacks
9974 #endif
9975
9976 /* pcm configuration: identical with ALC880 */
9977 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
9978 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
9979 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
9980 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
9981
9982 static const hda_nid_t alc883_slave_dig_outs[] = {
9983         ALC1200_DIGOUT_NID, 0,
9984 };
9985
9986 static const hda_nid_t alc1200_slave_dig_outs[] = {
9987         ALC883_DIGOUT_NID, 0,
9988 };
9989
9990 /*
9991  * configuration and preset
9992  */
9993 static const char * const alc882_models[ALC882_MODEL_LAST] = {
9994         [ALC882_3ST_DIG]        = "3stack-dig",
9995         [ALC882_6ST_DIG]        = "6stack-dig",
9996         [ALC882_ARIMA]          = "arima",
9997         [ALC882_W2JC]           = "w2jc",
9998         [ALC882_TARGA]          = "targa",
9999         [ALC882_ASUS_A7J]       = "asus-a7j",
10000         [ALC882_ASUS_A7M]       = "asus-a7m",
10001         [ALC885_MACPRO]         = "macpro",
10002         [ALC885_MB5]            = "mb5",
10003         [ALC885_MACMINI3]       = "macmini3",
10004         [ALC885_MBA21]          = "mba21",
10005         [ALC885_MBP3]           = "mbp3",
10006         [ALC885_IMAC24]         = "imac24",
10007         [ALC885_IMAC91]         = "imac91",
10008         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
10009         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
10010         [ALC883_3ST_6ch]        = "3stack-6ch",
10011         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
10012         [ALC883_TARGA_DIG]      = "targa-dig",
10013         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
10014         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
10015         [ALC883_ACER]           = "acer",
10016         [ALC883_ACER_ASPIRE]    = "acer-aspire",
10017         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
10018         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
10019         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
10020         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
10021         [ALC883_MEDION]         = "medion",
10022         [ALC883_MEDION_WIM2160] = "medion-wim2160",
10023         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
10024         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
10025         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
10026         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
10027         [ALC888_LENOVO_SKY] = "lenovo-sky",
10028         [ALC883_HAIER_W66]      = "haier-w66",
10029         [ALC888_3ST_HP]         = "3stack-hp",
10030         [ALC888_6ST_DELL]       = "6stack-dell",
10031         [ALC883_MITAC]          = "mitac",
10032         [ALC883_CLEVO_M540R]    = "clevo-m540r",
10033         [ALC883_CLEVO_M720]     = "clevo-m720",
10034         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
10035         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
10036         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
10037         [ALC889A_INTEL]         = "intel-alc889a",
10038         [ALC889_INTEL]          = "intel-x58",
10039         [ALC1200_ASUS_P5Q]      = "asus-p5q",
10040         [ALC889A_MB31]          = "mb31",
10041         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
10042         [ALC882_AUTO]           = "auto",
10043 };
10044
10045 static const struct snd_pci_quirk alc882_cfg_tbl[] = {
10046         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
10047
10048         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
10049         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
10050         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
10051         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
10052         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
10053         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
10054         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
10055                 ALC888_ACER_ASPIRE_4930G),
10056         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
10057                 ALC888_ACER_ASPIRE_4930G),
10058         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
10059                 ALC888_ACER_ASPIRE_8930G),
10060         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
10061                 ALC888_ACER_ASPIRE_8930G),
10062         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
10063         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
10064         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
10065                 ALC888_ACER_ASPIRE_6530G),
10066         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
10067                 ALC888_ACER_ASPIRE_6530G),
10068         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
10069                 ALC888_ACER_ASPIRE_7730G),
10070         /* default Acer -- disabled as it causes more problems.
10071          *    model=auto should work fine now
10072          */
10073         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
10074
10075         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
10076
10077         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavilion", ALC883_6ST_DIG),
10078         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
10079         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
10080         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
10081         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
10082         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
10083
10084         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
10085         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
10086         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
10087         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
10088         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
10089         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
10090         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
10091         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
10092         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
10093         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
10094         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
10095
10096         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
10097         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
10098         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
10099         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
10100         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
10101         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
10102         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
10103         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
10104         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
10105
10106         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
10107         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
10108         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
10109         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
10110         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC882_AUTO),
10111         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
10112         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
10113         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
10114         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
10115         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
10116         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
10117         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
10118         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
10119         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
10120         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
10121         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
10122         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
10123         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
10124         SND_PCI_QUIRK(0x1462, 0x4570, "MSI Wind Top AE2220", ALC883_TARGA_DIG),
10125         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
10126         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
10127         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
10128         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
10129         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
10130         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
10131         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
10132         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
10133         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
10134         SND_PCI_QUIRK(0x1462, 0x7437, "MSI NetOn AP1900", ALC883_TARGA_DIG),
10135         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
10136         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
10137
10138         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
10139         SND_PCI_QUIRK(0x1558, 0x0571, "Clevo laptop M570U", ALC883_3ST_6ch_DIG),
10140         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
10141         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
10142         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
10143         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
10144         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
10145         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
10146         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
10147         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
10148                       ALC883_FUJITSU_PI2515),
10149         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
10150                 ALC888_FUJITSU_XA3530),
10151         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
10152         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
10153         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
10154         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
10155         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
10156         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
10157         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
10158         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
10159
10160         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
10161         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
10162         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
10163         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
10164         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
10165         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
10166         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC882_6ST_DIG),
10167
10168         {}
10169 };
10170
10171 /* codec SSID table for Intel Mac */
10172 static const struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
10173         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
10174         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
10175         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
10176         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
10177         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
10178         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
10179         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
10180         SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889A_MB31),
10181         SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_ASUS_A7M),
10182         SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC885_MBP3),
10183         SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC885_MBA21),
10184         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
10185         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
10186         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
10187         SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC885_IMAC91),
10188         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
10189         SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC885_MB5),
10190         /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
10191          * so apparently no perfect solution yet
10192          */
10193         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
10194         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
10195         SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC885_MACMINI3),
10196         {} /* terminator */
10197 };
10198
10199 static const struct alc_config_preset alc882_presets[] = {
10200         [ALC882_3ST_DIG] = {
10201                 .mixers = { alc882_base_mixer },
10202                 .init_verbs = { alc882_base_init_verbs,
10203                                 alc882_adc1_init_verbs },
10204                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10205                 .dac_nids = alc882_dac_nids,
10206                 .dig_out_nid = ALC882_DIGOUT_NID,
10207                 .dig_in_nid = ALC882_DIGIN_NID,
10208                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
10209                 .channel_mode = alc882_ch_modes,
10210                 .need_dac_fix = 1,
10211                 .input_mux = &alc882_capture_source,
10212         },
10213         [ALC882_6ST_DIG] = {
10214                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
10215                 .init_verbs = { alc882_base_init_verbs,
10216                                 alc882_adc1_init_verbs },
10217                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10218                 .dac_nids = alc882_dac_nids,
10219                 .dig_out_nid = ALC882_DIGOUT_NID,
10220                 .dig_in_nid = ALC882_DIGIN_NID,
10221                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
10222                 .channel_mode = alc882_sixstack_modes,
10223                 .input_mux = &alc882_capture_source,
10224         },
10225         [ALC882_ARIMA] = {
10226                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
10227                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10228                                 alc882_eapd_verbs },
10229                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10230                 .dac_nids = alc882_dac_nids,
10231                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
10232                 .channel_mode = alc882_sixstack_modes,
10233                 .input_mux = &alc882_capture_source,
10234         },
10235         [ALC882_W2JC] = {
10236                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
10237                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10238                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
10239                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10240                 .dac_nids = alc882_dac_nids,
10241                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
10242                 .channel_mode = alc880_threestack_modes,
10243                 .need_dac_fix = 1,
10244                 .input_mux = &alc882_capture_source,
10245                 .dig_out_nid = ALC882_DIGOUT_NID,
10246         },
10247            [ALC885_MBA21] = {
10248                         .mixers = { alc885_mba21_mixer },
10249                         .init_verbs = { alc885_mba21_init_verbs, alc880_gpio1_init_verbs },
10250                         .num_dacs = 2,
10251                         .dac_nids = alc882_dac_nids,
10252                         .channel_mode = alc885_mba21_ch_modes,
10253                         .num_channel_mode = ARRAY_SIZE(alc885_mba21_ch_modes),
10254                         .input_mux = &alc882_capture_source,
10255                         .unsol_event = alc_sku_unsol_event,
10256                         .setup = alc885_mba21_setup,
10257                         .init_hook = alc_hp_automute,
10258        },
10259         [ALC885_MBP3] = {
10260                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
10261                 .init_verbs = { alc885_mbp3_init_verbs,
10262                                 alc880_gpio1_init_verbs },
10263                 .num_dacs = 2,
10264                 .dac_nids = alc882_dac_nids,
10265                 .hp_nid = 0x04,
10266                 .channel_mode = alc885_mbp_4ch_modes,
10267                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
10268                 .input_mux = &alc882_capture_source,
10269                 .dig_out_nid = ALC882_DIGOUT_NID,
10270                 .dig_in_nid = ALC882_DIGIN_NID,
10271                 .unsol_event = alc_sku_unsol_event,
10272                 .setup = alc885_mbp3_setup,
10273                 .init_hook = alc_hp_automute,
10274         },
10275         [ALC885_MB5] = {
10276                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
10277                 .init_verbs = { alc885_mb5_init_verbs,
10278                                 alc880_gpio1_init_verbs },
10279                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10280                 .dac_nids = alc882_dac_nids,
10281                 .channel_mode = alc885_mb5_6ch_modes,
10282                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
10283                 .input_mux = &mb5_capture_source,
10284                 .dig_out_nid = ALC882_DIGOUT_NID,
10285                 .dig_in_nid = ALC882_DIGIN_NID,
10286                 .unsol_event = alc_sku_unsol_event,
10287                 .setup = alc885_mb5_setup,
10288                 .init_hook = alc_hp_automute,
10289         },
10290         [ALC885_MACMINI3] = {
10291                 .mixers = { alc885_macmini3_mixer, alc882_chmode_mixer },
10292                 .init_verbs = { alc885_macmini3_init_verbs,
10293                                 alc880_gpio1_init_verbs },
10294                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10295                 .dac_nids = alc882_dac_nids,
10296                 .channel_mode = alc885_macmini3_6ch_modes,
10297                 .num_channel_mode = ARRAY_SIZE(alc885_macmini3_6ch_modes),
10298                 .input_mux = &macmini3_capture_source,
10299                 .dig_out_nid = ALC882_DIGOUT_NID,
10300                 .dig_in_nid = ALC882_DIGIN_NID,
10301                 .unsol_event = alc_sku_unsol_event,
10302                 .setup = alc885_macmini3_setup,
10303                 .init_hook = alc_hp_automute,
10304         },
10305         [ALC885_MACPRO] = {
10306                 .mixers = { alc882_macpro_mixer },
10307                 .init_verbs = { alc882_macpro_init_verbs },
10308                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10309                 .dac_nids = alc882_dac_nids,
10310                 .dig_out_nid = ALC882_DIGOUT_NID,
10311                 .dig_in_nid = ALC882_DIGIN_NID,
10312                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
10313                 .channel_mode = alc882_ch_modes,
10314                 .input_mux = &alc882_capture_source,
10315                 .init_hook = alc885_macpro_init_hook,
10316         },
10317         [ALC885_IMAC24] = {
10318                 .mixers = { alc885_imac24_mixer },
10319                 .init_verbs = { alc885_imac24_init_verbs },
10320                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10321                 .dac_nids = alc882_dac_nids,
10322                 .dig_out_nid = ALC882_DIGOUT_NID,
10323                 .dig_in_nid = ALC882_DIGIN_NID,
10324                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
10325                 .channel_mode = alc882_ch_modes,
10326                 .input_mux = &alc882_capture_source,
10327                 .unsol_event = alc_sku_unsol_event,
10328                 .setup = alc885_imac24_setup,
10329                 .init_hook = alc885_imac24_init_hook,
10330         },
10331         [ALC885_IMAC91] = {
10332                 .mixers = {alc885_imac91_mixer},
10333                 .init_verbs = { alc885_imac91_init_verbs,
10334                                 alc880_gpio1_init_verbs },
10335                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10336                 .dac_nids = alc882_dac_nids,
10337                 .channel_mode = alc885_mba21_ch_modes,
10338                 .num_channel_mode = ARRAY_SIZE(alc885_mba21_ch_modes),
10339                 .input_mux = &alc889A_imac91_capture_source,
10340                 .dig_out_nid = ALC882_DIGOUT_NID,
10341                 .dig_in_nid = ALC882_DIGIN_NID,
10342                 .unsol_event = alc_sku_unsol_event,
10343                 .setup = alc885_imac91_setup,
10344                 .init_hook = alc_hp_automute,
10345         },
10346         [ALC882_TARGA] = {
10347                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
10348                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10349                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
10350                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10351                 .dac_nids = alc882_dac_nids,
10352                 .dig_out_nid = ALC882_DIGOUT_NID,
10353                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
10354                 .adc_nids = alc882_adc_nids,
10355                 .capsrc_nids = alc882_capsrc_nids,
10356                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
10357                 .channel_mode = alc882_3ST_6ch_modes,
10358                 .need_dac_fix = 1,
10359                 .input_mux = &alc882_capture_source,
10360                 .unsol_event = alc_sku_unsol_event,
10361                 .setup = alc882_targa_setup,
10362                 .init_hook = alc882_targa_automute,
10363         },
10364         [ALC882_ASUS_A7J] = {
10365                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
10366                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10367                                 alc882_asus_a7j_verbs},
10368                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10369                 .dac_nids = alc882_dac_nids,
10370                 .dig_out_nid = ALC882_DIGOUT_NID,
10371                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
10372                 .adc_nids = alc882_adc_nids,
10373                 .capsrc_nids = alc882_capsrc_nids,
10374                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
10375                 .channel_mode = alc882_3ST_6ch_modes,
10376                 .need_dac_fix = 1,
10377                 .input_mux = &alc882_capture_source,
10378         },
10379         [ALC882_ASUS_A7M] = {
10380                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
10381                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
10382                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
10383                                 alc882_asus_a7m_verbs },
10384                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
10385                 .dac_nids = alc882_dac_nids,
10386                 .dig_out_nid = ALC882_DIGOUT_NID,
10387                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
10388                 .channel_mode = alc880_threestack_modes,
10389                 .need_dac_fix = 1,
10390                 .input_mux = &alc882_capture_source,
10391         },
10392         [ALC883_3ST_2ch_DIG] = {
10393                 .mixers = { alc883_3ST_2ch_mixer },
10394                 .init_verbs = { alc883_init_verbs },
10395                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10396                 .dac_nids = alc883_dac_nids,
10397                 .dig_out_nid = ALC883_DIGOUT_NID,
10398                 .dig_in_nid = ALC883_DIGIN_NID,
10399                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10400                 .channel_mode = alc883_3ST_2ch_modes,
10401                 .input_mux = &alc883_capture_source,
10402         },
10403         [ALC883_3ST_6ch_DIG] = {
10404                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10405                 .init_verbs = { alc883_init_verbs },
10406                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10407                 .dac_nids = alc883_dac_nids,
10408                 .dig_out_nid = ALC883_DIGOUT_NID,
10409                 .dig_in_nid = ALC883_DIGIN_NID,
10410                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10411                 .channel_mode = alc883_3ST_6ch_modes,
10412                 .need_dac_fix = 1,
10413                 .input_mux = &alc883_capture_source,
10414         },
10415         [ALC883_3ST_6ch] = {
10416                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10417                 .init_verbs = { alc883_init_verbs },
10418                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10419                 .dac_nids = alc883_dac_nids,
10420                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10421                 .channel_mode = alc883_3ST_6ch_modes,
10422                 .need_dac_fix = 1,
10423                 .input_mux = &alc883_capture_source,
10424         },
10425         [ALC883_3ST_6ch_INTEL] = {
10426                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
10427                 .init_verbs = { alc883_init_verbs },
10428                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10429                 .dac_nids = alc883_dac_nids,
10430                 .dig_out_nid = ALC883_DIGOUT_NID,
10431                 .dig_in_nid = ALC883_DIGIN_NID,
10432                 .slave_dig_outs = alc883_slave_dig_outs,
10433                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
10434                 .channel_mode = alc883_3ST_6ch_intel_modes,
10435                 .need_dac_fix = 1,
10436                 .input_mux = &alc883_3stack_6ch_intel,
10437         },
10438         [ALC889A_INTEL] = {
10439                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
10440                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
10441                                 alc_hp15_unsol_verbs },
10442                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10443                 .dac_nids = alc883_dac_nids,
10444                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
10445                 .adc_nids = alc889_adc_nids,
10446                 .dig_out_nid = ALC883_DIGOUT_NID,
10447                 .dig_in_nid = ALC883_DIGIN_NID,
10448                 .slave_dig_outs = alc883_slave_dig_outs,
10449                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
10450                 .channel_mode = alc889_8ch_intel_modes,
10451                 .capsrc_nids = alc889_capsrc_nids,
10452                 .input_mux = &alc889_capture_source,
10453                 .setup = alc889_automute_setup,
10454                 .init_hook = alc_hp_automute,
10455                 .unsol_event = alc_sku_unsol_event,
10456                 .need_dac_fix = 1,
10457         },
10458         [ALC889_INTEL] = {
10459                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
10460                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
10461                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
10462                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10463                 .dac_nids = alc883_dac_nids,
10464                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
10465                 .adc_nids = alc889_adc_nids,
10466                 .dig_out_nid = ALC883_DIGOUT_NID,
10467                 .dig_in_nid = ALC883_DIGIN_NID,
10468                 .slave_dig_outs = alc883_slave_dig_outs,
10469                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
10470                 .channel_mode = alc889_8ch_intel_modes,
10471                 .capsrc_nids = alc889_capsrc_nids,
10472                 .input_mux = &alc889_capture_source,
10473                 .setup = alc889_automute_setup,
10474                 .init_hook = alc889_intel_init_hook,
10475                 .unsol_event = alc_sku_unsol_event,
10476                 .need_dac_fix = 1,
10477         },
10478         [ALC883_6ST_DIG] = {
10479                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
10480                 .init_verbs = { alc883_init_verbs },
10481                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10482                 .dac_nids = alc883_dac_nids,
10483                 .dig_out_nid = ALC883_DIGOUT_NID,
10484                 .dig_in_nid = ALC883_DIGIN_NID,
10485                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10486                 .channel_mode = alc883_sixstack_modes,
10487                 .input_mux = &alc883_capture_source,
10488         },
10489         [ALC883_TARGA_DIG] = {
10490                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
10491                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
10492                                 alc883_targa_verbs},
10493                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10494                 .dac_nids = alc883_dac_nids,
10495                 .dig_out_nid = ALC883_DIGOUT_NID,
10496                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10497                 .channel_mode = alc883_3ST_6ch_modes,
10498                 .need_dac_fix = 1,
10499                 .input_mux = &alc883_capture_source,
10500                 .unsol_event = alc883_targa_unsol_event,
10501                 .setup = alc882_targa_setup,
10502                 .init_hook = alc882_targa_automute,
10503         },
10504         [ALC883_TARGA_2ch_DIG] = {
10505                 .mixers = { alc883_targa_2ch_mixer},
10506                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
10507                                 alc883_targa_verbs},
10508                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10509                 .dac_nids = alc883_dac_nids,
10510                 .adc_nids = alc883_adc_nids_alt,
10511                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
10512                 .capsrc_nids = alc883_capsrc_nids,
10513                 .dig_out_nid = ALC883_DIGOUT_NID,
10514                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10515                 .channel_mode = alc883_3ST_2ch_modes,
10516                 .input_mux = &alc883_capture_source,
10517                 .unsol_event = alc883_targa_unsol_event,
10518                 .setup = alc882_targa_setup,
10519                 .init_hook = alc882_targa_automute,
10520         },
10521         [ALC883_TARGA_8ch_DIG] = {
10522                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
10523                             alc883_chmode_mixer },
10524                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
10525                                 alc883_targa_verbs },
10526                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10527                 .dac_nids = alc883_dac_nids,
10528                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10529                 .adc_nids = alc883_adc_nids_rev,
10530                 .capsrc_nids = alc883_capsrc_nids_rev,
10531                 .dig_out_nid = ALC883_DIGOUT_NID,
10532                 .dig_in_nid = ALC883_DIGIN_NID,
10533                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
10534                 .channel_mode = alc883_4ST_8ch_modes,
10535                 .need_dac_fix = 1,
10536                 .input_mux = &alc883_capture_source,
10537                 .unsol_event = alc883_targa_unsol_event,
10538                 .setup = alc882_targa_setup,
10539                 .init_hook = alc882_targa_automute,
10540         },
10541         [ALC883_ACER] = {
10542                 .mixers = { alc883_base_mixer },
10543                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
10544                  * and the headphone jack.  Turn this on and rely on the
10545                  * standard mute methods whenever the user wants to turn
10546                  * these outputs off.
10547                  */
10548                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
10549                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10550                 .dac_nids = alc883_dac_nids,
10551                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10552                 .channel_mode = alc883_3ST_2ch_modes,
10553                 .input_mux = &alc883_capture_source,
10554         },
10555         [ALC883_ACER_ASPIRE] = {
10556                 .mixers = { alc883_acer_aspire_mixer },
10557                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
10558                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10559                 .dac_nids = alc883_dac_nids,
10560                 .dig_out_nid = ALC883_DIGOUT_NID,
10561                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10562                 .channel_mode = alc883_3ST_2ch_modes,
10563                 .input_mux = &alc883_capture_source,
10564                 .unsol_event = alc_sku_unsol_event,
10565                 .setup = alc883_acer_aspire_setup,
10566                 .init_hook = alc_hp_automute,
10567         },
10568         [ALC888_ACER_ASPIRE_4930G] = {
10569                 .mixers = { alc888_acer_aspire_4930g_mixer,
10570                                 alc883_chmode_mixer },
10571                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10572                                 alc888_acer_aspire_4930g_verbs },
10573                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10574                 .dac_nids = alc883_dac_nids,
10575                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10576                 .adc_nids = alc883_adc_nids_rev,
10577                 .capsrc_nids = alc883_capsrc_nids_rev,
10578                 .dig_out_nid = ALC883_DIGOUT_NID,
10579                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10580                 .channel_mode = alc883_3ST_6ch_modes,
10581                 .need_dac_fix = 1,
10582                 .const_channel_count = 6,
10583                 .num_mux_defs =
10584                         ARRAY_SIZE(alc888_2_capture_sources),
10585                 .input_mux = alc888_2_capture_sources,
10586                 .unsol_event = alc_sku_unsol_event,
10587                 .setup = alc888_acer_aspire_4930g_setup,
10588                 .init_hook = alc_hp_automute,
10589         },
10590         [ALC888_ACER_ASPIRE_6530G] = {
10591                 .mixers = { alc888_acer_aspire_6530_mixer },
10592                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10593                                 alc888_acer_aspire_6530g_verbs },
10594                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10595                 .dac_nids = alc883_dac_nids,
10596                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10597                 .adc_nids = alc883_adc_nids_rev,
10598                 .capsrc_nids = alc883_capsrc_nids_rev,
10599                 .dig_out_nid = ALC883_DIGOUT_NID,
10600                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10601                 .channel_mode = alc883_3ST_2ch_modes,
10602                 .num_mux_defs =
10603                         ARRAY_SIZE(alc888_2_capture_sources),
10604                 .input_mux = alc888_acer_aspire_6530_sources,
10605                 .unsol_event = alc_sku_unsol_event,
10606                 .setup = alc888_acer_aspire_6530g_setup,
10607                 .init_hook = alc_hp_automute,
10608         },
10609         [ALC888_ACER_ASPIRE_8930G] = {
10610                 .mixers = { alc889_acer_aspire_8930g_mixer,
10611                                 alc883_chmode_mixer },
10612                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10613                                 alc889_acer_aspire_8930g_verbs,
10614                                 alc889_eapd_verbs},
10615                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10616                 .dac_nids = alc883_dac_nids,
10617                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
10618                 .adc_nids = alc889_adc_nids,
10619                 .capsrc_nids = alc889_capsrc_nids,
10620                 .dig_out_nid = ALC883_DIGOUT_NID,
10621                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10622                 .channel_mode = alc883_3ST_6ch_modes,
10623                 .need_dac_fix = 1,
10624                 .const_channel_count = 6,
10625                 .num_mux_defs =
10626                         ARRAY_SIZE(alc889_capture_sources),
10627                 .input_mux = alc889_capture_sources,
10628                 .unsol_event = alc_sku_unsol_event,
10629                 .setup = alc889_acer_aspire_8930g_setup,
10630                 .init_hook = alc_hp_automute,
10631 #ifdef CONFIG_SND_HDA_POWER_SAVE
10632                 .power_hook = alc_power_eapd,
10633 #endif
10634         },
10635         [ALC888_ACER_ASPIRE_7730G] = {
10636                 .mixers = { alc883_3ST_6ch_mixer,
10637                                 alc883_chmode_mixer },
10638                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
10639                                 alc888_acer_aspire_7730G_verbs },
10640                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10641                 .dac_nids = alc883_dac_nids,
10642                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10643                 .adc_nids = alc883_adc_nids_rev,
10644                 .capsrc_nids = alc883_capsrc_nids_rev,
10645                 .dig_out_nid = ALC883_DIGOUT_NID,
10646                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10647                 .channel_mode = alc883_3ST_6ch_modes,
10648                 .need_dac_fix = 1,
10649                 .const_channel_count = 6,
10650                 .input_mux = &alc883_capture_source,
10651                 .unsol_event = alc_sku_unsol_event,
10652                 .setup = alc888_acer_aspire_7730g_setup,
10653                 .init_hook = alc_hp_automute,
10654         },
10655         [ALC883_MEDION] = {
10656                 .mixers = { alc883_fivestack_mixer,
10657                             alc883_chmode_mixer },
10658                 .init_verbs = { alc883_init_verbs,
10659                                 alc883_medion_eapd_verbs },
10660                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10661                 .dac_nids = alc883_dac_nids,
10662                 .adc_nids = alc883_adc_nids_alt,
10663                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
10664                 .capsrc_nids = alc883_capsrc_nids,
10665                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10666                 .channel_mode = alc883_sixstack_modes,
10667                 .input_mux = &alc883_capture_source,
10668         },
10669         [ALC883_MEDION_WIM2160] = {
10670                 .mixers = { alc883_medion_wim2160_mixer },
10671                 .init_verbs = { alc883_init_verbs, alc883_medion_wim2160_verbs },
10672                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10673                 .dac_nids = alc883_dac_nids,
10674                 .dig_out_nid = ALC883_DIGOUT_NID,
10675                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
10676                 .adc_nids = alc883_adc_nids,
10677                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10678                 .channel_mode = alc883_3ST_2ch_modes,
10679                 .input_mux = &alc883_capture_source,
10680                 .unsol_event = alc_sku_unsol_event,
10681                 .setup = alc883_medion_wim2160_setup,
10682                 .init_hook = alc_hp_automute,
10683         },
10684         [ALC883_LAPTOP_EAPD] = {
10685                 .mixers = { alc883_base_mixer },
10686                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
10687                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10688                 .dac_nids = alc883_dac_nids,
10689                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10690                 .channel_mode = alc883_3ST_2ch_modes,
10691                 .input_mux = &alc883_capture_source,
10692         },
10693         [ALC883_CLEVO_M540R] = {
10694                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10695                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
10696                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10697                 .dac_nids = alc883_dac_nids,
10698                 .dig_out_nid = ALC883_DIGOUT_NID,
10699                 .dig_in_nid = ALC883_DIGIN_NID,
10700                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
10701                 .channel_mode = alc883_3ST_6ch_clevo_modes,
10702                 .need_dac_fix = 1,
10703                 .input_mux = &alc883_capture_source,
10704                 /* This machine has the hardware HP auto-muting, thus
10705                  * we need no software mute via unsol event
10706                  */
10707         },
10708         [ALC883_CLEVO_M720] = {
10709                 .mixers = { alc883_clevo_m720_mixer },
10710                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
10711                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10712                 .dac_nids = alc883_dac_nids,
10713                 .dig_out_nid = ALC883_DIGOUT_NID,
10714                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10715                 .channel_mode = alc883_3ST_2ch_modes,
10716                 .input_mux = &alc883_capture_source,
10717                 .unsol_event = alc883_clevo_m720_unsol_event,
10718                 .setup = alc883_clevo_m720_setup,
10719                 .init_hook = alc883_clevo_m720_init_hook,
10720         },
10721         [ALC883_LENOVO_101E_2ch] = {
10722                 .mixers = { alc883_lenovo_101e_2ch_mixer},
10723                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
10724                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10725                 .dac_nids = alc883_dac_nids,
10726                 .adc_nids = alc883_adc_nids_alt,
10727                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
10728                 .capsrc_nids = alc883_capsrc_nids,
10729                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10730                 .channel_mode = alc883_3ST_2ch_modes,
10731                 .input_mux = &alc883_lenovo_101e_capture_source,
10732                 .setup = alc883_lenovo_101e_setup,
10733                 .unsol_event = alc_sku_unsol_event,
10734                 .init_hook = alc_inithook,
10735         },
10736         [ALC883_LENOVO_NB0763] = {
10737                 .mixers = { alc883_lenovo_nb0763_mixer },
10738                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
10739                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10740                 .dac_nids = alc883_dac_nids,
10741                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10742                 .channel_mode = alc883_3ST_2ch_modes,
10743                 .need_dac_fix = 1,
10744                 .input_mux = &alc883_lenovo_nb0763_capture_source,
10745                 .unsol_event = alc_sku_unsol_event,
10746                 .setup = alc883_lenovo_nb0763_setup,
10747                 .init_hook = alc_hp_automute,
10748         },
10749         [ALC888_LENOVO_MS7195_DIG] = {
10750                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10751                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
10752                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10753                 .dac_nids = alc883_dac_nids,
10754                 .dig_out_nid = ALC883_DIGOUT_NID,
10755                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10756                 .channel_mode = alc883_3ST_6ch_modes,
10757                 .need_dac_fix = 1,
10758                 .input_mux = &alc883_capture_source,
10759                 .unsol_event = alc_sku_unsol_event,
10760                 .setup = alc888_lenovo_ms7195_setup,
10761                 .init_hook = alc_inithook,
10762         },
10763         [ALC883_HAIER_W66] = {
10764                 .mixers = { alc883_targa_2ch_mixer},
10765                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
10766                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10767                 .dac_nids = alc883_dac_nids,
10768                 .dig_out_nid = ALC883_DIGOUT_NID,
10769                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10770                 .channel_mode = alc883_3ST_2ch_modes,
10771                 .input_mux = &alc883_capture_source,
10772                 .unsol_event = alc_sku_unsol_event,
10773                 .setup = alc883_haier_w66_setup,
10774                 .init_hook = alc_hp_automute,
10775         },
10776         [ALC888_3ST_HP] = {
10777                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10778                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
10779                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10780                 .dac_nids = alc883_dac_nids,
10781                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
10782                 .channel_mode = alc888_3st_hp_modes,
10783                 .need_dac_fix = 1,
10784                 .input_mux = &alc883_capture_source,
10785                 .unsol_event = alc_sku_unsol_event,
10786                 .setup = alc888_3st_hp_setup,
10787                 .init_hook = alc_hp_automute,
10788         },
10789         [ALC888_6ST_DELL] = {
10790                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
10791                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
10792                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10793                 .dac_nids = alc883_dac_nids,
10794                 .dig_out_nid = ALC883_DIGOUT_NID,
10795                 .dig_in_nid = ALC883_DIGIN_NID,
10796                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10797                 .channel_mode = alc883_sixstack_modes,
10798                 .input_mux = &alc883_capture_source,
10799                 .unsol_event = alc_sku_unsol_event,
10800                 .setup = alc888_6st_dell_setup,
10801                 .init_hook = alc_hp_automute,
10802         },
10803         [ALC883_MITAC] = {
10804                 .mixers = { alc883_mitac_mixer },
10805                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
10806                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10807                 .dac_nids = alc883_dac_nids,
10808                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10809                 .channel_mode = alc883_3ST_2ch_modes,
10810                 .input_mux = &alc883_capture_source,
10811                 .unsol_event = alc_sku_unsol_event,
10812                 .setup = alc883_mitac_setup,
10813                 .init_hook = alc_hp_automute,
10814         },
10815         [ALC883_FUJITSU_PI2515] = {
10816                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
10817                 .init_verbs = { alc883_init_verbs,
10818                                 alc883_2ch_fujitsu_pi2515_verbs},
10819                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10820                 .dac_nids = alc883_dac_nids,
10821                 .dig_out_nid = ALC883_DIGOUT_NID,
10822                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10823                 .channel_mode = alc883_3ST_2ch_modes,
10824                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
10825                 .unsol_event = alc_sku_unsol_event,
10826                 .setup = alc883_2ch_fujitsu_pi2515_setup,
10827                 .init_hook = alc_hp_automute,
10828         },
10829         [ALC888_FUJITSU_XA3530] = {
10830                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
10831                 .init_verbs = { alc883_init_verbs,
10832                         alc888_fujitsu_xa3530_verbs },
10833                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10834                 .dac_nids = alc883_dac_nids,
10835                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
10836                 .adc_nids = alc883_adc_nids_rev,
10837                 .capsrc_nids = alc883_capsrc_nids_rev,
10838                 .dig_out_nid = ALC883_DIGOUT_NID,
10839                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
10840                 .channel_mode = alc888_4ST_8ch_intel_modes,
10841                 .num_mux_defs =
10842                         ARRAY_SIZE(alc888_2_capture_sources),
10843                 .input_mux = alc888_2_capture_sources,
10844                 .unsol_event = alc_sku_unsol_event,
10845                 .setup = alc888_fujitsu_xa3530_setup,
10846                 .init_hook = alc_hp_automute,
10847         },
10848         [ALC888_LENOVO_SKY] = {
10849                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
10850                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
10851                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10852                 .dac_nids = alc883_dac_nids,
10853                 .dig_out_nid = ALC883_DIGOUT_NID,
10854                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10855                 .channel_mode = alc883_sixstack_modes,
10856                 .need_dac_fix = 1,
10857                 .input_mux = &alc883_lenovo_sky_capture_source,
10858                 .unsol_event = alc_sku_unsol_event,
10859                 .setup = alc888_lenovo_sky_setup,
10860                 .init_hook = alc_hp_automute,
10861         },
10862         [ALC888_ASUS_M90V] = {
10863                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
10864                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
10865                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10866                 .dac_nids = alc883_dac_nids,
10867                 .dig_out_nid = ALC883_DIGOUT_NID,
10868                 .dig_in_nid = ALC883_DIGIN_NID,
10869                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
10870                 .channel_mode = alc883_3ST_6ch_modes,
10871                 .need_dac_fix = 1,
10872                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
10873                 .unsol_event = alc_sku_unsol_event,
10874                 .setup = alc883_mode2_setup,
10875                 .init_hook = alc_inithook,
10876         },
10877         [ALC888_ASUS_EEE1601] = {
10878                 .mixers = { alc883_asus_eee1601_mixer },
10879                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
10880                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
10881                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10882                 .dac_nids = alc883_dac_nids,
10883                 .dig_out_nid = ALC883_DIGOUT_NID,
10884                 .dig_in_nid = ALC883_DIGIN_NID,
10885                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10886                 .channel_mode = alc883_3ST_2ch_modes,
10887                 .need_dac_fix = 1,
10888                 .input_mux = &alc883_asus_eee1601_capture_source,
10889                 .unsol_event = alc_sku_unsol_event,
10890                 .init_hook = alc883_eee1601_inithook,
10891         },
10892         [ALC1200_ASUS_P5Q] = {
10893                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
10894                 .init_verbs = { alc883_init_verbs },
10895                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10896                 .dac_nids = alc883_dac_nids,
10897                 .dig_out_nid = ALC1200_DIGOUT_NID,
10898                 .dig_in_nid = ALC883_DIGIN_NID,
10899                 .slave_dig_outs = alc1200_slave_dig_outs,
10900                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
10901                 .channel_mode = alc883_sixstack_modes,
10902                 .input_mux = &alc883_capture_source,
10903         },
10904         [ALC889A_MB31] = {
10905                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
10906                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
10907                         alc880_gpio1_init_verbs },
10908                 .adc_nids = alc883_adc_nids,
10909                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
10910                 .capsrc_nids = alc883_capsrc_nids,
10911                 .dac_nids = alc883_dac_nids,
10912                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10913                 .channel_mode = alc889A_mb31_6ch_modes,
10914                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
10915                 .input_mux = &alc889A_mb31_capture_source,
10916                 .dig_out_nid = ALC883_DIGOUT_NID,
10917                 .unsol_event = alc889A_mb31_unsol_event,
10918                 .init_hook = alc889A_mb31_automute,
10919         },
10920         [ALC883_SONY_VAIO_TT] = {
10921                 .mixers = { alc883_vaiott_mixer },
10922                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
10923                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
10924                 .dac_nids = alc883_dac_nids,
10925                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
10926                 .channel_mode = alc883_3ST_2ch_modes,
10927                 .input_mux = &alc883_capture_source,
10928                 .unsol_event = alc_sku_unsol_event,
10929                 .setup = alc883_vaiott_setup,
10930                 .init_hook = alc_hp_automute,
10931         },
10932 };
10933
10934
10935 /*
10936  * Pin config fixes
10937  */
10938 enum {
10939         PINFIX_ABIT_AW9D_MAX,
10940         PINFIX_LENOVO_Y530,
10941         PINFIX_PB_M5210,
10942         PINFIX_ACER_ASPIRE_7736,
10943 };
10944
10945 static const struct alc_fixup alc882_fixups[] = {
10946         [PINFIX_ABIT_AW9D_MAX] = {
10947                 .type = ALC_FIXUP_PINS,
10948                 .v.pins = (const struct alc_pincfg[]) {
10949                         { 0x15, 0x01080104 }, /* side */
10950                         { 0x16, 0x01011012 }, /* rear */
10951                         { 0x17, 0x01016011 }, /* clfe */
10952                         { }
10953                 }
10954         },
10955         [PINFIX_LENOVO_Y530] = {
10956                 .type = ALC_FIXUP_PINS,
10957                 .v.pins = (const struct alc_pincfg[]) {
10958                         { 0x15, 0x99130112 }, /* rear int speakers */
10959                         { 0x16, 0x99130111 }, /* subwoofer */
10960                         { }
10961                 }
10962         },
10963         [PINFIX_PB_M5210] = {
10964                 .type = ALC_FIXUP_VERBS,
10965                 .v.verbs = (const struct hda_verb[]) {
10966                         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
10967                         {}
10968                 }
10969         },
10970         [PINFIX_ACER_ASPIRE_7736] = {
10971                 .type = ALC_FIXUP_SKU,
10972                 .v.sku = ALC_FIXUP_SKU_IGNORE,
10973         },
10974 };
10975
10976 static const struct snd_pci_quirk alc882_fixup_tbl[] = {
10977         SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
10978         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
10979         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
10980         SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
10981         {}
10982 };
10983
10984 /*
10985  * BIOS auto configuration
10986  */
10987 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
10988                                                 const struct auto_pin_cfg *cfg)
10989 {
10990         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
10991 }
10992
10993 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
10994                                               hda_nid_t nid, int pin_type,
10995                                               hda_nid_t dac)
10996 {
10997         int idx;
10998
10999         /* set as output */
11000         alc_set_pin_output(codec, nid, pin_type);
11001
11002         if (snd_hda_get_conn_list(codec, nid, NULL) < 2)
11003                 return;
11004
11005         if (dac == 0x25)
11006                 idx = 4;
11007         else if (dac >= 0x02 && dac <= 0x05)
11008                 idx = dac - 2;
11009         else
11010                 return;
11011         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
11012 }
11013
11014 #define alc882_auto_init_dac    alc880_auto_init_dac
11015
11016 static void alc882_auto_init_multi_out(struct hda_codec *codec)
11017 {
11018         struct alc_spec *spec = codec->spec;
11019         int i;
11020
11021         for (i = 0; i <= HDA_SIDE; i++) {
11022                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11023                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11024                 if (nid)
11025                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
11026                                         spec->multiout.dac_nids[i]);
11027         }
11028         /* mute DACs */
11029         for (i = 0; i < spec->multiout.num_dacs; i++)
11030                 alc882_auto_init_dac(codec, spec->multiout.dac_nids[i]);
11031 }
11032
11033 static void alc882_auto_init_hp_out(struct hda_codec *codec)
11034 {
11035         struct alc_spec *spec = codec->spec;
11036         hda_nid_t pin, dac;
11037         int i;
11038
11039         if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT) {
11040                 for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
11041                         pin = spec->autocfg.hp_pins[i];
11042                         if (!pin)
11043                                 break;
11044                         dac = spec->multiout.hp_nid;
11045                         if (!dac)
11046                                 dac = spec->multiout.dac_nids[0]; /* to front */
11047                         alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
11048                 }
11049         }
11050
11051         if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT) {
11052                 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
11053                         pin = spec->autocfg.speaker_pins[i];
11054                         if (!pin)
11055                                 break;
11056                         dac = spec->multiout.extra_out_nid[0];
11057                         if (!dac)
11058                                 dac = spec->multiout.dac_nids[0]; /* to front */
11059                         alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
11060                 }
11061         }
11062
11063         /* mute DACs */
11064         alc882_auto_init_dac(codec, spec->multiout.hp_nid);
11065         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
11066                 alc882_auto_init_dac(codec, spec->multiout.extra_out_nid[i]);
11067 }
11068
11069 #define alc882_auto_init_analog_input   alc880_auto_init_analog_input
11070
11071 static void alc882_auto_init_input_src(struct hda_codec *codec)
11072 {
11073         struct alc_spec *spec = codec->spec;
11074         int c;
11075
11076         for (c = 0; c < spec->num_adc_nids; c++) {
11077                 hda_nid_t nid = spec->capsrc_nids[c];
11078                 unsigned int mux_idx;
11079                 const struct hda_input_mux *imux;
11080                 int conns, mute, idx, item;
11081                 unsigned int wid_type;
11082
11083                 /* mute ADC */
11084                 if (query_amp_caps(codec, spec->adc_nids[c], HDA_INPUT) &
11085                     AC_AMPCAP_MUTE)
11086                         snd_hda_codec_write(codec, spec->adc_nids[c], 0,
11087                                     AC_VERB_SET_AMP_GAIN_MUTE,
11088                                     AMP_IN_MUTE(0));
11089                 else if (query_amp_caps(codec, nid, HDA_OUTPUT) &
11090                          AC_AMPCAP_MUTE)
11091                         snd_hda_codec_write(codec, nid, 0,
11092                                     AC_VERB_SET_AMP_GAIN_MUTE,
11093                                     AMP_OUT_MUTE);
11094
11095                 conns = snd_hda_get_conn_list(codec, nid, NULL);
11096                 if (conns <= 0)
11097                         continue;
11098                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
11099                 imux = &spec->input_mux[mux_idx];
11100                 if (!imux->num_items && mux_idx > 0)
11101                         imux = &spec->input_mux[0];
11102                 wid_type = get_wcaps_type(get_wcaps(codec, nid));
11103                 for (idx = 0; idx < conns; idx++) {
11104                         /* if the current connection is the selected one,
11105                          * unmute it as default - otherwise mute it
11106                          */
11107                         mute = AMP_IN_MUTE(idx);
11108                         for (item = 0; item < imux->num_items; item++) {
11109                                 if (imux->items[item].index == idx) {
11110                                         if (spec->cur_mux[c] == item)
11111                                                 mute = AMP_IN_UNMUTE(idx);
11112                                         break;
11113                                 }
11114                         }
11115                         /* initialize the mute status if mute-amp is present */
11116                         if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
11117                                 snd_hda_codec_write(codec, nid, 0,
11118                                                     AC_VERB_SET_AMP_GAIN_MUTE,
11119                                                     mute);
11120                         if (wid_type == AC_WID_AUD_SEL &&
11121                             mute != AMP_IN_MUTE(idx))
11122                                 snd_hda_codec_write(codec, nid, 0,
11123                                                     AC_VERB_SET_CONNECT_SEL,
11124                                                     idx);
11125                 }
11126         }
11127 }
11128
11129 /* add mic boosts if needed */
11130 static int alc_auto_add_mic_boost(struct hda_codec *codec)
11131 {
11132         struct alc_spec *spec = codec->spec;
11133         struct auto_pin_cfg *cfg = &spec->autocfg;
11134         int i, err;
11135         int type_idx = 0;
11136         hda_nid_t nid;
11137         const char *prev_label = NULL;
11138
11139         for (i = 0; i < cfg->num_inputs; i++) {
11140                 if (cfg->inputs[i].type > AUTO_PIN_MIC)
11141                         break;
11142                 nid = cfg->inputs[i].pin;
11143                 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
11144                         const char *label;
11145                         char boost_label[32];
11146
11147                         label = hda_get_autocfg_input_label(codec, cfg, i);
11148                         if (prev_label && !strcmp(label, prev_label))
11149                                 type_idx++;
11150                         else
11151                                 type_idx = 0;
11152                         prev_label = label;
11153
11154                         snprintf(boost_label, sizeof(boost_label),
11155                                  "%s Boost Volume", label);
11156                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11157                                           boost_label, type_idx,
11158                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11159                         if (err < 0)
11160                                 return err;
11161                 }
11162         }
11163         return 0;
11164 }
11165
11166 /* almost identical with ALC880 parser... */
11167 static int alc882_parse_auto_config(struct hda_codec *codec)
11168 {
11169         struct alc_spec *spec = codec->spec;
11170         static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
11171         int err;
11172
11173         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11174                                            alc882_ignore);
11175         if (err < 0)
11176                 return err;
11177         if (!spec->autocfg.line_outs)
11178                 return 0; /* can't find valid BIOS pin config */
11179
11180         err = alc880_auto_fill_dac_nids(codec);
11181         if (err < 0)
11182                 return err;
11183         err = alc_auto_add_multi_channel_mode(codec, alc880_auto_fill_dac_nids);
11184         if (err < 0)
11185                 return err;
11186         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
11187         if (err < 0)
11188                 return err;
11189         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
11190                                            "Headphone");
11191         if (err < 0)
11192                 return err;
11193         err = alc880_auto_create_extra_out(spec,
11194                                            spec->autocfg.speaker_pins[0],
11195                                            "Speaker");
11196         if (err < 0)
11197                 return err;
11198         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
11199         if (err < 0)
11200                 return err;
11201
11202         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11203
11204         alc_auto_parse_digital(codec);
11205
11206         if (spec->kctls.list)
11207                 add_mixer(spec, spec->kctls.list);
11208
11209         /* if ADC 0x07 is available, initialize it, too */
11210         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
11211                 add_verb(spec, alc882_adc1_init_verbs);
11212
11213         spec->num_mux_defs = 1;
11214         spec->input_mux = &spec->private_imux[0];
11215
11216         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
11217
11218         err = alc_auto_add_mic_boost(codec);
11219         if (err < 0)
11220                 return err;
11221
11222         return 1; /* config found */
11223 }
11224
11225 /* additional initialization for auto-configuration model */
11226 static void alc882_auto_init(struct hda_codec *codec)
11227 {
11228         struct alc_spec *spec = codec->spec;
11229         alc882_auto_init_multi_out(codec);
11230         alc882_auto_init_hp_out(codec);
11231         alc882_auto_init_analog_input(codec);
11232         alc882_auto_init_input_src(codec);
11233         alc_auto_init_digital(codec);
11234         if (spec->unsol_event)
11235                 alc_inithook(codec);
11236 }
11237
11238 static int patch_alc882(struct hda_codec *codec)
11239 {
11240         struct alc_spec *spec;
11241         int err, board_config;
11242
11243         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11244         if (spec == NULL)
11245                 return -ENOMEM;
11246
11247         codec->spec = spec;
11248
11249         spec->mixer_nid = 0x0b;
11250
11251         switch (codec->vendor_id) {
11252         case 0x10ec0882:
11253         case 0x10ec0885:
11254                 break;
11255         default:
11256                 /* ALC883 and variants */
11257                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11258                 break;
11259         }
11260
11261         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
11262                                                   alc882_models,
11263                                                   alc882_cfg_tbl);
11264
11265         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
11266                 board_config = snd_hda_check_board_codec_sid_config(codec,
11267                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
11268
11269         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
11270                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11271                        codec->chip_name);
11272                 board_config = ALC882_AUTO;
11273         }
11274
11275         if (board_config == ALC882_AUTO) {
11276                 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
11277                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
11278         }
11279
11280         alc_auto_parse_customize_define(codec);
11281
11282         if (board_config == ALC882_AUTO) {
11283                 /* automatic parse from the BIOS config */
11284                 err = alc882_parse_auto_config(codec);
11285                 if (err < 0) {
11286                         alc_free(codec);
11287                         return err;
11288                 } else if (!err) {
11289                         printk(KERN_INFO
11290                                "hda_codec: Cannot set up configuration "
11291                                "from BIOS.  Using base mode...\n");
11292                         board_config = ALC882_3ST_DIG;
11293                 }
11294         }
11295
11296         if (has_cdefine_beep(codec)) {
11297                 err = snd_hda_attach_beep_device(codec, 0x1);
11298                 if (err < 0) {
11299                         alc_free(codec);
11300                         return err;
11301                 }
11302         }
11303
11304         if (board_config != ALC882_AUTO)
11305                 setup_preset(codec, &alc882_presets[board_config]);
11306
11307         spec->stream_analog_playback = &alc882_pcm_analog_playback;
11308         spec->stream_analog_capture = &alc882_pcm_analog_capture;
11309         /* FIXME: setup DAC5 */
11310         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
11311         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
11312
11313         spec->stream_digital_playback = &alc882_pcm_digital_playback;
11314         spec->stream_digital_capture = &alc882_pcm_digital_capture;
11315
11316         if (!spec->adc_nids && spec->input_mux) {
11317                 int i, j;
11318                 spec->num_adc_nids = 0;
11319                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
11320                         const struct hda_input_mux *imux = spec->input_mux;
11321                         hda_nid_t cap;
11322                         hda_nid_t nid = alc882_adc_nids[i];
11323                         unsigned int wcap = get_wcaps(codec, nid);
11324                         /* get type */
11325                         wcap = get_wcaps_type(wcap);
11326                         if (wcap != AC_WID_AUD_IN)
11327                                 continue;
11328                         spec->private_adc_nids[spec->num_adc_nids] = nid;
11329                         err = snd_hda_get_connections(codec, nid, &cap, 1);
11330                         if (err < 0)
11331                                 continue;
11332                         err = snd_hda_get_conn_list(codec, cap, NULL);
11333                         if (err < 0)
11334                                 continue;
11335                         for (j = 0; j < imux->num_items; j++)
11336                                 if (imux->items[j].index >= err)
11337                                         break;
11338                         if (j < imux->num_items)
11339                                 continue;
11340                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
11341                         spec->num_adc_nids++;
11342                 }
11343                 spec->adc_nids = spec->private_adc_nids;
11344                 spec->capsrc_nids = spec->private_capsrc_nids;
11345         }
11346
11347         set_capture_mixer(codec);
11348
11349         if (has_cdefine_beep(codec))
11350                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11351
11352         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
11353
11354         spec->vmaster_nid = 0x0c;
11355
11356         codec->patch_ops = alc_patch_ops;
11357         if (board_config == ALC882_AUTO)
11358                 spec->init_hook = alc882_auto_init;
11359
11360         alc_init_jacks(codec);
11361 #ifdef CONFIG_SND_HDA_POWER_SAVE
11362         if (!spec->loopback.amplist)
11363                 spec->loopback.amplist = alc882_loopbacks;
11364 #endif
11365
11366         return 0;
11367 }
11368
11369
11370 /*
11371  * ALC262 support
11372  */
11373
11374 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
11375 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
11376
11377 #define alc262_dac_nids         alc260_dac_nids
11378 #define alc262_adc_nids         alc882_adc_nids
11379 #define alc262_adc_nids_alt     alc882_adc_nids_alt
11380 #define alc262_capsrc_nids      alc882_capsrc_nids
11381 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
11382
11383 #define alc262_modes            alc260_modes
11384 #define alc262_capture_source   alc882_capture_source
11385
11386 static const hda_nid_t alc262_dmic_adc_nids[1] = {
11387         /* ADC0 */
11388         0x09
11389 };
11390
11391 static const hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
11392
11393 static const struct snd_kcontrol_new alc262_base_mixer[] = {
11394         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11395         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11396         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11397         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11398         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11399         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11400         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11401         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11402         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11403         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11404         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11405         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11406         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
11407         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11408         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
11409         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11410         { } /* end */
11411 };
11412
11413 /* update HP, line and mono-out pins according to the master switch */
11414 #define alc262_hp_master_update         alc260_hp_master_update
11415
11416 static void alc262_hp_bpc_setup(struct hda_codec *codec)
11417 {
11418         struct alc_spec *spec = codec->spec;
11419
11420         spec->autocfg.hp_pins[0] = 0x1b;
11421         spec->autocfg.speaker_pins[0] = 0x16;
11422         spec->automute = 1;
11423         spec->automute_mode = ALC_AUTOMUTE_PIN;
11424 }
11425
11426 static void alc262_hp_wildwest_setup(struct hda_codec *codec)
11427 {
11428         struct alc_spec *spec = codec->spec;
11429
11430         spec->autocfg.hp_pins[0] = 0x15;
11431         spec->autocfg.speaker_pins[0] = 0x16;
11432         spec->automute = 1;
11433         spec->automute_mode = ALC_AUTOMUTE_PIN;
11434 }
11435
11436 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
11437 #define alc262_hp_master_sw_put         alc260_hp_master_sw_put
11438
11439 #define ALC262_HP_MASTER_SWITCH                                 \
11440         {                                                       \
11441                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
11442                 .name = "Master Playback Switch",               \
11443                 .info = snd_ctl_boolean_mono_info,              \
11444                 .get = alc262_hp_master_sw_get,                 \
11445                 .put = alc262_hp_master_sw_put,                 \
11446         }, \
11447         {                                                       \
11448                 .iface = NID_MAPPING,                           \
11449                 .name = "Master Playback Switch",               \
11450                 .private_value = 0x15 | (0x16 << 8) | (0x1b << 16),     \
11451         }
11452
11453
11454 static const struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
11455         ALC262_HP_MASTER_SWITCH,
11456         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11457         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11458         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11459         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
11460                               HDA_OUTPUT),
11461         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
11462                             HDA_OUTPUT),
11463         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11464         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11465         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11466         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11467         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11468         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11469         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11470         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11471         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11472         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11473         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
11474         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
11475         { } /* end */
11476 };
11477
11478 static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
11479         ALC262_HP_MASTER_SWITCH,
11480         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11481         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11482         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11483         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11484         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
11485                               HDA_OUTPUT),
11486         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
11487                             HDA_OUTPUT),
11488         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
11489         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
11490         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x1a, 0, HDA_INPUT),
11491         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
11492         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
11493         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11494         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11495         { } /* end */
11496 };
11497
11498 static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
11499         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11500         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11501         HDA_CODEC_VOLUME("Rear Mic Boost Volume", 0x18, 0, HDA_INPUT),
11502         { } /* end */
11503 };
11504
11505 /* mute/unmute internal speaker according to the hp jack and mute state */
11506 static void alc262_hp_t5735_setup(struct hda_codec *codec)
11507 {
11508         struct alc_spec *spec = codec->spec;
11509
11510         spec->autocfg.hp_pins[0] = 0x15;
11511         spec->autocfg.speaker_pins[0] = 0x14;
11512         spec->automute = 1;
11513         spec->automute_mode = ALC_AUTOMUTE_PIN;
11514 }
11515
11516 static const struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
11517         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11518         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11519         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11520         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11521         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11522         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11523         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11524         { } /* end */
11525 };
11526
11527 static const struct hda_verb alc262_hp_t5735_verbs[] = {
11528         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11529         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11530
11531         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11532         { }
11533 };
11534
11535 static const struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
11536         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11537         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11538         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
11539         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
11540         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
11541         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
11542         { } /* end */
11543 };
11544
11545 static const struct hda_verb alc262_hp_rp5700_verbs[] = {
11546         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11547         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11548         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11549         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11550         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11551         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11552         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11553         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11554         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
11555         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
11556         {}
11557 };
11558
11559 static const struct hda_input_mux alc262_hp_rp5700_capture_source = {
11560         .num_items = 1,
11561         .items = {
11562                 { "Line", 0x1 },
11563         },
11564 };
11565
11566 /* bind hp and internal speaker mute (with plug check) as master switch */
11567 #define alc262_hippo_master_update      alc262_hp_master_update
11568 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
11569 #define alc262_hippo_master_sw_put      alc262_hp_master_sw_put
11570
11571 #define ALC262_HIPPO_MASTER_SWITCH                              \
11572         {                                                       \
11573                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
11574                 .name = "Master Playback Switch",               \
11575                 .info = snd_ctl_boolean_mono_info,              \
11576                 .get = alc262_hippo_master_sw_get,              \
11577                 .put = alc262_hippo_master_sw_put,              \
11578         },                                                      \
11579         {                                                       \
11580                 .iface = NID_MAPPING,                           \
11581                 .name = "Master Playback Switch",               \
11582                 .subdevice = SUBDEV_HP(0) | (SUBDEV_LINE(0) << 8) | \
11583                              (SUBDEV_SPEAKER(0) << 16), \
11584         }
11585
11586 static const struct snd_kcontrol_new alc262_hippo_mixer[] = {
11587         ALC262_HIPPO_MASTER_SWITCH,
11588         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11589         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11590         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11591         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11592         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11593         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11594         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11595         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11596         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11597         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11598         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11599         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11600         { } /* end */
11601 };
11602
11603 static const struct snd_kcontrol_new alc262_hippo1_mixer[] = {
11604         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11605         ALC262_HIPPO_MASTER_SWITCH,
11606         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11607         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11608         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11609         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11610         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11611         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11612         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11613         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11614         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11615         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11616         { } /* end */
11617 };
11618
11619 /* mute/unmute internal speaker according to the hp jack and mute state */
11620 static void alc262_hippo_setup(struct hda_codec *codec)
11621 {
11622         struct alc_spec *spec = codec->spec;
11623
11624         spec->autocfg.hp_pins[0] = 0x15;
11625         spec->autocfg.speaker_pins[0] = 0x14;
11626         spec->automute = 1;
11627         spec->automute_mode = ALC_AUTOMUTE_AMP;
11628 }
11629
11630 static void alc262_hippo1_setup(struct hda_codec *codec)
11631 {
11632         struct alc_spec *spec = codec->spec;
11633
11634         spec->autocfg.hp_pins[0] = 0x1b;
11635         spec->autocfg.speaker_pins[0] = 0x14;
11636         spec->automute = 1;
11637         spec->automute_mode = ALC_AUTOMUTE_AMP;
11638 }
11639
11640
11641 static const struct snd_kcontrol_new alc262_sony_mixer[] = {
11642         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11643         ALC262_HIPPO_MASTER_SWITCH,
11644         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11645         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11646         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11647         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11648         { } /* end */
11649 };
11650
11651 static const struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
11652         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11653         ALC262_HIPPO_MASTER_SWITCH,
11654         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11655         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11656         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11657         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11658         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11659         { } /* end */
11660 };
11661
11662 static const struct snd_kcontrol_new alc262_tyan_mixer[] = {
11663         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11664         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
11665         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
11666         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
11667         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11668         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11669         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11670         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11671         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11672         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11673         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11674         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
11675         { } /* end */
11676 };
11677
11678 static const struct hda_verb alc262_tyan_verbs[] = {
11679         /* Headphone automute */
11680         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11681         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11682         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11683
11684         /* P11 AUX_IN, white 4-pin connector */
11685         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11686         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
11687         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
11688         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
11689
11690         {}
11691 };
11692
11693 /* unsolicited event for HP jack sensing */
11694 static void alc262_tyan_setup(struct hda_codec *codec)
11695 {
11696         struct alc_spec *spec = codec->spec;
11697
11698         spec->autocfg.hp_pins[0] = 0x1b;
11699         spec->autocfg.speaker_pins[0] = 0x15;
11700         spec->automute = 1;
11701         spec->automute_mode = ALC_AUTOMUTE_AMP;
11702 }
11703
11704
11705 #define alc262_capture_mixer            alc882_capture_mixer
11706 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
11707
11708 /*
11709  * generic initialization of ADC, input mixers and output mixers
11710  */
11711 static const struct hda_verb alc262_init_verbs[] = {
11712         /*
11713          * Unmute ADC0-2 and set the default input to mic-in
11714          */
11715         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11716         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11717         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11718         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11719         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11720         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11721
11722         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11723          * mixer widget
11724          * Note: PASD motherboards uses the Line In 2 as the input for
11725          * front panel mic (mic 2)
11726          */
11727         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11728         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11729         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11730         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11731         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11732         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11733
11734         /*
11735          * Set up output mixers (0x0c - 0x0e)
11736          */
11737         /* set vol=0 to output mixers */
11738         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11739         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11740         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11741         /* set up input amps for analog loopback */
11742         /* Amp Indices: DAC = 0, mixer = 1 */
11743         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11744         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11745         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11746         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11747         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11748         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11749
11750         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11751         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11752         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11753         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11754         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11755         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11756
11757         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11758         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11759         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11760         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11761         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11762
11763         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11764         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11765
11766         /* FIXME: use matrix-type input source selection */
11767         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11768         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11769         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11770         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11771         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11772         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11773         /* Input mixer2 */
11774         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11775         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11776         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11777         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11778         /* Input mixer3 */
11779         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11780         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11781         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11782         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11783
11784         { }
11785 };
11786
11787 static const struct hda_verb alc262_eapd_verbs[] = {
11788         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11789         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11790         { }
11791 };
11792
11793 static const struct hda_verb alc262_hippo1_unsol_verbs[] = {
11794         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11795         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11796         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
11797
11798         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11799         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11800         {}
11801 };
11802
11803 static const struct hda_verb alc262_sony_unsol_verbs[] = {
11804         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11805         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11806         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
11807
11808         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11809         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11810         {}
11811 };
11812
11813 static const struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
11814         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
11815         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11816         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11817         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11818         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11819         { } /* end */
11820 };
11821
11822 static const struct hda_verb alc262_toshiba_s06_verbs[] = {
11823         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11824         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11825         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11826         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11827         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
11828         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11829         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11830         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11831         {}
11832 };
11833
11834 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
11835 {
11836         struct alc_spec *spec = codec->spec;
11837
11838         spec->autocfg.hp_pins[0] = 0x15;
11839         spec->autocfg.speaker_pins[0] = 0x14;
11840         spec->ext_mic.pin = 0x18;
11841         spec->ext_mic.mux_idx = 0;
11842         spec->int_mic.pin = 0x12;
11843         spec->int_mic.mux_idx = 9;
11844         spec->auto_mic = 1;
11845         spec->automute = 1;
11846         spec->automute_mode = ALC_AUTOMUTE_PIN;
11847 }
11848
11849 /*
11850  * nec model
11851  *  0x15 = headphone
11852  *  0x16 = internal speaker
11853  *  0x18 = external mic
11854  */
11855
11856 static const struct snd_kcontrol_new alc262_nec_mixer[] = {
11857         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
11858         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
11859
11860         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11861         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11862         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11863
11864         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
11865         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11866         { } /* end */
11867 };
11868
11869 static const struct hda_verb alc262_nec_verbs[] = {
11870         /* Unmute Speaker */
11871         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11872
11873         /* Headphone */
11874         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11875         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11876
11877         /* External mic to headphone */
11878         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11879         /* External mic to speaker */
11880         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11881         {}
11882 };
11883
11884 /*
11885  * fujitsu model
11886  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
11887  *  0x1b = port replicator headphone out
11888  */
11889
11890 #define ALC_HP_EVENT    ALC880_HP_EVENT
11891
11892 static const struct hda_verb alc262_fujitsu_unsol_verbs[] = {
11893         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
11894         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11895         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
11896         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11897         {}
11898 };
11899
11900 static const struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
11901         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
11902         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11903         {}
11904 };
11905
11906 static const struct hda_verb alc262_lenovo_3000_init_verbs[] = {
11907         /* Front Mic pin: input vref at 50% */
11908         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
11909         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11910         {}
11911 };
11912
11913 static const struct hda_input_mux alc262_fujitsu_capture_source = {
11914         .num_items = 3,
11915         .items = {
11916                 { "Mic", 0x0 },
11917                 { "Internal Mic", 0x1 },
11918                 { "CD", 0x4 },
11919         },
11920 };
11921
11922 static const struct hda_input_mux alc262_HP_capture_source = {
11923         .num_items = 5,
11924         .items = {
11925                 { "Mic", 0x0 },
11926                 { "Front Mic", 0x1 },
11927                 { "Line", 0x2 },
11928                 { "CD", 0x4 },
11929                 { "AUX IN", 0x6 },
11930         },
11931 };
11932
11933 static const struct hda_input_mux alc262_HP_D7000_capture_source = {
11934         .num_items = 4,
11935         .items = {
11936                 { "Mic", 0x0 },
11937                 { "Front Mic", 0x2 },
11938                 { "Line", 0x1 },
11939                 { "CD", 0x4 },
11940         },
11941 };
11942
11943 static void alc262_fujitsu_setup(struct hda_codec *codec)
11944 {
11945         struct alc_spec *spec = codec->spec;
11946
11947         spec->autocfg.hp_pins[0] = 0x14;
11948         spec->autocfg.hp_pins[1] = 0x1b;
11949         spec->autocfg.speaker_pins[0] = 0x15;
11950         spec->automute = 1;
11951         spec->automute_mode = ALC_AUTOMUTE_AMP;
11952 }
11953
11954 /* bind volumes of both NID 0x0c and 0x0d */
11955 static const struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
11956         .ops = &snd_hda_bind_vol,
11957         .values = {
11958                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
11959                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
11960                 0
11961         },
11962 };
11963
11964 static const struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
11965         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
11966         {
11967                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11968                 .name = "Master Playback Switch",
11969                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
11970                 .info = snd_ctl_boolean_mono_info,
11971                 .get = alc262_hp_master_sw_get,
11972                 .put = alc262_hp_master_sw_put,
11973         },
11974         {
11975                 .iface = NID_MAPPING,
11976                 .name = "Master Playback Switch",
11977                 .private_value = 0x1b,
11978         },
11979         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11980         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11981         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
11982         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11983         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11984         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
11985         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11986         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11987         { } /* end */
11988 };
11989
11990 static void alc262_lenovo_3000_setup(struct hda_codec *codec)
11991 {
11992         struct alc_spec *spec = codec->spec;
11993
11994         spec->autocfg.hp_pins[0] = 0x1b;
11995         spec->autocfg.speaker_pins[0] = 0x14;
11996         spec->autocfg.speaker_pins[1] = 0x16;
11997         spec->automute = 1;
11998         spec->automute_mode = ALC_AUTOMUTE_AMP;
11999 }
12000
12001 static const struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
12002         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
12003         {
12004                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12005                 .name = "Master Playback Switch",
12006                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
12007                 .info = snd_ctl_boolean_mono_info,
12008                 .get = alc262_hp_master_sw_get,
12009                 .put = alc262_hp_master_sw_put,
12010         },
12011         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12012         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12013         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
12014         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12015         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12016         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
12017         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12018         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12019         { } /* end */
12020 };
12021
12022 static const struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
12023         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
12024         ALC262_HIPPO_MASTER_SWITCH,
12025         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12026         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12027         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
12028         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12029         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12030         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
12031         { } /* end */
12032 };
12033
12034 /* additional init verbs for Benq laptops */
12035 static const struct hda_verb alc262_EAPD_verbs[] = {
12036         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
12037         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
12038         {}
12039 };
12040
12041 static const struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
12042         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12043         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12044
12045         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
12046         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
12047         {}
12048 };
12049
12050 /* Samsung Q1 Ultra Vista model setup */
12051 static const struct snd_kcontrol_new alc262_ultra_mixer[] = {
12052         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
12053         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
12054         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12055         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12056         HDA_CODEC_VOLUME("Mic Boost Volume", 0x19, 0, HDA_INPUT),
12057         HDA_CODEC_VOLUME("Headphone Mic Boost Volume", 0x15, 0, HDA_INPUT),
12058         { } /* end */
12059 };
12060
12061 static const struct hda_verb alc262_ultra_verbs[] = {
12062         /* output mixer */
12063         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12064         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12065         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12066         /* speaker */
12067         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12068         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12069         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12070         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12071         /* HP */
12072         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12073         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12074         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12075         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12076         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12077         /* internal mic */
12078         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12079         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12080         /* ADC, choose mic */
12081         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12082         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12083         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12084         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12087         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12088         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
12089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
12090         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
12091         {}
12092 };
12093
12094 /* mute/unmute internal speaker according to the hp jack and mute state */
12095 static void alc262_ultra_automute(struct hda_codec *codec)
12096 {
12097         struct alc_spec *spec = codec->spec;
12098         unsigned int mute;
12099
12100         mute = 0;
12101         /* auto-mute only when HP is used as HP */
12102         if (!spec->cur_mux[0]) {
12103                 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
12104                 if (spec->jack_present)
12105                         mute = HDA_AMP_MUTE;
12106         }
12107         /* mute/unmute internal speaker */
12108         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12109                                  HDA_AMP_MUTE, mute);
12110         /* mute/unmute HP */
12111         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12112                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
12113 }
12114
12115 /* unsolicited event for HP jack sensing */
12116 static void alc262_ultra_unsol_event(struct hda_codec *codec,
12117                                        unsigned int res)
12118 {
12119         if ((res >> 26) != ALC880_HP_EVENT)
12120                 return;
12121         alc262_ultra_automute(codec);
12122 }
12123
12124 static const struct hda_input_mux alc262_ultra_capture_source = {
12125         .num_items = 2,
12126         .items = {
12127                 { "Mic", 0x1 },
12128                 { "Headphone", 0x7 },
12129         },
12130 };
12131
12132 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
12133                                      struct snd_ctl_elem_value *ucontrol)
12134 {
12135         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12136         struct alc_spec *spec = codec->spec;
12137         int ret;
12138
12139         ret = alc_mux_enum_put(kcontrol, ucontrol);
12140         if (!ret)
12141                 return 0;
12142         /* reprogram the HP pin as mic or HP according to the input source */
12143         snd_hda_codec_write_cache(codec, 0x15, 0,
12144                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
12145                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
12146         alc262_ultra_automute(codec); /* mute/unmute HP */
12147         return ret;
12148 }
12149
12150 static const struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
12151         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
12152         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
12153         {
12154                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12155                 .name = "Capture Source",
12156                 .info = alc_mux_enum_info,
12157                 .get = alc_mux_enum_get,
12158                 .put = alc262_ultra_mux_enum_put,
12159         },
12160         {
12161                 .iface = NID_MAPPING,
12162                 .name = "Capture Source",
12163                 .private_value = 0x15,
12164         },
12165         { } /* end */
12166 };
12167
12168 /* We use two mixers depending on the output pin; 0x16 is a mono output
12169  * and thus it's bound with a different mixer.
12170  * This function returns which mixer amp should be used.
12171  */
12172 static int alc262_check_volbit(hda_nid_t nid)
12173 {
12174         if (!nid)
12175                 return 0;
12176         else if (nid == 0x16)
12177                 return 2;
12178         else
12179                 return 1;
12180 }
12181
12182 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
12183                                   const char *pfx, int *vbits, int idx)
12184 {
12185         unsigned long val;
12186         int vbit;
12187
12188         vbit = alc262_check_volbit(nid);
12189         if (!vbit)
12190                 return 0;
12191         if (*vbits & vbit) /* a volume control for this mixer already there */
12192                 return 0;
12193         *vbits |= vbit;
12194         if (vbit == 2)
12195                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
12196         else
12197                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
12198         return __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, idx, val);
12199 }
12200
12201 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
12202                                  const char *pfx, int idx)
12203 {
12204         unsigned long val;
12205
12206         if (!nid)
12207                 return 0;
12208         if (nid == 0x16)
12209                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
12210         else
12211                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
12212         return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, idx, val);
12213 }
12214
12215 /* add playback controls from the parsed DAC table */
12216 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
12217                                              const struct auto_pin_cfg *cfg)
12218 {
12219         const char *pfx;
12220         int vbits;
12221         int i, index, err;
12222
12223         spec->multiout.num_dacs = 1;    /* only use one dac */
12224         spec->multiout.dac_nids = spec->private_dac_nids;
12225         spec->private_dac_nids[0] = 2;
12226
12227         for (i = 0; i < 2; i++) {
12228                 pfx = alc_get_line_out_pfx(spec, i, true, &index);
12229                 if (!pfx)
12230                         pfx = "PCM";
12231                 err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[i], pfx,
12232                                             index);
12233                 if (err < 0)
12234                         return err;
12235                 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
12236                         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[i],
12237                                                     "Speaker", i);
12238                         if (err < 0)
12239                                 return err;
12240                 }
12241                 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
12242                         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[i],
12243                                                     "Headphone", i);
12244                         if (err < 0)
12245                                 return err;
12246                 }
12247         }
12248
12249         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
12250                 alc262_check_volbit(cfg->speaker_pins[0]) |
12251                 alc262_check_volbit(cfg->hp_pins[0]);
12252         vbits = 0;
12253         for (i = 0; i < 2; i++) {
12254                 pfx = alc_get_line_out_pfx(spec, i, true, &index);
12255                 if (!pfx)
12256                         pfx = "PCM";
12257                 err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[i], pfx,
12258                                              &vbits, i);
12259                 if (err < 0)
12260                         return err;
12261                 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
12262                         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[i],
12263                                                      "Speaker", &vbits, i);
12264                         if (err < 0)
12265                                 return err;
12266                 }
12267                 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
12268                         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[i],
12269                                                      "Headphone", &vbits, i);
12270                         if (err < 0)
12271                                 return err;
12272                 }
12273         }
12274         return 0;
12275 }
12276
12277 #define alc262_auto_create_input_ctls \
12278         alc882_auto_create_input_ctls
12279
12280 static const struct hda_verb alc262_HP_BPC_init_verbs[] = {
12281         /*
12282          * Unmute ADC0-2 and set the default input to mic-in
12283          */
12284         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
12285         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12286         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12287         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12288         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12289         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12290
12291         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
12292          * mixer widget
12293          * Note: PASD motherboards uses the Line In 2 as the input for
12294          * front panel mic (mic 2)
12295          */
12296         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12297         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12298         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12299         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12300         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12301         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12302         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12303         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
12304
12305         /*
12306          * Set up output mixers (0x0c - 0x0e)
12307          */
12308         /* set vol=0 to output mixers */
12309         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12310         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12311         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12312
12313         /* set up input amps for analog loopback */
12314         /* Amp Indices: DAC = 0, mixer = 1 */
12315         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12316         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12317         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12318         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12319         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12320         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12321
12322         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12323         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12324         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12325
12326         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12327         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12328
12329         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12330         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12331
12332         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12333         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12334         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12335         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12336         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12337
12338         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12339         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12340         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12341         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12342         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12343         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12344
12345
12346         /* FIXME: use matrix-type input source selection */
12347         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
12348         /* Input mixer1: only unmute Mic */
12349         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12350         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
12351         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
12352         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
12353         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
12354         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
12355         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
12356         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
12357         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
12358         /* Input mixer2 */
12359         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12360         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
12361         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
12362         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
12363         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
12364         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
12365         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
12366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
12367         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
12368         /* Input mixer3 */
12369         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
12371         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
12372         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
12373         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
12374         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
12375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
12376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
12377         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
12378
12379         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12380
12381         { }
12382 };
12383
12384 static const struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
12385         /*
12386          * Unmute ADC0-2 and set the default input to mic-in
12387          */
12388         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
12389         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12390         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12391         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12392         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12393         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12394
12395         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
12396          * mixer widget
12397          * Note: PASD motherboards uses the Line In 2 as the input for front
12398          * panel mic (mic 2)
12399          */
12400         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12401         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12402         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12403         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12404         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12405         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12406         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
12407         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
12408         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
12409         /*
12410          * Set up output mixers (0x0c - 0x0e)
12411          */
12412         /* set vol=0 to output mixers */
12413         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12414         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12415         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12416
12417         /* set up input amps for analog loopback */
12418         /* Amp Indices: DAC = 0, mixer = 1 */
12419         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12420         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12421         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12422         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12423         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12424         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12425
12426
12427         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
12428         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
12429         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
12430         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
12431         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
12432         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
12433         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
12434
12435         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12436         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12437
12438         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12439         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12440
12441         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
12442         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12443         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12444         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
12445         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12446         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
12447
12448         /* FIXME: use matrix-type input source selection */
12449         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12450         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12451         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
12452         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
12453         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
12454         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
12455         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
12456         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
12457         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
12458         /* Input mixer2 */
12459         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12460         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
12461         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
12462         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
12463         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
12464         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
12465         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
12466         /* Input mixer3 */
12467         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
12468         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
12469         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
12470         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
12471         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
12472         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
12473         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
12474
12475         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12476
12477         { }
12478 };
12479
12480 static const struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
12481
12482         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
12483         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12484         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
12485
12486         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
12487         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
12488         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
12489         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
12490
12491         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
12492         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12493         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12494         {}
12495 };
12496
12497 /*
12498  * Pin config fixes
12499  */
12500 enum {
12501         PINFIX_FSC_H270,
12502         PINFIX_HP_Z200,
12503 };
12504
12505 static const struct alc_fixup alc262_fixups[] = {
12506         [PINFIX_FSC_H270] = {
12507                 .type = ALC_FIXUP_PINS,
12508                 .v.pins = (const struct alc_pincfg[]) {
12509                         { 0x14, 0x99130110 }, /* speaker */
12510                         { 0x15, 0x0221142f }, /* front HP */
12511                         { 0x1b, 0x0121141f }, /* rear HP */
12512                         { }
12513                 }
12514         },
12515         [PINFIX_HP_Z200] = {
12516                 .type = ALC_FIXUP_PINS,
12517                 .v.pins = (const struct alc_pincfg[]) {
12518                         { 0x16, 0x99130120 }, /* internal speaker */
12519                         { }
12520                 }
12521         },
12522 };
12523
12524 static const struct snd_pci_quirk alc262_fixup_tbl[] = {
12525         SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
12526         SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
12527         {}
12528 };
12529
12530
12531 #ifdef CONFIG_SND_HDA_POWER_SAVE
12532 #define alc262_loopbacks        alc880_loopbacks
12533 #endif
12534
12535 /* pcm configuration: identical with ALC880 */
12536 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
12537 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
12538 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
12539 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
12540
12541 /*
12542  * BIOS auto configuration
12543  */
12544 static int alc262_parse_auto_config(struct hda_codec *codec)
12545 {
12546         struct alc_spec *spec = codec->spec;
12547         int err;
12548         static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
12549
12550         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12551                                            alc262_ignore);
12552         if (err < 0)
12553                 return err;
12554         if (!spec->autocfg.line_outs) {
12555                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12556                         spec->multiout.max_channels = 2;
12557                         spec->no_analog = 1;
12558                         goto dig_only;
12559                 }
12560                 return 0; /* can't find valid BIOS pin config */
12561         }
12562         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
12563         if (err < 0)
12564                 return err;
12565         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
12566         if (err < 0)
12567                 return err;
12568
12569         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12570
12571  dig_only:
12572         alc_auto_parse_digital(codec);
12573
12574         if (spec->kctls.list)
12575                 add_mixer(spec, spec->kctls.list);
12576
12577         spec->num_mux_defs = 1;
12578         spec->input_mux = &spec->private_imux[0];
12579
12580         err = alc_auto_add_mic_boost(codec);
12581         if (err < 0)
12582                 return err;
12583
12584         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
12585
12586         return 1;
12587 }
12588
12589 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
12590 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
12591 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
12592 #define alc262_auto_init_input_src      alc882_auto_init_input_src
12593
12594
12595 /* init callback for auto-configuration model -- overriding the default init */
12596 static void alc262_auto_init(struct hda_codec *codec)
12597 {
12598         struct alc_spec *spec = codec->spec;
12599         alc262_auto_init_multi_out(codec);
12600         alc262_auto_init_hp_out(codec);
12601         alc262_auto_init_analog_input(codec);
12602         alc262_auto_init_input_src(codec);
12603         alc_auto_init_digital(codec);
12604         if (spec->unsol_event)
12605                 alc_inithook(codec);
12606 }
12607
12608 /*
12609  * configuration and preset
12610  */
12611 static const char * const alc262_models[ALC262_MODEL_LAST] = {
12612         [ALC262_BASIC]          = "basic",
12613         [ALC262_HIPPO]          = "hippo",
12614         [ALC262_HIPPO_1]        = "hippo_1",
12615         [ALC262_FUJITSU]        = "fujitsu",
12616         [ALC262_HP_BPC]         = "hp-bpc",
12617         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
12618         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
12619         [ALC262_HP_RP5700]      = "hp-rp5700",
12620         [ALC262_BENQ_ED8]       = "benq",
12621         [ALC262_BENQ_T31]       = "benq-t31",
12622         [ALC262_SONY_ASSAMD]    = "sony-assamd",
12623         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
12624         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
12625         [ALC262_ULTRA]          = "ultra",
12626         [ALC262_LENOVO_3000]    = "lenovo-3000",
12627         [ALC262_NEC]            = "nec",
12628         [ALC262_TYAN]           = "tyan",
12629         [ALC262_AUTO]           = "auto",
12630 };
12631
12632 static const struct snd_pci_quirk alc262_cfg_tbl[] = {
12633         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
12634         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
12635         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
12636                            ALC262_HP_BPC),
12637         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
12638                            ALC262_HP_BPC),
12639         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1500, "HP z series",
12640                            ALC262_HP_BPC),
12641         SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200",
12642                            ALC262_AUTO),
12643         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
12644                            ALC262_HP_BPC),
12645         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
12646         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
12647         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
12648         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
12649         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
12650         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
12651         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
12652         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
12653         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
12654         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
12655         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
12656         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
12657                       ALC262_HP_TC_T5735),
12658         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
12659         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
12660         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
12661         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
12662         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
12663         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
12664         SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
12665         SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
12666 #if 0 /* disable the quirk since model=auto works better in recent versions */
12667         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
12668                            ALC262_SONY_ASSAMD),
12669 #endif
12670         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
12671                       ALC262_TOSHIBA_RX1),
12672         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
12673         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
12674         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
12675         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
12676         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
12677                            ALC262_ULTRA),
12678         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
12679         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
12680         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
12681         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
12682         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
12683         {}
12684 };
12685
12686 static const struct alc_config_preset alc262_presets[] = {
12687         [ALC262_BASIC] = {
12688                 .mixers = { alc262_base_mixer },
12689                 .init_verbs = { alc262_init_verbs },
12690                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12691                 .dac_nids = alc262_dac_nids,
12692                 .hp_nid = 0x03,
12693                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12694                 .channel_mode = alc262_modes,
12695                 .input_mux = &alc262_capture_source,
12696         },
12697         [ALC262_HIPPO] = {
12698                 .mixers = { alc262_hippo_mixer },
12699                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
12700                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12701                 .dac_nids = alc262_dac_nids,
12702                 .hp_nid = 0x03,
12703                 .dig_out_nid = ALC262_DIGOUT_NID,
12704                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12705                 .channel_mode = alc262_modes,
12706                 .input_mux = &alc262_capture_source,
12707                 .unsol_event = alc_sku_unsol_event,
12708                 .setup = alc262_hippo_setup,
12709                 .init_hook = alc_inithook,
12710         },
12711         [ALC262_HIPPO_1] = {
12712                 .mixers = { alc262_hippo1_mixer },
12713                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
12714                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12715                 .dac_nids = alc262_dac_nids,
12716                 .hp_nid = 0x02,
12717                 .dig_out_nid = ALC262_DIGOUT_NID,
12718                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12719                 .channel_mode = alc262_modes,
12720                 .input_mux = &alc262_capture_source,
12721                 .unsol_event = alc_sku_unsol_event,
12722                 .setup = alc262_hippo1_setup,
12723                 .init_hook = alc_inithook,
12724         },
12725         [ALC262_FUJITSU] = {
12726                 .mixers = { alc262_fujitsu_mixer },
12727                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
12728                                 alc262_fujitsu_unsol_verbs },
12729                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12730                 .dac_nids = alc262_dac_nids,
12731                 .hp_nid = 0x03,
12732                 .dig_out_nid = ALC262_DIGOUT_NID,
12733                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12734                 .channel_mode = alc262_modes,
12735                 .input_mux = &alc262_fujitsu_capture_source,
12736                 .unsol_event = alc_sku_unsol_event,
12737                 .setup = alc262_fujitsu_setup,
12738                 .init_hook = alc_inithook,
12739         },
12740         [ALC262_HP_BPC] = {
12741                 .mixers = { alc262_HP_BPC_mixer },
12742                 .init_verbs = { alc262_HP_BPC_init_verbs },
12743                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12744                 .dac_nids = alc262_dac_nids,
12745                 .hp_nid = 0x03,
12746                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12747                 .channel_mode = alc262_modes,
12748                 .input_mux = &alc262_HP_capture_source,
12749                 .unsol_event = alc_sku_unsol_event,
12750                 .setup = alc262_hp_bpc_setup,
12751                 .init_hook = alc_inithook,
12752         },
12753         [ALC262_HP_BPC_D7000_WF] = {
12754                 .mixers = { alc262_HP_BPC_WildWest_mixer },
12755                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
12756                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12757                 .dac_nids = alc262_dac_nids,
12758                 .hp_nid = 0x03,
12759                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12760                 .channel_mode = alc262_modes,
12761                 .input_mux = &alc262_HP_D7000_capture_source,
12762                 .unsol_event = alc_sku_unsol_event,
12763                 .setup = alc262_hp_wildwest_setup,
12764                 .init_hook = alc_inithook,
12765         },
12766         [ALC262_HP_BPC_D7000_WL] = {
12767                 .mixers = { alc262_HP_BPC_WildWest_mixer,
12768                             alc262_HP_BPC_WildWest_option_mixer },
12769                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
12770                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12771                 .dac_nids = alc262_dac_nids,
12772                 .hp_nid = 0x03,
12773                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12774                 .channel_mode = alc262_modes,
12775                 .input_mux = &alc262_HP_D7000_capture_source,
12776                 .unsol_event = alc_sku_unsol_event,
12777                 .setup = alc262_hp_wildwest_setup,
12778                 .init_hook = alc_inithook,
12779         },
12780         [ALC262_HP_TC_T5735] = {
12781                 .mixers = { alc262_hp_t5735_mixer },
12782                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
12783                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12784                 .dac_nids = alc262_dac_nids,
12785                 .hp_nid = 0x03,
12786                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12787                 .channel_mode = alc262_modes,
12788                 .input_mux = &alc262_capture_source,
12789                 .unsol_event = alc_sku_unsol_event,
12790                 .setup = alc262_hp_t5735_setup,
12791                 .init_hook = alc_inithook,
12792         },
12793         [ALC262_HP_RP5700] = {
12794                 .mixers = { alc262_hp_rp5700_mixer },
12795                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
12796                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12797                 .dac_nids = alc262_dac_nids,
12798                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12799                 .channel_mode = alc262_modes,
12800                 .input_mux = &alc262_hp_rp5700_capture_source,
12801         },
12802         [ALC262_BENQ_ED8] = {
12803                 .mixers = { alc262_base_mixer },
12804                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
12805                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12806                 .dac_nids = alc262_dac_nids,
12807                 .hp_nid = 0x03,
12808                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12809                 .channel_mode = alc262_modes,
12810                 .input_mux = &alc262_capture_source,
12811         },
12812         [ALC262_SONY_ASSAMD] = {
12813                 .mixers = { alc262_sony_mixer },
12814                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
12815                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12816                 .dac_nids = alc262_dac_nids,
12817                 .hp_nid = 0x02,
12818                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12819                 .channel_mode = alc262_modes,
12820                 .input_mux = &alc262_capture_source,
12821                 .unsol_event = alc_sku_unsol_event,
12822                 .setup = alc262_hippo_setup,
12823                 .init_hook = alc_inithook,
12824         },
12825         [ALC262_BENQ_T31] = {
12826                 .mixers = { alc262_benq_t31_mixer },
12827                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
12828                                 alc_hp15_unsol_verbs },
12829                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12830                 .dac_nids = alc262_dac_nids,
12831                 .hp_nid = 0x03,
12832                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12833                 .channel_mode = alc262_modes,
12834                 .input_mux = &alc262_capture_source,
12835                 .unsol_event = alc_sku_unsol_event,
12836                 .setup = alc262_hippo_setup,
12837                 .init_hook = alc_inithook,
12838         },
12839         [ALC262_ULTRA] = {
12840                 .mixers = { alc262_ultra_mixer },
12841                 .cap_mixer = alc262_ultra_capture_mixer,
12842                 .init_verbs = { alc262_ultra_verbs },
12843                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12844                 .dac_nids = alc262_dac_nids,
12845                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12846                 .channel_mode = alc262_modes,
12847                 .input_mux = &alc262_ultra_capture_source,
12848                 .adc_nids = alc262_adc_nids, /* ADC0 */
12849                 .capsrc_nids = alc262_capsrc_nids,
12850                 .num_adc_nids = 1, /* single ADC */
12851                 .unsol_event = alc262_ultra_unsol_event,
12852                 .init_hook = alc262_ultra_automute,
12853         },
12854         [ALC262_LENOVO_3000] = {
12855                 .mixers = { alc262_lenovo_3000_mixer },
12856                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
12857                                 alc262_lenovo_3000_unsol_verbs,
12858                                 alc262_lenovo_3000_init_verbs },
12859                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12860                 .dac_nids = alc262_dac_nids,
12861                 .hp_nid = 0x03,
12862                 .dig_out_nid = ALC262_DIGOUT_NID,
12863                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12864                 .channel_mode = alc262_modes,
12865                 .input_mux = &alc262_fujitsu_capture_source,
12866                 .unsol_event = alc_sku_unsol_event,
12867                 .setup = alc262_lenovo_3000_setup,
12868                 .init_hook = alc_inithook,
12869         },
12870         [ALC262_NEC] = {
12871                 .mixers = { alc262_nec_mixer },
12872                 .init_verbs = { alc262_nec_verbs },
12873                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12874                 .dac_nids = alc262_dac_nids,
12875                 .hp_nid = 0x03,
12876                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12877                 .channel_mode = alc262_modes,
12878                 .input_mux = &alc262_capture_source,
12879         },
12880         [ALC262_TOSHIBA_S06] = {
12881                 .mixers = { alc262_toshiba_s06_mixer },
12882                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
12883                                                         alc262_eapd_verbs },
12884                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12885                 .capsrc_nids = alc262_dmic_capsrc_nids,
12886                 .dac_nids = alc262_dac_nids,
12887                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
12888                 .num_adc_nids = 1, /* single ADC */
12889                 .dig_out_nid = ALC262_DIGOUT_NID,
12890                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12891                 .channel_mode = alc262_modes,
12892                 .unsol_event = alc_sku_unsol_event,
12893                 .setup = alc262_toshiba_s06_setup,
12894                 .init_hook = alc_inithook,
12895         },
12896         [ALC262_TOSHIBA_RX1] = {
12897                 .mixers = { alc262_toshiba_rx1_mixer },
12898                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
12899                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12900                 .dac_nids = alc262_dac_nids,
12901                 .hp_nid = 0x03,
12902                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12903                 .channel_mode = alc262_modes,
12904                 .input_mux = &alc262_capture_source,
12905                 .unsol_event = alc_sku_unsol_event,
12906                 .setup = alc262_hippo_setup,
12907                 .init_hook = alc_inithook,
12908         },
12909         [ALC262_TYAN] = {
12910                 .mixers = { alc262_tyan_mixer },
12911                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
12912                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
12913                 .dac_nids = alc262_dac_nids,
12914                 .hp_nid = 0x02,
12915                 .dig_out_nid = ALC262_DIGOUT_NID,
12916                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
12917                 .channel_mode = alc262_modes,
12918                 .input_mux = &alc262_capture_source,
12919                 .unsol_event = alc_sku_unsol_event,
12920                 .setup = alc262_tyan_setup,
12921                 .init_hook = alc_hp_automute,
12922         },
12923 };
12924
12925 static int patch_alc262(struct hda_codec *codec)
12926 {
12927         struct alc_spec *spec;
12928         int board_config;
12929         int err;
12930
12931         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12932         if (spec == NULL)
12933                 return -ENOMEM;
12934
12935         codec->spec = spec;
12936
12937         spec->mixer_nid = 0x0b;
12938
12939 #if 0
12940         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
12941          * under-run
12942          */
12943         {
12944         int tmp;
12945         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
12946         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
12947         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
12948         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
12949         }
12950 #endif
12951         alc_auto_parse_customize_define(codec);
12952
12953         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
12954
12955         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
12956                                                   alc262_models,
12957                                                   alc262_cfg_tbl);
12958
12959         if (board_config < 0) {
12960                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12961                        codec->chip_name);
12962                 board_config = ALC262_AUTO;
12963         }
12964
12965         if (board_config == ALC262_AUTO) {
12966                 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
12967                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
12968         }
12969
12970         if (board_config == ALC262_AUTO) {
12971                 /* automatic parse from the BIOS config */
12972                 err = alc262_parse_auto_config(codec);
12973                 if (err < 0) {
12974                         alc_free(codec);
12975                         return err;
12976                 } else if (!err) {
12977                         printk(KERN_INFO
12978                                "hda_codec: Cannot set up configuration "
12979                                "from BIOS.  Using base mode...\n");
12980                         board_config = ALC262_BASIC;
12981                 }
12982         }
12983
12984         if (!spec->no_analog && has_cdefine_beep(codec)) {
12985                 err = snd_hda_attach_beep_device(codec, 0x1);
12986                 if (err < 0) {
12987                         alc_free(codec);
12988                         return err;
12989                 }
12990         }
12991
12992         if (board_config != ALC262_AUTO)
12993                 setup_preset(codec, &alc262_presets[board_config]);
12994
12995         spec->stream_analog_playback = &alc262_pcm_analog_playback;
12996         spec->stream_analog_capture = &alc262_pcm_analog_capture;
12997
12998         spec->stream_digital_playback = &alc262_pcm_digital_playback;
12999         spec->stream_digital_capture = &alc262_pcm_digital_capture;
13000
13001         if (!spec->adc_nids && spec->input_mux) {
13002                 int i;
13003                 /* check whether the digital-mic has to be supported */
13004                 for (i = 0; i < spec->input_mux->num_items; i++) {
13005                         if (spec->input_mux->items[i].index >= 9)
13006                                 break;
13007                 }
13008                 if (i < spec->input_mux->num_items) {
13009                         /* use only ADC0 */
13010                         spec->adc_nids = alc262_dmic_adc_nids;
13011                         spec->num_adc_nids = 1;
13012                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
13013                 } else {
13014                         /* all analog inputs */
13015                         /* check whether NID 0x07 is valid */
13016                         unsigned int wcap = get_wcaps(codec, 0x07);
13017
13018                         /* get type */
13019                         wcap = get_wcaps_type(wcap);
13020                         if (wcap != AC_WID_AUD_IN) {
13021                                 spec->adc_nids = alc262_adc_nids_alt;
13022                                 spec->num_adc_nids =
13023                                         ARRAY_SIZE(alc262_adc_nids_alt);
13024                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
13025                         } else {
13026                                 spec->adc_nids = alc262_adc_nids;
13027                                 spec->num_adc_nids =
13028                                         ARRAY_SIZE(alc262_adc_nids);
13029                                 spec->capsrc_nids = alc262_capsrc_nids;
13030                         }
13031                 }
13032         }
13033         if (!spec->cap_mixer && !spec->no_analog)
13034                 set_capture_mixer(codec);
13035         if (!spec->no_analog && has_cdefine_beep(codec))
13036                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
13037
13038         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
13039
13040         spec->vmaster_nid = 0x0c;
13041
13042         codec->patch_ops = alc_patch_ops;
13043         if (board_config == ALC262_AUTO)
13044                 spec->init_hook = alc262_auto_init;
13045         spec->shutup = alc_eapd_shutup;
13046
13047         alc_init_jacks(codec);
13048 #ifdef CONFIG_SND_HDA_POWER_SAVE
13049         if (!spec->loopback.amplist)
13050                 spec->loopback.amplist = alc262_loopbacks;
13051 #endif
13052
13053         return 0;
13054 }
13055
13056 /*
13057  *  ALC268 channel source setting (2 channel)
13058  */
13059 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
13060 #define alc268_modes            alc260_modes
13061
13062 static const hda_nid_t alc268_dac_nids[2] = {
13063         /* front, hp */
13064         0x02, 0x03
13065 };
13066
13067 static const hda_nid_t alc268_adc_nids[2] = {
13068         /* ADC0-1 */
13069         0x08, 0x07
13070 };
13071
13072 static const hda_nid_t alc268_adc_nids_alt[1] = {
13073         /* ADC0 */
13074         0x08
13075 };
13076
13077 static const hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
13078
13079 static const struct snd_kcontrol_new alc268_base_mixer[] = {
13080         /* output mixer control */
13081         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13082         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13083         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13084         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13085         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13086         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
13087         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13088         { }
13089 };
13090
13091 static const struct snd_kcontrol_new alc268_toshiba_mixer[] = {
13092         /* output mixer control */
13093         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13094         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13095         ALC262_HIPPO_MASTER_SWITCH,
13096         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13097         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
13098         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13099         { }
13100 };
13101
13102 /* bind Beep switches of both NID 0x0f and 0x10 */
13103 static const struct hda_bind_ctls alc268_bind_beep_sw = {
13104         .ops = &snd_hda_bind_sw,
13105         .values = {
13106                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
13107                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
13108                 0
13109         },
13110 };
13111
13112 static const struct snd_kcontrol_new alc268_beep_mixer[] = {
13113         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
13114         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
13115         { }
13116 };
13117
13118 static const struct hda_verb alc268_eapd_verbs[] = {
13119         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13120         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13121         { }
13122 };
13123
13124 /* Toshiba specific */
13125 static const struct hda_verb alc268_toshiba_verbs[] = {
13126         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13127         { } /* end */
13128 };
13129
13130 /* Acer specific */
13131 /* bind volumes of both NID 0x02 and 0x03 */
13132 static const struct hda_bind_ctls alc268_acer_bind_master_vol = {
13133         .ops = &snd_hda_bind_vol,
13134         .values = {
13135                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
13136                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
13137                 0
13138         },
13139 };
13140
13141 static void alc268_acer_setup(struct hda_codec *codec)
13142 {
13143         struct alc_spec *spec = codec->spec;
13144
13145         spec->autocfg.hp_pins[0] = 0x14;
13146         spec->autocfg.speaker_pins[0] = 0x15;
13147         spec->automute = 1;
13148         spec->automute_mode = ALC_AUTOMUTE_AMP;
13149 }
13150
13151 #define alc268_acer_master_sw_get       alc262_hp_master_sw_get
13152 #define alc268_acer_master_sw_put       alc262_hp_master_sw_put
13153
13154 static const struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
13155         /* output mixer control */
13156         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
13157         {
13158                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13159                 .name = "Master Playback Switch",
13160                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x15,
13161                 .info = snd_ctl_boolean_mono_info,
13162                 .get = alc268_acer_master_sw_get,
13163                 .put = alc268_acer_master_sw_put,
13164         },
13165         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
13166         { }
13167 };
13168
13169 static const struct snd_kcontrol_new alc268_acer_mixer[] = {
13170         /* output mixer control */
13171         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
13172         {
13173                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13174                 .name = "Master Playback Switch",
13175                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
13176                 .info = snd_ctl_boolean_mono_info,
13177                 .get = alc268_acer_master_sw_get,
13178                 .put = alc268_acer_master_sw_put,
13179         },
13180         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13181         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13182         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13183         { }
13184 };
13185
13186 static const struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
13187         /* output mixer control */
13188         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
13189         {
13190                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13191                 .name = "Master Playback Switch",
13192                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
13193                 .info = snd_ctl_boolean_mono_info,
13194                 .get = alc268_acer_master_sw_get,
13195                 .put = alc268_acer_master_sw_put,
13196         },
13197         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13198         HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
13199         { }
13200 };
13201
13202 static const struct hda_verb alc268_acer_aspire_one_verbs[] = {
13203         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13204         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13205         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13206         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13207         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
13208         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
13209         { }
13210 };
13211
13212 static const struct hda_verb alc268_acer_verbs[] = {
13213         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
13214         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13215         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13216         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13217         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13218         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13219         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13220         { }
13221 };
13222
13223 /* unsolicited event for HP jack sensing */
13224 #define alc268_toshiba_setup            alc262_hippo_setup
13225
13226 static void alc268_acer_lc_setup(struct hda_codec *codec)
13227 {
13228         struct alc_spec *spec = codec->spec;
13229         spec->autocfg.hp_pins[0] = 0x15;
13230         spec->autocfg.speaker_pins[0] = 0x14;
13231         spec->automute = 1;
13232         spec->automute_mode = ALC_AUTOMUTE_AMP;
13233         spec->ext_mic.pin = 0x18;
13234         spec->ext_mic.mux_idx = 0;
13235         spec->int_mic.pin = 0x12;
13236         spec->int_mic.mux_idx = 6;
13237         spec->auto_mic = 1;
13238 }
13239
13240 static const struct snd_kcontrol_new alc268_dell_mixer[] = {
13241         /* output mixer control */
13242         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13243         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13244         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13245         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13246         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13247         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13248         { }
13249 };
13250
13251 static const struct hda_verb alc268_dell_verbs[] = {
13252         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13253         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13254         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13255         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
13256         { }
13257 };
13258
13259 /* mute/unmute internal speaker according to the hp jack and mute state */
13260 static void alc268_dell_setup(struct hda_codec *codec)
13261 {
13262         struct alc_spec *spec = codec->spec;
13263
13264         spec->autocfg.hp_pins[0] = 0x15;
13265         spec->autocfg.speaker_pins[0] = 0x14;
13266         spec->ext_mic.pin = 0x18;
13267         spec->ext_mic.mux_idx = 0;
13268         spec->int_mic.pin = 0x19;
13269         spec->int_mic.mux_idx = 1;
13270         spec->auto_mic = 1;
13271         spec->automute = 1;
13272         spec->automute_mode = ALC_AUTOMUTE_PIN;
13273 }
13274
13275 static const struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
13276         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13277         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13278         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13279         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13280         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13281         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
13282         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
13283         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
13284         { }
13285 };
13286
13287 static const struct hda_verb alc267_quanta_il1_verbs[] = {
13288         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13289         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
13290         { }
13291 };
13292
13293 static void alc267_quanta_il1_setup(struct hda_codec *codec)
13294 {
13295         struct alc_spec *spec = codec->spec;
13296         spec->autocfg.hp_pins[0] = 0x15;
13297         spec->autocfg.speaker_pins[0] = 0x14;
13298         spec->ext_mic.pin = 0x18;
13299         spec->ext_mic.mux_idx = 0;
13300         spec->int_mic.pin = 0x19;
13301         spec->int_mic.mux_idx = 1;
13302         spec->auto_mic = 1;
13303         spec->automute = 1;
13304         spec->automute_mode = ALC_AUTOMUTE_PIN;
13305 }
13306
13307 /*
13308  * generic initialization of ADC, input mixers and output mixers
13309  */
13310 static const struct hda_verb alc268_base_init_verbs[] = {
13311         /* Unmute DAC0-1 and set vol = 0 */
13312         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13313         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13314
13315         /*
13316          * Set up output mixers (0x0c - 0x0e)
13317          */
13318         /* set vol=0 to output mixers */
13319         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13320         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
13321
13322         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13323         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13324
13325         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
13326         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
13327         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
13328         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13329         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13330         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13331         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13332         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13333
13334         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13335         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13336         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13337         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13338         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13339
13340         /* set PCBEEP vol = 0, mute connections */
13341         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13342         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13343         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13344
13345         /* Unmute Selector 23h,24h and set the default input to mic-in */
13346
13347         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
13348         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13349         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
13350         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13351
13352         { }
13353 };
13354
13355 /* only for model=test */
13356 #ifdef CONFIG_SND_DEBUG
13357 /*
13358  * generic initialization of ADC, input mixers and output mixers
13359  */
13360 static const struct hda_verb alc268_volume_init_verbs[] = {
13361         /* set output DAC */
13362         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13363         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13364
13365         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13366         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
13367         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13368         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13369         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
13370
13371         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13372         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13373         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13374
13375         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13376         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13377         { }
13378 };
13379 #endif /* CONFIG_SND_DEBUG */
13380
13381 /* set PCBEEP vol = 0, mute connections */
13382 static const struct hda_verb alc268_beep_init_verbs[] = {
13383         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13384         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13385         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13386         { }
13387 };
13388
13389 static const struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
13390         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13391         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
13392         { } /* end */
13393 };
13394
13395 static const struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
13396         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13397         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
13398         _DEFINE_CAPSRC(1),
13399         { } /* end */
13400 };
13401
13402 static const struct snd_kcontrol_new alc268_capture_mixer[] = {
13403         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13404         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
13405         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
13406         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
13407         _DEFINE_CAPSRC(2),
13408         { } /* end */
13409 };
13410
13411 static const struct hda_input_mux alc268_capture_source = {
13412         .num_items = 4,
13413         .items = {
13414                 { "Mic", 0x0 },
13415                 { "Front Mic", 0x1 },
13416                 { "Line", 0x2 },
13417                 { "CD", 0x3 },
13418         },
13419 };
13420
13421 static const struct hda_input_mux alc268_acer_capture_source = {
13422         .num_items = 3,
13423         .items = {
13424                 { "Mic", 0x0 },
13425                 { "Internal Mic", 0x1 },
13426                 { "Line", 0x2 },
13427         },
13428 };
13429
13430 static const struct hda_input_mux alc268_acer_dmic_capture_source = {
13431         .num_items = 3,
13432         .items = {
13433                 { "Mic", 0x0 },
13434                 { "Internal Mic", 0x6 },
13435                 { "Line", 0x2 },
13436         },
13437 };
13438
13439 #ifdef CONFIG_SND_DEBUG
13440 static const struct snd_kcontrol_new alc268_test_mixer[] = {
13441         /* Volume widgets */
13442         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13443         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13444         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13445         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
13446         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
13447         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
13448         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
13449         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
13450         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
13451         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
13452         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
13453         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
13454         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
13455         /* The below appears problematic on some hardwares */
13456         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
13457         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
13458         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
13459         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
13460         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
13461
13462         /* Modes for retasking pin widgets */
13463         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
13464         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
13465         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
13466         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
13467
13468         /* Controls for GPIO pins, assuming they are configured as outputs */
13469         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
13470         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
13471         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
13472         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
13473
13474         /* Switches to allow the digital SPDIF output pin to be enabled.
13475          * The ALC268 does not have an SPDIF input.
13476          */
13477         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
13478
13479         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
13480          * this output to turn on an external amplifier.
13481          */
13482         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
13483         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
13484
13485         { } /* end */
13486 };
13487 #endif
13488
13489 /* create input playback/capture controls for the given pin */
13490 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
13491                                     const char *ctlname, int idx)
13492 {
13493         hda_nid_t dac;
13494         int err;
13495
13496         switch (nid) {
13497         case 0x14:
13498         case 0x16:
13499                 dac = 0x02;
13500                 break;
13501         case 0x15:
13502         case 0x1a: /* ALC259/269 only */
13503         case 0x1b: /* ALC259/269 only */
13504         case 0x21: /* ALC269vb has this pin, too */
13505                 dac = 0x03;
13506                 break;
13507         default:
13508                 snd_printd(KERN_WARNING "hda_codec: "
13509                            "ignoring pin 0x%x as unknown\n", nid);
13510                 return 0;
13511         }
13512         if (spec->multiout.dac_nids[0] != dac &&
13513             spec->multiout.dac_nids[1] != dac) {
13514                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
13515                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
13516                                                       HDA_OUTPUT));
13517                 if (err < 0)
13518                         return err;
13519                 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
13520         }
13521
13522         if (nid != 0x16)
13523                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
13524                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
13525         else /* mono */
13526                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
13527                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
13528         if (err < 0)
13529                 return err;
13530         return 0;
13531 }
13532
13533 /* add playback controls from the parsed DAC table */
13534 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
13535                                              const struct auto_pin_cfg *cfg)
13536 {
13537         hda_nid_t nid;
13538         int err;
13539
13540         spec->multiout.dac_nids = spec->private_dac_nids;
13541
13542         nid = cfg->line_out_pins[0];
13543         if (nid) {
13544                 const char *name;
13545                 int index;
13546                 name = alc_get_line_out_pfx(spec, 0, true, &index);
13547                 err = alc268_new_analog_output(spec, nid, name, 0);
13548                 if (err < 0)
13549                         return err;
13550         }
13551
13552         nid = cfg->speaker_pins[0];
13553         if (nid == 0x1d) {
13554                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
13555                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
13556                 if (err < 0)
13557                         return err;
13558         } else if (nid) {
13559                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
13560                 if (err < 0)
13561                         return err;
13562         }
13563         nid = cfg->hp_pins[0];
13564         if (nid) {
13565                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
13566                 if (err < 0)
13567                         return err;
13568         }
13569
13570         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
13571         if (nid == 0x16) {
13572                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
13573                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
13574                 if (err < 0)
13575                         return err;
13576         }
13577         return 0;
13578 }
13579
13580 /* create playback/capture controls for input pins */
13581 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
13582                                                 const struct auto_pin_cfg *cfg)
13583 {
13584         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
13585 }
13586
13587 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
13588                                               hda_nid_t nid, int pin_type)
13589 {
13590         int idx;
13591
13592         alc_set_pin_output(codec, nid, pin_type);
13593         if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
13594                 return;
13595         if (nid == 0x14 || nid == 0x16)
13596                 idx = 0;
13597         else
13598                 idx = 1;
13599         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
13600 }
13601
13602 static void alc268_auto_init_dac(struct hda_codec *codec, hda_nid_t nid)
13603 {
13604         if (!nid)
13605                 return;
13606         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13607                             AMP_OUT_ZERO);
13608 }
13609
13610 static void alc268_auto_init_multi_out(struct hda_codec *codec)
13611 {
13612         struct alc_spec *spec = codec->spec;
13613         int i;
13614
13615         for (i = 0; i < spec->autocfg.line_outs; i++) {
13616                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13617                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13618                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
13619         }
13620         /* mute DACs */
13621         for (i = 0; i < spec->multiout.num_dacs; i++)
13622                 alc268_auto_init_dac(codec, spec->multiout.dac_nids[i]);
13623 }
13624
13625 static void alc268_auto_init_hp_out(struct hda_codec *codec)
13626 {
13627         struct alc_spec *spec = codec->spec;
13628         hda_nid_t pin;
13629         int i;
13630
13631         for (i = 0; i < spec->autocfg.hp_outs; i++) {
13632                 pin = spec->autocfg.hp_pins[i];
13633                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
13634         }
13635         for (i = 0; i < spec->autocfg.speaker_outs; i++) {
13636                 pin = spec->autocfg.speaker_pins[i];
13637                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
13638         }
13639         if (spec->autocfg.mono_out_pin)
13640                 snd_hda_codec_write(codec, spec->autocfg.mono_out_pin, 0,
13641                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
13642         /* mute DACs */
13643         alc268_auto_init_dac(codec, spec->multiout.hp_nid);
13644         for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
13645                 alc268_auto_init_dac(codec, spec->multiout.extra_out_nid[i]);
13646 }
13647
13648 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
13649 {
13650         struct alc_spec *spec = codec->spec;
13651         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
13652         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
13653         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
13654         unsigned int    dac_vol1, dac_vol2;
13655
13656         if (line_nid == 0x1d || speaker_nid == 0x1d) {
13657                 snd_hda_codec_write(codec, speaker_nid, 0,
13658                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
13659                 /* mute mixer inputs from 0x1d */
13660                 snd_hda_codec_write(codec, 0x0f, 0,
13661                                     AC_VERB_SET_AMP_GAIN_MUTE,
13662                                     AMP_IN_UNMUTE(1));
13663                 snd_hda_codec_write(codec, 0x10, 0,
13664                                     AC_VERB_SET_AMP_GAIN_MUTE,
13665                                     AMP_IN_UNMUTE(1));
13666         } else {
13667                 /* unmute mixer inputs from 0x1d */
13668                 snd_hda_codec_write(codec, 0x0f, 0,
13669                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
13670                 snd_hda_codec_write(codec, 0x10, 0,
13671                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
13672         }
13673
13674         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
13675         if (line_nid == 0x14)
13676                 dac_vol2 = AMP_OUT_ZERO;
13677         else if (line_nid == 0x15)
13678                 dac_vol1 = AMP_OUT_ZERO;
13679         if (hp_nid == 0x14)
13680                 dac_vol2 = AMP_OUT_ZERO;
13681         else if (hp_nid == 0x15)
13682                 dac_vol1 = AMP_OUT_ZERO;
13683         if (line_nid != 0x16 || hp_nid != 0x16 ||
13684             spec->autocfg.line_out_pins[1] != 0x16 ||
13685             spec->autocfg.line_out_pins[2] != 0x16)
13686                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
13687
13688         snd_hda_codec_write(codec, 0x02, 0,
13689                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
13690         snd_hda_codec_write(codec, 0x03, 0,
13691                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
13692 }
13693
13694 /* pcm configuration: identical with ALC880 */
13695 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
13696 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
13697 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
13698 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
13699
13700 /*
13701  * BIOS auto configuration
13702  */
13703 static int alc268_parse_auto_config(struct hda_codec *codec)
13704 {
13705         struct alc_spec *spec = codec->spec;
13706         int err;
13707         static const hda_nid_t alc268_ignore[] = { 0 };
13708
13709         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13710                                            alc268_ignore);
13711         if (err < 0)
13712                 return err;
13713         if (!spec->autocfg.line_outs) {
13714                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
13715                         spec->multiout.max_channels = 2;
13716                         spec->no_analog = 1;
13717                         goto dig_only;
13718                 }
13719                 return 0; /* can't find valid BIOS pin config */
13720         }
13721         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
13722         if (err < 0)
13723                 return err;
13724         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
13725         if (err < 0)
13726                 return err;
13727
13728         spec->multiout.max_channels = 2;
13729
13730  dig_only:
13731         /* digital only support output */
13732         alc_auto_parse_digital(codec);
13733         if (spec->kctls.list)
13734                 add_mixer(spec, spec->kctls.list);
13735
13736         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
13737                 add_mixer(spec, alc268_beep_mixer);
13738                 add_verb(spec, alc268_beep_init_verbs);
13739         }
13740
13741         spec->num_mux_defs = 2;
13742         spec->input_mux = &spec->private_imux[0];
13743
13744         err = alc_auto_add_mic_boost(codec);
13745         if (err < 0)
13746                 return err;
13747
13748         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
13749
13750         return 1;
13751 }
13752
13753 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
13754 #define alc268_auto_init_input_src      alc882_auto_init_input_src
13755
13756 /* init callback for auto-configuration model -- overriding the default init */
13757 static void alc268_auto_init(struct hda_codec *codec)
13758 {
13759         struct alc_spec *spec = codec->spec;
13760         alc268_auto_init_multi_out(codec);
13761         alc268_auto_init_hp_out(codec);
13762         alc268_auto_init_mono_speaker_out(codec);
13763         alc268_auto_init_analog_input(codec);
13764         alc268_auto_init_input_src(codec);
13765         alc_auto_init_digital(codec);
13766         if (spec->unsol_event)
13767                 alc_inithook(codec);
13768 }
13769
13770 /*
13771  * configuration and preset
13772  */
13773 static const char * const alc268_models[ALC268_MODEL_LAST] = {
13774         [ALC267_QUANTA_IL1]     = "quanta-il1",
13775         [ALC268_3ST]            = "3stack",
13776         [ALC268_TOSHIBA]        = "toshiba",
13777         [ALC268_ACER]           = "acer",
13778         [ALC268_ACER_DMIC]      = "acer-dmic",
13779         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
13780         [ALC268_DELL]           = "dell",
13781         [ALC268_ZEPTO]          = "zepto",
13782 #ifdef CONFIG_SND_DEBUG
13783         [ALC268_TEST]           = "test",
13784 #endif
13785         [ALC268_AUTO]           = "auto",
13786 };
13787
13788 static const struct snd_pci_quirk alc268_cfg_tbl[] = {
13789         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
13790         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
13791         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
13792         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
13793         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
13794         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
13795                                                 ALC268_ACER_ASPIRE_ONE),
13796         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
13797         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron 910", ALC268_AUTO),
13798         SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
13799                         "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
13800         /* almost compatible with toshiba but with optional digital outs;
13801          * auto-probing seems working fine
13802          */
13803         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
13804                            ALC268_AUTO),
13805         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
13806         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
13807         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
13808         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
13809         {}
13810 };
13811
13812 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
13813 static const struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
13814         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
13815         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
13816         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
13817                            ALC268_TOSHIBA),
13818         {}
13819 };
13820
13821 static const struct alc_config_preset alc268_presets[] = {
13822         [ALC267_QUANTA_IL1] = {
13823                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
13824                             alc268_capture_nosrc_mixer },
13825                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13826                                 alc267_quanta_il1_verbs },
13827                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13828                 .dac_nids = alc268_dac_nids,
13829                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13830                 .adc_nids = alc268_adc_nids_alt,
13831                 .hp_nid = 0x03,
13832                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13833                 .channel_mode = alc268_modes,
13834                 .unsol_event = alc_sku_unsol_event,
13835                 .setup = alc267_quanta_il1_setup,
13836                 .init_hook = alc_inithook,
13837         },
13838         [ALC268_3ST] = {
13839                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
13840                             alc268_beep_mixer },
13841                 .init_verbs = { alc268_base_init_verbs },
13842                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13843                 .dac_nids = alc268_dac_nids,
13844                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13845                 .adc_nids = alc268_adc_nids_alt,
13846                 .capsrc_nids = alc268_capsrc_nids,
13847                 .hp_nid = 0x03,
13848                 .dig_out_nid = ALC268_DIGOUT_NID,
13849                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13850                 .channel_mode = alc268_modes,
13851                 .input_mux = &alc268_capture_source,
13852         },
13853         [ALC268_TOSHIBA] = {
13854                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
13855                             alc268_beep_mixer },
13856                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13857                                 alc268_toshiba_verbs },
13858                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13859                 .dac_nids = alc268_dac_nids,
13860                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13861                 .adc_nids = alc268_adc_nids_alt,
13862                 .capsrc_nids = alc268_capsrc_nids,
13863                 .hp_nid = 0x03,
13864                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13865                 .channel_mode = alc268_modes,
13866                 .input_mux = &alc268_capture_source,
13867                 .unsol_event = alc_sku_unsol_event,
13868                 .setup = alc268_toshiba_setup,
13869                 .init_hook = alc_inithook,
13870         },
13871         [ALC268_ACER] = {
13872                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
13873                             alc268_beep_mixer },
13874                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13875                                 alc268_acer_verbs },
13876                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13877                 .dac_nids = alc268_dac_nids,
13878                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13879                 .adc_nids = alc268_adc_nids_alt,
13880                 .capsrc_nids = alc268_capsrc_nids,
13881                 .hp_nid = 0x02,
13882                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13883                 .channel_mode = alc268_modes,
13884                 .input_mux = &alc268_acer_capture_source,
13885                 .unsol_event = alc_sku_unsol_event,
13886                 .setup = alc268_acer_setup,
13887                 .init_hook = alc_inithook,
13888         },
13889         [ALC268_ACER_DMIC] = {
13890                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
13891                             alc268_beep_mixer },
13892                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13893                                 alc268_acer_verbs },
13894                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13895                 .dac_nids = alc268_dac_nids,
13896                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13897                 .adc_nids = alc268_adc_nids_alt,
13898                 .capsrc_nids = alc268_capsrc_nids,
13899                 .hp_nid = 0x02,
13900                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13901                 .channel_mode = alc268_modes,
13902                 .input_mux = &alc268_acer_dmic_capture_source,
13903                 .unsol_event = alc_sku_unsol_event,
13904                 .setup = alc268_acer_setup,
13905                 .init_hook = alc_inithook,
13906         },
13907         [ALC268_ACER_ASPIRE_ONE] = {
13908                 .mixers = { alc268_acer_aspire_one_mixer,
13909                             alc268_beep_mixer,
13910                             alc268_capture_nosrc_mixer },
13911                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13912                                 alc268_acer_aspire_one_verbs },
13913                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13914                 .dac_nids = alc268_dac_nids,
13915                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13916                 .adc_nids = alc268_adc_nids_alt,
13917                 .capsrc_nids = alc268_capsrc_nids,
13918                 .hp_nid = 0x03,
13919                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13920                 .channel_mode = alc268_modes,
13921                 .unsol_event = alc_sku_unsol_event,
13922                 .setup = alc268_acer_lc_setup,
13923                 .init_hook = alc_inithook,
13924         },
13925         [ALC268_DELL] = {
13926                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
13927                             alc268_capture_nosrc_mixer },
13928                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13929                                 alc268_dell_verbs },
13930                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13931                 .dac_nids = alc268_dac_nids,
13932                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13933                 .adc_nids = alc268_adc_nids_alt,
13934                 .capsrc_nids = alc268_capsrc_nids,
13935                 .hp_nid = 0x02,
13936                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13937                 .channel_mode = alc268_modes,
13938                 .unsol_event = alc_sku_unsol_event,
13939                 .setup = alc268_dell_setup,
13940                 .init_hook = alc_inithook,
13941         },
13942         [ALC268_ZEPTO] = {
13943                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
13944                             alc268_beep_mixer },
13945                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13946                                 alc268_toshiba_verbs },
13947                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13948                 .dac_nids = alc268_dac_nids,
13949                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13950                 .adc_nids = alc268_adc_nids_alt,
13951                 .capsrc_nids = alc268_capsrc_nids,
13952                 .hp_nid = 0x03,
13953                 .dig_out_nid = ALC268_DIGOUT_NID,
13954                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13955                 .channel_mode = alc268_modes,
13956                 .input_mux = &alc268_capture_source,
13957                 .unsol_event = alc_sku_unsol_event,
13958                 .setup = alc268_toshiba_setup,
13959                 .init_hook = alc_inithook,
13960         },
13961 #ifdef CONFIG_SND_DEBUG
13962         [ALC268_TEST] = {
13963                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
13964                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
13965                                 alc268_volume_init_verbs,
13966                                 alc268_beep_init_verbs },
13967                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
13968                 .dac_nids = alc268_dac_nids,
13969                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
13970                 .adc_nids = alc268_adc_nids_alt,
13971                 .capsrc_nids = alc268_capsrc_nids,
13972                 .hp_nid = 0x03,
13973                 .dig_out_nid = ALC268_DIGOUT_NID,
13974                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
13975                 .channel_mode = alc268_modes,
13976                 .input_mux = &alc268_capture_source,
13977         },
13978 #endif
13979 };
13980
13981 static int patch_alc268(struct hda_codec *codec)
13982 {
13983         struct alc_spec *spec;
13984         int board_config;
13985         int i, has_beep, err;
13986
13987         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13988         if (spec == NULL)
13989                 return -ENOMEM;
13990
13991         codec->spec = spec;
13992
13993         /* ALC268 has no aa-loopback mixer */
13994
13995         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
13996                                                   alc268_models,
13997                                                   alc268_cfg_tbl);
13998
13999         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
14000                 board_config = snd_hda_check_board_codec_sid_config(codec,
14001                         ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
14002
14003         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
14004                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14005                        codec->chip_name);
14006                 board_config = ALC268_AUTO;
14007         }
14008
14009         if (board_config == ALC268_AUTO) {
14010                 /* automatic parse from the BIOS config */
14011                 err = alc268_parse_auto_config(codec);
14012                 if (err < 0) {
14013                         alc_free(codec);
14014                         return err;
14015                 } else if (!err) {
14016                         printk(KERN_INFO
14017                                "hda_codec: Cannot set up configuration "
14018                                "from BIOS.  Using base mode...\n");
14019                         board_config = ALC268_3ST;
14020                 }
14021         }
14022
14023         if (board_config != ALC268_AUTO)
14024                 setup_preset(codec, &alc268_presets[board_config]);
14025
14026         spec->stream_analog_playback = &alc268_pcm_analog_playback;
14027         spec->stream_analog_capture = &alc268_pcm_analog_capture;
14028         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
14029
14030         spec->stream_digital_playback = &alc268_pcm_digital_playback;
14031
14032         has_beep = 0;
14033         for (i = 0; i < spec->num_mixers; i++) {
14034                 if (spec->mixers[i] == alc268_beep_mixer) {
14035                         has_beep = 1;
14036                         break;
14037                 }
14038         }
14039
14040         if (has_beep) {
14041                 err = snd_hda_attach_beep_device(codec, 0x1);
14042                 if (err < 0) {
14043                         alc_free(codec);
14044                         return err;
14045                 }
14046                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
14047                         /* override the amp caps for beep generator */
14048                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
14049                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
14050                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
14051                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
14052                                           (0 << AC_AMPCAP_MUTE_SHIFT));
14053         }
14054
14055         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
14056                 /* check whether NID 0x07 is valid */
14057                 unsigned int wcap = get_wcaps(codec, 0x07);
14058
14059                 spec->capsrc_nids = alc268_capsrc_nids;
14060                 /* get type */
14061                 wcap = get_wcaps_type(wcap);
14062                 if (spec->auto_mic ||
14063                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
14064                         spec->adc_nids = alc268_adc_nids_alt;
14065                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
14066                         if (spec->auto_mic)
14067                                 fixup_automic_adc(codec);
14068                         if (spec->auto_mic || spec->input_mux->num_items == 1)
14069                                 add_mixer(spec, alc268_capture_nosrc_mixer);
14070                         else
14071                                 add_mixer(spec, alc268_capture_alt_mixer);
14072                 } else {
14073                         spec->adc_nids = alc268_adc_nids;
14074                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
14075                         add_mixer(spec, alc268_capture_mixer);
14076                 }
14077         }
14078
14079         spec->vmaster_nid = 0x02;
14080
14081         codec->patch_ops = alc_patch_ops;
14082         if (board_config == ALC268_AUTO)
14083                 spec->init_hook = alc268_auto_init;
14084         spec->shutup = alc_eapd_shutup;
14085
14086         alc_init_jacks(codec);
14087
14088         return 0;
14089 }
14090
14091 /*
14092  *  ALC269 channel source setting (2 channel)
14093  */
14094 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
14095
14096 #define alc269_dac_nids         alc260_dac_nids
14097
14098 static const hda_nid_t alc269_adc_nids[1] = {
14099         /* ADC1 */
14100         0x08,
14101 };
14102
14103 static const hda_nid_t alc269_capsrc_nids[1] = {
14104         0x23,
14105 };
14106
14107 static const hda_nid_t alc269vb_adc_nids[1] = {
14108         /* ADC1 */
14109         0x09,
14110 };
14111
14112 static const hda_nid_t alc269vb_capsrc_nids[1] = {
14113         0x22,
14114 };
14115
14116 static const hda_nid_t alc269_adc_candidates[] = {
14117         0x08, 0x09, 0x07, 0x11,
14118 };
14119
14120 #define alc269_modes            alc260_modes
14121 #define alc269_capture_source   alc880_lg_lw_capture_source
14122
14123 static const struct snd_kcontrol_new alc269_base_mixer[] = {
14124         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14125         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14126         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14127         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14128         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14129         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14130         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14131         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14132         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14133         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
14134         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14135         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
14136         { } /* end */
14137 };
14138
14139 static const struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
14140         /* output mixer control */
14141         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
14142         {
14143                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14144                 .name = "Master Playback Switch",
14145                 .subdevice = HDA_SUBDEV_AMP_FLAG,
14146                 .info = snd_hda_mixer_amp_switch_info,
14147                 .get = snd_hda_mixer_amp_switch_get,
14148                 .put = alc268_acer_master_sw_put,
14149                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14150         },
14151         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14152         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14153         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14154         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14155         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14156         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14157         { }
14158 };
14159
14160 static const struct snd_kcontrol_new alc269_lifebook_mixer[] = {
14161         /* output mixer control */
14162         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
14163         {
14164                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14165                 .name = "Master Playback Switch",
14166                 .subdevice = HDA_SUBDEV_AMP_FLAG,
14167                 .info = snd_hda_mixer_amp_switch_info,
14168                 .get = snd_hda_mixer_amp_switch_get,
14169                 .put = alc268_acer_master_sw_put,
14170                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14171         },
14172         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14173         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14174         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14175         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
14176         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
14177         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14178         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
14179         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
14180         HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x1b, 0, HDA_INPUT),
14181         { }
14182 };
14183
14184 static const struct snd_kcontrol_new alc269_laptop_mixer[] = {
14185         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14186         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14187         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14188         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14189         { } /* end */
14190 };
14191
14192 static const struct snd_kcontrol_new alc269vb_laptop_mixer[] = {
14193         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14194         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14195         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14196         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14197         { } /* end */
14198 };
14199
14200 static const struct snd_kcontrol_new alc269_asus_mixer[] = {
14201         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14202         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x0, HDA_INPUT),
14203         { } /* end */
14204 };
14205
14206 /* capture mixer elements */
14207 static const struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
14208         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
14209         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
14210         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14211         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14212         { } /* end */
14213 };
14214
14215 static const struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = {
14216         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
14217         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
14218         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14219         { } /* end */
14220 };
14221
14222 static const struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = {
14223         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14224         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14225         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14226         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
14227         { } /* end */
14228 };
14229
14230 static const struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = {
14231         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14232         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14233         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
14234         { } /* end */
14235 };
14236
14237 /* FSC amilo */
14238 #define alc269_fujitsu_mixer    alc269_laptop_mixer
14239
14240 static const struct hda_verb alc269_quanta_fl1_verbs[] = {
14241         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14242         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14243         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14244         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
14245         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14246         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14247         { }
14248 };
14249
14250 static const struct hda_verb alc269_lifebook_verbs[] = {
14251         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14252         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
14253         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14254         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14255         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
14256         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14257         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14258         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
14259         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14260         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14261         { }
14262 };
14263
14264 /* toggle speaker-output according to the hp-jack state */
14265 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
14266 {
14267         alc_hp_automute(codec);
14268
14269         snd_hda_codec_write(codec, 0x20, 0,
14270                         AC_VERB_SET_COEF_INDEX, 0x0c);
14271         snd_hda_codec_write(codec, 0x20, 0,
14272                         AC_VERB_SET_PROC_COEF, 0x680);
14273
14274         snd_hda_codec_write(codec, 0x20, 0,
14275                         AC_VERB_SET_COEF_INDEX, 0x0c);
14276         snd_hda_codec_write(codec, 0x20, 0,
14277                         AC_VERB_SET_PROC_COEF, 0x480);
14278 }
14279
14280 #define alc269_lifebook_speaker_automute \
14281         alc269_quanta_fl1_speaker_automute
14282
14283 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
14284 {
14285         unsigned int present_laptop;
14286         unsigned int present_dock;
14287
14288         present_laptop  = snd_hda_jack_detect(codec, 0x18);
14289         present_dock    = snd_hda_jack_detect(codec, 0x1b);
14290
14291         /* Laptop mic port overrides dock mic port, design decision */
14292         if (present_dock)
14293                 snd_hda_codec_write(codec, 0x23, 0,
14294                                 AC_VERB_SET_CONNECT_SEL, 0x3);
14295         if (present_laptop)
14296                 snd_hda_codec_write(codec, 0x23, 0,
14297                                 AC_VERB_SET_CONNECT_SEL, 0x0);
14298         if (!present_dock && !present_laptop)
14299                 snd_hda_codec_write(codec, 0x23, 0,
14300                                 AC_VERB_SET_CONNECT_SEL, 0x1);
14301 }
14302
14303 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
14304                                     unsigned int res)
14305 {
14306         switch (res >> 26) {
14307         case ALC880_HP_EVENT:
14308                 alc269_quanta_fl1_speaker_automute(codec);
14309                 break;
14310         case ALC880_MIC_EVENT:
14311                 alc_mic_automute(codec);
14312                 break;
14313         }
14314 }
14315
14316 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
14317                                         unsigned int res)
14318 {
14319         if ((res >> 26) == ALC880_HP_EVENT)
14320                 alc269_lifebook_speaker_automute(codec);
14321         if ((res >> 26) == ALC880_MIC_EVENT)
14322                 alc269_lifebook_mic_autoswitch(codec);
14323 }
14324
14325 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
14326 {
14327         struct alc_spec *spec = codec->spec;
14328         spec->autocfg.hp_pins[0] = 0x15;
14329         spec->autocfg.speaker_pins[0] = 0x14;
14330         spec->automute_mixer_nid[0] = 0x0c;
14331         spec->automute = 1;
14332         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14333         spec->ext_mic.pin = 0x18;
14334         spec->ext_mic.mux_idx = 0;
14335         spec->int_mic.pin = 0x19;
14336         spec->int_mic.mux_idx = 1;
14337         spec->auto_mic = 1;
14338 }
14339
14340 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
14341 {
14342         alc269_quanta_fl1_speaker_automute(codec);
14343         alc_mic_automute(codec);
14344 }
14345
14346 static void alc269_lifebook_setup(struct hda_codec *codec)
14347 {
14348         struct alc_spec *spec = codec->spec;
14349         spec->autocfg.hp_pins[0] = 0x15;
14350         spec->autocfg.hp_pins[1] = 0x1a;
14351         spec->autocfg.speaker_pins[0] = 0x14;
14352         spec->automute_mixer_nid[0] = 0x0c;
14353         spec->automute = 1;
14354         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14355 }
14356
14357 static void alc269_lifebook_init_hook(struct hda_codec *codec)
14358 {
14359         alc269_lifebook_speaker_automute(codec);
14360         alc269_lifebook_mic_autoswitch(codec);
14361 }
14362
14363 static const struct hda_verb alc269_laptop_dmic_init_verbs[] = {
14364         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14365         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
14366         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14367         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
14368         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14369         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14370         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14371         {}
14372 };
14373
14374 static const struct hda_verb alc269_laptop_amic_init_verbs[] = {
14375         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14376         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
14377         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14378         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
14379         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14380         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14381         {}
14382 };
14383
14384 static const struct hda_verb alc269vb_laptop_dmic_init_verbs[] = {
14385         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
14386         {0x22, AC_VERB_SET_CONNECT_SEL, 0x06},
14387         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14388         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
14389         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14390         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14391         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14392         {}
14393 };
14394
14395 static const struct hda_verb alc269vb_laptop_amic_init_verbs[] = {
14396         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
14397         {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
14398         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
14399         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
14400         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14401         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14402         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14403         {}
14404 };
14405
14406 static const struct hda_verb alc271_acer_dmic_verbs[] = {
14407         {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
14408         {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
14409         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14410         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14411         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14412         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14413         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},
14414         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14415         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14416         {0x22, AC_VERB_SET_CONNECT_SEL, 6},
14417         { }
14418 };
14419
14420 static void alc269_laptop_amic_setup(struct hda_codec *codec)
14421 {
14422         struct alc_spec *spec = codec->spec;
14423         spec->autocfg.hp_pins[0] = 0x15;
14424         spec->autocfg.speaker_pins[0] = 0x14;
14425         spec->automute_mixer_nid[0] = 0x0c;
14426         spec->automute = 1;
14427         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14428         spec->ext_mic.pin = 0x18;
14429         spec->ext_mic.mux_idx = 0;
14430         spec->int_mic.pin = 0x19;
14431         spec->int_mic.mux_idx = 1;
14432         spec->auto_mic = 1;
14433 }
14434
14435 static void alc269_laptop_dmic_setup(struct hda_codec *codec)
14436 {
14437         struct alc_spec *spec = codec->spec;
14438         spec->autocfg.hp_pins[0] = 0x15;
14439         spec->autocfg.speaker_pins[0] = 0x14;
14440         spec->automute_mixer_nid[0] = 0x0c;
14441         spec->automute = 1;
14442         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14443         spec->ext_mic.pin = 0x18;
14444         spec->ext_mic.mux_idx = 0;
14445         spec->int_mic.pin = 0x12;
14446         spec->int_mic.mux_idx = 5;
14447         spec->auto_mic = 1;
14448 }
14449
14450 static void alc269vb_laptop_amic_setup(struct hda_codec *codec)
14451 {
14452         struct alc_spec *spec = codec->spec;
14453         spec->autocfg.hp_pins[0] = 0x21;
14454         spec->autocfg.speaker_pins[0] = 0x14;
14455         spec->automute_mixer_nid[0] = 0x0c;
14456         spec->automute = 1;
14457         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14458         spec->ext_mic.pin = 0x18;
14459         spec->ext_mic.mux_idx = 0;
14460         spec->int_mic.pin = 0x19;
14461         spec->int_mic.mux_idx = 1;
14462         spec->auto_mic = 1;
14463 }
14464
14465 static void alc269vb_laptop_dmic_setup(struct hda_codec *codec)
14466 {
14467         struct alc_spec *spec = codec->spec;
14468         spec->autocfg.hp_pins[0] = 0x21;
14469         spec->autocfg.speaker_pins[0] = 0x14;
14470         spec->automute_mixer_nid[0] = 0x0c;
14471         spec->automute = 1;
14472         spec->automute_mode = ALC_AUTOMUTE_MIXER;
14473         spec->ext_mic.pin = 0x18;
14474         spec->ext_mic.mux_idx = 0;
14475         spec->int_mic.pin = 0x12;
14476         spec->int_mic.mux_idx = 6;
14477         spec->auto_mic = 1;
14478 }
14479
14480 /*
14481  * generic initialization of ADC, input mixers and output mixers
14482  */
14483 static const struct hda_verb alc269_init_verbs[] = {
14484         /*
14485          * Unmute ADC0 and set the default input to mic-in
14486          */
14487         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14488
14489         /*
14490          * Set up output mixers (0x02 - 0x03)
14491          */
14492         /* set vol=0 to output mixers */
14493         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14494         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14495
14496         /* set up input amps for analog loopback */
14497         /* Amp Indices: DAC = 0, mixer = 1 */
14498         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14499         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14500         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14501         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14502         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14503         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14504
14505         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14506         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14507         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14508         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14509         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14510         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14511         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14512
14513         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14514         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14515
14516         /* FIXME: use Mux-type input source selection */
14517         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
14518         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
14519         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
14520
14521         /* set EAPD */
14522         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14523         { }
14524 };
14525
14526 static const struct hda_verb alc269vb_init_verbs[] = {
14527         /*
14528          * Unmute ADC0 and set the default input to mic-in
14529          */
14530         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14531
14532         /*
14533          * Set up output mixers (0x02 - 0x03)
14534          */
14535         /* set vol=0 to output mixers */
14536         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14537         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14538
14539         /* set up input amps for analog loopback */
14540         /* Amp Indices: DAC = 0, mixer = 1 */
14541         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14543         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14544         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14545         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14546         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14547
14548         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14549         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14550         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14551         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14552         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14553         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14554         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14555
14556         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14557         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14558
14559         /* FIXME: use Mux-type input source selection */
14560         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
14561         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
14562         {0x22, AC_VERB_SET_CONNECT_SEL, 0x00},
14563
14564         /* set EAPD */
14565         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14566         { }
14567 };
14568
14569 #define alc269_auto_create_multi_out_ctls \
14570         alc268_auto_create_multi_out_ctls
14571 #define alc269_auto_create_input_ctls \
14572         alc268_auto_create_input_ctls
14573
14574 #ifdef CONFIG_SND_HDA_POWER_SAVE
14575 #define alc269_loopbacks        alc880_loopbacks
14576 #endif
14577
14578 /* pcm configuration: identical with ALC880 */
14579 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
14580 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
14581 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
14582 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
14583
14584 static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
14585         .substreams = 1,
14586         .channels_min = 2,
14587         .channels_max = 8,
14588         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
14589         /* NID is set in alc_build_pcms */
14590         .ops = {
14591                 .open = alc880_playback_pcm_open,
14592                 .prepare = alc880_playback_pcm_prepare,
14593                 .cleanup = alc880_playback_pcm_cleanup
14594         },
14595 };
14596
14597 static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
14598         .substreams = 1,
14599         .channels_min = 2,
14600         .channels_max = 2,
14601         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
14602         /* NID is set in alc_build_pcms */
14603 };
14604
14605 #ifdef CONFIG_SND_HDA_POWER_SAVE
14606 static int alc269_mic2_for_mute_led(struct hda_codec *codec)
14607 {
14608         switch (codec->subsystem_id) {
14609         case 0x103c1586:
14610                 return 1;
14611         }
14612         return 0;
14613 }
14614
14615 static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
14616 {
14617         /* update mute-LED according to the speaker mute state */
14618         if (nid == 0x01 || nid == 0x14) {
14619                 int pinval;
14620                 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
14621                     HDA_AMP_MUTE)
14622                         pinval = 0x24;
14623                 else
14624                         pinval = 0x20;
14625                 /* mic2 vref pin is used for mute LED control */
14626                 snd_hda_codec_update_cache(codec, 0x19, 0,
14627                                            AC_VERB_SET_PIN_WIDGET_CONTROL,
14628                                            pinval);
14629         }
14630         return alc_check_power_status(codec, nid);
14631 }
14632 #endif /* CONFIG_SND_HDA_POWER_SAVE */
14633
14634 static int alc275_setup_dual_adc(struct hda_codec *codec)
14635 {
14636         struct alc_spec *spec = codec->spec;
14637
14638         if (codec->vendor_id != 0x10ec0275 || !spec->auto_mic)
14639                 return 0;
14640         if ((spec->ext_mic.pin >= 0x18 && spec->int_mic.pin <= 0x13) ||
14641             (spec->ext_mic.pin <= 0x12 && spec->int_mic.pin >= 0x18)) {
14642                 if (spec->ext_mic.pin <= 0x12) {
14643                         spec->private_adc_nids[0] = 0x08;
14644                         spec->private_adc_nids[1] = 0x11;
14645                         spec->private_capsrc_nids[0] = 0x23;
14646                         spec->private_capsrc_nids[1] = 0x22;
14647                 } else {
14648                         spec->private_adc_nids[0] = 0x11;
14649                         spec->private_adc_nids[1] = 0x08;
14650                         spec->private_capsrc_nids[0] = 0x22;
14651                         spec->private_capsrc_nids[1] = 0x23;
14652                 }
14653                 spec->adc_nids = spec->private_adc_nids;
14654                 spec->capsrc_nids = spec->private_capsrc_nids;
14655                 spec->num_adc_nids = 2;
14656                 spec->dual_adc_switch = 1;
14657                 snd_printdd("realtek: enabling dual ADC switchg (%02x:%02x)\n",
14658                             spec->adc_nids[0], spec->adc_nids[1]);
14659                 return 1;
14660         }
14661         return 0;
14662 }
14663
14664 /* different alc269-variants */
14665 enum {
14666         ALC269_TYPE_ALC269VA,
14667         ALC269_TYPE_ALC269VB,
14668         ALC269_TYPE_ALC269VC,
14669 };
14670
14671 /*
14672  * BIOS auto configuration
14673  */
14674 static int alc269_parse_auto_config(struct hda_codec *codec)
14675 {
14676         struct alc_spec *spec = codec->spec;
14677         int err;
14678         static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
14679
14680         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14681                                            alc269_ignore);
14682         if (err < 0)
14683                 return err;
14684
14685         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
14686         if (err < 0)
14687                 return err;
14688         if (spec->codec_variant == ALC269_TYPE_ALC269VA)
14689                 err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
14690         else
14691                 err = alc_auto_create_input_ctls(codec, &spec->autocfg, 0,
14692                                                  0x22, 0);
14693         if (err < 0)
14694                 return err;
14695
14696         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14697
14698         alc_auto_parse_digital(codec);
14699
14700         if (spec->kctls.list)
14701                 add_mixer(spec, spec->kctls.list);
14702
14703         if (spec->codec_variant != ALC269_TYPE_ALC269VA)
14704                 alc_ssid_check(codec, 0, 0x1b, 0x14, 0x21);
14705         else
14706                 alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
14707
14708         spec->num_mux_defs = 1;
14709         spec->input_mux = &spec->private_imux[0];
14710
14711         if (!alc275_setup_dual_adc(codec))
14712                 fillup_priv_adc_nids(codec, alc269_adc_candidates,
14713                                      sizeof(alc269_adc_candidates));
14714
14715         err = alc_auto_add_mic_boost(codec);
14716         if (err < 0)
14717                 return err;
14718
14719         if (!spec->cap_mixer && !spec->no_analog)
14720                 set_capture_mixer(codec);
14721
14722         return 1;
14723 }
14724
14725 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
14726 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
14727 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
14728 #define alc269_auto_init_input_src      alc882_auto_init_input_src
14729
14730
14731 /* init callback for auto-configuration model -- overriding the default init */
14732 static void alc269_auto_init(struct hda_codec *codec)
14733 {
14734         struct alc_spec *spec = codec->spec;
14735         alc269_auto_init_multi_out(codec);
14736         alc269_auto_init_hp_out(codec);
14737         alc269_auto_init_analog_input(codec);
14738         if (!spec->dual_adc_switch)
14739                 alc269_auto_init_input_src(codec);
14740         alc_auto_init_digital(codec);
14741         if (spec->unsol_event)
14742                 alc_inithook(codec);
14743 }
14744
14745 static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
14746 {
14747         int val = alc_read_coef_idx(codec, 0x04);
14748         if (power_up)
14749                 val |= 1 << 11;
14750         else
14751                 val &= ~(1 << 11);
14752         alc_write_coef_idx(codec, 0x04, val);
14753 }
14754
14755 static void alc269_shutup(struct hda_codec *codec)
14756 {
14757         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
14758                 alc269_toggle_power_output(codec, 0);
14759         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
14760                 alc269_toggle_power_output(codec, 0);
14761                 msleep(150);
14762         }
14763 }
14764
14765 #ifdef SND_HDA_NEEDS_RESUME
14766 static int alc269_resume(struct hda_codec *codec)
14767 {
14768         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
14769                 alc269_toggle_power_output(codec, 0);
14770                 msleep(150);
14771         }
14772
14773         codec->patch_ops.init(codec);
14774
14775         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
14776                 alc269_toggle_power_output(codec, 1);
14777                 msleep(200);
14778         }
14779
14780         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
14781                 alc269_toggle_power_output(codec, 1);
14782
14783         snd_hda_codec_resume_amp(codec);
14784         snd_hda_codec_resume_cache(codec);
14785         hda_call_check_power_status(codec, 0x01);
14786         return 0;
14787 }
14788 #endif /* SND_HDA_NEEDS_RESUME */
14789
14790 static void alc269_fixup_hweq(struct hda_codec *codec,
14791                                const struct alc_fixup *fix, int action)
14792 {
14793         int coef;
14794
14795         if (action != ALC_FIXUP_ACT_INIT)
14796                 return;
14797         coef = alc_read_coef_idx(codec, 0x1e);
14798         alc_write_coef_idx(codec, 0x1e, coef | 0x80);
14799 }
14800
14801 static void alc271_fixup_dmic(struct hda_codec *codec,
14802                               const struct alc_fixup *fix, int action)
14803 {
14804         static const struct hda_verb verbs[] = {
14805                 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
14806                 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
14807                 {}
14808         };
14809         unsigned int cfg;
14810
14811         if (strcmp(codec->chip_name, "ALC271X"))
14812                 return;
14813         cfg = snd_hda_codec_get_pincfg(codec, 0x12);
14814         if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
14815                 snd_hda_sequence_write(codec, verbs);
14816 }
14817
14818 enum {
14819         ALC269_FIXUP_SONY_VAIO,
14820         ALC275_FIXUP_SONY_VAIO_GPIO2,
14821         ALC269_FIXUP_DELL_M101Z,
14822         ALC269_FIXUP_SKU_IGNORE,
14823         ALC269_FIXUP_ASUS_G73JW,
14824         ALC269_FIXUP_LENOVO_EAPD,
14825         ALC275_FIXUP_SONY_HWEQ,
14826         ALC271_FIXUP_DMIC,
14827 };
14828
14829 static const struct alc_fixup alc269_fixups[] = {
14830         [ALC269_FIXUP_SONY_VAIO] = {
14831                 .type = ALC_FIXUP_VERBS,
14832                 .v.verbs = (const struct hda_verb[]) {
14833                         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
14834                         {}
14835                 }
14836         },
14837         [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
14838                 .type = ALC_FIXUP_VERBS,
14839                 .v.verbs = (const struct hda_verb[]) {
14840                         {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
14841                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
14842                         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
14843                         { }
14844                 },
14845                 .chained = true,
14846                 .chain_id = ALC269_FIXUP_SONY_VAIO
14847         },
14848         [ALC269_FIXUP_DELL_M101Z] = {
14849                 .type = ALC_FIXUP_VERBS,
14850                 .v.verbs = (const struct hda_verb[]) {
14851                         /* Enables internal speaker */
14852                         {0x20, AC_VERB_SET_COEF_INDEX, 13},
14853                         {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
14854                         {}
14855                 }
14856         },
14857         [ALC269_FIXUP_SKU_IGNORE] = {
14858                 .type = ALC_FIXUP_SKU,
14859                 .v.sku = ALC_FIXUP_SKU_IGNORE,
14860         },
14861         [ALC269_FIXUP_ASUS_G73JW] = {
14862                 .type = ALC_FIXUP_PINS,
14863                 .v.pins = (const struct alc_pincfg[]) {
14864                         { 0x17, 0x99130111 }, /* subwoofer */
14865                         { }
14866                 }
14867         },
14868         [ALC269_FIXUP_LENOVO_EAPD] = {
14869                 .type = ALC_FIXUP_VERBS,
14870                 .v.verbs = (const struct hda_verb[]) {
14871                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
14872                         {}
14873                 }
14874         },
14875         [ALC275_FIXUP_SONY_HWEQ] = {
14876                 .type = ALC_FIXUP_FUNC,
14877                 .v.func = alc269_fixup_hweq,
14878                 .chained = true,
14879                 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
14880         },
14881         [ALC271_FIXUP_DMIC] = {
14882                 .type = ALC_FIXUP_FUNC,
14883                 .v.func = alc271_fixup_dmic,
14884         },
14885 };
14886
14887 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
14888         SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
14889         SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
14890         SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
14891         SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
14892         SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
14893         SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
14894         SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
14895         SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
14896         SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
14897         SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
14898         SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
14899         SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
14900         SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
14901         {}
14902 };
14903
14904
14905 /*
14906  * configuration and preset
14907  */
14908 static const char * const alc269_models[ALC269_MODEL_LAST] = {
14909         [ALC269_BASIC]                  = "basic",
14910         [ALC269_QUANTA_FL1]             = "quanta",
14911         [ALC269_AMIC]                   = "laptop-amic",
14912         [ALC269_DMIC]                   = "laptop-dmic",
14913         [ALC269_FUJITSU]                = "fujitsu",
14914         [ALC269_LIFEBOOK]               = "lifebook",
14915         [ALC269_AUTO]                   = "auto",
14916 };
14917
14918 static const struct snd_pci_quirk alc269_cfg_tbl[] = {
14919         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
14920         SND_PCI_QUIRK(0x1025, 0x047c, "ACER ZGA", ALC271_ACER),
14921         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
14922                       ALC269_AMIC),
14923         SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC),
14924         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269VB_AMIC),
14925         SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269VB_AMIC),
14926         SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_AMIC),
14927         SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269VB_AMIC),
14928         SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269VB_AMIC),
14929         SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269VB_AMIC),
14930         SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269VB_AMIC),
14931         SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_AMIC),
14932         SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269VB_AMIC),
14933         SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_AMIC),
14934         SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_AMIC),
14935         SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_AMIC),
14936         SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_AMIC),
14937         SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_AMIC),
14938         SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_AMIC),
14939         SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_AMIC),
14940         SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_AMIC),
14941         SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_AMIC),
14942         SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_AMIC),
14943         SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_AMIC),
14944         SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_AMIC),
14945         SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_AMIC),
14946         SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_AMIC),
14947         SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_AMIC),
14948         SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_AMIC),
14949         SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_AMIC),
14950         SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_AMIC),
14951         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_AMIC),
14952         SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_AMIC),
14953         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_AMIC),
14954         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_DMIC),
14955         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_AMIC),
14956         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_AMIC),
14957         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_AMIC),
14958         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_AMIC),
14959         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
14960                       ALC269_DMIC),
14961         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
14962                       ALC269_DMIC),
14963         SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005HA", ALC269_DMIC),
14964         SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005HA", ALC269_DMIC),
14965         SND_PCI_QUIRK(0x104d, 0x9071, "Sony VAIO", ALC269_AUTO),
14966         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
14967         SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_DMIC),
14968         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
14969         SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_AMIC),
14970         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_AMIC),
14971         SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_DMIC),
14972         SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_DMIC),
14973         {}
14974 };
14975
14976 static const struct alc_config_preset alc269_presets[] = {
14977         [ALC269_BASIC] = {
14978                 .mixers = { alc269_base_mixer },
14979                 .init_verbs = { alc269_init_verbs },
14980                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
14981                 .dac_nids = alc269_dac_nids,
14982                 .hp_nid = 0x03,
14983                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
14984                 .channel_mode = alc269_modes,
14985                 .input_mux = &alc269_capture_source,
14986         },
14987         [ALC269_QUANTA_FL1] = {
14988                 .mixers = { alc269_quanta_fl1_mixer },
14989                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
14990                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
14991                 .dac_nids = alc269_dac_nids,
14992                 .hp_nid = 0x03,
14993                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
14994                 .channel_mode = alc269_modes,
14995                 .input_mux = &alc269_capture_source,
14996                 .unsol_event = alc269_quanta_fl1_unsol_event,
14997                 .setup = alc269_quanta_fl1_setup,
14998                 .init_hook = alc269_quanta_fl1_init_hook,
14999         },
15000         [ALC269_AMIC] = {
15001                 .mixers = { alc269_laptop_mixer },
15002                 .cap_mixer = alc269_laptop_analog_capture_mixer,
15003                 .init_verbs = { alc269_init_verbs,
15004                                 alc269_laptop_amic_init_verbs },
15005                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15006                 .dac_nids = alc269_dac_nids,
15007                 .hp_nid = 0x03,
15008                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15009                 .channel_mode = alc269_modes,
15010                 .unsol_event = alc_sku_unsol_event,
15011                 .setup = alc269_laptop_amic_setup,
15012                 .init_hook = alc_inithook,
15013         },
15014         [ALC269_DMIC] = {
15015                 .mixers = { alc269_laptop_mixer },
15016                 .cap_mixer = alc269_laptop_digital_capture_mixer,
15017                 .init_verbs = { alc269_init_verbs,
15018                                 alc269_laptop_dmic_init_verbs },
15019                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15020                 .dac_nids = alc269_dac_nids,
15021                 .hp_nid = 0x03,
15022                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15023                 .channel_mode = alc269_modes,
15024                 .unsol_event = alc_sku_unsol_event,
15025                 .setup = alc269_laptop_dmic_setup,
15026                 .init_hook = alc_inithook,
15027         },
15028         [ALC269VB_AMIC] = {
15029                 .mixers = { alc269vb_laptop_mixer },
15030                 .cap_mixer = alc269vb_laptop_analog_capture_mixer,
15031                 .init_verbs = { alc269vb_init_verbs,
15032                                 alc269vb_laptop_amic_init_verbs },
15033                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15034                 .dac_nids = alc269_dac_nids,
15035                 .hp_nid = 0x03,
15036                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15037                 .channel_mode = alc269_modes,
15038                 .unsol_event = alc_sku_unsol_event,
15039                 .setup = alc269vb_laptop_amic_setup,
15040                 .init_hook = alc_inithook,
15041         },
15042         [ALC269VB_DMIC] = {
15043                 .mixers = { alc269vb_laptop_mixer },
15044                 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
15045                 .init_verbs = { alc269vb_init_verbs,
15046                                 alc269vb_laptop_dmic_init_verbs },
15047                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15048                 .dac_nids = alc269_dac_nids,
15049                 .hp_nid = 0x03,
15050                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15051                 .channel_mode = alc269_modes,
15052                 .unsol_event = alc_sku_unsol_event,
15053                 .setup = alc269vb_laptop_dmic_setup,
15054                 .init_hook = alc_inithook,
15055         },
15056         [ALC269_FUJITSU] = {
15057                 .mixers = { alc269_fujitsu_mixer },
15058                 .cap_mixer = alc269_laptop_digital_capture_mixer,
15059                 .init_verbs = { alc269_init_verbs,
15060                                 alc269_laptop_dmic_init_verbs },
15061                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15062                 .dac_nids = alc269_dac_nids,
15063                 .hp_nid = 0x03,
15064                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15065                 .channel_mode = alc269_modes,
15066                 .unsol_event = alc_sku_unsol_event,
15067                 .setup = alc269_laptop_dmic_setup,
15068                 .init_hook = alc_inithook,
15069         },
15070         [ALC269_LIFEBOOK] = {
15071                 .mixers = { alc269_lifebook_mixer },
15072                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
15073                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15074                 .dac_nids = alc269_dac_nids,
15075                 .hp_nid = 0x03,
15076                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15077                 .channel_mode = alc269_modes,
15078                 .input_mux = &alc269_capture_source,
15079                 .unsol_event = alc269_lifebook_unsol_event,
15080                 .setup = alc269_lifebook_setup,
15081                 .init_hook = alc269_lifebook_init_hook,
15082         },
15083         [ALC271_ACER] = {
15084                 .mixers = { alc269_asus_mixer },
15085                 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
15086                 .init_verbs = { alc269_init_verbs, alc271_acer_dmic_verbs },
15087                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
15088                 .dac_nids = alc269_dac_nids,
15089                 .adc_nids = alc262_dmic_adc_nids,
15090                 .num_adc_nids = ARRAY_SIZE(alc262_dmic_adc_nids),
15091                 .capsrc_nids = alc262_dmic_capsrc_nids,
15092                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
15093                 .channel_mode = alc269_modes,
15094                 .input_mux = &alc269_capture_source,
15095                 .dig_out_nid = ALC880_DIGOUT_NID,
15096                 .unsol_event = alc_sku_unsol_event,
15097                 .setup = alc269vb_laptop_dmic_setup,
15098                 .init_hook = alc_inithook,
15099         },
15100 };
15101
15102 static int alc269_fill_coef(struct hda_codec *codec)
15103 {
15104         int val;
15105
15106         if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
15107                 alc_write_coef_idx(codec, 0xf, 0x960b);
15108                 alc_write_coef_idx(codec, 0xe, 0x8817);
15109         }
15110
15111         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
15112                 alc_write_coef_idx(codec, 0xf, 0x960b);
15113                 alc_write_coef_idx(codec, 0xe, 0x8814);
15114         }
15115
15116         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
15117                 val = alc_read_coef_idx(codec, 0x04);
15118                 /* Power up output pin */
15119                 alc_write_coef_idx(codec, 0x04, val | (1<<11));
15120         }
15121
15122         if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
15123                 val = alc_read_coef_idx(codec, 0xd);
15124                 if ((val & 0x0c00) >> 10 != 0x1) {
15125                         /* Capless ramp up clock control */
15126                         alc_write_coef_idx(codec, 0xd, val | (1<<10));
15127                 }
15128                 val = alc_read_coef_idx(codec, 0x17);
15129                 if ((val & 0x01c0) >> 6 != 0x4) {
15130                         /* Class D power on reset */
15131                         alc_write_coef_idx(codec, 0x17, val | (1<<7));
15132                 }
15133         }
15134
15135         val = alc_read_coef_idx(codec, 0xd); /* Class D */
15136         alc_write_coef_idx(codec, 0xd, val | (1<<14));
15137
15138         val = alc_read_coef_idx(codec, 0x4); /* HP */
15139         alc_write_coef_idx(codec, 0x4, val | (1<<11));
15140
15141         return 0;
15142 }
15143
15144 static int patch_alc269(struct hda_codec *codec)
15145 {
15146         struct alc_spec *spec;
15147         int board_config, coef;
15148         int err;
15149
15150         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15151         if (spec == NULL)
15152                 return -ENOMEM;
15153
15154         codec->spec = spec;
15155
15156         spec->mixer_nid = 0x0b;
15157
15158         alc_auto_parse_customize_define(codec);
15159
15160         if (codec->vendor_id == 0x10ec0269) {
15161                 spec->codec_variant = ALC269_TYPE_ALC269VA;
15162                 coef = alc_read_coef_idx(codec, 0);
15163                 if ((coef & 0x00f0) == 0x0010) {
15164                         if (codec->bus->pci->subsystem_vendor == 0x1025 &&
15165                             spec->cdefine.platform_type == 1) {
15166                                 alc_codec_rename(codec, "ALC271X");
15167                         } else if ((coef & 0xf000) == 0x2000) {
15168                                 alc_codec_rename(codec, "ALC259");
15169                         } else if ((coef & 0xf000) == 0x3000) {
15170                                 alc_codec_rename(codec, "ALC258");
15171                         } else if ((coef & 0xfff0) == 0x3010) {
15172                                 alc_codec_rename(codec, "ALC277");
15173                         } else {
15174                                 alc_codec_rename(codec, "ALC269VB");
15175                         }
15176                         spec->codec_variant = ALC269_TYPE_ALC269VB;
15177                 } else if ((coef & 0x00f0) == 0x0020) {
15178                         if (coef == 0xa023)
15179                                 alc_codec_rename(codec, "ALC259");
15180                         else if (coef == 0x6023)
15181                                 alc_codec_rename(codec, "ALC281X");
15182                         else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
15183                                  codec->bus->pci->subsystem_device == 0x21f3)
15184                                 alc_codec_rename(codec, "ALC3202");
15185                         else
15186                                 alc_codec_rename(codec, "ALC269VC");
15187                         spec->codec_variant = ALC269_TYPE_ALC269VC;
15188                 } else
15189                         alc_fix_pll_init(codec, 0x20, 0x04, 15);
15190                 alc269_fill_coef(codec);
15191         }
15192
15193         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
15194                                                   alc269_models,
15195                                                   alc269_cfg_tbl);
15196
15197         if (board_config < 0) {
15198                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15199                        codec->chip_name);
15200                 board_config = ALC269_AUTO;
15201         }
15202
15203         if (board_config == ALC269_AUTO) {
15204                 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
15205                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
15206         }
15207
15208         if (board_config == ALC269_AUTO) {
15209                 /* automatic parse from the BIOS config */
15210                 err = alc269_parse_auto_config(codec);
15211                 if (err < 0) {
15212                         alc_free(codec);
15213                         return err;
15214                 } else if (!err) {
15215                         printk(KERN_INFO
15216                                "hda_codec: Cannot set up configuration "
15217                                "from BIOS.  Using base mode...\n");
15218                         board_config = ALC269_BASIC;
15219                 }
15220         }
15221
15222         if (has_cdefine_beep(codec)) {
15223                 err = snd_hda_attach_beep_device(codec, 0x1);
15224                 if (err < 0) {
15225                         alc_free(codec);
15226                         return err;
15227                 }
15228         }
15229
15230         if (board_config != ALC269_AUTO)
15231                 setup_preset(codec, &alc269_presets[board_config]);
15232
15233         if (board_config == ALC269_QUANTA_FL1) {
15234                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
15235                  * fix the sample rate of analog I/O to 44.1kHz
15236                  */
15237                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
15238                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
15239         } else if (spec->dual_adc_switch) {
15240                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
15241                 /* switch ADC dynamically */
15242                 spec->stream_analog_capture = &dualmic_pcm_analog_capture;
15243         } else {
15244                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
15245                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
15246         }
15247         spec->stream_digital_playback = &alc269_pcm_digital_playback;
15248         spec->stream_digital_capture = &alc269_pcm_digital_capture;
15249
15250         if (!spec->adc_nids) { /* wasn't filled automatically? use default */
15251                 if (spec->codec_variant == ALC269_TYPE_ALC269VA) {
15252                         spec->adc_nids = alc269_adc_nids;
15253                         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
15254                         spec->capsrc_nids = alc269_capsrc_nids;
15255                 } else {
15256                         spec->adc_nids = alc269vb_adc_nids;
15257                         spec->num_adc_nids = ARRAY_SIZE(alc269vb_adc_nids);
15258                         spec->capsrc_nids = alc269vb_capsrc_nids;
15259                 }
15260         }
15261
15262         if (!spec->cap_mixer)
15263                 set_capture_mixer(codec);
15264         if (has_cdefine_beep(codec))
15265                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
15266
15267         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
15268
15269         spec->vmaster_nid = 0x02;
15270
15271         codec->patch_ops = alc_patch_ops;
15272 #ifdef SND_HDA_NEEDS_RESUME
15273         codec->patch_ops.resume = alc269_resume;
15274 #endif
15275         if (board_config == ALC269_AUTO)
15276                 spec->init_hook = alc269_auto_init;
15277         spec->shutup = alc269_shutup;
15278
15279         alc_init_jacks(codec);
15280 #ifdef CONFIG_SND_HDA_POWER_SAVE
15281         if (!spec->loopback.amplist)
15282                 spec->loopback.amplist = alc269_loopbacks;
15283         if (alc269_mic2_for_mute_led(codec))
15284                 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
15285 #endif
15286
15287         return 0;
15288 }
15289
15290 /*
15291  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
15292  */
15293
15294 /*
15295  * set the path ways for 2 channel output
15296  * need to set the codec line out and mic 1 pin widgets to inputs
15297  */
15298 static const struct hda_verb alc861_threestack_ch2_init[] = {
15299         /* set pin widget 1Ah (line in) for input */
15300         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15301         /* set pin widget 18h (mic1/2) for input, for mic also enable
15302          * the vref
15303          */
15304         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15305
15306         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
15307 #if 0
15308         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
15309         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
15310 #endif
15311         { } /* end */
15312 };
15313 /*
15314  * 6ch mode
15315  * need to set the codec line out and mic 1 pin widgets to outputs
15316  */
15317 static const struct hda_verb alc861_threestack_ch6_init[] = {
15318         /* set pin widget 1Ah (line in) for output (Back Surround)*/
15319         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15320         /* set pin widget 18h (mic1) for output (CLFE)*/
15321         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15322
15323         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
15324         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
15325
15326         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
15327 #if 0
15328         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
15329         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
15330 #endif
15331         { } /* end */
15332 };
15333
15334 static const struct hda_channel_mode alc861_threestack_modes[2] = {
15335         { 2, alc861_threestack_ch2_init },
15336         { 6, alc861_threestack_ch6_init },
15337 };
15338 /* Set mic1 as input and unmute the mixer */
15339 static const struct hda_verb alc861_uniwill_m31_ch2_init[] = {
15340         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15341         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
15342         { } /* end */
15343 };
15344 /* Set mic1 as output and mute mixer */
15345 static const struct hda_verb alc861_uniwill_m31_ch4_init[] = {
15346         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15347         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
15348         { } /* end */
15349 };
15350
15351 static const struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
15352         { 2, alc861_uniwill_m31_ch2_init },
15353         { 4, alc861_uniwill_m31_ch4_init },
15354 };
15355
15356 /* Set mic1 and line-in as input and unmute the mixer */
15357 static const struct hda_verb alc861_asus_ch2_init[] = {
15358         /* set pin widget 1Ah (line in) for input */
15359         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15360         /* set pin widget 18h (mic1/2) for input, for mic also enable
15361          * the vref
15362          */
15363         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15364
15365         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
15366 #if 0
15367         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
15368         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
15369 #endif
15370         { } /* end */
15371 };
15372 /* Set mic1 nad line-in as output and mute mixer */
15373 static const struct hda_verb alc861_asus_ch6_init[] = {
15374         /* set pin widget 1Ah (line in) for output (Back Surround)*/
15375         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15376         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
15377         /* set pin widget 18h (mic1) for output (CLFE)*/
15378         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15379         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
15380         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
15381         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
15382
15383         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
15384 #if 0
15385         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
15386         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
15387 #endif
15388         { } /* end */
15389 };
15390
15391 static const struct hda_channel_mode alc861_asus_modes[2] = {
15392         { 2, alc861_asus_ch2_init },
15393         { 6, alc861_asus_ch6_init },
15394 };
15395
15396 /* patch-ALC861 */
15397
15398 static const struct snd_kcontrol_new alc861_base_mixer[] = {
15399         /* output mixer control */
15400         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15401         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15402         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15403         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15404         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
15405
15406         /*Input mixer control */
15407         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15408            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
15409         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15410         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15411         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15412         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15413         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15414         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15415         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15416         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
15417
15418         { } /* end */
15419 };
15420
15421 static const struct snd_kcontrol_new alc861_3ST_mixer[] = {
15422         /* output mixer control */
15423         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15424         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15425         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15426         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15427         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
15428
15429         /* Input mixer control */
15430         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15431            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
15432         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15433         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15434         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15435         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15436         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15437         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15438         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15439         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
15440
15441         {
15442                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15443                 .name = "Channel Mode",
15444                 .info = alc_ch_mode_info,
15445                 .get = alc_ch_mode_get,
15446                 .put = alc_ch_mode_put,
15447                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
15448         },
15449         { } /* end */
15450 };
15451
15452 static const struct snd_kcontrol_new alc861_toshiba_mixer[] = {
15453         /* output mixer control */
15454         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15455         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15456         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15457
15458         { } /* end */
15459 };
15460
15461 static const struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
15462         /* output mixer control */
15463         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15464         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15465         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15466         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15467         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
15468
15469         /* Input mixer control */
15470         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15471            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
15472         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15473         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15474         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15475         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15476         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15477         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15478         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15479         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
15480
15481         {
15482                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15483                 .name = "Channel Mode",
15484                 .info = alc_ch_mode_info,
15485                 .get = alc_ch_mode_get,
15486                 .put = alc_ch_mode_put,
15487                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
15488         },
15489         { } /* end */
15490 };
15491
15492 static const struct snd_kcontrol_new alc861_asus_mixer[] = {
15493         /* output mixer control */
15494         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
15495         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
15496         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
15497         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
15498         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
15499
15500         /* Input mixer control */
15501         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
15502         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15503         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15504         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15505         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
15506         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
15507         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
15508         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
15509         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
15510         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
15511
15512         {
15513                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15514                 .name = "Channel Mode",
15515                 .info = alc_ch_mode_info,
15516                 .get = alc_ch_mode_get,
15517                 .put = alc_ch_mode_put,
15518                 .private_value = ARRAY_SIZE(alc861_asus_modes),
15519         },
15520         { }
15521 };
15522
15523 /* additional mixer */
15524 static const struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
15525         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
15526         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
15527         { }
15528 };
15529
15530 /*
15531  * generic initialization of ADC, input mixers and output mixers
15532  */
15533 static const struct hda_verb alc861_base_init_verbs[] = {
15534         /*
15535          * Unmute ADC0 and set the default input to mic-in
15536          */
15537         /* port-A for surround (rear panel) */
15538         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15539         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
15540         /* port-B for mic-in (rear panel) with vref */
15541         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15542         /* port-C for line-in (rear panel) */
15543         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15544         /* port-D for Front */
15545         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15546         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15547         /* port-E for HP out (front panel) */
15548         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
15549         /* route front PCM to HP */
15550         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15551         /* port-F for mic-in (front panel) with vref */
15552         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15553         /* port-G for CLFE (rear panel) */
15554         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15555         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15556         /* port-H for side (rear panel) */
15557         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15558         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
15559         /* CD-in */
15560         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15561         /* route front mic to ADC1*/
15562         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15563         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15564
15565         /* Unmute DAC0~3 & spdif out*/
15566         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15567         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15568         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15569         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15570         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15571
15572         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15573         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15574         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15575         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15576         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15577
15578         /* Unmute Stereo Mixer 15 */
15579         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15580         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15581         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15582         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15583
15584         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15585         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15586         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15587         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15588         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15589         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15590         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15591         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15592         /* hp used DAC 3 (Front) */
15593         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15594         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15595
15596         { }
15597 };
15598
15599 static const struct hda_verb alc861_threestack_init_verbs[] = {
15600         /*
15601          * Unmute ADC0 and set the default input to mic-in
15602          */
15603         /* port-A for surround (rear panel) */
15604         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15605         /* port-B for mic-in (rear panel) with vref */
15606         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15607         /* port-C for line-in (rear panel) */
15608         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15609         /* port-D for Front */
15610         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15611         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15612         /* port-E for HP out (front panel) */
15613         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
15614         /* route front PCM to HP */
15615         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15616         /* port-F for mic-in (front panel) with vref */
15617         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15618         /* port-G for CLFE (rear panel) */
15619         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15620         /* port-H for side (rear panel) */
15621         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15622         /* CD-in */
15623         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15624         /* route front mic to ADC1*/
15625         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15626         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15627         /* Unmute DAC0~3 & spdif out*/
15628         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15629         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15630         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15631         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15633
15634         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15635         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15636         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15637         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15638         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15639
15640         /* Unmute Stereo Mixer 15 */
15641         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15642         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15643         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15644         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15645
15646         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15647         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15648         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15649         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15650         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15651         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15652         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15653         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15654         /* hp used DAC 3 (Front) */
15655         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15656         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15657         { }
15658 };
15659
15660 static const struct hda_verb alc861_uniwill_m31_init_verbs[] = {
15661         /*
15662          * Unmute ADC0 and set the default input to mic-in
15663          */
15664         /* port-A for surround (rear panel) */
15665         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15666         /* port-B for mic-in (rear panel) with vref */
15667         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15668         /* port-C for line-in (rear panel) */
15669         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15670         /* port-D for Front */
15671         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15672         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15673         /* port-E for HP out (front panel) */
15674         /* this has to be set to VREF80 */
15675         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15676         /* route front PCM to HP */
15677         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15678         /* port-F for mic-in (front panel) with vref */
15679         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15680         /* port-G for CLFE (rear panel) */
15681         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15682         /* port-H for side (rear panel) */
15683         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15684         /* CD-in */
15685         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15686         /* route front mic to ADC1*/
15687         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15688         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15689         /* Unmute DAC0~3 & spdif out*/
15690         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15691         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15692         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15693         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15694         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15695
15696         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15697         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15698         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15699         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15700         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15701
15702         /* Unmute Stereo Mixer 15 */
15703         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15704         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15705         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15706         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15707
15708         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15709         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15710         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15711         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15712         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15713         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15714         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15715         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15716         /* hp used DAC 3 (Front) */
15717         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15718         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15719         { }
15720 };
15721
15722 static const struct hda_verb alc861_asus_init_verbs[] = {
15723         /*
15724          * Unmute ADC0 and set the default input to mic-in
15725          */
15726         /* port-A for surround (rear panel)
15727          * according to codec#0 this is the HP jack
15728          */
15729         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
15730         /* route front PCM to HP */
15731         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
15732         /* port-B for mic-in (rear panel) with vref */
15733         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15734         /* port-C for line-in (rear panel) */
15735         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15736         /* port-D for Front */
15737         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15738         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
15739         /* port-E for HP out (front panel) */
15740         /* this has to be set to VREF80 */
15741         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15742         /* route front PCM to HP */
15743         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
15744         /* port-F for mic-in (front panel) with vref */
15745         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
15746         /* port-G for CLFE (rear panel) */
15747         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15748         /* port-H for side (rear panel) */
15749         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
15750         /* CD-in */
15751         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
15752         /* route front mic to ADC1*/
15753         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
15754         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15755         /* Unmute DAC0~3 & spdif out*/
15756         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15757         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15758         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15759         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15760         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15761         /* Unmute Mixer 14 (mic) 1c (Line in)*/
15762         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15763         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15764         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15765         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15766
15767         /* Unmute Stereo Mixer 15 */
15768         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15769         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15770         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15771         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
15772
15773         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15774         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15775         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15776         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15777         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15778         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15779         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15780         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15781         /* hp used DAC 3 (Front) */
15782         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
15783         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15784         { }
15785 };
15786
15787 /* additional init verbs for ASUS laptops */
15788 static const struct hda_verb alc861_asus_laptop_init_verbs[] = {
15789         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
15790         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
15791         { }
15792 };
15793
15794 static const struct hda_verb alc861_toshiba_init_verbs[] = {
15795         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15796
15797         { }
15798 };
15799
15800 /* toggle speaker-output according to the hp-jack state */
15801 static void alc861_toshiba_automute(struct hda_codec *codec)
15802 {
15803         unsigned int present = snd_hda_jack_detect(codec, 0x0f);
15804
15805         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
15806                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
15807         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
15808                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
15809 }
15810
15811 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
15812                                        unsigned int res)
15813 {
15814         if ((res >> 26) == ALC880_HP_EVENT)
15815                 alc861_toshiba_automute(codec);
15816 }
15817
15818 /* pcm configuration: identical with ALC880 */
15819 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
15820 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
15821 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
15822 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
15823
15824
15825 #define ALC861_DIGOUT_NID       0x07
15826
15827 static const struct hda_channel_mode alc861_8ch_modes[1] = {
15828         { 8, NULL }
15829 };
15830
15831 static const hda_nid_t alc861_dac_nids[4] = {
15832         /* front, surround, clfe, side */
15833         0x03, 0x06, 0x05, 0x04
15834 };
15835
15836 static const hda_nid_t alc660_dac_nids[3] = {
15837         /* front, clfe, surround */
15838         0x03, 0x05, 0x06
15839 };
15840
15841 static const hda_nid_t alc861_adc_nids[1] = {
15842         /* ADC0-2 */
15843         0x08,
15844 };
15845
15846 static const struct hda_input_mux alc861_capture_source = {
15847         .num_items = 5,
15848         .items = {
15849                 { "Mic", 0x0 },
15850                 { "Front Mic", 0x3 },
15851                 { "Line", 0x1 },
15852                 { "CD", 0x4 },
15853                 { "Mixer", 0x5 },
15854         },
15855 };
15856
15857 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
15858 {
15859         struct alc_spec *spec = codec->spec;
15860         hda_nid_t mix, srcs[5];
15861         int i, num;
15862
15863         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
15864                 return 0;
15865         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
15866         if (num < 0)
15867                 return 0;
15868         for (i = 0; i < num; i++) {
15869                 unsigned int type;
15870                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
15871                 if (type != AC_WID_AUD_OUT)
15872                         continue;
15873                 if (!found_in_nid_list(srcs[i], spec->multiout.dac_nids,
15874                                        spec->multiout.num_dacs))
15875                         return srcs[i];
15876         }
15877         return 0;
15878 }
15879
15880 /* fill in the dac_nids table from the parsed pin configuration */
15881 static int alc861_auto_fill_dac_nids(struct hda_codec *codec)
15882 {
15883         struct alc_spec *spec = codec->spec;
15884         const struct auto_pin_cfg *cfg = &spec->autocfg;
15885         int i;
15886         hda_nid_t nid, dac;
15887
15888         spec->multiout.dac_nids = spec->private_dac_nids;
15889         for (i = 0; i < cfg->line_outs; i++) {
15890                 nid = cfg->line_out_pins[i];
15891                 dac = alc861_look_for_dac(codec, nid);
15892                 if (!dac)
15893                         continue;
15894                 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
15895         }
15896         return 0;
15897 }
15898
15899 static int __alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
15900                                   hda_nid_t nid, int idx, unsigned int chs)
15901 {
15902         return __add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx, idx,
15903                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
15904 }
15905
15906 #define alc861_create_out_sw(codec, pfx, nid, chs) \
15907         __alc861_create_out_sw(codec, pfx, nid, 0, chs)
15908
15909 /* add playback controls from the parsed DAC table */
15910 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
15911                                              const struct auto_pin_cfg *cfg)
15912 {
15913         struct alc_spec *spec = codec->spec;
15914         hda_nid_t nid;
15915         int i, err, noutputs;
15916
15917         noutputs = cfg->line_outs;
15918         if (spec->multi_ios > 0)
15919                 noutputs += spec->multi_ios;
15920
15921         for (i = 0; i < noutputs; i++) {
15922                 const char *name;
15923                 int index;
15924                 nid = spec->multiout.dac_nids[i];
15925                 if (!nid)
15926                         continue;
15927                 name = alc_get_line_out_pfx(spec, i, true, &index);
15928                 if (!name) {
15929                         /* Center/LFE */
15930                         err = alc861_create_out_sw(codec, "Center", nid, 1);
15931                         if (err < 0)
15932                                 return err;
15933                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
15934                         if (err < 0)
15935                                 return err;
15936                 } else {
15937                         err = __alc861_create_out_sw(codec, name, nid, index, 3);
15938                         if (err < 0)
15939                                 return err;
15940                 }
15941         }
15942         return 0;
15943 }
15944
15945 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
15946 {
15947         struct alc_spec *spec = codec->spec;
15948         int err;
15949         hda_nid_t nid;
15950
15951         if (!pin)
15952                 return 0;
15953
15954         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
15955                 nid = alc861_look_for_dac(codec, pin);
15956                 if (nid) {
15957                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
15958                         if (err < 0)
15959                                 return err;
15960                         spec->multiout.hp_nid = nid;
15961                 }
15962         }
15963         return 0;
15964 }
15965
15966 /* create playback/capture controls for input pins */
15967 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
15968                                                 const struct auto_pin_cfg *cfg)
15969 {
15970         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
15971 }
15972
15973 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
15974                                               hda_nid_t nid,
15975                                               int pin_type, hda_nid_t dac)
15976 {
15977         hda_nid_t mix, srcs[5];
15978         int i, num;
15979
15980         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
15981                             pin_type);
15982         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15983                             AMP_OUT_UNMUTE);
15984         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
15985                 return;
15986         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
15987         if (num < 0)
15988                 return;
15989         for (i = 0; i < num; i++) {
15990                 unsigned int mute;
15991                 if (srcs[i] == dac || srcs[i] == 0x15)
15992                         mute = AMP_IN_UNMUTE(i);
15993                 else
15994                         mute = AMP_IN_MUTE(i);
15995                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15996                                     mute);
15997         }
15998 }
15999
16000 static void alc861_auto_init_multi_out(struct hda_codec *codec)
16001 {
16002         struct alc_spec *spec = codec->spec;
16003         int i;
16004
16005         for (i = 0; i < spec->autocfg.line_outs + spec->multi_ios; i++) {
16006                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16007                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16008                 if (nid)
16009                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
16010                                                           spec->multiout.dac_nids[i]);
16011         }
16012 }
16013
16014 static void alc861_auto_init_hp_out(struct hda_codec *codec)
16015 {
16016         struct alc_spec *spec = codec->spec;
16017
16018         if (spec->autocfg.hp_outs)
16019                 alc861_auto_set_output_and_unmute(codec,
16020                                                   spec->autocfg.hp_pins[0],
16021                                                   PIN_HP,
16022                                                   spec->multiout.hp_nid);
16023         if (spec->autocfg.speaker_outs)
16024                 alc861_auto_set_output_and_unmute(codec,
16025                                                   spec->autocfg.speaker_pins[0],
16026                                                   PIN_OUT,
16027                                                   spec->multiout.dac_nids[0]);
16028 }
16029
16030 #define alc861_auto_init_analog_input   alc880_auto_init_analog_input
16031
16032 /* parse the BIOS configuration and set up the alc_spec */
16033 /* return 1 if successful, 0 if the proper config is not found,
16034  * or a negative error code
16035  */
16036 static int alc861_parse_auto_config(struct hda_codec *codec)
16037 {
16038         struct alc_spec *spec = codec->spec;
16039         int err;
16040         static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
16041
16042         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16043                                            alc861_ignore);
16044         if (err < 0)
16045                 return err;
16046         if (!spec->autocfg.line_outs)
16047                 return 0; /* can't find valid BIOS pin config */
16048
16049         err = alc861_auto_fill_dac_nids(codec);
16050         if (err < 0)
16051                 return err;
16052         err = alc_auto_add_multi_channel_mode(codec, alc861_auto_fill_dac_nids);
16053         if (err < 0)
16054                 return err;
16055         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
16056         if (err < 0)
16057                 return err;
16058         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
16059         if (err < 0)
16060                 return err;
16061         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
16062         if (err < 0)
16063                 return err;
16064
16065         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16066
16067         alc_auto_parse_digital(codec);
16068
16069         if (spec->kctls.list)
16070                 add_mixer(spec, spec->kctls.list);
16071
16072         spec->num_mux_defs = 1;
16073         spec->input_mux = &spec->private_imux[0];
16074
16075         spec->adc_nids = alc861_adc_nids;
16076         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
16077         set_capture_mixer(codec);
16078
16079         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b, 0);
16080
16081         return 1;
16082 }
16083
16084 /* additional initialization for auto-configuration model */
16085 static void alc861_auto_init(struct hda_codec *codec)
16086 {
16087         struct alc_spec *spec = codec->spec;
16088         alc861_auto_init_multi_out(codec);
16089         alc861_auto_init_hp_out(codec);
16090         alc861_auto_init_analog_input(codec);
16091         alc_auto_init_digital(codec);
16092         if (spec->unsol_event)
16093                 alc_inithook(codec);
16094 }
16095
16096 #ifdef CONFIG_SND_HDA_POWER_SAVE
16097 static const struct hda_amp_list alc861_loopbacks[] = {
16098         { 0x15, HDA_INPUT, 0 },
16099         { 0x15, HDA_INPUT, 1 },
16100         { 0x15, HDA_INPUT, 2 },
16101         { 0x15, HDA_INPUT, 3 },
16102         { } /* end */
16103 };
16104 #endif
16105
16106
16107 /*
16108  * configuration and preset
16109  */
16110 static const char * const alc861_models[ALC861_MODEL_LAST] = {
16111         [ALC861_3ST]            = "3stack",
16112         [ALC660_3ST]            = "3stack-660",
16113         [ALC861_3ST_DIG]        = "3stack-dig",
16114         [ALC861_6ST_DIG]        = "6stack-dig",
16115         [ALC861_UNIWILL_M31]    = "uniwill-m31",
16116         [ALC861_TOSHIBA]        = "toshiba",
16117         [ALC861_ASUS]           = "asus",
16118         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
16119         [ALC861_AUTO]           = "auto",
16120 };
16121
16122 static const struct snd_pci_quirk alc861_cfg_tbl[] = {
16123         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
16124         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
16125         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
16126         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
16127         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
16128         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
16129         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
16130         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
16131          *        Any other models that need this preset?
16132          */
16133         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
16134         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
16135         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
16136         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
16137         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
16138         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
16139         /* FIXME: the below seems conflict */
16140         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
16141         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
16142         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
16143         {}
16144 };
16145
16146 static const struct alc_config_preset alc861_presets[] = {
16147         [ALC861_3ST] = {
16148                 .mixers = { alc861_3ST_mixer },
16149                 .init_verbs = { alc861_threestack_init_verbs },
16150                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16151                 .dac_nids = alc861_dac_nids,
16152                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
16153                 .channel_mode = alc861_threestack_modes,
16154                 .need_dac_fix = 1,
16155                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16156                 .adc_nids = alc861_adc_nids,
16157                 .input_mux = &alc861_capture_source,
16158         },
16159         [ALC861_3ST_DIG] = {
16160                 .mixers = { alc861_base_mixer },
16161                 .init_verbs = { alc861_threestack_init_verbs },
16162                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16163                 .dac_nids = alc861_dac_nids,
16164                 .dig_out_nid = ALC861_DIGOUT_NID,
16165                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
16166                 .channel_mode = alc861_threestack_modes,
16167                 .need_dac_fix = 1,
16168                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16169                 .adc_nids = alc861_adc_nids,
16170                 .input_mux = &alc861_capture_source,
16171         },
16172         [ALC861_6ST_DIG] = {
16173                 .mixers = { alc861_base_mixer },
16174                 .init_verbs = { alc861_base_init_verbs },
16175                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16176                 .dac_nids = alc861_dac_nids,
16177                 .dig_out_nid = ALC861_DIGOUT_NID,
16178                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
16179                 .channel_mode = alc861_8ch_modes,
16180                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16181                 .adc_nids = alc861_adc_nids,
16182                 .input_mux = &alc861_capture_source,
16183         },
16184         [ALC660_3ST] = {
16185                 .mixers = { alc861_3ST_mixer },
16186                 .init_verbs = { alc861_threestack_init_verbs },
16187                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
16188                 .dac_nids = alc660_dac_nids,
16189                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
16190                 .channel_mode = alc861_threestack_modes,
16191                 .need_dac_fix = 1,
16192                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16193                 .adc_nids = alc861_adc_nids,
16194                 .input_mux = &alc861_capture_source,
16195         },
16196         [ALC861_UNIWILL_M31] = {
16197                 .mixers = { alc861_uniwill_m31_mixer },
16198                 .init_verbs = { alc861_uniwill_m31_init_verbs },
16199                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16200                 .dac_nids = alc861_dac_nids,
16201                 .dig_out_nid = ALC861_DIGOUT_NID,
16202                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
16203                 .channel_mode = alc861_uniwill_m31_modes,
16204                 .need_dac_fix = 1,
16205                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16206                 .adc_nids = alc861_adc_nids,
16207                 .input_mux = &alc861_capture_source,
16208         },
16209         [ALC861_TOSHIBA] = {
16210                 .mixers = { alc861_toshiba_mixer },
16211                 .init_verbs = { alc861_base_init_verbs,
16212                                 alc861_toshiba_init_verbs },
16213                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16214                 .dac_nids = alc861_dac_nids,
16215                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
16216                 .channel_mode = alc883_3ST_2ch_modes,
16217                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16218                 .adc_nids = alc861_adc_nids,
16219                 .input_mux = &alc861_capture_source,
16220                 .unsol_event = alc861_toshiba_unsol_event,
16221                 .init_hook = alc861_toshiba_automute,
16222         },
16223         [ALC861_ASUS] = {
16224                 .mixers = { alc861_asus_mixer },
16225                 .init_verbs = { alc861_asus_init_verbs },
16226                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16227                 .dac_nids = alc861_dac_nids,
16228                 .dig_out_nid = ALC861_DIGOUT_NID,
16229                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
16230                 .channel_mode = alc861_asus_modes,
16231                 .need_dac_fix = 1,
16232                 .hp_nid = 0x06,
16233                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16234                 .adc_nids = alc861_adc_nids,
16235                 .input_mux = &alc861_capture_source,
16236         },
16237         [ALC861_ASUS_LAPTOP] = {
16238                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
16239                 .init_verbs = { alc861_asus_init_verbs,
16240                                 alc861_asus_laptop_init_verbs },
16241                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
16242                 .dac_nids = alc861_dac_nids,
16243                 .dig_out_nid = ALC861_DIGOUT_NID,
16244                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
16245                 .channel_mode = alc883_3ST_2ch_modes,
16246                 .need_dac_fix = 1,
16247                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
16248                 .adc_nids = alc861_adc_nids,
16249                 .input_mux = &alc861_capture_source,
16250         },
16251 };
16252
16253 /* Pin config fixes */
16254 enum {
16255         PINFIX_FSC_AMILO_PI1505,
16256 };
16257
16258 static const struct alc_fixup alc861_fixups[] = {
16259         [PINFIX_FSC_AMILO_PI1505] = {
16260                 .type = ALC_FIXUP_PINS,
16261                 .v.pins = (const struct alc_pincfg[]) {
16262                         { 0x0b, 0x0221101f }, /* HP */
16263                         { 0x0f, 0x90170310 }, /* speaker */
16264                         { }
16265                 }
16266         },
16267 };
16268
16269 static const struct snd_pci_quirk alc861_fixup_tbl[] = {
16270         SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
16271         {}
16272 };
16273
16274 static int patch_alc861(struct hda_codec *codec)
16275 {
16276         struct alc_spec *spec;
16277         int board_config;
16278         int err;
16279
16280         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16281         if (spec == NULL)
16282                 return -ENOMEM;
16283
16284         codec->spec = spec;
16285
16286         spec->mixer_nid = 0x15;
16287
16288         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
16289                                                   alc861_models,
16290                                                   alc861_cfg_tbl);
16291
16292         if (board_config < 0) {
16293                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
16294                        codec->chip_name);
16295                 board_config = ALC861_AUTO;
16296         }
16297
16298         if (board_config == ALC861_AUTO) {
16299                 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
16300                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
16301         }
16302
16303         if (board_config == ALC861_AUTO) {
16304                 /* automatic parse from the BIOS config */
16305                 err = alc861_parse_auto_config(codec);
16306                 if (err < 0) {
16307                         alc_free(codec);
16308                         return err;
16309                 } else if (!err) {
16310                         printk(KERN_INFO
16311                                "hda_codec: Cannot set up configuration "
16312                                "from BIOS.  Using base mode...\n");
16313                    board_config = ALC861_3ST_DIG;
16314                 }
16315         }
16316
16317         err = snd_hda_attach_beep_device(codec, 0x23);
16318         if (err < 0) {
16319                 alc_free(codec);
16320                 return err;
16321         }
16322
16323         if (board_config != ALC861_AUTO)
16324                 setup_preset(codec, &alc861_presets[board_config]);
16325
16326         spec->stream_analog_playback = &alc861_pcm_analog_playback;
16327         spec->stream_analog_capture = &alc861_pcm_analog_capture;
16328
16329         spec->stream_digital_playback = &alc861_pcm_digital_playback;
16330         spec->stream_digital_capture = &alc861_pcm_digital_capture;
16331
16332         if (!spec->cap_mixer)
16333                 set_capture_mixer(codec);
16334         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
16335
16336         spec->vmaster_nid = 0x03;
16337
16338         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
16339
16340         codec->patch_ops = alc_patch_ops;
16341         if (board_config == ALC861_AUTO) {
16342                 spec->init_hook = alc861_auto_init;
16343 #ifdef CONFIG_SND_HDA_POWER_SAVE
16344                 spec->power_hook = alc_power_eapd;
16345 #endif
16346         }
16347 #ifdef CONFIG_SND_HDA_POWER_SAVE
16348         if (!spec->loopback.amplist)
16349                 spec->loopback.amplist = alc861_loopbacks;
16350 #endif
16351
16352         return 0;
16353 }
16354
16355 /*
16356  * ALC861-VD support
16357  *
16358  * Based on ALC882
16359  *
16360  * In addition, an independent DAC
16361  */
16362 #define ALC861VD_DIGOUT_NID     0x06
16363
16364 static const hda_nid_t alc861vd_dac_nids[4] = {
16365         /* front, surr, clfe, side surr */
16366         0x02, 0x03, 0x04, 0x05
16367 };
16368
16369 /* dac_nids for ALC660vd are in a different order - according to
16370  * Realtek's driver.
16371  * This should probably result in a different mixer for 6stack models
16372  * of ALC660vd codecs, but for now there is only 3stack mixer
16373  * - and it is the same as in 861vd.
16374  * adc_nids in ALC660vd are (is) the same as in 861vd
16375  */
16376 static const hda_nid_t alc660vd_dac_nids[3] = {
16377         /* front, rear, clfe, rear_surr */
16378         0x02, 0x04, 0x03
16379 };
16380
16381 static const hda_nid_t alc861vd_adc_nids[1] = {
16382         /* ADC0 */
16383         0x09,
16384 };
16385
16386 static const hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
16387
16388 /* input MUX */
16389 /* FIXME: should be a matrix-type input source selection */
16390 static const struct hda_input_mux alc861vd_capture_source = {
16391         .num_items = 4,
16392         .items = {
16393                 { "Mic", 0x0 },
16394                 { "Front Mic", 0x1 },
16395                 { "Line", 0x2 },
16396                 { "CD", 0x4 },
16397         },
16398 };
16399
16400 static const struct hda_input_mux alc861vd_dallas_capture_source = {
16401         .num_items = 2,
16402         .items = {
16403                 { "Mic", 0x0 },
16404                 { "Internal Mic", 0x1 },
16405         },
16406 };
16407
16408 static const struct hda_input_mux alc861vd_hp_capture_source = {
16409         .num_items = 2,
16410         .items = {
16411                 { "Front Mic", 0x0 },
16412                 { "ATAPI Mic", 0x1 },
16413         },
16414 };
16415
16416 /*
16417  * 2ch mode
16418  */
16419 static const struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
16420         { 2, NULL }
16421 };
16422
16423 /*
16424  * 6ch mode
16425  */
16426 static const struct hda_verb alc861vd_6stack_ch6_init[] = {
16427         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
16428         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16429         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16430         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16431         { } /* end */
16432 };
16433
16434 /*
16435  * 8ch mode
16436  */
16437 static const struct hda_verb alc861vd_6stack_ch8_init[] = {
16438         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16439         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16440         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16441         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
16442         { } /* end */
16443 };
16444
16445 static const struct hda_channel_mode alc861vd_6stack_modes[2] = {
16446         { 6, alc861vd_6stack_ch6_init },
16447         { 8, alc861vd_6stack_ch8_init },
16448 };
16449
16450 static const struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
16451         {
16452                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16453                 .name = "Channel Mode",
16454                 .info = alc_ch_mode_info,
16455                 .get = alc_ch_mode_get,
16456                 .put = alc_ch_mode_put,
16457         },
16458         { } /* end */
16459 };
16460
16461 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
16462  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
16463  */
16464 static const struct snd_kcontrol_new alc861vd_6st_mixer[] = {
16465         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16466         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16467
16468         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16469         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
16470
16471         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
16472                                 HDA_OUTPUT),
16473         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
16474                                 HDA_OUTPUT),
16475         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
16476         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
16477
16478         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
16479         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
16480
16481         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16482
16483         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16484         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16485         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16486
16487         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16488         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16489         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16490
16491         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16492         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16493
16494         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
16495         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
16496
16497         { } /* end */
16498 };
16499
16500 static const struct snd_kcontrol_new alc861vd_3st_mixer[] = {
16501         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16502         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16503
16504         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16505
16506         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16507         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16508         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16509
16510         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16511         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16512         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16513
16514         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16515         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16516
16517         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
16518         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
16519
16520         { } /* end */
16521 };
16522
16523 static const struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
16524         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16525         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
16526         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16527
16528         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16529
16530         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16531         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16532         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16533
16534         HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
16535         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16536         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16537
16538         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
16539         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
16540
16541         { } /* end */
16542 };
16543
16544 /* Pin assignment: Speaker=0x14, HP = 0x15,
16545  *                 Mic=0x18, Internal Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
16546  */
16547 static const struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
16548         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16549         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
16550         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16551         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
16552         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
16553         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16554         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16555         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
16556         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16557         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16558         { } /* end */
16559 };
16560
16561 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
16562  *                 Front Mic=0x18, ATAPI Mic = 0x19,
16563  */
16564 static const struct snd_kcontrol_new alc861vd_hp_mixer[] = {
16565         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16566         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
16567         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16568         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
16569         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16570         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16571         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16572         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16573
16574         { } /* end */
16575 };
16576
16577 /*
16578  * generic initialization of ADC, input mixers and output mixers
16579  */
16580 static const struct hda_verb alc861vd_volume_init_verbs[] = {
16581         /*
16582          * Unmute ADC0 and set the default input to mic-in
16583          */
16584         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16585         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16586
16587         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
16588          * the analog-loopback mixer widget
16589          */
16590         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16591         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16592         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16593         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16594         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16595         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16596
16597         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
16598         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16599         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16600         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
16601         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
16602
16603         /*
16604          * Set up output mixers (0x02 - 0x05)
16605          */
16606         /* set vol=0 to output mixers */
16607         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16608         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16609         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16610         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16611
16612         /* set up input amps for analog loopback */
16613         /* Amp Indices: DAC = 0, mixer = 1 */
16614         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16615         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16616         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16617         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16618         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16619         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16620         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16621         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16622
16623         { }
16624 };
16625
16626 /*
16627  * 3-stack pin configuration:
16628  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
16629  */
16630 static const struct hda_verb alc861vd_3stack_init_verbs[] = {
16631         /*
16632          * Set pin mode and muting
16633          */
16634         /* set front pin widgets 0x14 for output */
16635         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16636         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16637         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
16638
16639         /* Mic (rear) pin: input vref at 80% */
16640         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16641         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16642         /* Front Mic pin: input vref at 80% */
16643         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16644         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16645         /* Line In pin: input */
16646         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16647         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16648         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16649         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16650         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16651         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16652         /* CD pin widget for input */
16653         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16654
16655         { }
16656 };
16657
16658 /*
16659  * 6-stack pin configuration:
16660  */
16661 static const struct hda_verb alc861vd_6stack_init_verbs[] = {
16662         /*
16663          * Set pin mode and muting
16664          */
16665         /* set front pin widgets 0x14 for output */
16666         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16667         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16668         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
16669
16670         /* Rear Pin: output 1 (0x0d) */
16671         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16672         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16673         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
16674         /* CLFE Pin: output 2 (0x0e) */
16675         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16676         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16677         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
16678         /* Side Pin: output 3 (0x0f) */
16679         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16680         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16681         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
16682
16683         /* Mic (rear) pin: input vref at 80% */
16684         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16685         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16686         /* Front Mic pin: input vref at 80% */
16687         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16688         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16689         /* Line In pin: input */
16690         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16691         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16692         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16693         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16694         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16695         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16696         /* CD pin widget for input */
16697         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16698
16699         { }
16700 };
16701
16702 static const struct hda_verb alc861vd_eapd_verbs[] = {
16703         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16704         { }
16705 };
16706
16707 static const struct hda_verb alc660vd_eapd_verbs[] = {
16708         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16709         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16710         { }
16711 };
16712
16713 static const struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
16714         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16715         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16716         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
16717         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16718         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16719         {}
16720 };
16721
16722 static void alc861vd_lenovo_setup(struct hda_codec *codec)
16723 {
16724         struct alc_spec *spec = codec->spec;
16725         spec->autocfg.hp_pins[0] = 0x1b;
16726         spec->autocfg.speaker_pins[0] = 0x14;
16727         spec->automute = 1;
16728         spec->automute_mode = ALC_AUTOMUTE_AMP;
16729 }
16730
16731 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
16732 {
16733         alc_hp_automute(codec);
16734         alc88x_simple_mic_automute(codec);
16735 }
16736
16737 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
16738                                         unsigned int res)
16739 {
16740         switch (res >> 26) {
16741         case ALC880_MIC_EVENT:
16742                 alc88x_simple_mic_automute(codec);
16743                 break;
16744         default:
16745                 alc_sku_unsol_event(codec, res);
16746                 break;
16747         }
16748 }
16749
16750 static const struct hda_verb alc861vd_dallas_verbs[] = {
16751         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16752         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16753         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16754         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16755
16756         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16757         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16758         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16759         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16760         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16761         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16762         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16763         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16764
16765         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16766         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16767         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16768         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16769         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16770         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16771         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16772         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16773
16774         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
16775         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16776         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
16777         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16778         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16779         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16780         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16781         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16782
16783         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16784         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16785         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16786         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16787
16788         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16789         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16790         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16791
16792         { } /* end */
16793 };
16794
16795 /* toggle speaker-output according to the hp-jack state */
16796 static void alc861vd_dallas_setup(struct hda_codec *codec)
16797 {
16798         struct alc_spec *spec = codec->spec;
16799
16800         spec->autocfg.hp_pins[0] = 0x15;
16801         spec->autocfg.speaker_pins[0] = 0x14;
16802         spec->automute = 1;
16803         spec->automute_mode = ALC_AUTOMUTE_AMP;
16804 }
16805
16806 #ifdef CONFIG_SND_HDA_POWER_SAVE
16807 #define alc861vd_loopbacks      alc880_loopbacks
16808 #endif
16809
16810 /* pcm configuration: identical with ALC880 */
16811 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
16812 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
16813 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
16814 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
16815
16816 /*
16817  * configuration and preset
16818  */
16819 static const char * const alc861vd_models[ALC861VD_MODEL_LAST] = {
16820         [ALC660VD_3ST]          = "3stack-660",
16821         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
16822         [ALC660VD_ASUS_V1S]     = "asus-v1s",
16823         [ALC861VD_3ST]          = "3stack",
16824         [ALC861VD_3ST_DIG]      = "3stack-digout",
16825         [ALC861VD_6ST_DIG]      = "6stack-digout",
16826         [ALC861VD_LENOVO]       = "lenovo",
16827         [ALC861VD_DALLAS]       = "dallas",
16828         [ALC861VD_HP]           = "hp",
16829         [ALC861VD_AUTO]         = "auto",
16830 };
16831
16832 static const struct snd_pci_quirk alc861vd_cfg_tbl[] = {
16833         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
16834         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
16835         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
16836         /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
16837         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
16838         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
16839         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
16840         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
16841         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
16842         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
16843         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
16844         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
16845         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
16846         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
16847         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
16848         {}
16849 };
16850
16851 static const struct alc_config_preset alc861vd_presets[] = {
16852         [ALC660VD_3ST] = {
16853                 .mixers = { alc861vd_3st_mixer },
16854                 .init_verbs = { alc861vd_volume_init_verbs,
16855                                  alc861vd_3stack_init_verbs },
16856                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16857                 .dac_nids = alc660vd_dac_nids,
16858                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16859                 .channel_mode = alc861vd_3stack_2ch_modes,
16860                 .input_mux = &alc861vd_capture_source,
16861         },
16862         [ALC660VD_3ST_DIG] = {
16863                 .mixers = { alc861vd_3st_mixer },
16864                 .init_verbs = { alc861vd_volume_init_verbs,
16865                                  alc861vd_3stack_init_verbs },
16866                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16867                 .dac_nids = alc660vd_dac_nids,
16868                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16869                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16870                 .channel_mode = alc861vd_3stack_2ch_modes,
16871                 .input_mux = &alc861vd_capture_source,
16872         },
16873         [ALC861VD_3ST] = {
16874                 .mixers = { alc861vd_3st_mixer },
16875                 .init_verbs = { alc861vd_volume_init_verbs,
16876                                  alc861vd_3stack_init_verbs },
16877                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16878                 .dac_nids = alc861vd_dac_nids,
16879                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16880                 .channel_mode = alc861vd_3stack_2ch_modes,
16881                 .input_mux = &alc861vd_capture_source,
16882         },
16883         [ALC861VD_3ST_DIG] = {
16884                 .mixers = { alc861vd_3st_mixer },
16885                 .init_verbs = { alc861vd_volume_init_verbs,
16886                                  alc861vd_3stack_init_verbs },
16887                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16888                 .dac_nids = alc861vd_dac_nids,
16889                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16890                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16891                 .channel_mode = alc861vd_3stack_2ch_modes,
16892                 .input_mux = &alc861vd_capture_source,
16893         },
16894         [ALC861VD_6ST_DIG] = {
16895                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
16896                 .init_verbs = { alc861vd_volume_init_verbs,
16897                                 alc861vd_6stack_init_verbs },
16898                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16899                 .dac_nids = alc861vd_dac_nids,
16900                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16901                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
16902                 .channel_mode = alc861vd_6stack_modes,
16903                 .input_mux = &alc861vd_capture_source,
16904         },
16905         [ALC861VD_LENOVO] = {
16906                 .mixers = { alc861vd_lenovo_mixer },
16907                 .init_verbs = { alc861vd_volume_init_verbs,
16908                                 alc861vd_3stack_init_verbs,
16909                                 alc861vd_eapd_verbs,
16910                                 alc861vd_lenovo_unsol_verbs },
16911                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16912                 .dac_nids = alc660vd_dac_nids,
16913                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16914                 .channel_mode = alc861vd_3stack_2ch_modes,
16915                 .input_mux = &alc861vd_capture_source,
16916                 .unsol_event = alc861vd_lenovo_unsol_event,
16917                 .setup = alc861vd_lenovo_setup,
16918                 .init_hook = alc861vd_lenovo_init_hook,
16919         },
16920         [ALC861VD_DALLAS] = {
16921                 .mixers = { alc861vd_dallas_mixer },
16922                 .init_verbs = { alc861vd_dallas_verbs },
16923                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16924                 .dac_nids = alc861vd_dac_nids,
16925                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16926                 .channel_mode = alc861vd_3stack_2ch_modes,
16927                 .input_mux = &alc861vd_dallas_capture_source,
16928                 .unsol_event = alc_sku_unsol_event,
16929                 .setup = alc861vd_dallas_setup,
16930                 .init_hook = alc_hp_automute,
16931         },
16932         [ALC861VD_HP] = {
16933                 .mixers = { alc861vd_hp_mixer },
16934                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
16935                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
16936                 .dac_nids = alc861vd_dac_nids,
16937                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16938                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16939                 .channel_mode = alc861vd_3stack_2ch_modes,
16940                 .input_mux = &alc861vd_hp_capture_source,
16941                 .unsol_event = alc_sku_unsol_event,
16942                 .setup = alc861vd_dallas_setup,
16943                 .init_hook = alc_hp_automute,
16944         },
16945         [ALC660VD_ASUS_V1S] = {
16946                 .mixers = { alc861vd_lenovo_mixer },
16947                 .init_verbs = { alc861vd_volume_init_verbs,
16948                                 alc861vd_3stack_init_verbs,
16949                                 alc861vd_eapd_verbs,
16950                                 alc861vd_lenovo_unsol_verbs },
16951                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
16952                 .dac_nids = alc660vd_dac_nids,
16953                 .dig_out_nid = ALC861VD_DIGOUT_NID,
16954                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
16955                 .channel_mode = alc861vd_3stack_2ch_modes,
16956                 .input_mux = &alc861vd_capture_source,
16957                 .unsol_event = alc861vd_lenovo_unsol_event,
16958                 .setup = alc861vd_lenovo_setup,
16959                 .init_hook = alc861vd_lenovo_init_hook,
16960         },
16961 };
16962
16963 /*
16964  * BIOS auto configuration
16965  */
16966 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
16967                                                 const struct auto_pin_cfg *cfg)
16968 {
16969         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x22, 0);
16970 }
16971
16972
16973 #define alc861vd_auto_init_multi_out    alc882_auto_init_multi_out
16974 #define alc861vd_auto_init_hp_out       alc882_auto_init_hp_out
16975 #define alc861vd_auto_init_analog_input alc882_auto_init_analog_input
16976 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
16977
16978 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
16979 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
16980
16981 /* add playback controls from the parsed DAC table */
16982 /* Based on ALC880 version. But ALC861VD has separate,
16983  * different NIDs for mute/unmute switch and volume control */
16984 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
16985                                              const struct auto_pin_cfg *cfg)
16986 {
16987         hda_nid_t nid_v, nid_s;
16988         int i, err, noutputs;
16989
16990         noutputs = cfg->line_outs;
16991         if (spec->multi_ios > 0)
16992                 noutputs += spec->multi_ios;
16993
16994         for (i = 0; i < noutputs; i++) {
16995                 const char *name;
16996                 int index;
16997                 if (!spec->multiout.dac_nids[i])
16998                         continue;
16999                 nid_v = alc861vd_idx_to_mixer_vol(
17000                                 alc880_dac_to_idx(
17001                                         spec->multiout.dac_nids[i]));
17002                 nid_s = alc861vd_idx_to_mixer_switch(
17003                                 alc880_dac_to_idx(
17004                                         spec->multiout.dac_nids[i]));
17005
17006                 name = alc_get_line_out_pfx(spec, i, true, &index);
17007                 if (!name) {
17008                         /* Center/LFE */
17009                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
17010                                               "Center",
17011                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
17012                                                               HDA_OUTPUT));
17013                         if (err < 0)
17014                                 return err;
17015                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
17016                                               "LFE",
17017                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
17018                                                               HDA_OUTPUT));
17019                         if (err < 0)
17020                                 return err;
17021                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
17022                                              "Center",
17023                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
17024                                                               HDA_INPUT));
17025                         if (err < 0)
17026                                 return err;
17027                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
17028                                              "LFE",
17029                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
17030                                                               HDA_INPUT));
17031                         if (err < 0)
17032                                 return err;
17033                 } else {
17034                         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
17035                                                 name, index,
17036                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
17037                                                               HDA_OUTPUT));
17038                         if (err < 0)
17039                                 return err;
17040                         err = __add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
17041                                                name, index,
17042                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
17043                                                               HDA_INPUT));
17044                         if (err < 0)
17045                                 return err;
17046                 }
17047         }
17048         return 0;
17049 }
17050
17051 /* add playback controls for speaker and HP outputs */
17052 /* Based on ALC880 version. But ALC861VD has separate,
17053  * different NIDs for mute/unmute switch and volume control */
17054 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
17055                                         hda_nid_t pin, const char *pfx)
17056 {
17057         hda_nid_t nid_v, nid_s;
17058         int err;
17059
17060         if (!pin)
17061                 return 0;
17062
17063         if (alc880_is_fixed_pin(pin)) {
17064                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17065                 /* specify the DAC as the extra output */
17066                 if (!spec->multiout.hp_nid)
17067                         spec->multiout.hp_nid = nid_v;
17068                 else
17069                         spec->multiout.extra_out_nid[0] = nid_v;
17070                 /* control HP volume/switch on the output mixer amp */
17071                 nid_v = alc861vd_idx_to_mixer_vol(
17072                                 alc880_fixed_pin_idx(pin));
17073                 nid_s = alc861vd_idx_to_mixer_switch(
17074                                 alc880_fixed_pin_idx(pin));
17075
17076                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17077                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
17078                 if (err < 0)
17079                         return err;
17080                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
17081                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
17082                 if (err < 0)
17083                         return err;
17084         } else if (alc880_is_multi_pin(pin)) {
17085                 /* set manual connection */
17086                 /* we have only a switch on HP-out PIN */
17087                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17088                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17089                 if (err < 0)
17090                         return err;
17091         }
17092         return 0;
17093 }
17094
17095 /* parse the BIOS configuration and set up the alc_spec
17096  * return 1 if successful, 0 if the proper config is not found,
17097  * or a negative error code
17098  * Based on ALC880 version - had to change it to override
17099  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
17100 static int alc861vd_parse_auto_config(struct hda_codec *codec)
17101 {
17102         struct alc_spec *spec = codec->spec;
17103         int err;
17104         static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
17105
17106         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17107                                            alc861vd_ignore);
17108         if (err < 0)
17109                 return err;
17110         if (!spec->autocfg.line_outs)
17111                 return 0; /* can't find valid BIOS pin config */
17112
17113         err = alc880_auto_fill_dac_nids(codec);
17114         if (err < 0)
17115                 return err;
17116         err = alc_auto_add_multi_channel_mode(codec, alc880_auto_fill_dac_nids);
17117         if (err < 0)
17118                 return err;
17119         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
17120         if (err < 0)
17121                 return err;
17122         err = alc861vd_auto_create_extra_out(spec,
17123                                              spec->autocfg.speaker_pins[0],
17124                                              "Speaker");
17125         if (err < 0)
17126                 return err;
17127         err = alc861vd_auto_create_extra_out(spec,
17128                                              spec->autocfg.hp_pins[0],
17129                                              "Headphone");
17130         if (err < 0)
17131                 return err;
17132         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
17133         if (err < 0)
17134                 return err;
17135
17136         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17137
17138         alc_auto_parse_digital(codec);
17139
17140         if (spec->kctls.list)
17141                 add_mixer(spec, spec->kctls.list);
17142
17143         spec->num_mux_defs = 1;
17144         spec->input_mux = &spec->private_imux[0];
17145
17146         err = alc_auto_add_mic_boost(codec);
17147         if (err < 0)
17148                 return err;
17149
17150         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
17151
17152         return 1;
17153 }
17154
17155 /* additional initialization for auto-configuration model */
17156 static void alc861vd_auto_init(struct hda_codec *codec)
17157 {
17158         struct alc_spec *spec = codec->spec;
17159         alc861vd_auto_init_multi_out(codec);
17160         alc861vd_auto_init_hp_out(codec);
17161         alc861vd_auto_init_analog_input(codec);
17162         alc861vd_auto_init_input_src(codec);
17163         alc_auto_init_digital(codec);
17164         if (spec->unsol_event)
17165                 alc_inithook(codec);
17166 }
17167
17168 enum {
17169         ALC660VD_FIX_ASUS_GPIO1
17170 };
17171
17172 /* reset GPIO1 */
17173 static const struct alc_fixup alc861vd_fixups[] = {
17174         [ALC660VD_FIX_ASUS_GPIO1] = {
17175                 .type = ALC_FIXUP_VERBS,
17176                 .v.verbs = (const struct hda_verb[]) {
17177                         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
17178                         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
17179                         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
17180                         { }
17181                 }
17182         },
17183 };
17184
17185 static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
17186         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
17187         {}
17188 };
17189
17190 static int patch_alc861vd(struct hda_codec *codec)
17191 {
17192         struct alc_spec *spec;
17193         int err, board_config;
17194
17195         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17196         if (spec == NULL)
17197                 return -ENOMEM;
17198
17199         codec->spec = spec;
17200
17201         spec->mixer_nid = 0x0b;
17202
17203         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
17204                                                   alc861vd_models,
17205                                                   alc861vd_cfg_tbl);
17206
17207         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
17208                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17209                        codec->chip_name);
17210                 board_config = ALC861VD_AUTO;
17211         }
17212
17213         if (board_config == ALC861VD_AUTO) {
17214                 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
17215                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
17216         }
17217
17218         if (board_config == ALC861VD_AUTO) {
17219                 /* automatic parse from the BIOS config */
17220                 err = alc861vd_parse_auto_config(codec);
17221                 if (err < 0) {
17222                         alc_free(codec);
17223                         return err;
17224                 } else if (!err) {
17225                         printk(KERN_INFO
17226                                "hda_codec: Cannot set up configuration "
17227                                "from BIOS.  Using base mode...\n");
17228                         board_config = ALC861VD_3ST;
17229                 }
17230         }
17231
17232         err = snd_hda_attach_beep_device(codec, 0x23);
17233         if (err < 0) {
17234                 alc_free(codec);
17235                 return err;
17236         }
17237
17238         if (board_config != ALC861VD_AUTO)
17239                 setup_preset(codec, &alc861vd_presets[board_config]);
17240
17241         if (codec->vendor_id == 0x10ec0660) {
17242                 /* always turn on EAPD */
17243                 add_verb(spec, alc660vd_eapd_verbs);
17244         }
17245
17246         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
17247         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
17248
17249         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
17250         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
17251
17252         if (!spec->adc_nids) {
17253                 spec->adc_nids = alc861vd_adc_nids;
17254                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
17255         }
17256         if (!spec->capsrc_nids)
17257                 spec->capsrc_nids = alc861vd_capsrc_nids;
17258
17259         set_capture_mixer(codec);
17260         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17261
17262         spec->vmaster_nid = 0x02;
17263
17264         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
17265
17266         codec->patch_ops = alc_patch_ops;
17267
17268         if (board_config == ALC861VD_AUTO)
17269                 spec->init_hook = alc861vd_auto_init;
17270         spec->shutup = alc_eapd_shutup;
17271 #ifdef CONFIG_SND_HDA_POWER_SAVE
17272         if (!spec->loopback.amplist)
17273                 spec->loopback.amplist = alc861vd_loopbacks;
17274 #endif
17275
17276         return 0;
17277 }
17278
17279 /*
17280  * ALC662 support
17281  *
17282  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
17283  * configuration.  Each pin widget can choose any input DACs and a mixer.
17284  * Each ADC is connected from a mixer of all inputs.  This makes possible
17285  * 6-channel independent captures.
17286  *
17287  * In addition, an independent DAC for the multi-playback (not used in this
17288  * driver yet).
17289  */
17290 #define ALC662_DIGOUT_NID       0x06
17291 #define ALC662_DIGIN_NID        0x0a
17292
17293 static const hda_nid_t alc662_dac_nids[3] = {
17294         /* front, rear, clfe */
17295         0x02, 0x03, 0x04
17296 };
17297
17298 static const hda_nid_t alc272_dac_nids[2] = {
17299         0x02, 0x03
17300 };
17301
17302 static const hda_nid_t alc662_adc_nids[2] = {
17303         /* ADC1-2 */
17304         0x09, 0x08
17305 };
17306
17307 static const hda_nid_t alc272_adc_nids[1] = {
17308         /* ADC1-2 */
17309         0x08,
17310 };
17311
17312 static const hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
17313 static const hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
17314
17315
17316 /* input MUX */
17317 /* FIXME: should be a matrix-type input source selection */
17318 static const struct hda_input_mux alc662_capture_source = {
17319         .num_items = 4,
17320         .items = {
17321                 { "Mic", 0x0 },
17322                 { "Front Mic", 0x1 },
17323                 { "Line", 0x2 },
17324                 { "CD", 0x4 },
17325         },
17326 };
17327
17328 static const struct hda_input_mux alc662_lenovo_101e_capture_source = {
17329         .num_items = 2,
17330         .items = {
17331                 { "Mic", 0x1 },
17332                 { "Line", 0x2 },
17333         },
17334 };
17335
17336 static const struct hda_input_mux alc663_capture_source = {
17337         .num_items = 3,
17338         .items = {
17339                 { "Mic", 0x0 },
17340                 { "Front Mic", 0x1 },
17341                 { "Line", 0x2 },
17342         },
17343 };
17344
17345 #if 0 /* set to 1 for testing other input sources below */
17346 static const struct hda_input_mux alc272_nc10_capture_source = {
17347         .num_items = 16,
17348         .items = {
17349                 { "Autoselect Mic", 0x0 },
17350                 { "Internal Mic", 0x1 },
17351                 { "In-0x02", 0x2 },
17352                 { "In-0x03", 0x3 },
17353                 { "In-0x04", 0x4 },
17354                 { "In-0x05", 0x5 },
17355                 { "In-0x06", 0x6 },
17356                 { "In-0x07", 0x7 },
17357                 { "In-0x08", 0x8 },
17358                 { "In-0x09", 0x9 },
17359                 { "In-0x0a", 0x0a },
17360                 { "In-0x0b", 0x0b },
17361                 { "In-0x0c", 0x0c },
17362                 { "In-0x0d", 0x0d },
17363                 { "In-0x0e", 0x0e },
17364                 { "In-0x0f", 0x0f },
17365         },
17366 };
17367 #endif
17368
17369 /*
17370  * 2ch mode
17371  */
17372 static const struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
17373         { 2, NULL }
17374 };
17375
17376 /*
17377  * 2ch mode
17378  */
17379 static const struct hda_verb alc662_3ST_ch2_init[] = {
17380         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
17381         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
17382         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
17383         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
17384         { } /* end */
17385 };
17386
17387 /*
17388  * 6ch mode
17389  */
17390 static const struct hda_verb alc662_3ST_ch6_init[] = {
17391         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17392         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
17393         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
17394         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17395         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
17396         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
17397         { } /* end */
17398 };
17399
17400 static const struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
17401         { 2, alc662_3ST_ch2_init },
17402         { 6, alc662_3ST_ch6_init },
17403 };
17404
17405 /*
17406  * 2ch mode
17407  */
17408 static const struct hda_verb alc662_sixstack_ch6_init[] = {
17409         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
17410         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
17411         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17412         { } /* end */
17413 };
17414
17415 /*
17416  * 6ch mode
17417  */
17418 static const struct hda_verb alc662_sixstack_ch8_init[] = {
17419         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17420         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17421         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
17422         { } /* end */
17423 };
17424
17425 static const struct hda_channel_mode alc662_5stack_modes[2] = {
17426         { 2, alc662_sixstack_ch6_init },
17427         { 6, alc662_sixstack_ch8_init },
17428 };
17429
17430 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
17431  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
17432  */
17433
17434 static const struct snd_kcontrol_new alc662_base_mixer[] = {
17435         /* output mixer control */
17436         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
17437         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
17438         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
17439         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
17440         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
17441         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
17442         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
17443         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
17444         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17445
17446         /*Input mixer control */
17447         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
17448         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
17449         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
17450         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
17451         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
17452         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
17453         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
17454         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
17455         { } /* end */
17456 };
17457
17458 static const struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
17459         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17460         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
17461         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17462         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
17463         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
17464         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17465         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17466         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17467         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17468         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17469         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17470         { } /* end */
17471 };
17472
17473 static const struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
17474         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17475         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
17476         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17477         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
17478         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
17479         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
17480         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
17481         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
17482         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17483         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
17484         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
17485         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17486         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17487         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17488         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17489         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17490         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17491         { } /* end */
17492 };
17493
17494 static const struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
17495         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17496         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
17497         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17498         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
17499         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17500         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17501         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17502         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17503         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17504         { } /* end */
17505 };
17506
17507 static const struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
17508         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17509         ALC262_HIPPO_MASTER_SWITCH,
17510
17511         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
17512         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17513         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17514
17515         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
17516         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17517         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17518         { } /* end */
17519 };
17520
17521 static const struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
17522         ALC262_HIPPO_MASTER_SWITCH,
17523         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17524         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17525         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
17526         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
17527         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
17528         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17529         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17530         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17531         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17532         { } /* end */
17533 };
17534
17535 static const struct hda_bind_ctls alc663_asus_bind_master_vol = {
17536         .ops = &snd_hda_bind_vol,
17537         .values = {
17538                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
17539                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
17540                 0
17541         },
17542 };
17543
17544 static const struct hda_bind_ctls alc663_asus_one_bind_switch = {
17545         .ops = &snd_hda_bind_sw,
17546         .values = {
17547                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17548                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
17549                 0
17550         },
17551 };
17552
17553 static const struct snd_kcontrol_new alc663_m51va_mixer[] = {
17554         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17555         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
17556         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17557         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17558         { } /* end */
17559 };
17560
17561 static const struct hda_bind_ctls alc663_asus_tree_bind_switch = {
17562         .ops = &snd_hda_bind_sw,
17563         .values = {
17564                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17565                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
17566                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
17567                 0
17568         },
17569 };
17570
17571 static const struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
17572         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17573         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
17574         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17575         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17576         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17577         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17578
17579         { } /* end */
17580 };
17581
17582 static const struct hda_bind_ctls alc663_asus_four_bind_switch = {
17583         .ops = &snd_hda_bind_sw,
17584         .values = {
17585                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17586                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
17587                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
17588                 0
17589         },
17590 };
17591
17592 static const struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
17593         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17594         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
17595         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17596         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17597         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17598         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17599         { } /* end */
17600 };
17601
17602 static const struct snd_kcontrol_new alc662_1bjd_mixer[] = {
17603         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17604         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
17605         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17606         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17607         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17608         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17609         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17610         { } /* end */
17611 };
17612
17613 static const struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
17614         .ops = &snd_hda_bind_vol,
17615         .values = {
17616                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
17617                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
17618                 0
17619         },
17620 };
17621
17622 static const struct hda_bind_ctls alc663_asus_two_bind_switch = {
17623         .ops = &snd_hda_bind_sw,
17624         .values = {
17625                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17626                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
17627                 0
17628         },
17629 };
17630
17631 static const struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
17632         HDA_BIND_VOL("Master Playback Volume",
17633                                 &alc663_asus_two_bind_master_vol),
17634         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
17635         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17636         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17637         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17638         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17639         { } /* end */
17640 };
17641
17642 static const struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
17643         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
17644         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
17645         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17646         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
17647         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17648         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17649         { } /* end */
17650 };
17651
17652 static const struct snd_kcontrol_new alc663_g71v_mixer[] = {
17653         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17654         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
17655         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
17656         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 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         { } /* end */
17664 };
17665
17666 static const struct snd_kcontrol_new alc663_g50v_mixer[] = {
17667         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
17668         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
17669         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17670
17671         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17672         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17673         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17674         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17675         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
17676         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
17677         { } /* end */
17678 };
17679
17680 static const struct hda_bind_ctls alc663_asus_mode7_8_all_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(0x15, 3, 0, HDA_OUTPUT),
17685                 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
17686                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
17687                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
17688                 0
17689         },
17690 };
17691
17692 static const struct hda_bind_ctls alc663_asus_mode7_8_sp_bind_switch = {
17693         .ops = &snd_hda_bind_sw,
17694         .values = {
17695                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
17696                 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
17697                 0
17698         },
17699 };
17700
17701 static const struct snd_kcontrol_new alc663_mode7_mixer[] = {
17702         HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
17703         HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
17704         HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
17705         HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
17706         HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17707         HDA_CODEC_VOLUME("IntMic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17708         HDA_CODEC_MUTE("IntMic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17709         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
17710         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
17711         { } /* end */
17712 };
17713
17714 static const struct snd_kcontrol_new alc663_mode8_mixer[] = {
17715         HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
17716         HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
17717         HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
17718         HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x15, 0x0, HDA_OUTPUT),
17719         HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
17720         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
17721         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
17722         { } /* end */
17723 };
17724
17725
17726 static const struct snd_kcontrol_new alc662_chmode_mixer[] = {
17727         {
17728                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
17729                 .name = "Channel Mode",
17730                 .info = alc_ch_mode_info,
17731                 .get = alc_ch_mode_get,
17732                 .put = alc_ch_mode_put,
17733         },
17734         { } /* end */
17735 };
17736
17737 static const struct hda_verb alc662_init_verbs[] = {
17738         /* ADC: mute amp left and right */
17739         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17740         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
17741
17742         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17743         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17744         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17745         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17746         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17747         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17748
17749         /* Front Pin: output 0 (0x0c) */
17750         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17751         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17752
17753         /* Rear Pin: output 1 (0x0d) */
17754         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17755         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17756
17757         /* CLFE Pin: output 2 (0x0e) */
17758         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17759         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17760
17761         /* Mic (rear) pin: input vref at 80% */
17762         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
17763         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
17764         /* Front Mic pin: input vref at 80% */
17765         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
17766         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
17767         /* Line In pin: input */
17768         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17769         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
17770         /* Line-2 In: Headphone output (output 0 - 0x0c) */
17771         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17772         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17773         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
17774         /* CD pin widget for input */
17775         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17776
17777         /* FIXME: use matrix-type input source selection */
17778         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
17779         /* Input mixer */
17780         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17781         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
17782
17783         { }
17784 };
17785
17786 static const struct hda_verb alc662_eapd_init_verbs[] = {
17787         /* always trun on EAPD */
17788         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
17789         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
17790         { }
17791 };
17792
17793 static const struct hda_verb alc662_sue_init_verbs[] = {
17794         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
17795         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
17796         {}
17797 };
17798
17799 static const struct hda_verb alc662_eeepc_sue_init_verbs[] = {
17800         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17801         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17802         {}
17803 };
17804
17805 /* Set Unsolicited Event*/
17806 static const struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
17807         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17808         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17809         {}
17810 };
17811
17812 static const struct hda_verb alc663_m51va_init_verbs[] = {
17813         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17814         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17815         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17816         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17817         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17818         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17819         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17820         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17821         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17822         {}
17823 };
17824
17825 static const struct hda_verb alc663_21jd_amic_init_verbs[] = {
17826         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17827         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17828         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* 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         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17833         {}
17834 };
17835
17836 static const struct hda_verb alc662_1bjd_amic_init_verbs[] = {
17837         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17838         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17839         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17840         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
17841         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17842         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17843         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17844         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17845         {}
17846 };
17847
17848 static const struct hda_verb alc663_15jd_amic_init_verbs[] = {
17849         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17850         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17851         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17852         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17853         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17854         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17855         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17856         {}
17857 };
17858
17859 static const struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
17860         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17861         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17862         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17863         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
17864         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17865         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17866         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
17867         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17868         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17869         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17870         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17871         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17872         {}
17873 };
17874
17875 static const struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
17876         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17877         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17878         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17879         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
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         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17884         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
17885         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17886         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17887         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17888         {}
17889 };
17890
17891 static const struct hda_verb alc663_g71v_init_verbs[] = {
17892         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17893         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
17894         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
17895
17896         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17897         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17898         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
17899
17900         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
17901         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
17902         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
17903         {}
17904 };
17905
17906 static const struct hda_verb alc663_g50v_init_verbs[] = {
17907         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17908         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17909         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
17910
17911         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17912         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17913         {}
17914 };
17915
17916 static const struct hda_verb alc662_ecs_init_verbs[] = {
17917         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
17918         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17919         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17920         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17921         {}
17922 };
17923
17924 static const struct hda_verb alc272_dell_zm1_init_verbs[] = {
17925         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17926         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17927         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17928         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17929         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17930         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17931         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17932         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17933         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17934         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17935         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17936         {}
17937 };
17938
17939 static const struct hda_verb alc272_dell_init_verbs[] = {
17940         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17941         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17942         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17943         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17944         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17945         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17946         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17947         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17948         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17949         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17950         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17951         {}
17952 };
17953
17954 static const struct hda_verb alc663_mode7_init_verbs[] = {
17955         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17956         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17957         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17958         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17959         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17960         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17961         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
17962         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17963         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17964         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17965         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17966         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17967         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17968         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17969         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17970         {}
17971 };
17972
17973 static const struct hda_verb alc663_mode8_init_verbs[] = {
17974         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17975         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17977         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
17978         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17979         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
17980         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17981         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
17982         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
17983         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
17984         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
17985         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
17986         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
17987         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17988         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
17989         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
17990         {}
17991 };
17992
17993 static const struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
17994         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
17995         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
17996         { } /* end */
17997 };
17998
17999 static const struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
18000         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
18001         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
18002         { } /* end */
18003 };
18004
18005 static void alc662_lenovo_101e_setup(struct hda_codec *codec)
18006 {
18007         struct alc_spec *spec = codec->spec;
18008
18009         spec->autocfg.hp_pins[0] = 0x1b;
18010         spec->autocfg.line_out_pins[0] = 0x14;
18011         spec->autocfg.speaker_pins[0] = 0x15;
18012         spec->automute = 1;
18013         spec->detect_line = 1;
18014         spec->automute_lines = 1;
18015         spec->automute_mode = ALC_AUTOMUTE_AMP;
18016 }
18017
18018 static void alc662_eeepc_setup(struct hda_codec *codec)
18019 {
18020         struct alc_spec *spec = codec->spec;
18021
18022         alc262_hippo1_setup(codec);
18023         spec->ext_mic.pin = 0x18;
18024         spec->ext_mic.mux_idx = 0;
18025         spec->int_mic.pin = 0x19;
18026         spec->int_mic.mux_idx = 1;
18027         spec->auto_mic = 1;
18028 }
18029
18030 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
18031 {
18032         struct alc_spec *spec = codec->spec;
18033
18034         spec->autocfg.hp_pins[0] = 0x14;
18035         spec->autocfg.speaker_pins[0] = 0x1b;
18036         spec->automute = 1;
18037         spec->automute_mode = ALC_AUTOMUTE_AMP;
18038 }
18039
18040 static void alc663_m51va_setup(struct hda_codec *codec)
18041 {
18042         struct alc_spec *spec = codec->spec;
18043         spec->autocfg.hp_pins[0] = 0x21;
18044         spec->autocfg.speaker_pins[0] = 0x14;
18045         spec->automute_mixer_nid[0] = 0x0c;
18046         spec->automute = 1;
18047         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18048         spec->ext_mic.pin = 0x18;
18049         spec->ext_mic.mux_idx = 0;
18050         spec->int_mic.pin = 0x12;
18051         spec->int_mic.mux_idx = 9;
18052         spec->auto_mic = 1;
18053 }
18054
18055 /* ***************** Mode1 ******************************/
18056 static void alc663_mode1_setup(struct hda_codec *codec)
18057 {
18058         struct alc_spec *spec = codec->spec;
18059         spec->autocfg.hp_pins[0] = 0x21;
18060         spec->autocfg.speaker_pins[0] = 0x14;
18061         spec->automute_mixer_nid[0] = 0x0c;
18062         spec->automute = 1;
18063         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18064         spec->ext_mic.pin = 0x18;
18065         spec->ext_mic.mux_idx = 0;
18066         spec->int_mic.pin = 0x19;
18067         spec->int_mic.mux_idx = 1;
18068         spec->auto_mic = 1;
18069 }
18070
18071 /* ***************** Mode2 ******************************/
18072 static void alc662_mode2_setup(struct hda_codec *codec)
18073 {
18074         struct alc_spec *spec = codec->spec;
18075         spec->autocfg.hp_pins[0] = 0x1b;
18076         spec->autocfg.speaker_pins[0] = 0x14;
18077         spec->automute = 1;
18078         spec->automute_mode = ALC_AUTOMUTE_PIN;
18079         spec->ext_mic.pin = 0x18;
18080         spec->ext_mic.mux_idx = 0;
18081         spec->int_mic.pin = 0x19;
18082         spec->int_mic.mux_idx = 1;
18083         spec->auto_mic = 1;
18084 }
18085
18086 /* ***************** Mode3 ******************************/
18087 static void alc663_mode3_setup(struct hda_codec *codec)
18088 {
18089         struct alc_spec *spec = codec->spec;
18090         spec->autocfg.hp_pins[0] = 0x21;
18091         spec->autocfg.hp_pins[0] = 0x15;
18092         spec->autocfg.speaker_pins[0] = 0x14;
18093         spec->automute = 1;
18094         spec->automute_mode = ALC_AUTOMUTE_PIN;
18095         spec->ext_mic.pin = 0x18;
18096         spec->ext_mic.mux_idx = 0;
18097         spec->int_mic.pin = 0x19;
18098         spec->int_mic.mux_idx = 1;
18099         spec->auto_mic = 1;
18100 }
18101
18102 /* ***************** Mode4 ******************************/
18103 static void alc663_mode4_setup(struct hda_codec *codec)
18104 {
18105         struct alc_spec *spec = codec->spec;
18106         spec->autocfg.hp_pins[0] = 0x21;
18107         spec->autocfg.speaker_pins[0] = 0x14;
18108         spec->autocfg.speaker_pins[1] = 0x16;
18109         spec->automute_mixer_nid[0] = 0x0c;
18110         spec->automute_mixer_nid[1] = 0x0e;
18111         spec->automute = 1;
18112         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18113         spec->ext_mic.pin = 0x18;
18114         spec->ext_mic.mux_idx = 0;
18115         spec->int_mic.pin = 0x19;
18116         spec->int_mic.mux_idx = 1;
18117         spec->auto_mic = 1;
18118 }
18119
18120 /* ***************** Mode5 ******************************/
18121 static void alc663_mode5_setup(struct hda_codec *codec)
18122 {
18123         struct alc_spec *spec = codec->spec;
18124         spec->autocfg.hp_pins[0] = 0x15;
18125         spec->autocfg.speaker_pins[0] = 0x14;
18126         spec->autocfg.speaker_pins[1] = 0x16;
18127         spec->automute_mixer_nid[0] = 0x0c;
18128         spec->automute_mixer_nid[1] = 0x0e;
18129         spec->automute = 1;
18130         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18131         spec->ext_mic.pin = 0x18;
18132         spec->ext_mic.mux_idx = 0;
18133         spec->int_mic.pin = 0x19;
18134         spec->int_mic.mux_idx = 1;
18135         spec->auto_mic = 1;
18136 }
18137
18138 /* ***************** Mode6 ******************************/
18139 static void alc663_mode6_setup(struct hda_codec *codec)
18140 {
18141         struct alc_spec *spec = codec->spec;
18142         spec->autocfg.hp_pins[0] = 0x1b;
18143         spec->autocfg.hp_pins[0] = 0x15;
18144         spec->autocfg.speaker_pins[0] = 0x14;
18145         spec->automute_mixer_nid[0] = 0x0c;
18146         spec->automute = 1;
18147         spec->automute_mode = ALC_AUTOMUTE_MIXER;
18148         spec->ext_mic.pin = 0x18;
18149         spec->ext_mic.mux_idx = 0;
18150         spec->int_mic.pin = 0x19;
18151         spec->int_mic.mux_idx = 1;
18152         spec->auto_mic = 1;
18153 }
18154
18155 /* ***************** Mode7 ******************************/
18156 static void alc663_mode7_setup(struct hda_codec *codec)
18157 {
18158         struct alc_spec *spec = codec->spec;
18159         spec->autocfg.hp_pins[0] = 0x1b;
18160         spec->autocfg.hp_pins[0] = 0x21;
18161         spec->autocfg.speaker_pins[0] = 0x14;
18162         spec->autocfg.speaker_pins[0] = 0x17;
18163         spec->automute = 1;
18164         spec->automute_mode = ALC_AUTOMUTE_PIN;
18165         spec->ext_mic.pin = 0x18;
18166         spec->ext_mic.mux_idx = 0;
18167         spec->int_mic.pin = 0x19;
18168         spec->int_mic.mux_idx = 1;
18169         spec->auto_mic = 1;
18170 }
18171
18172 /* ***************** Mode8 ******************************/
18173 static void alc663_mode8_setup(struct hda_codec *codec)
18174 {
18175         struct alc_spec *spec = codec->spec;
18176         spec->autocfg.hp_pins[0] = 0x21;
18177         spec->autocfg.hp_pins[1] = 0x15;
18178         spec->autocfg.speaker_pins[0] = 0x14;
18179         spec->autocfg.speaker_pins[0] = 0x17;
18180         spec->automute = 1;
18181         spec->automute_mode = ALC_AUTOMUTE_PIN;
18182         spec->ext_mic.pin = 0x18;
18183         spec->ext_mic.mux_idx = 0;
18184         spec->int_mic.pin = 0x12;
18185         spec->int_mic.mux_idx = 9;
18186         spec->auto_mic = 1;
18187 }
18188
18189 static void alc663_g71v_setup(struct hda_codec *codec)
18190 {
18191         struct alc_spec *spec = codec->spec;
18192         spec->autocfg.hp_pins[0] = 0x21;
18193         spec->autocfg.line_out_pins[0] = 0x15;
18194         spec->autocfg.speaker_pins[0] = 0x14;
18195         spec->automute = 1;
18196         spec->automute_mode = ALC_AUTOMUTE_AMP;
18197         spec->detect_line = 1;
18198         spec->automute_lines = 1;
18199         spec->ext_mic.pin = 0x18;
18200         spec->ext_mic.mux_idx = 0;
18201         spec->int_mic.pin = 0x12;
18202         spec->int_mic.mux_idx = 9;
18203         spec->auto_mic = 1;
18204 }
18205
18206 #define alc663_g50v_setup       alc663_m51va_setup
18207
18208 static const struct snd_kcontrol_new alc662_ecs_mixer[] = {
18209         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
18210         ALC262_HIPPO_MASTER_SWITCH,
18211
18212         HDA_CODEC_VOLUME("Mic/LineIn Boost Volume", 0x18, 0, HDA_INPUT),
18213         HDA_CODEC_VOLUME("Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
18214         HDA_CODEC_MUTE("Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
18215
18216         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
18217         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
18218         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
18219         { } /* end */
18220 };
18221
18222 static const struct snd_kcontrol_new alc272_nc10_mixer[] = {
18223         /* Master Playback automatically created from Speaker and Headphone */
18224         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
18225         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
18226         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
18227         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
18228
18229         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
18230         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
18231         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
18232
18233         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
18234         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
18235         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
18236         { } /* end */
18237 };
18238
18239 #ifdef CONFIG_SND_HDA_POWER_SAVE
18240 #define alc662_loopbacks        alc880_loopbacks
18241 #endif
18242
18243
18244 /* pcm configuration: identical with ALC880 */
18245 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
18246 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
18247 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
18248 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
18249
18250 /*
18251  * configuration and preset
18252  */
18253 static const char * const alc662_models[ALC662_MODEL_LAST] = {
18254         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
18255         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
18256         [ALC662_3ST_6ch]        = "3stack-6ch",
18257         [ALC662_5ST_DIG]        = "5stack-dig",
18258         [ALC662_LENOVO_101E]    = "lenovo-101e",
18259         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
18260         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
18261         [ALC662_ECS] = "ecs",
18262         [ALC663_ASUS_M51VA] = "m51va",
18263         [ALC663_ASUS_G71V] = "g71v",
18264         [ALC663_ASUS_H13] = "h13",
18265         [ALC663_ASUS_G50V] = "g50v",
18266         [ALC663_ASUS_MODE1] = "asus-mode1",
18267         [ALC662_ASUS_MODE2] = "asus-mode2",
18268         [ALC663_ASUS_MODE3] = "asus-mode3",
18269         [ALC663_ASUS_MODE4] = "asus-mode4",
18270         [ALC663_ASUS_MODE5] = "asus-mode5",
18271         [ALC663_ASUS_MODE6] = "asus-mode6",
18272         [ALC663_ASUS_MODE7] = "asus-mode7",
18273         [ALC663_ASUS_MODE8] = "asus-mode8",
18274         [ALC272_DELL]           = "dell",
18275         [ALC272_DELL_ZM1]       = "dell-zm1",
18276         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
18277         [ALC662_AUTO]           = "auto",
18278 };
18279
18280 static const struct snd_pci_quirk alc662_cfg_tbl[] = {
18281         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
18282         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
18283         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
18284         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
18285         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
18286         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC663_ASUS_MODE1),
18287         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
18288         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
18289         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
18290         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
18291         SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC663_ASUS_MODE1),
18292         SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC663_ASUS_MODE1),
18293         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
18294         SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC663_ASUS_MODE7),
18295         SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC663_ASUS_MODE7),
18296         SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC663_ASUS_MODE8),
18297         SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC663_ASUS_MODE3),
18298         SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC663_ASUS_MODE1),
18299         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
18300         SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_ASUS_MODE2),
18301         SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC663_ASUS_MODE1),
18302         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
18303         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
18304         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
18305         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
18306         SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC663_ASUS_MODE1),
18307         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
18308         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
18309         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
18310         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
18311         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
18312         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
18313         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
18314         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
18315         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
18316         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
18317         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
18318         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
18319         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
18320         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
18321         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
18322         SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC663_ASUS_MODE1),
18323         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
18324         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
18325         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
18326         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
18327         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
18328         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
18329         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
18330         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
18331         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
18332         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
18333         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
18334         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
18335         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
18336         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
18337         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
18338         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
18339         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
18340         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
18341         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
18342         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
18343         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
18344         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
18345                       ALC662_3ST_6ch_DIG),
18346         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB20x", ALC662_AUTO),
18347         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
18348         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
18349                       ALC662_3ST_6ch_DIG),
18350         SND_PCI_QUIRK(0x152d, 0x2304, "Quanta WH1", ALC663_ASUS_H13),
18351         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
18352         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
18353         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
18354         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
18355                                         ALC662_3ST_6ch_DIG),
18356         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
18357                            ALC663_ASUS_H13),
18358         SND_PCI_QUIRK(0x1991, 0x5628, "Ordissimo EVE", ALC662_LENOVO_101E),
18359         {}
18360 };
18361
18362 static const struct alc_config_preset alc662_presets[] = {
18363         [ALC662_3ST_2ch_DIG] = {
18364                 .mixers = { alc662_3ST_2ch_mixer },
18365                 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
18366                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18367                 .dac_nids = alc662_dac_nids,
18368                 .dig_out_nid = ALC662_DIGOUT_NID,
18369                 .dig_in_nid = ALC662_DIGIN_NID,
18370                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18371                 .channel_mode = alc662_3ST_2ch_modes,
18372                 .input_mux = &alc662_capture_source,
18373         },
18374         [ALC662_3ST_6ch_DIG] = {
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                 .dig_out_nid = ALC662_DIGOUT_NID,
18380                 .dig_in_nid = ALC662_DIGIN_NID,
18381                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18382                 .channel_mode = alc662_3ST_6ch_modes,
18383                 .need_dac_fix = 1,
18384                 .input_mux = &alc662_capture_source,
18385         },
18386         [ALC662_3ST_6ch] = {
18387                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
18388                 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
18389                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18390                 .dac_nids = alc662_dac_nids,
18391                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18392                 .channel_mode = alc662_3ST_6ch_modes,
18393                 .need_dac_fix = 1,
18394                 .input_mux = &alc662_capture_source,
18395         },
18396         [ALC662_5ST_DIG] = {
18397                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
18398                 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
18399                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18400                 .dac_nids = alc662_dac_nids,
18401                 .dig_out_nid = ALC662_DIGOUT_NID,
18402                 .dig_in_nid = ALC662_DIGIN_NID,
18403                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
18404                 .channel_mode = alc662_5stack_modes,
18405                 .input_mux = &alc662_capture_source,
18406         },
18407         [ALC662_LENOVO_101E] = {
18408                 .mixers = { alc662_lenovo_101e_mixer },
18409                 .init_verbs = { alc662_init_verbs,
18410                                 alc662_eapd_init_verbs,
18411                                 alc662_sue_init_verbs },
18412                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18413                 .dac_nids = alc662_dac_nids,
18414                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18415                 .channel_mode = alc662_3ST_2ch_modes,
18416                 .input_mux = &alc662_lenovo_101e_capture_source,
18417                 .unsol_event = alc_sku_unsol_event,
18418                 .setup = alc662_lenovo_101e_setup,
18419                 .init_hook = alc_inithook,
18420         },
18421         [ALC662_ASUS_EEEPC_P701] = {
18422                 .mixers = { alc662_eeepc_p701_mixer },
18423                 .init_verbs = { alc662_init_verbs,
18424                                 alc662_eapd_init_verbs,
18425                                 alc662_eeepc_sue_init_verbs },
18426                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18427                 .dac_nids = alc662_dac_nids,
18428                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18429                 .channel_mode = alc662_3ST_2ch_modes,
18430                 .unsol_event = alc_sku_unsol_event,
18431                 .setup = alc662_eeepc_setup,
18432                 .init_hook = alc_inithook,
18433         },
18434         [ALC662_ASUS_EEEPC_EP20] = {
18435                 .mixers = { alc662_eeepc_ep20_mixer,
18436                             alc662_chmode_mixer },
18437                 .init_verbs = { alc662_init_verbs,
18438                                 alc662_eapd_init_verbs,
18439                                 alc662_eeepc_ep20_sue_init_verbs },
18440                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18441                 .dac_nids = alc662_dac_nids,
18442                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18443                 .channel_mode = alc662_3ST_6ch_modes,
18444                 .input_mux = &alc662_lenovo_101e_capture_source,
18445                 .unsol_event = alc_sku_unsol_event,
18446                 .setup = alc662_eeepc_ep20_setup,
18447                 .init_hook = alc_inithook,
18448         },
18449         [ALC662_ECS] = {
18450                 .mixers = { alc662_ecs_mixer },
18451                 .init_verbs = { alc662_init_verbs,
18452                                 alc662_eapd_init_verbs,
18453                                 alc662_ecs_init_verbs },
18454                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18455                 .dac_nids = alc662_dac_nids,
18456                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18457                 .channel_mode = alc662_3ST_2ch_modes,
18458                 .unsol_event = alc_sku_unsol_event,
18459                 .setup = alc662_eeepc_setup,
18460                 .init_hook = alc_inithook,
18461         },
18462         [ALC663_ASUS_M51VA] = {
18463                 .mixers = { alc663_m51va_mixer },
18464                 .init_verbs = { alc662_init_verbs,
18465                                 alc662_eapd_init_verbs,
18466                                 alc663_m51va_init_verbs },
18467                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18468                 .dac_nids = alc662_dac_nids,
18469                 .dig_out_nid = ALC662_DIGOUT_NID,
18470                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18471                 .channel_mode = alc662_3ST_2ch_modes,
18472                 .unsol_event = alc_sku_unsol_event,
18473                 .setup = alc663_m51va_setup,
18474                 .init_hook = alc_inithook,
18475         },
18476         [ALC663_ASUS_G71V] = {
18477                 .mixers = { alc663_g71v_mixer },
18478                 .init_verbs = { alc662_init_verbs,
18479                                 alc662_eapd_init_verbs,
18480                                 alc663_g71v_init_verbs },
18481                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18482                 .dac_nids = alc662_dac_nids,
18483                 .dig_out_nid = ALC662_DIGOUT_NID,
18484                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18485                 .channel_mode = alc662_3ST_2ch_modes,
18486                 .unsol_event = alc_sku_unsol_event,
18487                 .setup = alc663_g71v_setup,
18488                 .init_hook = alc_inithook,
18489         },
18490         [ALC663_ASUS_H13] = {
18491                 .mixers = { alc663_m51va_mixer },
18492                 .init_verbs = { alc662_init_verbs,
18493                                 alc662_eapd_init_verbs,
18494                                 alc663_m51va_init_verbs },
18495                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18496                 .dac_nids = alc662_dac_nids,
18497                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18498                 .channel_mode = alc662_3ST_2ch_modes,
18499                 .setup = alc663_m51va_setup,
18500                 .unsol_event = alc_sku_unsol_event,
18501                 .init_hook = alc_inithook,
18502         },
18503         [ALC663_ASUS_G50V] = {
18504                 .mixers = { alc663_g50v_mixer },
18505                 .init_verbs = { alc662_init_verbs,
18506                                 alc662_eapd_init_verbs,
18507                                 alc663_g50v_init_verbs },
18508                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18509                 .dac_nids = alc662_dac_nids,
18510                 .dig_out_nid = ALC662_DIGOUT_NID,
18511                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
18512                 .channel_mode = alc662_3ST_6ch_modes,
18513                 .input_mux = &alc663_capture_source,
18514                 .unsol_event = alc_sku_unsol_event,
18515                 .setup = alc663_g50v_setup,
18516                 .init_hook = alc_inithook,
18517         },
18518         [ALC663_ASUS_MODE1] = {
18519                 .mixers = { alc663_m51va_mixer },
18520                 .cap_mixer = alc662_auto_capture_mixer,
18521                 .init_verbs = { alc662_init_verbs,
18522                                 alc662_eapd_init_verbs,
18523                                 alc663_21jd_amic_init_verbs },
18524                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18525                 .hp_nid = 0x03,
18526                 .dac_nids = alc662_dac_nids,
18527                 .dig_out_nid = ALC662_DIGOUT_NID,
18528                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18529                 .channel_mode = alc662_3ST_2ch_modes,
18530                 .unsol_event = alc_sku_unsol_event,
18531                 .setup = alc663_mode1_setup,
18532                 .init_hook = alc_inithook,
18533         },
18534         [ALC662_ASUS_MODE2] = {
18535                 .mixers = { alc662_1bjd_mixer },
18536                 .cap_mixer = alc662_auto_capture_mixer,
18537                 .init_verbs = { alc662_init_verbs,
18538                                 alc662_eapd_init_verbs,
18539                                 alc662_1bjd_amic_init_verbs },
18540                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18541                 .dac_nids = alc662_dac_nids,
18542                 .dig_out_nid = ALC662_DIGOUT_NID,
18543                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18544                 .channel_mode = alc662_3ST_2ch_modes,
18545                 .unsol_event = alc_sku_unsol_event,
18546                 .setup = alc662_mode2_setup,
18547                 .init_hook = alc_inithook,
18548         },
18549         [ALC663_ASUS_MODE3] = {
18550                 .mixers = { alc663_two_hp_m1_mixer },
18551                 .cap_mixer = alc662_auto_capture_mixer,
18552                 .init_verbs = { alc662_init_verbs,
18553                                 alc662_eapd_init_verbs,
18554                                 alc663_two_hp_amic_m1_init_verbs },
18555                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18556                 .hp_nid = 0x03,
18557                 .dac_nids = alc662_dac_nids,
18558                 .dig_out_nid = ALC662_DIGOUT_NID,
18559                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18560                 .channel_mode = alc662_3ST_2ch_modes,
18561                 .unsol_event = alc_sku_unsol_event,
18562                 .setup = alc663_mode3_setup,
18563                 .init_hook = alc_inithook,
18564         },
18565         [ALC663_ASUS_MODE4] = {
18566                 .mixers = { alc663_asus_21jd_clfe_mixer },
18567                 .cap_mixer = alc662_auto_capture_mixer,
18568                 .init_verbs = { alc662_init_verbs,
18569                                 alc662_eapd_init_verbs,
18570                                 alc663_21jd_amic_init_verbs},
18571                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18572                 .hp_nid = 0x03,
18573                 .dac_nids = alc662_dac_nids,
18574                 .dig_out_nid = ALC662_DIGOUT_NID,
18575                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18576                 .channel_mode = alc662_3ST_2ch_modes,
18577                 .unsol_event = alc_sku_unsol_event,
18578                 .setup = alc663_mode4_setup,
18579                 .init_hook = alc_inithook,
18580         },
18581         [ALC663_ASUS_MODE5] = {
18582                 .mixers = { alc663_asus_15jd_clfe_mixer },
18583                 .cap_mixer = alc662_auto_capture_mixer,
18584                 .init_verbs = { alc662_init_verbs,
18585                                 alc662_eapd_init_verbs,
18586                                 alc663_15jd_amic_init_verbs },
18587                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18588                 .hp_nid = 0x03,
18589                 .dac_nids = alc662_dac_nids,
18590                 .dig_out_nid = ALC662_DIGOUT_NID,
18591                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18592                 .channel_mode = alc662_3ST_2ch_modes,
18593                 .unsol_event = alc_sku_unsol_event,
18594                 .setup = alc663_mode5_setup,
18595                 .init_hook = alc_inithook,
18596         },
18597         [ALC663_ASUS_MODE6] = {
18598                 .mixers = { alc663_two_hp_m2_mixer },
18599                 .cap_mixer = alc662_auto_capture_mixer,
18600                 .init_verbs = { alc662_init_verbs,
18601                                 alc662_eapd_init_verbs,
18602                                 alc663_two_hp_amic_m2_init_verbs },
18603                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18604                 .hp_nid = 0x03,
18605                 .dac_nids = alc662_dac_nids,
18606                 .dig_out_nid = ALC662_DIGOUT_NID,
18607                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18608                 .channel_mode = alc662_3ST_2ch_modes,
18609                 .unsol_event = alc_sku_unsol_event,
18610                 .setup = alc663_mode6_setup,
18611                 .init_hook = alc_inithook,
18612         },
18613         [ALC663_ASUS_MODE7] = {
18614                 .mixers = { alc663_mode7_mixer },
18615                 .cap_mixer = alc662_auto_capture_mixer,
18616                 .init_verbs = { alc662_init_verbs,
18617                                 alc662_eapd_init_verbs,
18618                                 alc663_mode7_init_verbs },
18619                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18620                 .hp_nid = 0x03,
18621                 .dac_nids = alc662_dac_nids,
18622                 .dig_out_nid = ALC662_DIGOUT_NID,
18623                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18624                 .channel_mode = alc662_3ST_2ch_modes,
18625                 .unsol_event = alc_sku_unsol_event,
18626                 .setup = alc663_mode7_setup,
18627                 .init_hook = alc_inithook,
18628         },
18629         [ALC663_ASUS_MODE8] = {
18630                 .mixers = { alc663_mode8_mixer },
18631                 .cap_mixer = alc662_auto_capture_mixer,
18632                 .init_verbs = { alc662_init_verbs,
18633                                 alc662_eapd_init_verbs,
18634                                 alc663_mode8_init_verbs },
18635                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
18636                 .hp_nid = 0x03,
18637                 .dac_nids = alc662_dac_nids,
18638                 .dig_out_nid = ALC662_DIGOUT_NID,
18639                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18640                 .channel_mode = alc662_3ST_2ch_modes,
18641                 .unsol_event = alc_sku_unsol_event,
18642                 .setup = alc663_mode8_setup,
18643                 .init_hook = alc_inithook,
18644         },
18645         [ALC272_DELL] = {
18646                 .mixers = { alc663_m51va_mixer },
18647                 .cap_mixer = alc272_auto_capture_mixer,
18648                 .init_verbs = { alc662_init_verbs,
18649                                 alc662_eapd_init_verbs,
18650                                 alc272_dell_init_verbs },
18651                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
18652                 .dac_nids = alc272_dac_nids,
18653                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18654                 .adc_nids = alc272_adc_nids,
18655                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
18656                 .capsrc_nids = alc272_capsrc_nids,
18657                 .channel_mode = alc662_3ST_2ch_modes,
18658                 .unsol_event = alc_sku_unsol_event,
18659                 .setup = alc663_m51va_setup,
18660                 .init_hook = alc_inithook,
18661         },
18662         [ALC272_DELL_ZM1] = {
18663                 .mixers = { alc663_m51va_mixer },
18664                 .cap_mixer = alc662_auto_capture_mixer,
18665                 .init_verbs = { alc662_init_verbs,
18666                                 alc662_eapd_init_verbs,
18667                                 alc272_dell_zm1_init_verbs },
18668                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
18669                 .dac_nids = alc272_dac_nids,
18670                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18671                 .adc_nids = alc662_adc_nids,
18672                 .num_adc_nids = 1,
18673                 .capsrc_nids = alc662_capsrc_nids,
18674                 .channel_mode = alc662_3ST_2ch_modes,
18675                 .unsol_event = alc_sku_unsol_event,
18676                 .setup = alc663_m51va_setup,
18677                 .init_hook = alc_inithook,
18678         },
18679         [ALC272_SAMSUNG_NC10] = {
18680                 .mixers = { alc272_nc10_mixer },
18681                 .init_verbs = { alc662_init_verbs,
18682                                 alc662_eapd_init_verbs,
18683                                 alc663_21jd_amic_init_verbs },
18684                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
18685                 .dac_nids = alc272_dac_nids,
18686                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
18687                 .channel_mode = alc662_3ST_2ch_modes,
18688                 /*.input_mux = &alc272_nc10_capture_source,*/
18689                 .unsol_event = alc_sku_unsol_event,
18690                 .setup = alc663_mode4_setup,
18691                 .init_hook = alc_inithook,
18692         },
18693 };
18694
18695
18696 /*
18697  * BIOS auto configuration
18698  */
18699
18700 /* convert from MIX nid to DAC */
18701 static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
18702 {
18703         hda_nid_t list[5];
18704         int i, num;
18705
18706         num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
18707         for (i = 0; i < num; i++) {
18708                 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
18709                         return list[i];
18710         }
18711         return 0;
18712 }
18713
18714 /* go down to the selector widget before the mixer */
18715 static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
18716 {
18717         hda_nid_t srcs[5];
18718         int num = snd_hda_get_connections(codec, pin, srcs,
18719                                           ARRAY_SIZE(srcs));
18720         if (num != 1 ||
18721             get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
18722                 return pin;
18723         return srcs[0];
18724 }
18725
18726 /* get MIX nid connected to the given pin targeted to DAC */
18727 static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
18728                                    hda_nid_t dac)
18729 {
18730         hda_nid_t mix[5];
18731         int i, num;
18732
18733         pin = alc_go_down_to_selector(codec, pin);
18734         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
18735         for (i = 0; i < num; i++) {
18736                 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
18737                         return mix[i];
18738         }
18739         return 0;
18740 }
18741
18742 /* select the connection from pin to DAC if needed */
18743 static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
18744                                hda_nid_t dac)
18745 {
18746         hda_nid_t mix[5];
18747         int i, num;
18748
18749         pin = alc_go_down_to_selector(codec, pin);
18750         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
18751         if (num < 2)
18752                 return 0;
18753         for (i = 0; i < num; i++) {
18754                 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
18755                         snd_hda_codec_update_cache(codec, pin, 0,
18756                                                    AC_VERB_SET_CONNECT_SEL, i);
18757                         return 0;
18758                 }
18759         }
18760         return 0;
18761 }
18762
18763 /* look for an empty DAC slot */
18764 static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
18765 {
18766         struct alc_spec *spec = codec->spec;
18767         hda_nid_t srcs[5];
18768         int i, num;
18769
18770         pin = alc_go_down_to_selector(codec, pin);
18771         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
18772         for (i = 0; i < num; i++) {
18773                 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
18774                 if (!nid)
18775                         continue;
18776                 if (found_in_nid_list(nid, spec->multiout.dac_nids,
18777                                       spec->multiout.num_dacs))
18778                         continue;
18779                 if (spec->multiout.hp_nid == nid)
18780                         continue;
18781                 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
18782                                       ARRAY_SIZE(spec->multiout.extra_out_nid)))
18783                     continue;
18784                 return nid;
18785         }
18786         return 0;
18787 }
18788
18789 static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
18790 {
18791         hda_nid_t sel = alc_go_down_to_selector(codec, pin);
18792         if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
18793                 return alc_auto_look_for_dac(codec, pin);
18794         return 0;
18795 }
18796
18797 /* fill in the dac_nids table from the parsed pin configuration */
18798 static int alc662_auto_fill_dac_nids(struct hda_codec *codec)
18799 {
18800         struct alc_spec *spec = codec->spec;
18801         const struct auto_pin_cfg *cfg = &spec->autocfg;
18802         bool redone = false;
18803         int i;
18804
18805  again:
18806         spec->multiout.num_dacs = 0;
18807         spec->multiout.hp_nid = 0;
18808         spec->multiout.extra_out_nid[0] = 0;
18809         memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
18810         spec->multiout.dac_nids = spec->private_dac_nids;
18811
18812         /* fill hard-wired DACs first */
18813         if (!redone) {
18814                 for (i = 0; i < cfg->line_outs; i++)
18815                         spec->private_dac_nids[i] =
18816                                 get_dac_if_single(codec, cfg->line_out_pins[i]);
18817                 if (cfg->hp_outs)
18818                         spec->multiout.hp_nid =
18819                                 get_dac_if_single(codec, cfg->hp_pins[0]);
18820                 if (cfg->speaker_outs)
18821                         spec->multiout.extra_out_nid[0] =
18822                                 get_dac_if_single(codec, cfg->speaker_pins[0]);
18823         }
18824
18825         for (i = 0; i < cfg->line_outs; i++) {
18826                 hda_nid_t pin = cfg->line_out_pins[i];
18827                 if (spec->private_dac_nids[i])
18828                         continue;
18829                 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
18830                 if (!spec->private_dac_nids[i] && !redone) {
18831                         /* if we can't find primary DACs, re-probe without
18832                          * checking the hard-wired DACs
18833                          */
18834                         redone = true;
18835                         goto again;
18836                 }
18837         }
18838
18839         for (i = 0; i < cfg->line_outs; i++) {
18840                 if (spec->private_dac_nids[i])
18841                         spec->multiout.num_dacs++;
18842                 else
18843                         memmove(spec->private_dac_nids + i,
18844                                 spec->private_dac_nids + i + 1,
18845                                 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
18846         }
18847
18848         if (cfg->hp_outs && !spec->multiout.hp_nid)
18849                 spec->multiout.hp_nid =
18850                         alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
18851         if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
18852                 spec->multiout.extra_out_nid[0] =
18853                         alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
18854
18855         return 0;
18856 }
18857
18858 static int alc662_add_vol_ctl(struct hda_codec *codec,
18859                               const char *pfx, int cidx,
18860                               hda_nid_t nid, unsigned int chs)
18861 {
18862         return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
18863                                  HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
18864 }
18865
18866 #define alc662_add_stereo_vol(codec, pfx, cidx, nid)    \
18867         alc662_add_vol_ctl(codec, pfx, cidx, nid, 3)
18868
18869 /* create a mute-switch for the given mixer widget;
18870  * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
18871  */
18872 static int alc662_add_sw_ctl(struct hda_codec *codec,
18873                              const char *pfx, int cidx,
18874                              hda_nid_t nid, unsigned int chs)
18875 {
18876         int type;
18877         unsigned long val;
18878         if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
18879                 type = ALC_CTL_WIDGET_MUTE;
18880                 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
18881         } else {
18882                 type = ALC_CTL_BIND_MUTE;
18883                 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
18884         }
18885         return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
18886 }
18887
18888 #define alc662_add_stereo_sw(codec, pfx, cidx, nid)     \
18889         alc662_add_sw_ctl(codec, pfx, cidx, nid, 3)
18890
18891 /* add playback controls from the parsed DAC table */
18892 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
18893                                              const struct auto_pin_cfg *cfg)
18894 {
18895         struct alc_spec *spec = codec->spec;
18896         hda_nid_t nid, mix, pin;
18897         int i, err, noutputs;
18898
18899         noutputs = cfg->line_outs;
18900         if (spec->multi_ios > 0)
18901                 noutputs += spec->multi_ios;
18902
18903         for (i = 0; i < noutputs; i++) {
18904                 const char *name;
18905                 int index;
18906                 nid = spec->multiout.dac_nids[i];
18907                 if (!nid)
18908                         continue;
18909                 if (i >= cfg->line_outs)
18910                         pin = spec->multi_io[i - 1].pin;
18911                 else
18912                         pin = cfg->line_out_pins[i];
18913                 mix = alc_auto_dac_to_mix(codec, pin, nid);
18914                 if (!mix)
18915                         continue;
18916                 name = alc_get_line_out_pfx(spec, i, true, &index);
18917                 if (!name) {
18918                         /* Center/LFE */
18919                         err = alc662_add_vol_ctl(codec, "Center", 0, nid, 1);
18920                         if (err < 0)
18921                                 return err;
18922                         err = alc662_add_vol_ctl(codec, "LFE", 0, nid, 2);
18923                         if (err < 0)
18924                                 return err;
18925                         err = alc662_add_sw_ctl(codec, "Center", 0, mix, 1);
18926                         if (err < 0)
18927                                 return err;
18928                         err = alc662_add_sw_ctl(codec, "LFE", 0, mix, 2);
18929                         if (err < 0)
18930                                 return err;
18931                 } else {
18932                         err = alc662_add_stereo_vol(codec, name, index, nid);
18933                         if (err < 0)
18934                                 return err;
18935                         err = alc662_add_stereo_sw(codec, name, index, mix);
18936                         if (err < 0)
18937                                 return err;
18938                 }
18939         }
18940         return 0;
18941 }
18942
18943 /* add playback controls for speaker and HP outputs */
18944 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
18945                                         hda_nid_t dac, const char *pfx)
18946 {
18947         struct alc_spec *spec = codec->spec;
18948         hda_nid_t mix;
18949         int err;
18950
18951         if (!pin)
18952                 return 0;
18953         if (!dac) {
18954                 /* the corresponding DAC is already occupied */
18955                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
18956                         return 0; /* no way */
18957                 /* create a switch only */
18958                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
18959                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
18960         }
18961
18962         mix = alc_auto_dac_to_mix(codec, pin, dac);
18963         if (!mix)
18964                 return 0;
18965         err = alc662_add_stereo_vol(codec, pfx, 0, dac);
18966         if (err < 0)
18967                 return err;
18968         err = alc662_add_stereo_sw(codec, pfx, 0, mix);
18969         if (err < 0)
18970                 return err;
18971         return 0;
18972 }
18973
18974 /* create playback/capture controls for input pins */
18975 #define alc662_auto_create_input_ctls \
18976         alc882_auto_create_input_ctls
18977
18978 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
18979                                               hda_nid_t nid, int pin_type,
18980                                               hda_nid_t dac)
18981 {
18982         int i, num;
18983         hda_nid_t mix;
18984         hda_nid_t srcs[HDA_MAX_CONNECTIONS];
18985
18986         alc_set_pin_output(codec, nid, pin_type);
18987         nid = alc_go_down_to_selector(codec, nid);
18988         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
18989         for (i = 0; i < num; i++) {
18990                 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
18991                         continue;
18992                 mix = srcs[i];
18993                 break;
18994         }
18995         if (!mix)
18996                 return;
18997
18998         /* need the manual connection? */
18999         if (num > 1)
19000                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
19001         /* unmute mixer widget inputs */
19002         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
19003                             AMP_IN_UNMUTE(0));
19004         snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
19005                             AMP_IN_UNMUTE(1));
19006         /* initialize volume */
19007         if (query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
19008                 nid = dac;
19009         else if (query_amp_caps(codec, mix, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
19010                 nid = mix;
19011         else
19012                 return;
19013         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
19014                             AMP_OUT_ZERO);
19015 }
19016
19017 static void alc662_auto_init_multi_out(struct hda_codec *codec)
19018 {
19019         struct alc_spec *spec = codec->spec;
19020         int pin_type = get_pin_type(spec->autocfg.line_out_type);
19021         int i;
19022
19023         for (i = 0; i <= HDA_SIDE; i++) {
19024                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
19025                 if (nid)
19026                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
19027                                         spec->multiout.dac_nids[i]);
19028         }
19029 }
19030
19031 static void alc662_auto_init_hp_out(struct hda_codec *codec)
19032 {
19033         struct alc_spec *spec = codec->spec;
19034         hda_nid_t pin;
19035
19036         pin = spec->autocfg.hp_pins[0];
19037         if (pin)
19038                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
19039                                                   spec->multiout.hp_nid);
19040         pin = spec->autocfg.speaker_pins[0];
19041         if (pin)
19042                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
19043                                         spec->multiout.extra_out_nid[0]);
19044 }
19045
19046 #define alc662_auto_init_analog_input   alc882_auto_init_analog_input
19047 #define alc662_auto_init_input_src      alc882_auto_init_input_src
19048
19049 /*
19050  * multi-io helper
19051  */
19052 static int alc_auto_fill_multi_ios(struct hda_codec *codec,
19053                                    unsigned int location)
19054 {
19055         struct alc_spec *spec = codec->spec;
19056         struct auto_pin_cfg *cfg = &spec->autocfg;
19057         int type, i, num_pins = 0;
19058
19059         for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
19060                 for (i = 0; i < cfg->num_inputs; i++) {
19061                         hda_nid_t nid = cfg->inputs[i].pin;
19062                         hda_nid_t dac;
19063                         unsigned int defcfg, caps;
19064                         if (cfg->inputs[i].type != type)
19065                                 continue;
19066                         defcfg = snd_hda_codec_get_pincfg(codec, nid);
19067                         if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
19068                                 continue;
19069                         if (location && get_defcfg_location(defcfg) != location)
19070                                 continue;
19071                         caps = snd_hda_query_pin_caps(codec, nid);
19072                         if (!(caps & AC_PINCAP_OUT))
19073                                 continue;
19074                         dac = alc_auto_look_for_dac(codec, nid);
19075                         if (!dac)
19076                                 continue;
19077                         spec->multi_io[num_pins].pin = nid;
19078                         spec->multi_io[num_pins].dac = dac;
19079                         num_pins++;
19080                         spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
19081                 }
19082         }
19083         spec->multiout.num_dacs = 1;
19084         if (num_pins < 2)
19085                 return 0;
19086         return num_pins;
19087 }
19088
19089 static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
19090                                  struct snd_ctl_elem_info *uinfo)
19091 {
19092         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19093         struct alc_spec *spec = codec->spec;
19094
19095         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
19096         uinfo->count = 1;
19097         uinfo->value.enumerated.items = spec->multi_ios + 1;
19098         if (uinfo->value.enumerated.item > spec->multi_ios)
19099                 uinfo->value.enumerated.item = spec->multi_ios;
19100         sprintf(uinfo->value.enumerated.name, "%dch",
19101                 (uinfo->value.enumerated.item + 1) * 2);
19102         return 0;
19103 }
19104
19105 static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
19106                                 struct snd_ctl_elem_value *ucontrol)
19107 {
19108         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19109         struct alc_spec *spec = codec->spec;
19110         ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
19111         return 0;
19112 }
19113
19114 static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
19115 {
19116         struct alc_spec *spec = codec->spec;
19117         hda_nid_t nid = spec->multi_io[idx].pin;
19118
19119         if (!spec->multi_io[idx].ctl_in)
19120                 spec->multi_io[idx].ctl_in =
19121                         snd_hda_codec_read(codec, nid, 0,
19122                                            AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
19123         if (output) {
19124                 snd_hda_codec_update_cache(codec, nid, 0,
19125                                            AC_VERB_SET_PIN_WIDGET_CONTROL,
19126                                            PIN_OUT);
19127                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
19128                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
19129                                                  HDA_AMP_MUTE, 0);
19130                 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
19131         } else {
19132                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
19133                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
19134                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
19135                 snd_hda_codec_update_cache(codec, nid, 0,
19136                                            AC_VERB_SET_PIN_WIDGET_CONTROL,
19137                                            spec->multi_io[idx].ctl_in);
19138         }
19139         return 0;
19140 }
19141
19142 static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
19143                                 struct snd_ctl_elem_value *ucontrol)
19144 {
19145         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19146         struct alc_spec *spec = codec->spec;
19147         int i, ch;
19148
19149         ch = ucontrol->value.enumerated.item[0];
19150         if (ch < 0 || ch > spec->multi_ios)
19151                 return -EINVAL;
19152         if (ch == (spec->ext_channel_count - 1) / 2)
19153                 return 0;
19154         spec->ext_channel_count = (ch + 1) * 2;
19155         for (i = 0; i < spec->multi_ios; i++)
19156                 alc_set_multi_io(codec, i, i < ch);
19157         spec->multiout.max_channels = spec->ext_channel_count;
19158         return 1;
19159 }
19160
19161 static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
19162         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
19163         .name = "Channel Mode",
19164         .info = alc_auto_ch_mode_info,
19165         .get = alc_auto_ch_mode_get,
19166         .put = alc_auto_ch_mode_put,
19167 };
19168
19169 static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
19170                                            int (*fill_dac)(struct hda_codec *))
19171 {
19172         struct alc_spec *spec = codec->spec;
19173         struct auto_pin_cfg *cfg = &spec->autocfg;
19174         unsigned int location, defcfg;
19175         int num_pins;
19176
19177         if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) {
19178                 /* use HP as primary out */
19179                 cfg->speaker_outs = cfg->line_outs;
19180                 memcpy(cfg->speaker_pins, cfg->line_out_pins,
19181                        sizeof(cfg->speaker_pins));
19182                 cfg->line_outs = cfg->hp_outs;
19183                 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
19184                 cfg->hp_outs = 0;
19185                 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
19186                 cfg->line_out_type = AUTO_PIN_HP_OUT;
19187                 if (fill_dac)
19188                         fill_dac(codec);
19189         }
19190         if (cfg->line_outs != 1 ||
19191             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
19192                 return 0;
19193
19194         defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
19195         location = get_defcfg_location(defcfg);
19196
19197         num_pins = alc_auto_fill_multi_ios(codec, location);
19198         if (num_pins > 0) {
19199                 struct snd_kcontrol_new *knew;
19200
19201                 knew = alc_kcontrol_new(spec);
19202                 if (!knew)
19203                         return -ENOMEM;
19204                 *knew = alc_auto_channel_mode_enum;
19205                 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
19206                 if (!knew->name)
19207                         return -ENOMEM;
19208
19209                 spec->multi_ios = num_pins;
19210                 spec->ext_channel_count = 2;
19211                 spec->multiout.num_dacs = num_pins + 1;
19212         }
19213         return 0;
19214 }
19215
19216 static int alc662_parse_auto_config(struct hda_codec *codec)
19217 {
19218         struct alc_spec *spec = codec->spec;
19219         int err;
19220         static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
19221
19222         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
19223                                            alc662_ignore);
19224         if (err < 0)
19225                 return err;
19226         if (!spec->autocfg.line_outs)
19227                 return 0; /* can't find valid BIOS pin config */
19228
19229         err = alc662_auto_fill_dac_nids(codec);
19230         if (err < 0)
19231                 return err;
19232         err = alc_auto_add_multi_channel_mode(codec, alc662_auto_fill_dac_nids);
19233         if (err < 0)
19234                 return err;
19235         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
19236         if (err < 0)
19237                 return err;
19238         err = alc662_auto_create_extra_out(codec,
19239                                            spec->autocfg.speaker_pins[0],
19240                                            spec->multiout.extra_out_nid[0],
19241                                            "Speaker");
19242         if (err < 0)
19243                 return err;
19244         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
19245                                            spec->multiout.hp_nid,
19246                                            "Headphone");
19247         if (err < 0)
19248                 return err;
19249         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
19250         if (err < 0)
19251                 return err;
19252
19253         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
19254
19255         alc_auto_parse_digital(codec);
19256
19257         if (spec->kctls.list)
19258                 add_mixer(spec, spec->kctls.list);
19259
19260         spec->num_mux_defs = 1;
19261         spec->input_mux = &spec->private_imux[0];
19262
19263         err = alc_auto_add_mic_boost(codec);
19264         if (err < 0)
19265                 return err;
19266
19267         if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
19268             codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
19269             alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0x21);
19270         else
19271             alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
19272
19273         return 1;
19274 }
19275
19276 /* additional initialization for auto-configuration model */
19277 static void alc662_auto_init(struct hda_codec *codec)
19278 {
19279         struct alc_spec *spec = codec->spec;
19280         alc662_auto_init_multi_out(codec);
19281         alc662_auto_init_hp_out(codec);
19282         alc662_auto_init_analog_input(codec);
19283         alc662_auto_init_input_src(codec);
19284         alc_auto_init_digital(codec);
19285         if (spec->unsol_event)
19286                 alc_inithook(codec);
19287 }
19288
19289 static void alc272_fixup_mario(struct hda_codec *codec,
19290                                const struct alc_fixup *fix, int action)
19291 {
19292         if (action != ALC_FIXUP_ACT_PROBE)
19293                 return;
19294         if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
19295                                       (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
19296                                       (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
19297                                       (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
19298                                       (0 << AC_AMPCAP_MUTE_SHIFT)))
19299                 printk(KERN_WARNING
19300                        "hda_codec: failed to override amp caps for NID 0x2\n");
19301 }
19302
19303 enum {
19304         ALC662_FIXUP_ASPIRE,
19305         ALC662_FIXUP_IDEAPAD,
19306         ALC272_FIXUP_MARIO,
19307         ALC662_FIXUP_CZC_P10T,
19308         ALC662_FIXUP_SKU_IGNORE,
19309 };
19310
19311 static const struct alc_fixup alc662_fixups[] = {
19312         [ALC662_FIXUP_ASPIRE] = {
19313                 .type = ALC_FIXUP_PINS,
19314                 .v.pins = (const struct alc_pincfg[]) {
19315                         { 0x15, 0x99130112 }, /* subwoofer */
19316                         { }
19317                 }
19318         },
19319         [ALC662_FIXUP_IDEAPAD] = {
19320                 .type = ALC_FIXUP_PINS,
19321                 .v.pins = (const struct alc_pincfg[]) {
19322                         { 0x17, 0x99130112 }, /* subwoofer */
19323                         { }
19324                 }
19325         },
19326         [ALC272_FIXUP_MARIO] = {
19327                 .type = ALC_FIXUP_FUNC,
19328                 .v.func = alc272_fixup_mario,
19329         },
19330         [ALC662_FIXUP_CZC_P10T] = {
19331                 .type = ALC_FIXUP_VERBS,
19332                 .v.verbs = (const struct hda_verb[]) {
19333                         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
19334                         {}
19335                 }
19336         },
19337         [ALC662_FIXUP_SKU_IGNORE] = {
19338                 .type = ALC_FIXUP_SKU,
19339                 .v.sku = ALC_FIXUP_SKU_IGNORE,
19340         },
19341 };
19342
19343 static const struct snd_pci_quirk alc662_fixup_tbl[] = {
19344         SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
19345         SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
19346         SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
19347         SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
19348         SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
19349         SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
19350         SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
19351         {}
19352 };
19353
19354 static const struct alc_model_fixup alc662_fixup_models[] = {
19355         {.id = ALC272_FIXUP_MARIO, .name = "mario"},
19356         {}
19357 };
19358
19359
19360 static int patch_alc662(struct hda_codec *codec)
19361 {
19362         struct alc_spec *spec;
19363         int err, board_config;
19364         int coef;
19365
19366         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
19367         if (!spec)
19368                 return -ENOMEM;
19369
19370         codec->spec = spec;
19371
19372         spec->mixer_nid = 0x0b;
19373
19374         alc_auto_parse_customize_define(codec);
19375
19376         alc_fix_pll_init(codec, 0x20, 0x04, 15);
19377
19378         coef = alc_read_coef_idx(codec, 0);
19379         if (coef == 0x8020 || coef == 0x8011)
19380                 alc_codec_rename(codec, "ALC661");
19381         else if (coef & (1 << 14) &&
19382                 codec->bus->pci->subsystem_vendor == 0x1025 &&
19383                 spec->cdefine.platform_type == 1)
19384                 alc_codec_rename(codec, "ALC272X");
19385         else if (coef == 0x4011)
19386                 alc_codec_rename(codec, "ALC656");
19387
19388         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
19389                                                   alc662_models,
19390                                                   alc662_cfg_tbl);
19391         if (board_config < 0) {
19392                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
19393                        codec->chip_name);
19394                 board_config = ALC662_AUTO;
19395         }
19396
19397         if (board_config == ALC662_AUTO) {
19398                 alc_pick_fixup(codec, alc662_fixup_models,
19399                                alc662_fixup_tbl, alc662_fixups);
19400                 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
19401                 /* automatic parse from the BIOS config */
19402                 err = alc662_parse_auto_config(codec);
19403                 if (err < 0) {
19404                         alc_free(codec);
19405                         return err;
19406                 } else if (!err) {
19407                         printk(KERN_INFO
19408                                "hda_codec: Cannot set up configuration "
19409                                "from BIOS.  Using base mode...\n");
19410                         board_config = ALC662_3ST_2ch_DIG;
19411                 }
19412         }
19413
19414         if (has_cdefine_beep(codec)) {
19415                 err = snd_hda_attach_beep_device(codec, 0x1);
19416                 if (err < 0) {
19417                         alc_free(codec);
19418                         return err;
19419                 }
19420         }
19421
19422         if (board_config != ALC662_AUTO)
19423                 setup_preset(codec, &alc662_presets[board_config]);
19424
19425         spec->stream_analog_playback = &alc662_pcm_analog_playback;
19426         spec->stream_analog_capture = &alc662_pcm_analog_capture;
19427
19428         spec->stream_digital_playback = &alc662_pcm_digital_playback;
19429         spec->stream_digital_capture = &alc662_pcm_digital_capture;
19430
19431         if (!spec->adc_nids) {
19432                 spec->adc_nids = alc662_adc_nids;
19433                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
19434         }
19435         if (!spec->capsrc_nids)
19436                 spec->capsrc_nids = alc662_capsrc_nids;
19437
19438         if (!spec->cap_mixer)
19439                 set_capture_mixer(codec);
19440
19441         if (has_cdefine_beep(codec)) {
19442                 switch (codec->vendor_id) {
19443                 case 0x10ec0662:
19444                         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
19445                         break;
19446                 case 0x10ec0272:
19447                 case 0x10ec0663:
19448                 case 0x10ec0665:
19449                         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
19450                         break;
19451                 case 0x10ec0273:
19452                         set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
19453                         break;
19454                 }
19455         }
19456         spec->vmaster_nid = 0x02;
19457
19458         alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
19459
19460         codec->patch_ops = alc_patch_ops;
19461         if (board_config == ALC662_AUTO)
19462                 spec->init_hook = alc662_auto_init;
19463         spec->shutup = alc_eapd_shutup;
19464
19465         alc_init_jacks(codec);
19466
19467 #ifdef CONFIG_SND_HDA_POWER_SAVE
19468         if (!spec->loopback.amplist)
19469                 spec->loopback.amplist = alc662_loopbacks;
19470 #endif
19471
19472         return 0;
19473 }
19474
19475 static int patch_alc888(struct hda_codec *codec)
19476 {
19477         if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
19478                 kfree(codec->chip_name);
19479                 if (codec->vendor_id == 0x10ec0887)
19480                         codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
19481                 else
19482                         codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
19483                 if (!codec->chip_name) {
19484                         alc_free(codec);
19485                         return -ENOMEM;
19486                 }
19487                 return patch_alc662(codec);
19488         }
19489         return patch_alc882(codec);
19490 }
19491
19492 static int patch_alc899(struct hda_codec *codec)
19493 {
19494         if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
19495                 kfree(codec->chip_name);
19496                 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
19497         }
19498         return patch_alc882(codec);
19499 }
19500
19501 /*
19502  * ALC680 support
19503  */
19504 #define ALC680_DIGIN_NID        ALC880_DIGIN_NID
19505 #define ALC680_DIGOUT_NID       ALC880_DIGOUT_NID
19506 #define alc680_modes            alc260_modes
19507
19508 static const hda_nid_t alc680_dac_nids[3] = {
19509         /* Lout1, Lout2, hp */
19510         0x02, 0x03, 0x04
19511 };
19512
19513 static const hda_nid_t alc680_adc_nids[3] = {
19514         /* ADC0-2 */
19515         /* DMIC, MIC, Line-in*/
19516         0x07, 0x08, 0x09
19517 };
19518
19519 /*
19520  * Analog capture ADC cgange
19521  */
19522 static void alc680_rec_autoswitch(struct hda_codec *codec)
19523 {
19524         struct alc_spec *spec = codec->spec;
19525         struct auto_pin_cfg *cfg = &spec->autocfg;
19526         int pin_found = 0;
19527         int type_found = AUTO_PIN_LAST;
19528         hda_nid_t nid;
19529         int i;
19530
19531         for (i = 0; i < cfg->num_inputs; i++) {
19532                 nid = cfg->inputs[i].pin;
19533                 if (!is_jack_detectable(codec, nid))
19534                         continue;
19535                 if (snd_hda_jack_detect(codec, nid)) {
19536                         if (cfg->inputs[i].type < type_found) {
19537                                 type_found = cfg->inputs[i].type;
19538                                 pin_found = nid;
19539                         }
19540                 }
19541         }
19542
19543         nid = 0x07;
19544         if (pin_found)
19545                 snd_hda_get_connections(codec, pin_found, &nid, 1);
19546
19547         if (nid != spec->cur_adc)
19548                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
19549         spec->cur_adc = nid;
19550         snd_hda_codec_setup_stream(codec, nid, spec->cur_adc_stream_tag, 0,
19551                                    spec->cur_adc_format);
19552 }
19553
19554 static int alc680_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
19555                                       struct hda_codec *codec,
19556                                       unsigned int stream_tag,
19557                                       unsigned int format,
19558                                       struct snd_pcm_substream *substream)
19559 {
19560         struct alc_spec *spec = codec->spec;
19561
19562         spec->cur_adc = 0x07;
19563         spec->cur_adc_stream_tag = stream_tag;
19564         spec->cur_adc_format = format;
19565
19566         alc680_rec_autoswitch(codec);
19567         return 0;
19568 }
19569
19570 static int alc680_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
19571                                       struct hda_codec *codec,
19572                                       struct snd_pcm_substream *substream)
19573 {
19574         snd_hda_codec_cleanup_stream(codec, 0x07);
19575         snd_hda_codec_cleanup_stream(codec, 0x08);
19576         snd_hda_codec_cleanup_stream(codec, 0x09);
19577         return 0;
19578 }
19579
19580 static const struct hda_pcm_stream alc680_pcm_analog_auto_capture = {
19581         .substreams = 1, /* can be overridden */
19582         .channels_min = 2,
19583         .channels_max = 2,
19584         /* NID is set in alc_build_pcms */
19585         .ops = {
19586                 .prepare = alc680_capture_pcm_prepare,
19587                 .cleanup = alc680_capture_pcm_cleanup
19588         },
19589 };
19590
19591 static const struct snd_kcontrol_new alc680_base_mixer[] = {
19592         /* output mixer control */
19593         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
19594         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
19595         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x4, 0x0, HDA_OUTPUT),
19596         HDA_CODEC_MUTE("Headphone Playback Switch", 0x16, 0x0, HDA_OUTPUT),
19597         HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x12, 0, HDA_INPUT),
19598         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
19599         HDA_CODEC_VOLUME("Line In Boost Volume", 0x19, 0, HDA_INPUT),
19600         { }
19601 };
19602
19603 static const struct hda_bind_ctls alc680_bind_cap_vol = {
19604         .ops = &snd_hda_bind_vol,
19605         .values = {
19606                 HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
19607                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
19608                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
19609                 0
19610         },
19611 };
19612
19613 static const struct hda_bind_ctls alc680_bind_cap_switch = {
19614         .ops = &snd_hda_bind_sw,
19615         .values = {
19616                 HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
19617                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
19618                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
19619                 0
19620         },
19621 };
19622
19623 static const struct snd_kcontrol_new alc680_master_capture_mixer[] = {
19624         HDA_BIND_VOL("Capture Volume", &alc680_bind_cap_vol),
19625         HDA_BIND_SW("Capture Switch", &alc680_bind_cap_switch),
19626         { } /* end */
19627 };
19628
19629 /*
19630  * generic initialization of ADC, input mixers and output mixers
19631  */
19632 static const struct hda_verb alc680_init_verbs[] = {
19633         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
19634         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
19635         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
19636
19637         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
19638         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
19639         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
19640         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
19641         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
19642         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
19643
19644         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19645         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19646         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19647         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19648         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
19649
19650         {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT   | AC_USRSP_EN},
19651         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT  | AC_USRSP_EN},
19652         {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT  | AC_USRSP_EN},
19653
19654         { }
19655 };
19656
19657 /* toggle speaker-output according to the hp-jack state */
19658 static void alc680_base_setup(struct hda_codec *codec)
19659 {
19660         struct alc_spec *spec = codec->spec;
19661
19662         spec->autocfg.hp_pins[0] = 0x16;
19663         spec->autocfg.speaker_pins[0] = 0x14;
19664         spec->autocfg.speaker_pins[1] = 0x15;
19665         spec->autocfg.num_inputs = 2;
19666         spec->autocfg.inputs[0].pin = 0x18;
19667         spec->autocfg.inputs[0].type = AUTO_PIN_MIC;
19668         spec->autocfg.inputs[1].pin = 0x19;
19669         spec->autocfg.inputs[1].type = AUTO_PIN_LINE_IN;
19670         spec->automute = 1;
19671         spec->automute_mode = ALC_AUTOMUTE_AMP;
19672 }
19673
19674 static void alc680_unsol_event(struct hda_codec *codec,
19675                                            unsigned int res)
19676 {
19677         if ((res >> 26) == ALC880_HP_EVENT)
19678                 alc_hp_automute(codec);
19679         if ((res >> 26) == ALC880_MIC_EVENT)
19680                 alc680_rec_autoswitch(codec);
19681 }
19682
19683 static void alc680_inithook(struct hda_codec *codec)
19684 {
19685         alc_hp_automute(codec);
19686         alc680_rec_autoswitch(codec);
19687 }
19688
19689 /* create input playback/capture controls for the given pin */
19690 static int alc680_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
19691                                     const char *ctlname, int idx)
19692 {
19693         hda_nid_t dac;
19694         int err;
19695
19696         switch (nid) {
19697         case 0x14:
19698                 dac = 0x02;
19699                 break;
19700         case 0x15:
19701                 dac = 0x03;
19702                 break;
19703         case 0x16:
19704                 dac = 0x04;
19705                 break;
19706         default:
19707                 return 0;
19708         }
19709         if (spec->multiout.dac_nids[0] != dac &&
19710             spec->multiout.dac_nids[1] != dac) {
19711                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
19712                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
19713                                                       HDA_OUTPUT));
19714                 if (err < 0)
19715                         return err;
19716
19717                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
19718                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
19719
19720                 if (err < 0)
19721                         return err;
19722                 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
19723         }
19724
19725         return 0;
19726 }
19727
19728 /* add playback controls from the parsed DAC table */
19729 static int alc680_auto_create_multi_out_ctls(struct alc_spec *spec,
19730                                              const struct auto_pin_cfg *cfg)
19731 {
19732         hda_nid_t nid;
19733         int err;
19734
19735         spec->multiout.dac_nids = spec->private_dac_nids;
19736
19737         nid = cfg->line_out_pins[0];
19738         if (nid) {
19739                 const char *name;
19740                 int index;
19741                 name = alc_get_line_out_pfx(spec, 0, true, &index);
19742                 err = alc680_new_analog_output(spec, nid, name, 0);
19743                 if (err < 0)
19744                         return err;
19745         }
19746
19747         nid = cfg->speaker_pins[0];
19748         if (nid) {
19749                 err = alc680_new_analog_output(spec, nid, "Speaker", 0);
19750                 if (err < 0)
19751                         return err;
19752         }
19753         nid = cfg->hp_pins[0];
19754         if (nid) {
19755                 err = alc680_new_analog_output(spec, nid, "Headphone", 0);
19756                 if (err < 0)
19757                         return err;
19758         }
19759
19760         return 0;
19761 }
19762
19763 static void alc680_auto_set_output_and_unmute(struct hda_codec *codec,
19764                                               hda_nid_t nid, int pin_type)
19765 {
19766         alc_set_pin_output(codec, nid, pin_type);
19767 }
19768
19769 static void alc680_auto_init_multi_out(struct hda_codec *codec)
19770 {
19771         struct alc_spec *spec = codec->spec;
19772         hda_nid_t nid = spec->autocfg.line_out_pins[0];
19773         if (nid) {
19774                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
19775                 alc680_auto_set_output_and_unmute(codec, nid, pin_type);
19776         }
19777 }
19778
19779 static void alc680_auto_init_hp_out(struct hda_codec *codec)
19780 {
19781         struct alc_spec *spec = codec->spec;
19782         hda_nid_t pin;
19783
19784         pin = spec->autocfg.hp_pins[0];
19785         if (pin)
19786                 alc680_auto_set_output_and_unmute(codec, pin, PIN_HP);
19787         pin = spec->autocfg.speaker_pins[0];
19788         if (pin)
19789                 alc680_auto_set_output_and_unmute(codec, pin, PIN_OUT);
19790 }
19791
19792 /* pcm configuration: identical with ALC880 */
19793 #define alc680_pcm_analog_playback      alc880_pcm_analog_playback
19794 #define alc680_pcm_analog_capture       alc880_pcm_analog_capture
19795 #define alc680_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
19796 #define alc680_pcm_digital_playback     alc880_pcm_digital_playback
19797 #define alc680_pcm_digital_capture      alc880_pcm_digital_capture
19798
19799 /*
19800  * BIOS auto configuration
19801  */
19802 static int alc680_parse_auto_config(struct hda_codec *codec)
19803 {
19804         struct alc_spec *spec = codec->spec;
19805         int err;
19806         static const hda_nid_t alc680_ignore[] = { 0 };
19807
19808         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
19809                                            alc680_ignore);
19810         if (err < 0)
19811                 return err;
19812
19813         if (!spec->autocfg.line_outs) {
19814                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
19815                         spec->multiout.max_channels = 2;
19816                         spec->no_analog = 1;
19817                         goto dig_only;
19818                 }
19819                 return 0; /* can't find valid BIOS pin config */
19820         }
19821         err = alc680_auto_create_multi_out_ctls(spec, &spec->autocfg);
19822         if (err < 0)
19823                 return err;
19824
19825         spec->multiout.max_channels = 2;
19826
19827  dig_only:
19828         /* digital only support output */
19829         alc_auto_parse_digital(codec);
19830         if (spec->kctls.list)
19831                 add_mixer(spec, spec->kctls.list);
19832
19833         err = alc_auto_add_mic_boost(codec);
19834         if (err < 0)
19835                 return err;
19836
19837         return 1;
19838 }
19839
19840 #define alc680_auto_init_analog_input   alc882_auto_init_analog_input
19841
19842 /* init callback for auto-configuration model -- overriding the default init */
19843 static void alc680_auto_init(struct hda_codec *codec)
19844 {
19845         struct alc_spec *spec = codec->spec;
19846         alc680_auto_init_multi_out(codec);
19847         alc680_auto_init_hp_out(codec);
19848         alc680_auto_init_analog_input(codec);
19849         alc_auto_init_digital(codec);
19850         if (spec->unsol_event)
19851                 alc_inithook(codec);
19852 }
19853
19854 /*
19855  * configuration and preset
19856  */
19857 static const char * const alc680_models[ALC680_MODEL_LAST] = {
19858         [ALC680_BASE]           = "base",
19859         [ALC680_AUTO]           = "auto",
19860 };
19861
19862 static const struct snd_pci_quirk alc680_cfg_tbl[] = {
19863         SND_PCI_QUIRK(0x1043, 0x12f3, "ASUS NX90", ALC680_BASE),
19864         {}
19865 };
19866
19867 static const struct alc_config_preset alc680_presets[] = {
19868         [ALC680_BASE] = {
19869                 .mixers = { alc680_base_mixer },
19870                 .cap_mixer =  alc680_master_capture_mixer,
19871                 .init_verbs = { alc680_init_verbs },
19872                 .num_dacs = ARRAY_SIZE(alc680_dac_nids),
19873                 .dac_nids = alc680_dac_nids,
19874                 .dig_out_nid = ALC680_DIGOUT_NID,
19875                 .num_channel_mode = ARRAY_SIZE(alc680_modes),
19876                 .channel_mode = alc680_modes,
19877                 .unsol_event = alc680_unsol_event,
19878                 .setup = alc680_base_setup,
19879                 .init_hook = alc680_inithook,
19880
19881         },
19882 };
19883
19884 static int patch_alc680(struct hda_codec *codec)
19885 {
19886         struct alc_spec *spec;
19887         int board_config;
19888         int err;
19889
19890         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
19891         if (spec == NULL)
19892                 return -ENOMEM;
19893
19894         codec->spec = spec;
19895
19896         /* ALC680 has no aa-loopback mixer */
19897
19898         board_config = snd_hda_check_board_config(codec, ALC680_MODEL_LAST,
19899                                                   alc680_models,
19900                                                   alc680_cfg_tbl);
19901
19902         if (board_config < 0 || board_config >= ALC680_MODEL_LAST) {
19903                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
19904                        codec->chip_name);
19905                 board_config = ALC680_AUTO;
19906         }
19907
19908         if (board_config == ALC680_AUTO) {
19909                 /* automatic parse from the BIOS config */
19910                 err = alc680_parse_auto_config(codec);
19911                 if (err < 0) {
19912                         alc_free(codec);
19913                         return err;
19914                 } else if (!err) {
19915                         printk(KERN_INFO
19916                                "hda_codec: Cannot set up configuration "
19917                                "from BIOS.  Using base mode...\n");
19918                         board_config = ALC680_BASE;
19919                 }
19920         }
19921
19922         if (board_config != ALC680_AUTO)
19923                 setup_preset(codec, &alc680_presets[board_config]);
19924
19925         spec->stream_analog_playback = &alc680_pcm_analog_playback;
19926         spec->stream_analog_capture = &alc680_pcm_analog_auto_capture;
19927         spec->stream_digital_playback = &alc680_pcm_digital_playback;
19928         spec->stream_digital_capture = &alc680_pcm_digital_capture;
19929
19930         if (!spec->adc_nids) {
19931                 spec->adc_nids = alc680_adc_nids;
19932                 spec->num_adc_nids = ARRAY_SIZE(alc680_adc_nids);
19933         }
19934
19935         if (!spec->cap_mixer)
19936                 set_capture_mixer(codec);
19937
19938         spec->vmaster_nid = 0x02;
19939
19940         codec->patch_ops = alc_patch_ops;
19941         if (board_config == ALC680_AUTO)
19942                 spec->init_hook = alc680_auto_init;
19943
19944         return 0;
19945 }
19946
19947 /*
19948  * patch entries
19949  */
19950 static const struct hda_codec_preset snd_hda_preset_realtek[] = {
19951         { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
19952         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
19953         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
19954         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
19955         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
19956         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
19957         { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
19958         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
19959         { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
19960         { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
19961         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
19962           .patch = patch_alc861 },
19963         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
19964         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
19965         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
19966         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
19967           .patch = patch_alc882 },
19968         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
19969           .patch = patch_alc662 },
19970         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
19971         { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
19972         { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
19973         { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
19974         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
19975         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
19976         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
19977         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
19978           .patch = patch_alc882 },
19979         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
19980           .patch = patch_alc882 },
19981         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
19982         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
19983         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
19984           .patch = patch_alc882 },
19985         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
19986         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
19987         { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
19988         { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
19989         {} /* terminator */
19990 };
19991
19992 MODULE_ALIAS("snd-hda-codec-id:10ec*");
19993
19994 MODULE_LICENSE("GPL");
19995 MODULE_DESCRIPTION("Realtek HD-audio codec");
19996
19997 static struct hda_codec_preset_list realtek_list = {
19998         .preset = snd_hda_preset_realtek,
19999         .owner = THIS_MODULE,
20000 };
20001
20002 static int __init patch_realtek_init(void)
20003 {
20004         return snd_hda_add_codec_preset(&realtek_list);
20005 }
20006
20007 static void __exit patch_realtek_exit(void)
20008 {
20009         snd_hda_delete_codec_preset(&realtek_list);
20010 }
20011
20012 module_init(patch_realtek_init)
20013 module_exit(patch_realtek_exit)