Merge branch 'fix/hda' into topic/hda
[sfrench/cifs-2.6.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 "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_TARGA_8ch_DIG,
218         ALC883_ACER,
219         ALC883_ACER_ASPIRE,
220         ALC888_ACER_ASPIRE_4930G,
221         ALC888_ACER_ASPIRE_6530G,
222         ALC888_ACER_ASPIRE_8930G,
223         ALC888_ACER_ASPIRE_7730G,
224         ALC883_MEDION,
225         ALC883_MEDION_MD2,
226         ALC883_LAPTOP_EAPD,
227         ALC883_LENOVO_101E_2ch,
228         ALC883_LENOVO_NB0763,
229         ALC888_LENOVO_MS7195_DIG,
230         ALC888_LENOVO_SKY,
231         ALC883_HAIER_W66,
232         ALC888_3ST_HP,
233         ALC888_6ST_DELL,
234         ALC883_MITAC,
235         ALC883_CLEVO_M540R,
236         ALC883_CLEVO_M720,
237         ALC883_FUJITSU_PI2515,
238         ALC888_FUJITSU_XA3530,
239         ALC883_3ST_6ch_INTEL,
240         ALC889A_INTEL,
241         ALC889_INTEL,
242         ALC888_ASUS_M90V,
243         ALC888_ASUS_EEE1601,
244         ALC889A_MB31,
245         ALC1200_ASUS_P5Q,
246         ALC883_SONY_VAIO_TT,
247         ALC882_AUTO,
248         ALC882_MODEL_LAST,
249 };
250
251 /* for GPIO Poll */
252 #define GPIO_MASK       0x03
253
254 /* extra amp-initialization sequence types */
255 enum {
256         ALC_INIT_NONE,
257         ALC_INIT_DEFAULT,
258         ALC_INIT_GPIO1,
259         ALC_INIT_GPIO2,
260         ALC_INIT_GPIO3,
261 };
262
263 struct alc_mic_route {
264         hda_nid_t pin;
265         unsigned char mux_idx;
266         unsigned char amix_idx;
267 };
268
269 #define MUX_IDX_UNDEF   ((unsigned char)-1)
270
271 struct alc_spec {
272         /* codec parameterization */
273         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
274         unsigned int num_mixers;
275         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
276         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
277
278         const struct hda_verb *init_verbs[10];  /* initialization verbs
279                                                  * don't forget NULL
280                                                  * termination!
281                                                  */
282         unsigned int num_init_verbs;
283
284         char stream_name_analog[32];    /* analog PCM stream */
285         struct hda_pcm_stream *stream_analog_playback;
286         struct hda_pcm_stream *stream_analog_capture;
287         struct hda_pcm_stream *stream_analog_alt_playback;
288         struct hda_pcm_stream *stream_analog_alt_capture;
289
290         char stream_name_digital[32];   /* digital PCM stream */
291         struct hda_pcm_stream *stream_digital_playback;
292         struct hda_pcm_stream *stream_digital_capture;
293
294         /* playback */
295         struct hda_multi_out multiout;  /* playback set-up
296                                          * max_channels, dacs must be set
297                                          * dig_out_nid and hp_nid are optional
298                                          */
299         hda_nid_t alt_dac_nid;
300         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
301         int dig_out_type;
302
303         /* capture */
304         unsigned int num_adc_nids;
305         hda_nid_t *adc_nids;
306         hda_nid_t *capsrc_nids;
307         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
308
309         /* capture source */
310         unsigned int num_mux_defs;
311         const struct hda_input_mux *input_mux;
312         unsigned int cur_mux[3];
313         struct alc_mic_route ext_mic;
314         struct alc_mic_route int_mic;
315
316         /* channel model */
317         const struct hda_channel_mode *channel_mode;
318         int num_channel_mode;
319         int need_dac_fix;
320         int const_channel_count;
321         int ext_channel_count;
322
323         /* PCM information */
324         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
325
326         /* dynamic controls, init_verbs and input_mux */
327         struct auto_pin_cfg autocfg;
328         struct snd_array kctls;
329         struct hda_input_mux private_imux[3];
330         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
331         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
332         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
333
334         /* hooks */
335         void (*init_hook)(struct hda_codec *codec);
336         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
337
338         /* for pin sensing */
339         unsigned int sense_updated: 1;
340         unsigned int jack_present: 1;
341         unsigned int master_sw: 1;
342         unsigned int auto_mic:1;
343
344         /* other flags */
345         unsigned int no_analog :1; /* digital I/O only */
346         int init_amp;
347
348         /* for virtual master */
349         hda_nid_t vmaster_nid;
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_loopback_check loopback;
352 #endif
353
354         /* for PLL fix */
355         hda_nid_t pll_nid;
356         unsigned int pll_coef_idx, pll_coef_bit;
357 };
358
359 /*
360  * configuration template - to be copied to the spec instance
361  */
362 struct alc_config_preset {
363         struct snd_kcontrol_new *mixers[5]; /* should be identical size
364                                              * with spec
365                                              */
366         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
367         const struct hda_verb *init_verbs[5];
368         unsigned int num_dacs;
369         hda_nid_t *dac_nids;
370         hda_nid_t dig_out_nid;          /* optional */
371         hda_nid_t hp_nid;               /* optional */
372         hda_nid_t *slave_dig_outs;
373         unsigned int num_adc_nids;
374         hda_nid_t *adc_nids;
375         hda_nid_t *capsrc_nids;
376         hda_nid_t dig_in_nid;
377         unsigned int num_channel_mode;
378         const struct hda_channel_mode *channel_mode;
379         int need_dac_fix;
380         int const_channel_count;
381         unsigned int num_mux_defs;
382         const struct hda_input_mux *input_mux;
383         void (*unsol_event)(struct hda_codec *, unsigned int);
384         void (*setup)(struct hda_codec *);
385         void (*init_hook)(struct hda_codec *);
386 #ifdef CONFIG_SND_HDA_POWER_SAVE
387         struct hda_amp_list *loopbacks;
388 #endif
389 };
390
391
392 /*
393  * input MUX handling
394  */
395 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
396                              struct snd_ctl_elem_info *uinfo)
397 {
398         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399         struct alc_spec *spec = codec->spec;
400         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
401         if (mux_idx >= spec->num_mux_defs)
402                 mux_idx = 0;
403         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
404 }
405
406 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
407                             struct snd_ctl_elem_value *ucontrol)
408 {
409         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410         struct alc_spec *spec = codec->spec;
411         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412
413         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
414         return 0;
415 }
416
417 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
418                             struct snd_ctl_elem_value *ucontrol)
419 {
420         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
421         struct alc_spec *spec = codec->spec;
422         const struct hda_input_mux *imux;
423         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
424         unsigned int mux_idx;
425         hda_nid_t nid = spec->capsrc_nids ?
426                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
427         unsigned int type;
428
429         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
430         imux = &spec->input_mux[mux_idx];
431
432         type = get_wcaps_type(get_wcaps(codec, nid));
433         if (type == AC_WID_AUD_MIX) {
434                 /* Matrix-mixer style (e.g. ALC882) */
435                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
436                 unsigned int i, idx;
437
438                 idx = ucontrol->value.enumerated.item[0];
439                 if (idx >= imux->num_items)
440                         idx = imux->num_items - 1;
441                 if (*cur_val == idx)
442                         return 0;
443                 for (i = 0; i < imux->num_items; i++) {
444                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
445                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
446                                                  imux->items[i].index,
447                                                  HDA_AMP_MUTE, v);
448                 }
449                 *cur_val = idx;
450                 return 1;
451         } else {
452                 /* MUX style (e.g. ALC880) */
453                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
454                                              &spec->cur_mux[adc_idx]);
455         }
456 }
457
458 /*
459  * channel mode setting
460  */
461 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
462                             struct snd_ctl_elem_info *uinfo)
463 {
464         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465         struct alc_spec *spec = codec->spec;
466         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
467                                     spec->num_channel_mode);
468 }
469
470 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
471                            struct snd_ctl_elem_value *ucontrol)
472 {
473         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474         struct alc_spec *spec = codec->spec;
475         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
476                                    spec->num_channel_mode,
477                                    spec->ext_channel_count);
478 }
479
480 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
481                            struct snd_ctl_elem_value *ucontrol)
482 {
483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
484         struct alc_spec *spec = codec->spec;
485         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
486                                       spec->num_channel_mode,
487                                       &spec->ext_channel_count);
488         if (err >= 0 && !spec->const_channel_count) {
489                 spec->multiout.max_channels = spec->ext_channel_count;
490                 if (spec->need_dac_fix)
491                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
492         }
493         return err;
494 }
495
496 /*
497  * Control the mode of pin widget settings via the mixer.  "pc" is used
498  * instead of "%" to avoid consequences of accidently treating the % as
499  * being part of a format specifier.  Maximum allowed length of a value is
500  * 63 characters plus NULL terminator.
501  *
502  * Note: some retasking pin complexes seem to ignore requests for input
503  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
504  * are requested.  Therefore order this list so that this behaviour will not
505  * cause problems when mixer clients move through the enum sequentially.
506  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
507  * March 2006.
508  */
509 static char *alc_pin_mode_names[] = {
510         "Mic 50pc bias", "Mic 80pc bias",
511         "Line in", "Line out", "Headphone out",
512 };
513 static unsigned char alc_pin_mode_values[] = {
514         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
515 };
516 /* The control can present all 5 options, or it can limit the options based
517  * in the pin being assumed to be exclusively an input or an output pin.  In
518  * addition, "input" pins may or may not process the mic bias option
519  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
520  * accept requests for bias as of chip versions up to March 2006) and/or
521  * wiring in the computer.
522  */
523 #define ALC_PIN_DIR_IN              0x00
524 #define ALC_PIN_DIR_OUT             0x01
525 #define ALC_PIN_DIR_INOUT           0x02
526 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
527 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
528
529 /* Info about the pin modes supported by the different pin direction modes.
530  * For each direction the minimum and maximum values are given.
531  */
532 static signed char alc_pin_mode_dir_info[5][2] = {
533         { 0, 2 },    /* ALC_PIN_DIR_IN */
534         { 3, 4 },    /* ALC_PIN_DIR_OUT */
535         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
536         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
537         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
538 };
539 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
540 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
541 #define alc_pin_mode_n_items(_dir) \
542         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
543
544 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
545                              struct snd_ctl_elem_info *uinfo)
546 {
547         unsigned int item_num = uinfo->value.enumerated.item;
548         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
549
550         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
551         uinfo->count = 1;
552         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
553
554         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
555                 item_num = alc_pin_mode_min(dir);
556         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
557         return 0;
558 }
559
560 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
561                             struct snd_ctl_elem_value *ucontrol)
562 {
563         unsigned int i;
564         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565         hda_nid_t nid = kcontrol->private_value & 0xffff;
566         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
567         long *valp = ucontrol->value.integer.value;
568         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
569                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
570                                                  0x00);
571
572         /* Find enumerated value for current pinctl setting */
573         i = alc_pin_mode_min(dir);
574         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
575                 i++;
576         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
577         return 0;
578 }
579
580 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
581                             struct snd_ctl_elem_value *ucontrol)
582 {
583         signed int change;
584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585         hda_nid_t nid = kcontrol->private_value & 0xffff;
586         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
587         long val = *ucontrol->value.integer.value;
588         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
589                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
590                                                  0x00);
591
592         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
593                 val = alc_pin_mode_min(dir);
594
595         change = pinctl != alc_pin_mode_values[val];
596         if (change) {
597                 /* Set pin mode to that requested */
598                 snd_hda_codec_write_cache(codec, nid, 0,
599                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
600                                           alc_pin_mode_values[val]);
601
602                 /* Also enable the retasking pin's input/output as required
603                  * for the requested pin mode.  Enum values of 2 or less are
604                  * input modes.
605                  *
606                  * Dynamically switching the input/output buffers probably
607                  * reduces noise slightly (particularly on input) so we'll
608                  * do it.  However, having both input and output buffers
609                  * enabled simultaneously doesn't seem to be problematic if
610                  * this turns out to be necessary in the future.
611                  */
612                 if (val <= 2) {
613                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
614                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
615                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
616                                                  HDA_AMP_MUTE, 0);
617                 } else {
618                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
619                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
620                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
621                                                  HDA_AMP_MUTE, 0);
622                 }
623         }
624         return change;
625 }
626
627 #define ALC_PIN_MODE(xname, nid, dir) \
628         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
629           .info = alc_pin_mode_info, \
630           .get = alc_pin_mode_get, \
631           .put = alc_pin_mode_put, \
632           .private_value = nid | (dir<<16) }
633
634 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
635  * together using a mask with more than one bit set.  This control is
636  * currently used only by the ALC260 test model.  At this stage they are not
637  * needed for any "production" models.
638  */
639 #ifdef CONFIG_SND_DEBUG
640 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
641
642 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
643                              struct snd_ctl_elem_value *ucontrol)
644 {
645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646         hda_nid_t nid = kcontrol->private_value & 0xffff;
647         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
648         long *valp = ucontrol->value.integer.value;
649         unsigned int val = snd_hda_codec_read(codec, nid, 0,
650                                               AC_VERB_GET_GPIO_DATA, 0x00);
651
652         *valp = (val & mask) != 0;
653         return 0;
654 }
655 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
656                              struct snd_ctl_elem_value *ucontrol)
657 {
658         signed int change;
659         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660         hda_nid_t nid = kcontrol->private_value & 0xffff;
661         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
662         long val = *ucontrol->value.integer.value;
663         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
664                                                     AC_VERB_GET_GPIO_DATA,
665                                                     0x00);
666
667         /* Set/unset the masked GPIO bit(s) as needed */
668         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
669         if (val == 0)
670                 gpio_data &= ~mask;
671         else
672                 gpio_data |= mask;
673         snd_hda_codec_write_cache(codec, nid, 0,
674                                   AC_VERB_SET_GPIO_DATA, gpio_data);
675
676         return change;
677 }
678 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
679         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
680           .info = alc_gpio_data_info, \
681           .get = alc_gpio_data_get, \
682           .put = alc_gpio_data_put, \
683           .private_value = nid | (mask<<16) }
684 #endif   /* CONFIG_SND_DEBUG */
685
686 /* A switch control to allow the enabling of the digital IO pins on the
687  * ALC260.  This is incredibly simplistic; the intention of this control is
688  * to provide something in the test model allowing digital outputs to be
689  * identified if present.  If models are found which can utilise these
690  * outputs a more complete mixer control can be devised for those models if
691  * necessary.
692  */
693 #ifdef CONFIG_SND_DEBUG
694 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
695
696 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
697                               struct snd_ctl_elem_value *ucontrol)
698 {
699         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700         hda_nid_t nid = kcontrol->private_value & 0xffff;
701         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
702         long *valp = ucontrol->value.integer.value;
703         unsigned int val = snd_hda_codec_read(codec, nid, 0,
704                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
705
706         *valp = (val & mask) != 0;
707         return 0;
708 }
709 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
710                               struct snd_ctl_elem_value *ucontrol)
711 {
712         signed int change;
713         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714         hda_nid_t nid = kcontrol->private_value & 0xffff;
715         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
716         long val = *ucontrol->value.integer.value;
717         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
718                                                     AC_VERB_GET_DIGI_CONVERT_1,
719                                                     0x00);
720
721         /* Set/unset the masked control bit(s) as needed */
722         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
723         if (val==0)
724                 ctrl_data &= ~mask;
725         else
726                 ctrl_data |= mask;
727         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
728                                   ctrl_data);
729
730         return change;
731 }
732 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
733         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
734           .info = alc_spdif_ctrl_info, \
735           .get = alc_spdif_ctrl_get, \
736           .put = alc_spdif_ctrl_put, \
737           .private_value = nid | (mask<<16) }
738 #endif   /* CONFIG_SND_DEBUG */
739
740 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
741  * Again, this is only used in the ALC26x test models to help identify when
742  * the EAPD line must be asserted for features to work.
743  */
744 #ifdef CONFIG_SND_DEBUG
745 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
746
747 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
748                               struct snd_ctl_elem_value *ucontrol)
749 {
750         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751         hda_nid_t nid = kcontrol->private_value & 0xffff;
752         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
753         long *valp = ucontrol->value.integer.value;
754         unsigned int val = snd_hda_codec_read(codec, nid, 0,
755                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
756
757         *valp = (val & mask) != 0;
758         return 0;
759 }
760
761 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
762                               struct snd_ctl_elem_value *ucontrol)
763 {
764         int change;
765         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766         hda_nid_t nid = kcontrol->private_value & 0xffff;
767         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
768         long val = *ucontrol->value.integer.value;
769         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
770                                                     AC_VERB_GET_EAPD_BTLENABLE,
771                                                     0x00);
772
773         /* Set/unset the masked control bit(s) as needed */
774         change = (!val ? 0 : mask) != (ctrl_data & mask);
775         if (!val)
776                 ctrl_data &= ~mask;
777         else
778                 ctrl_data |= mask;
779         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
780                                   ctrl_data);
781
782         return change;
783 }
784
785 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
786         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
787           .info = alc_eapd_ctrl_info, \
788           .get = alc_eapd_ctrl_get, \
789           .put = alc_eapd_ctrl_put, \
790           .private_value = nid | (mask<<16) }
791 #endif   /* CONFIG_SND_DEBUG */
792
793 /*
794  * set up the input pin config (depending on the given auto-pin type)
795  */
796 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
797                               int auto_pin_type)
798 {
799         unsigned int val = PIN_IN;
800
801         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
802                 unsigned int pincap;
803                 pincap = snd_hda_query_pin_caps(codec, nid);
804                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
805                 if (pincap & AC_PINCAP_VREF_80)
806                         val = PIN_VREF80;
807                 else if (pincap & AC_PINCAP_VREF_50)
808                         val = PIN_VREF50;
809                 else if (pincap & AC_PINCAP_VREF_100)
810                         val = PIN_VREF100;
811                 else if (pincap & AC_PINCAP_VREF_GRD)
812                         val = PIN_VREFGRD;
813         }
814         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
815 }
816
817 /*
818  */
819 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
820 {
821         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
822                 return;
823         spec->mixers[spec->num_mixers++] = mix;
824 }
825
826 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
827 {
828         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
829                 return;
830         spec->init_verbs[spec->num_init_verbs++] = verb;
831 }
832
833 #ifdef CONFIG_PROC_FS
834 /*
835  * hook for proc
836  */
837 static void print_realtek_coef(struct snd_info_buffer *buffer,
838                                struct hda_codec *codec, hda_nid_t nid)
839 {
840         int coeff;
841
842         if (nid != 0x20)
843                 return;
844         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
845         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
846         coeff = snd_hda_codec_read(codec, nid, 0,
847                                    AC_VERB_GET_COEF_INDEX, 0);
848         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
849 }
850 #else
851 #define print_realtek_coef      NULL
852 #endif
853
854 /*
855  * set up from the preset table
856  */
857 static void setup_preset(struct hda_codec *codec,
858                          const struct alc_config_preset *preset)
859 {
860         struct alc_spec *spec = codec->spec;
861         int i;
862
863         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
864                 add_mixer(spec, preset->mixers[i]);
865         spec->cap_mixer = preset->cap_mixer;
866         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
867              i++)
868                 add_verb(spec, preset->init_verbs[i]);
869
870         spec->channel_mode = preset->channel_mode;
871         spec->num_channel_mode = preset->num_channel_mode;
872         spec->need_dac_fix = preset->need_dac_fix;
873         spec->const_channel_count = preset->const_channel_count;
874
875         if (preset->const_channel_count)
876                 spec->multiout.max_channels = preset->const_channel_count;
877         else
878                 spec->multiout.max_channels = spec->channel_mode[0].channels;
879         spec->ext_channel_count = spec->channel_mode[0].channels;
880
881         spec->multiout.num_dacs = preset->num_dacs;
882         spec->multiout.dac_nids = preset->dac_nids;
883         spec->multiout.dig_out_nid = preset->dig_out_nid;
884         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
885         spec->multiout.hp_nid = preset->hp_nid;
886
887         spec->num_mux_defs = preset->num_mux_defs;
888         if (!spec->num_mux_defs)
889                 spec->num_mux_defs = 1;
890         spec->input_mux = preset->input_mux;
891
892         spec->num_adc_nids = preset->num_adc_nids;
893         spec->adc_nids = preset->adc_nids;
894         spec->capsrc_nids = preset->capsrc_nids;
895         spec->dig_in_nid = preset->dig_in_nid;
896
897         spec->unsol_event = preset->unsol_event;
898         spec->init_hook = preset->init_hook;
899 #ifdef CONFIG_SND_HDA_POWER_SAVE
900         spec->loopback.amplist = preset->loopbacks;
901 #endif
902
903         if (preset->setup)
904                 preset->setup(codec);
905 }
906
907 /* Enable GPIO mask and set output */
908 static struct hda_verb alc_gpio1_init_verbs[] = {
909         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
910         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
911         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
912         { }
913 };
914
915 static struct hda_verb alc_gpio2_init_verbs[] = {
916         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
917         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
918         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
919         { }
920 };
921
922 static struct hda_verb alc_gpio3_init_verbs[] = {
923         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
924         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
925         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
926         { }
927 };
928
929 /*
930  * Fix hardware PLL issue
931  * On some codecs, the analog PLL gating control must be off while
932  * the default value is 1.
933  */
934 static void alc_fix_pll(struct hda_codec *codec)
935 {
936         struct alc_spec *spec = codec->spec;
937         unsigned int val;
938
939         if (!spec->pll_nid)
940                 return;
941         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
942                             spec->pll_coef_idx);
943         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
944                                  AC_VERB_GET_PROC_COEF, 0);
945         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
946                             spec->pll_coef_idx);
947         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
948                             val & ~(1 << spec->pll_coef_bit));
949 }
950
951 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
952                              unsigned int coef_idx, unsigned int coef_bit)
953 {
954         struct alc_spec *spec = codec->spec;
955         spec->pll_nid = nid;
956         spec->pll_coef_idx = coef_idx;
957         spec->pll_coef_bit = coef_bit;
958         alc_fix_pll(codec);
959 }
960
961 static void alc_automute_pin(struct hda_codec *codec)
962 {
963         struct alc_spec *spec = codec->spec;
964         unsigned int present, pincap;
965         unsigned int nid = spec->autocfg.hp_pins[0];
966         int i;
967
968         if (!nid)
969                 return;
970         pincap = snd_hda_query_pin_caps(codec, nid);
971         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
972                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
973         present = snd_hda_codec_read(codec, nid, 0,
974                                      AC_VERB_GET_PIN_SENSE, 0);
975         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
976         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
977                 nid = spec->autocfg.speaker_pins[i];
978                 if (!nid)
979                         break;
980                 snd_hda_codec_write(codec, nid, 0,
981                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
982                                     spec->jack_present ? 0 : PIN_OUT);
983         }
984 }
985
986 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
987                                 hda_nid_t nid)
988 {
989         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
990         int i, nums;
991
992         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
993         for (i = 0; i < nums; i++)
994                 if (conn[i] == nid)
995                         return i;
996         return -1;
997 }
998
999 static void alc_mic_automute(struct hda_codec *codec)
1000 {
1001         struct alc_spec *spec = codec->spec;
1002         struct alc_mic_route *dead, *alive;
1003         unsigned int present, type;
1004         hda_nid_t cap_nid;
1005
1006         if (!spec->auto_mic)
1007                 return;
1008         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1009                 return;
1010         if (snd_BUG_ON(!spec->adc_nids))
1011                 return;
1012
1013         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1014
1015         present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
1016                                      AC_VERB_GET_PIN_SENSE, 0);
1017         present &= AC_PINSENSE_PRESENCE;
1018         if (present) {
1019                 alive = &spec->ext_mic;
1020                 dead = &spec->int_mic;
1021         } else {
1022                 alive = &spec->int_mic;
1023                 dead = &spec->ext_mic;
1024         }
1025
1026         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1027         if (type == AC_WID_AUD_MIX) {
1028                 /* Matrix-mixer style (e.g. ALC882) */
1029                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1030                                          alive->mux_idx,
1031                                          HDA_AMP_MUTE, 0);
1032                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1033                                          dead->mux_idx,
1034                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1035         } else {
1036                 /* MUX style (e.g. ALC880) */
1037                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1038                                           AC_VERB_SET_CONNECT_SEL,
1039                                           alive->mux_idx);
1040         }
1041
1042         /* FIXME: analog mixer */
1043 }
1044
1045 /* unsolicited event for HP jack sensing */
1046 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1047 {
1048         if (codec->vendor_id == 0x10ec0880)
1049                 res >>= 28;
1050         else
1051                 res >>= 26;
1052         switch (res) {
1053         case ALC880_HP_EVENT:
1054                 alc_automute_pin(codec);
1055                 break;
1056         case ALC880_MIC_EVENT:
1057                 alc_mic_automute(codec);
1058                 break;
1059         }
1060 }
1061
1062 static void alc_inithook(struct hda_codec *codec)
1063 {
1064         alc_automute_pin(codec);
1065         alc_mic_automute(codec);
1066 }
1067
1068 /* additional initialization for ALC888 variants */
1069 static void alc888_coef_init(struct hda_codec *codec)
1070 {
1071         unsigned int tmp;
1072
1073         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1074         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1075         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1076         if ((tmp & 0xf0) == 0x20)
1077                 /* alc888S-VC */
1078                 snd_hda_codec_read(codec, 0x20, 0,
1079                                    AC_VERB_SET_PROC_COEF, 0x830);
1080          else
1081                  /* alc888-VB */
1082                  snd_hda_codec_read(codec, 0x20, 0,
1083                                     AC_VERB_SET_PROC_COEF, 0x3030);
1084 }
1085
1086 static void alc889_coef_init(struct hda_codec *codec)
1087 {
1088         unsigned int tmp;
1089
1090         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1091         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1092         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1093         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1094 }
1095
1096 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1097 {
1098         unsigned int tmp;
1099
1100         switch (type) {
1101         case ALC_INIT_GPIO1:
1102                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1103                 break;
1104         case ALC_INIT_GPIO2:
1105                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1106                 break;
1107         case ALC_INIT_GPIO3:
1108                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1109                 break;
1110         case ALC_INIT_DEFAULT:
1111                 switch (codec->vendor_id) {
1112                 case 0x10ec0260:
1113                         snd_hda_codec_write(codec, 0x0f, 0,
1114                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1115                         snd_hda_codec_write(codec, 0x10, 0,
1116                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1117                         break;
1118                 case 0x10ec0262:
1119                 case 0x10ec0267:
1120                 case 0x10ec0268:
1121                 case 0x10ec0269:
1122                 case 0x10ec0272:
1123                 case 0x10ec0660:
1124                 case 0x10ec0662:
1125                 case 0x10ec0663:
1126                 case 0x10ec0862:
1127                 case 0x10ec0889:
1128                         snd_hda_codec_write(codec, 0x14, 0,
1129                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1130                         snd_hda_codec_write(codec, 0x15, 0,
1131                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1132                         break;
1133                 }
1134                 switch (codec->vendor_id) {
1135                 case 0x10ec0260:
1136                         snd_hda_codec_write(codec, 0x1a, 0,
1137                                             AC_VERB_SET_COEF_INDEX, 7);
1138                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1139                                                  AC_VERB_GET_PROC_COEF, 0);
1140                         snd_hda_codec_write(codec, 0x1a, 0,
1141                                             AC_VERB_SET_COEF_INDEX, 7);
1142                         snd_hda_codec_write(codec, 0x1a, 0,
1143                                             AC_VERB_SET_PROC_COEF,
1144                                             tmp | 0x2010);
1145                         break;
1146                 case 0x10ec0262:
1147                 case 0x10ec0880:
1148                 case 0x10ec0882:
1149                 case 0x10ec0883:
1150                 case 0x10ec0885:
1151                 case 0x10ec0887:
1152                 case 0x10ec0889:
1153                         alc889_coef_init(codec);
1154                         break;
1155                 case 0x10ec0888:
1156                         alc888_coef_init(codec);
1157                         break;
1158                 case 0x10ec0267:
1159                 case 0x10ec0268:
1160                         snd_hda_codec_write(codec, 0x20, 0,
1161                                             AC_VERB_SET_COEF_INDEX, 7);
1162                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1163                                                  AC_VERB_GET_PROC_COEF, 0);
1164                         snd_hda_codec_write(codec, 0x20, 0,
1165                                             AC_VERB_SET_COEF_INDEX, 7);
1166                         snd_hda_codec_write(codec, 0x20, 0,
1167                                             AC_VERB_SET_PROC_COEF,
1168                                             tmp | 0x3000);
1169                         break;
1170                 }
1171                 break;
1172         }
1173 }
1174
1175 static void alc_init_auto_hp(struct hda_codec *codec)
1176 {
1177         struct alc_spec *spec = codec->spec;
1178
1179         if (!spec->autocfg.hp_pins[0])
1180                 return;
1181
1182         if (!spec->autocfg.speaker_pins[0]) {
1183                 if (spec->autocfg.line_out_pins[0] &&
1184                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1185                         spec->autocfg.speaker_pins[0] =
1186                                 spec->autocfg.line_out_pins[0];
1187                 else
1188                         return;
1189         }
1190
1191         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1192                     spec->autocfg.hp_pins[0]);
1193         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1194                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1195                                   AC_USRSP_EN | ALC880_HP_EVENT);
1196         spec->unsol_event = alc_sku_unsol_event;
1197 }
1198
1199 static void alc_init_auto_mic(struct hda_codec *codec)
1200 {
1201         struct alc_spec *spec = codec->spec;
1202         struct auto_pin_cfg *cfg = &spec->autocfg;
1203         hda_nid_t fixed, ext;
1204         int i;
1205
1206         /* there must be only two mic inputs exclusively */
1207         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1208                 if (cfg->input_pins[i])
1209                         return;
1210
1211         fixed = ext = 0;
1212         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1213                 hda_nid_t nid = cfg->input_pins[i];
1214                 unsigned int defcfg;
1215                 if (!nid)
1216                         return;
1217                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1218                 switch (get_defcfg_connect(defcfg)) {
1219                 case AC_JACK_PORT_FIXED:
1220                         if (fixed)
1221                                 return; /* already occupied */
1222                         fixed = nid;
1223                         break;
1224                 case AC_JACK_PORT_COMPLEX:
1225                         if (ext)
1226                                 return; /* already occupied */
1227                         ext = nid;
1228                         break;
1229                 default:
1230                         return; /* invalid entry */
1231                 }
1232         }
1233         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1234                 return; /* no unsol support */
1235         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1236                     ext, fixed);
1237         spec->ext_mic.pin = ext;
1238         spec->int_mic.pin = fixed;
1239         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1240         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1241         spec->auto_mic = 1;
1242         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1243                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1244                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1245         spec->unsol_event = alc_sku_unsol_event;
1246 }
1247
1248 /* check subsystem ID and set up device-specific initialization;
1249  * return 1 if initialized, 0 if invalid SSID
1250  */
1251 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1252  *      31 ~ 16 :       Manufacture ID
1253  *      15 ~ 8  :       SKU ID
1254  *      7  ~ 0  :       Assembly ID
1255  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1256  */
1257 static int alc_subsystem_id(struct hda_codec *codec,
1258                             hda_nid_t porta, hda_nid_t porte,
1259                             hda_nid_t portd)
1260 {
1261         unsigned int ass, tmp, i;
1262         unsigned nid;
1263         struct alc_spec *spec = codec->spec;
1264
1265         ass = codec->subsystem_id & 0xffff;
1266         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1267                 goto do_sku;
1268
1269         /* invalid SSID, check the special NID pin defcfg instead */
1270         /*
1271          * 31~30        : port connectivity
1272          * 29~21        : reserve
1273          * 20           : PCBEEP input
1274          * 19~16        : Check sum (15:1)
1275          * 15~1         : Custom
1276          * 0            : override
1277         */
1278         nid = 0x1d;
1279         if (codec->vendor_id == 0x10ec0260)
1280                 nid = 0x17;
1281         ass = snd_hda_codec_get_pincfg(codec, nid);
1282         snd_printd("realtek: No valid SSID, "
1283                    "checking pincfg 0x%08x for NID 0x%x\n",
1284                    ass, nid);
1285         if (!(ass & 1) && !(ass & 0x100000))
1286                 return 0;
1287         if ((ass >> 30) != 1)   /* no physical connection */
1288                 return 0;
1289
1290         /* check sum */
1291         tmp = 0;
1292         for (i = 1; i < 16; i++) {
1293                 if ((ass >> i) & 1)
1294                         tmp++;
1295         }
1296         if (((ass >> 16) & 0xf) != tmp)
1297                 return 0;
1298 do_sku:
1299         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1300                    ass & 0xffff, codec->vendor_id);
1301         /*
1302          * 0 : override
1303          * 1 :  Swap Jack
1304          * 2 : 0 --> Desktop, 1 --> Laptop
1305          * 3~5 : External Amplifier control
1306          * 7~6 : Reserved
1307         */
1308         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1309         switch (tmp) {
1310         case 1:
1311                 spec->init_amp = ALC_INIT_GPIO1;
1312                 break;
1313         case 3:
1314                 spec->init_amp = ALC_INIT_GPIO2;
1315                 break;
1316         case 7:
1317                 spec->init_amp = ALC_INIT_GPIO3;
1318                 break;
1319         case 5:
1320                 spec->init_amp = ALC_INIT_DEFAULT;
1321                 break;
1322         }
1323
1324         /* is laptop or Desktop and enable the function "Mute internal speaker
1325          * when the external headphone out jack is plugged"
1326          */
1327         if (!(ass & 0x8000))
1328                 return 1;
1329         /*
1330          * 10~8 : Jack location
1331          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1332          * 14~13: Resvered
1333          * 15   : 1 --> enable the function "Mute internal speaker
1334          *              when the external headphone out jack is plugged"
1335          */
1336         if (!spec->autocfg.hp_pins[0]) {
1337                 hda_nid_t nid;
1338                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1339                 if (tmp == 0)
1340                         nid = porta;
1341                 else if (tmp == 1)
1342                         nid = porte;
1343                 else if (tmp == 2)
1344                         nid = portd;
1345                 else
1346                         return 1;
1347                 for (i = 0; i < spec->autocfg.line_outs; i++)
1348                         if (spec->autocfg.line_out_pins[i] == nid)
1349                                 return 1;
1350                 spec->autocfg.hp_pins[0] = nid;
1351         }
1352
1353         alc_init_auto_hp(codec);
1354         alc_init_auto_mic(codec);
1355         return 1;
1356 }
1357
1358 static void alc_ssid_check(struct hda_codec *codec,
1359                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1360 {
1361         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1362                 struct alc_spec *spec = codec->spec;
1363                 snd_printd("realtek: "
1364                            "Enable default setup for auto mode as fallback\n");
1365                 spec->init_amp = ALC_INIT_DEFAULT;
1366                 alc_init_auto_hp(codec);
1367                 alc_init_auto_mic(codec);
1368         }
1369 }
1370
1371 /*
1372  * Fix-up pin default configurations and add default verbs
1373  */
1374
1375 struct alc_pincfg {
1376         hda_nid_t nid;
1377         u32 val;
1378 };
1379
1380 struct alc_fixup {
1381         const struct alc_pincfg *pins;
1382         const struct hda_verb *verbs;
1383 };
1384
1385 static void alc_pick_fixup(struct hda_codec *codec,
1386                            const struct snd_pci_quirk *quirk,
1387                            const struct alc_fixup *fix)
1388 {
1389         const struct alc_pincfg *cfg;
1390
1391         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1392         if (!quirk)
1393                 return;
1394
1395         fix += quirk->value;
1396         cfg = fix->pins;
1397         if (cfg) {
1398                 for (; cfg->nid; cfg++)
1399                         snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1400         }
1401         if (fix->verbs)
1402                 add_verb(codec->spec, fix->verbs);
1403 }
1404
1405 /*
1406  * ALC888
1407  */
1408
1409 /*
1410  * 2ch mode
1411  */
1412 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1413 /* Mic-in jack as mic in */
1414         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1415         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1416 /* Line-in jack as Line in */
1417         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1418         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1419 /* Line-Out as Front */
1420         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1421         { } /* end */
1422 };
1423
1424 /*
1425  * 4ch mode
1426  */
1427 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1428 /* Mic-in jack as mic in */
1429         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1430         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1431 /* Line-in jack as Surround */
1432         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1433         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1434 /* Line-Out as Front */
1435         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1436         { } /* end */
1437 };
1438
1439 /*
1440  * 6ch mode
1441  */
1442 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1443 /* Mic-in jack as CLFE */
1444         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1445         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1446 /* Line-in jack as Surround */
1447         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1448         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1449 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1450         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1451         { } /* end */
1452 };
1453
1454 /*
1455  * 8ch mode
1456  */
1457 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1458 /* Mic-in jack as CLFE */
1459         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1460         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1461 /* Line-in jack as Surround */
1462         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1463         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1464 /* Line-Out as Side */
1465         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1466         { } /* end */
1467 };
1468
1469 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1470         { 2, alc888_4ST_ch2_intel_init },
1471         { 4, alc888_4ST_ch4_intel_init },
1472         { 6, alc888_4ST_ch6_intel_init },
1473         { 8, alc888_4ST_ch8_intel_init },
1474 };
1475
1476 /*
1477  * ALC888 Fujitsu Siemens Amillo xa3530
1478  */
1479
1480 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1481 /* Front Mic: set to PIN_IN (empty by default) */
1482         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1483 /* Connect Internal HP to Front */
1484         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1485         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1486         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1487 /* Connect Bass HP to Front */
1488         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1490         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1491 /* Connect Line-Out side jack (SPDIF) to Side */
1492         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1493         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1494         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1495 /* Connect Mic jack to CLFE */
1496         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1497         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1498         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1499 /* Connect Line-in jack to Surround */
1500         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1502         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1503 /* Connect HP out jack to Front */
1504         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1505         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1506         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1507 /* Enable unsolicited event for HP jack and Line-out jack */
1508         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1509         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1510         {}
1511 };
1512
1513 static void alc_automute_amp(struct hda_codec *codec)
1514 {
1515         struct alc_spec *spec = codec->spec;
1516         unsigned int val, mute, pincap;
1517         hda_nid_t nid;
1518         int i;
1519
1520         spec->jack_present = 0;
1521         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1522                 nid = spec->autocfg.hp_pins[i];
1523                 if (!nid)
1524                         break;
1525                 pincap = snd_hda_query_pin_caps(codec, nid);
1526                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1527                         snd_hda_codec_read(codec, nid, 0,
1528                                            AC_VERB_SET_PIN_SENSE, 0);
1529                 val = snd_hda_codec_read(codec, nid, 0,
1530                                          AC_VERB_GET_PIN_SENSE, 0);
1531                 if (val & AC_PINSENSE_PRESENCE) {
1532                         spec->jack_present = 1;
1533                         break;
1534                 }
1535         }
1536
1537         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1538         /* Toggle internal speakers muting */
1539         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1540                 nid = spec->autocfg.speaker_pins[i];
1541                 if (!nid)
1542                         break;
1543                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1544                                          HDA_AMP_MUTE, mute);
1545         }
1546 }
1547
1548 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1549                                          unsigned int res)
1550 {
1551         if (codec->vendor_id == 0x10ec0880)
1552                 res >>= 28;
1553         else
1554                 res >>= 26;
1555         if (res == ALC880_HP_EVENT)
1556                 alc_automute_amp(codec);
1557 }
1558
1559 static void alc889_automute_setup(struct hda_codec *codec)
1560 {
1561         struct alc_spec *spec = codec->spec;
1562
1563         spec->autocfg.hp_pins[0] = 0x15;
1564         spec->autocfg.speaker_pins[0] = 0x14;
1565         spec->autocfg.speaker_pins[1] = 0x16;
1566         spec->autocfg.speaker_pins[2] = 0x17;
1567         spec->autocfg.speaker_pins[3] = 0x19;
1568         spec->autocfg.speaker_pins[4] = 0x1a;
1569 }
1570
1571 static void alc889_intel_init_hook(struct hda_codec *codec)
1572 {
1573         alc889_coef_init(codec);
1574         alc_automute_amp(codec);
1575 }
1576
1577 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1578 {
1579         struct alc_spec *spec = codec->spec;
1580
1581         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1582         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1583         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1584         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1585 }
1586
1587 /*
1588  * ALC888 Acer Aspire 4930G model
1589  */
1590
1591 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1592 /* Front Mic: set to PIN_IN (empty by default) */
1593         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1594 /* Unselect Front Mic by default in input mixer 3 */
1595         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1596 /* Enable unsolicited event for HP jack */
1597         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1598 /* Connect Internal HP to front */
1599         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1600         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1601         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1602 /* Connect HP out to front */
1603         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1604         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1605         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1606         { }
1607 };
1608
1609 /*
1610  * ALC888 Acer Aspire 6530G model
1611  */
1612
1613 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1614 /* Bias voltage on for external mic port */
1615         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1616 /* Front Mic: set to PIN_IN (empty by default) */
1617         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1618 /* Unselect Front Mic by default in input mixer 3 */
1619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1620 /* Enable unsolicited event for HP jack */
1621         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1622 /* Enable speaker output */
1623         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1624         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1625 /* Enable headphone output */
1626         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1628         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1629         { }
1630 };
1631
1632 /*
1633  * ALC889 Acer Aspire 8930G model
1634  */
1635
1636 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1637 /* Front Mic: set to PIN_IN (empty by default) */
1638         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1639 /* Unselect Front Mic by default in input mixer 3 */
1640         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1641 /* Enable unsolicited event for HP jack */
1642         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1643 /* Connect Internal Front to Front */
1644         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1645         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1646         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1647 /* Connect Internal Rear to Rear */
1648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1650         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1651 /* Connect Internal CLFE to CLFE */
1652         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1653         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1654         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1655 /* Connect HP out to Front */
1656         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1657         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1658         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1659 /* Enable all DACs */
1660 /*  DAC DISABLE/MUTE 1? */
1661 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1662         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1663         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1664 /*  DAC DISABLE/MUTE 2? */
1665 /*  some bit here disables the other DACs. Init=0x4900 */
1666         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1667         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1668 /* Enable amplifiers */
1669         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1670         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1671 /* DMIC fix
1672  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1673  * which makes the stereo useless. However, either the mic or the ALC889
1674  * makes the signal become a difference/sum signal instead of standard
1675  * stereo, which is annoying. So instead we flip this bit which makes the
1676  * codec replicate the sum signal to both channels, turning it into a
1677  * normal mono mic.
1678  */
1679 /*  DMIC_CONTROL? Init value = 0x0001 */
1680         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1681         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1682         { }
1683 };
1684
1685 static struct hda_input_mux alc888_2_capture_sources[2] = {
1686         /* Front mic only available on one ADC */
1687         {
1688                 .num_items = 4,
1689                 .items = {
1690                         { "Mic", 0x0 },
1691                         { "Line", 0x2 },
1692                         { "CD", 0x4 },
1693                         { "Front Mic", 0xb },
1694                 },
1695         },
1696         {
1697                 .num_items = 3,
1698                 .items = {
1699                         { "Mic", 0x0 },
1700                         { "Line", 0x2 },
1701                         { "CD", 0x4 },
1702                 },
1703         }
1704 };
1705
1706 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1707         /* Interal mic only available on one ADC */
1708         {
1709                 .num_items = 5,
1710                 .items = {
1711                         { "Ext Mic", 0x0 },
1712                         { "Line In", 0x2 },
1713                         { "CD", 0x4 },
1714                         { "Input Mix", 0xa },
1715                         { "Int Mic", 0xb },
1716                 },
1717         },
1718         {
1719                 .num_items = 4,
1720                 .items = {
1721                         { "Ext Mic", 0x0 },
1722                         { "Line In", 0x2 },
1723                         { "CD", 0x4 },
1724                         { "Input Mix", 0xa },
1725                 },
1726         }
1727 };
1728
1729 static struct hda_input_mux alc889_capture_sources[3] = {
1730         /* Digital mic only available on first "ADC" */
1731         {
1732                 .num_items = 5,
1733                 .items = {
1734                         { "Mic", 0x0 },
1735                         { "Line", 0x2 },
1736                         { "CD", 0x4 },
1737                         { "Front Mic", 0xb },
1738                         { "Input Mix", 0xa },
1739                 },
1740         },
1741         {
1742                 .num_items = 4,
1743                 .items = {
1744                         { "Mic", 0x0 },
1745                         { "Line", 0x2 },
1746                         { "CD", 0x4 },
1747                         { "Input Mix", 0xa },
1748                 },
1749         },
1750         {
1751                 .num_items = 4,
1752                 .items = {
1753                         { "Mic", 0x0 },
1754                         { "Line", 0x2 },
1755                         { "CD", 0x4 },
1756                         { "Input Mix", 0xa },
1757                 },
1758         }
1759 };
1760
1761 static struct snd_kcontrol_new alc888_base_mixer[] = {
1762         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1763         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1764         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1765         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1766         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1767                 HDA_OUTPUT),
1768         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1769         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1770         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1771         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1772         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1773         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1774         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1775         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1776         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1777         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1778         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1779         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1780         { } /* end */
1781 };
1782
1783 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1784 {
1785         struct alc_spec *spec = codec->spec;
1786
1787         spec->autocfg.hp_pins[0] = 0x15;
1788         spec->autocfg.speaker_pins[0] = 0x14;
1789 }
1790
1791 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1792 {
1793         struct alc_spec *spec = codec->spec;
1794
1795         spec->autocfg.hp_pins[0] = 0x15;
1796         spec->autocfg.speaker_pins[0] = 0x14;
1797         spec->autocfg.speaker_pins[1] = 0x16;
1798         spec->autocfg.speaker_pins[2] = 0x17;
1799 }
1800
1801 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1802 {
1803         struct alc_spec *spec = codec->spec;
1804
1805         spec->autocfg.hp_pins[0] = 0x15;
1806         spec->autocfg.speaker_pins[0] = 0x14;
1807         spec->autocfg.speaker_pins[1] = 0x16;
1808         spec->autocfg.speaker_pins[2] = 0x1b;
1809 }
1810
1811 /*
1812  * ALC880 3-stack model
1813  *
1814  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1815  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1816  *                 F-Mic = 0x1b, HP = 0x19
1817  */
1818
1819 static hda_nid_t alc880_dac_nids[4] = {
1820         /* front, rear, clfe, rear_surr */
1821         0x02, 0x05, 0x04, 0x03
1822 };
1823
1824 static hda_nid_t alc880_adc_nids[3] = {
1825         /* ADC0-2 */
1826         0x07, 0x08, 0x09,
1827 };
1828
1829 /* The datasheet says the node 0x07 is connected from inputs,
1830  * but it shows zero connection in the real implementation on some devices.
1831  * Note: this is a 915GAV bug, fixed on 915GLV
1832  */
1833 static hda_nid_t alc880_adc_nids_alt[2] = {
1834         /* ADC1-2 */
1835         0x08, 0x09,
1836 };
1837
1838 #define ALC880_DIGOUT_NID       0x06
1839 #define ALC880_DIGIN_NID        0x0a
1840
1841 static struct hda_input_mux alc880_capture_source = {
1842         .num_items = 4,
1843         .items = {
1844                 { "Mic", 0x0 },
1845                 { "Front Mic", 0x3 },
1846                 { "Line", 0x2 },
1847                 { "CD", 0x4 },
1848         },
1849 };
1850
1851 /* channel source setting (2/6 channel selection for 3-stack) */
1852 /* 2ch mode */
1853 static struct hda_verb alc880_threestack_ch2_init[] = {
1854         /* set line-in to input, mute it */
1855         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1856         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1857         /* set mic-in to input vref 80%, mute it */
1858         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1859         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1860         { } /* end */
1861 };
1862
1863 /* 6ch mode */
1864 static struct hda_verb alc880_threestack_ch6_init[] = {
1865         /* set line-in to output, unmute it */
1866         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1867         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1868         /* set mic-in to output, unmute it */
1869         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1870         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1871         { } /* end */
1872 };
1873
1874 static struct hda_channel_mode alc880_threestack_modes[2] = {
1875         { 2, alc880_threestack_ch2_init },
1876         { 6, alc880_threestack_ch6_init },
1877 };
1878
1879 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1880         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1881         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1882         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1883         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1884         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1885         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1886         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1887         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1888         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1889         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1890         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1891         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1892         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1893         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1894         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1895         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1897         {
1898                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1899                 .name = "Channel Mode",
1900                 .info = alc_ch_mode_info,
1901                 .get = alc_ch_mode_get,
1902                 .put = alc_ch_mode_put,
1903         },
1904         { } /* end */
1905 };
1906
1907 /* capture mixer elements */
1908 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1909                             struct snd_ctl_elem_info *uinfo)
1910 {
1911         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1912         struct alc_spec *spec = codec->spec;
1913         int err;
1914
1915         mutex_lock(&codec->control_mutex);
1916         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1917                                                       HDA_INPUT);
1918         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1919         mutex_unlock(&codec->control_mutex);
1920         return err;
1921 }
1922
1923 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1924                            unsigned int size, unsigned int __user *tlv)
1925 {
1926         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1927         struct alc_spec *spec = codec->spec;
1928         int err;
1929
1930         mutex_lock(&codec->control_mutex);
1931         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1932                                                       HDA_INPUT);
1933         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1934         mutex_unlock(&codec->control_mutex);
1935         return err;
1936 }
1937
1938 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1939                              struct snd_ctl_elem_value *ucontrol);
1940
1941 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1942                                  struct snd_ctl_elem_value *ucontrol,
1943                                  getput_call_t func)
1944 {
1945         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1946         struct alc_spec *spec = codec->spec;
1947         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1948         int err;
1949
1950         mutex_lock(&codec->control_mutex);
1951         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1952                                                       3, 0, HDA_INPUT);
1953         err = func(kcontrol, ucontrol);
1954         mutex_unlock(&codec->control_mutex);
1955         return err;
1956 }
1957
1958 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1959                            struct snd_ctl_elem_value *ucontrol)
1960 {
1961         return alc_cap_getput_caller(kcontrol, ucontrol,
1962                                      snd_hda_mixer_amp_volume_get);
1963 }
1964
1965 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1966                            struct snd_ctl_elem_value *ucontrol)
1967 {
1968         return alc_cap_getput_caller(kcontrol, ucontrol,
1969                                      snd_hda_mixer_amp_volume_put);
1970 }
1971
1972 /* capture mixer elements */
1973 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1974
1975 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1976                           struct snd_ctl_elem_value *ucontrol)
1977 {
1978         return alc_cap_getput_caller(kcontrol, ucontrol,
1979                                      snd_hda_mixer_amp_switch_get);
1980 }
1981
1982 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1983                           struct snd_ctl_elem_value *ucontrol)
1984 {
1985         return alc_cap_getput_caller(kcontrol, ucontrol,
1986                                      snd_hda_mixer_amp_switch_put);
1987 }
1988
1989 #define _DEFINE_CAPMIX(num) \
1990         { \
1991                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1992                 .name = "Capture Switch", \
1993                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1994                 .count = num, \
1995                 .info = alc_cap_sw_info, \
1996                 .get = alc_cap_sw_get, \
1997                 .put = alc_cap_sw_put, \
1998         }, \
1999         { \
2000                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2001                 .name = "Capture Volume", \
2002                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2003                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2004                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2005                 .count = num, \
2006                 .info = alc_cap_vol_info, \
2007                 .get = alc_cap_vol_get, \
2008                 .put = alc_cap_vol_put, \
2009                 .tlv = { .c = alc_cap_vol_tlv }, \
2010         }
2011
2012 #define _DEFINE_CAPSRC(num) \
2013         { \
2014                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2015                 /* .name = "Capture Source", */ \
2016                 .name = "Input Source", \
2017                 .count = num, \
2018                 .info = alc_mux_enum_info, \
2019                 .get = alc_mux_enum_get, \
2020                 .put = alc_mux_enum_put, \
2021         }
2022
2023 #define DEFINE_CAPMIX(num) \
2024 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2025         _DEFINE_CAPMIX(num),                                  \
2026         _DEFINE_CAPSRC(num),                                  \
2027         { } /* end */                                         \
2028 }
2029
2030 #define DEFINE_CAPMIX_NOSRC(num) \
2031 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2032         _DEFINE_CAPMIX(num),                                        \
2033         { } /* end */                                               \
2034 }
2035
2036 /* up to three ADCs */
2037 DEFINE_CAPMIX(1);
2038 DEFINE_CAPMIX(2);
2039 DEFINE_CAPMIX(3);
2040 DEFINE_CAPMIX_NOSRC(1);
2041 DEFINE_CAPMIX_NOSRC(2);
2042 DEFINE_CAPMIX_NOSRC(3);
2043
2044 /*
2045  * ALC880 5-stack model
2046  *
2047  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2048  *      Side = 0x02 (0xd)
2049  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2050  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2051  */
2052
2053 /* additional mixers to alc880_three_stack_mixer */
2054 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2055         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2056         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2057         { } /* end */
2058 };
2059
2060 /* channel source setting (6/8 channel selection for 5-stack) */
2061 /* 6ch mode */
2062 static struct hda_verb alc880_fivestack_ch6_init[] = {
2063         /* set line-in to input, mute it */
2064         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2065         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2066         { } /* end */
2067 };
2068
2069 /* 8ch mode */
2070 static struct hda_verb alc880_fivestack_ch8_init[] = {
2071         /* set line-in to output, unmute it */
2072         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2073         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2074         { } /* end */
2075 };
2076
2077 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2078         { 6, alc880_fivestack_ch6_init },
2079         { 8, alc880_fivestack_ch8_init },
2080 };
2081
2082
2083 /*
2084  * ALC880 6-stack model
2085  *
2086  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2087  *      Side = 0x05 (0x0f)
2088  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2089  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2090  */
2091
2092 static hda_nid_t alc880_6st_dac_nids[4] = {
2093         /* front, rear, clfe, rear_surr */
2094         0x02, 0x03, 0x04, 0x05
2095 };
2096
2097 static struct hda_input_mux alc880_6stack_capture_source = {
2098         .num_items = 4,
2099         .items = {
2100                 { "Mic", 0x0 },
2101                 { "Front Mic", 0x1 },
2102                 { "Line", 0x2 },
2103                 { "CD", 0x4 },
2104         },
2105 };
2106
2107 /* fixed 8-channels */
2108 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2109         { 8, NULL },
2110 };
2111
2112 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2113         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2114         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2115         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2116         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2117         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2118         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2119         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2120         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2121         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2122         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2123         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2124         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2125         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2126         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2127         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2128         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2129         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2130         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2131         {
2132                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2133                 .name = "Channel Mode",
2134                 .info = alc_ch_mode_info,
2135                 .get = alc_ch_mode_get,
2136                 .put = alc_ch_mode_put,
2137         },
2138         { } /* end */
2139 };
2140
2141
2142 /*
2143  * ALC880 W810 model
2144  *
2145  * W810 has rear IO for:
2146  * Front (DAC 02)
2147  * Surround (DAC 03)
2148  * Center/LFE (DAC 04)
2149  * Digital out (06)
2150  *
2151  * The system also has a pair of internal speakers, and a headphone jack.
2152  * These are both connected to Line2 on the codec, hence to DAC 02.
2153  *
2154  * There is a variable resistor to control the speaker or headphone
2155  * volume. This is a hardware-only device without a software API.
2156  *
2157  * Plugging headphones in will disable the internal speakers. This is
2158  * implemented in hardware, not via the driver using jack sense. In
2159  * a similar fashion, plugging into the rear socket marked "front" will
2160  * disable both the speakers and headphones.
2161  *
2162  * For input, there's a microphone jack, and an "audio in" jack.
2163  * These may not do anything useful with this driver yet, because I
2164  * haven't setup any initialization verbs for these yet...
2165  */
2166
2167 static hda_nid_t alc880_w810_dac_nids[3] = {
2168         /* front, rear/surround, clfe */
2169         0x02, 0x03, 0x04
2170 };
2171
2172 /* fixed 6 channels */
2173 static struct hda_channel_mode alc880_w810_modes[1] = {
2174         { 6, NULL }
2175 };
2176
2177 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2178 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2179         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2180         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2181         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2182         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2183         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2184         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2185         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2186         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2187         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2188         { } /* end */
2189 };
2190
2191
2192 /*
2193  * Z710V model
2194  *
2195  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2196  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2197  *                 Line = 0x1a
2198  */
2199
2200 static hda_nid_t alc880_z71v_dac_nids[1] = {
2201         0x02
2202 };
2203 #define ALC880_Z71V_HP_DAC      0x03
2204
2205 /* fixed 2 channels */
2206 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2207         { 2, NULL }
2208 };
2209
2210 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2211         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2212         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2213         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2214         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2215         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2216         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2218         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2219         { } /* end */
2220 };
2221
2222
2223 /*
2224  * ALC880 F1734 model
2225  *
2226  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2227  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2228  */
2229
2230 static hda_nid_t alc880_f1734_dac_nids[1] = {
2231         0x03
2232 };
2233 #define ALC880_F1734_HP_DAC     0x02
2234
2235 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2236         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2237         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2238         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2239         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2240         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2241         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2242         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2243         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2244         { } /* end */
2245 };
2246
2247 static struct hda_input_mux alc880_f1734_capture_source = {
2248         .num_items = 2,
2249         .items = {
2250                 { "Mic", 0x1 },
2251                 { "CD", 0x4 },
2252         },
2253 };
2254
2255
2256 /*
2257  * ALC880 ASUS model
2258  *
2259  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2260  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2261  *  Mic = 0x18, Line = 0x1a
2262  */
2263
2264 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2265 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2266
2267 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2268         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2269         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2270         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2271         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2272         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2273         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2274         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2275         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2276         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2277         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2278         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2279         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2280         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2281         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2282         {
2283                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2284                 .name = "Channel Mode",
2285                 .info = alc_ch_mode_info,
2286                 .get = alc_ch_mode_get,
2287                 .put = alc_ch_mode_put,
2288         },
2289         { } /* end */
2290 };
2291
2292 /*
2293  * ALC880 ASUS W1V model
2294  *
2295  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2296  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2297  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2298  */
2299
2300 /* additional mixers to alc880_asus_mixer */
2301 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2302         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2303         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2304         { } /* end */
2305 };
2306
2307 /* TCL S700 */
2308 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2309         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2310         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2311         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2312         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2313         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2314         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2315         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2316         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2317         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2318         { } /* end */
2319 };
2320
2321 /* Uniwill */
2322 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2323         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2324         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2325         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2326         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2327         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2328         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2329         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2330         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2331         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2332         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2333         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2334         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2335         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2336         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2337         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2338         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2339         {
2340                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2341                 .name = "Channel Mode",
2342                 .info = alc_ch_mode_info,
2343                 .get = alc_ch_mode_get,
2344                 .put = alc_ch_mode_put,
2345         },
2346         { } /* end */
2347 };
2348
2349 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2350         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2351         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2352         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2353         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2354         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2355         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2356         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2357         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2358         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2359         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2360         { } /* end */
2361 };
2362
2363 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2364         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2365         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2366         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2367         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2368         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2369         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2370         { } /* end */
2371 };
2372
2373 /*
2374  * virtual master controls
2375  */
2376
2377 /*
2378  * slave controls for virtual master
2379  */
2380 static const char *alc_slave_vols[] = {
2381         "Front Playback Volume",
2382         "Surround Playback Volume",
2383         "Center Playback Volume",
2384         "LFE Playback Volume",
2385         "Side Playback Volume",
2386         "Headphone Playback Volume",
2387         "Speaker Playback Volume",
2388         "Mono Playback Volume",
2389         "Line-Out Playback Volume",
2390         "PCM Playback Volume",
2391         NULL,
2392 };
2393
2394 static const char *alc_slave_sws[] = {
2395         "Front Playback Switch",
2396         "Surround Playback Switch",
2397         "Center Playback Switch",
2398         "LFE Playback Switch",
2399         "Side Playback Switch",
2400         "Headphone Playback Switch",
2401         "Speaker Playback Switch",
2402         "Mono Playback Switch",
2403         "IEC958 Playback Switch",
2404         NULL,
2405 };
2406
2407 /*
2408  * build control elements
2409  */
2410
2411 static void alc_free_kctls(struct hda_codec *codec);
2412
2413 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2414 /* additional beep mixers; the actual parameters are overwritten at build */
2415 static struct snd_kcontrol_new alc_beep_mixer[] = {
2416         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2417         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2418         { } /* end */
2419 };
2420 #endif
2421
2422 static int alc_build_controls(struct hda_codec *codec)
2423 {
2424         struct alc_spec *spec = codec->spec;
2425         int err;
2426         int i;
2427
2428         for (i = 0; i < spec->num_mixers; i++) {
2429                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2430                 if (err < 0)
2431                         return err;
2432         }
2433         if (spec->cap_mixer) {
2434                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2435                 if (err < 0)
2436                         return err;
2437         }
2438         if (spec->multiout.dig_out_nid) {
2439                 err = snd_hda_create_spdif_out_ctls(codec,
2440                                                     spec->multiout.dig_out_nid);
2441                 if (err < 0)
2442                         return err;
2443                 if (!spec->no_analog) {
2444                         err = snd_hda_create_spdif_share_sw(codec,
2445                                                             &spec->multiout);
2446                         if (err < 0)
2447                                 return err;
2448                         spec->multiout.share_spdif = 1;
2449                 }
2450         }
2451         if (spec->dig_in_nid) {
2452                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2453                 if (err < 0)
2454                         return err;
2455         }
2456
2457 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2458         /* create beep controls if needed */
2459         if (spec->beep_amp) {
2460                 struct snd_kcontrol_new *knew;
2461                 for (knew = alc_beep_mixer; knew->name; knew++) {
2462                         struct snd_kcontrol *kctl;
2463                         kctl = snd_ctl_new1(knew, codec);
2464                         if (!kctl)
2465                                 return -ENOMEM;
2466                         kctl->private_value = spec->beep_amp;
2467                         err = snd_hda_ctl_add(codec,
2468                                         get_amp_nid_(spec->beep_amp), kctl);
2469                         if (err < 0)
2470                                 return err;
2471                 }
2472         }
2473 #endif
2474
2475         /* if we have no master control, let's create it */
2476         if (!spec->no_analog &&
2477             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2478                 unsigned int vmaster_tlv[4];
2479                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2480                                         HDA_OUTPUT, vmaster_tlv);
2481                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2482                                           vmaster_tlv, alc_slave_vols);
2483                 if (err < 0)
2484                         return err;
2485         }
2486         if (!spec->no_analog &&
2487             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2488                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2489                                           NULL, alc_slave_sws);
2490                 if (err < 0)
2491                         return err;
2492         }
2493
2494         alc_free_kctls(codec); /* no longer needed */
2495         return 0;
2496 }
2497
2498
2499 /*
2500  * initialize the codec volumes, etc
2501  */
2502
2503 /*
2504  * generic initialization of ADC, input mixers and output mixers
2505  */
2506 static struct hda_verb alc880_volume_init_verbs[] = {
2507         /*
2508          * Unmute ADC0-2 and set the default input to mic-in
2509          */
2510         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2511         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2512         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2513         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2514         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2515         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2516
2517         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2518          * mixer widget
2519          * Note: PASD motherboards uses the Line In 2 as the input for front
2520          * panel mic (mic 2)
2521          */
2522         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2525         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2526         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2527         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2528         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2529         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2530
2531         /*
2532          * Set up output mixers (0x0c - 0x0f)
2533          */
2534         /* set vol=0 to output mixers */
2535         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2536         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2537         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2538         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2539         /* set up input amps for analog loopback */
2540         /* Amp Indices: DAC = 0, mixer = 1 */
2541         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2543         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2544         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2545         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2546         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2547         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2548         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2549
2550         { }
2551 };
2552
2553 /*
2554  * 3-stack pin configuration:
2555  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2556  */
2557 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2558         /*
2559          * preset connection lists of input pins
2560          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2561          */
2562         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2563         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2564         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2565
2566         /*
2567          * Set pin mode and muting
2568          */
2569         /* set front pin widgets 0x14 for output */
2570         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2571         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2572         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2573         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2574         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2575         /* Mic2 (as headphone out) for HP output */
2576         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2577         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2578         /* Line In pin widget for input */
2579         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2580         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2581         /* Line2 (as front mic) pin widget for input and vref at 80% */
2582         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2583         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2584         /* CD pin widget for input */
2585         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2586
2587         { }
2588 };
2589
2590 /*
2591  * 5-stack pin configuration:
2592  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2593  * line-in/side = 0x1a, f-mic = 0x1b
2594  */
2595 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2596         /*
2597          * preset connection lists of input pins
2598          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2599          */
2600         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2601         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2602
2603         /*
2604          * Set pin mode and muting
2605          */
2606         /* set pin widgets 0x14-0x17 for output */
2607         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2608         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2609         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2610         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2611         /* unmute pins for output (no gain on this amp) */
2612         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2613         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2614         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2615         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2616
2617         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2618         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2619         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2620         /* Mic2 (as headphone out) for HP output */
2621         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2622         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2623         /* Line In pin widget for input */
2624         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2625         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2626         /* Line2 (as front mic) pin widget for input and vref at 80% */
2627         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2628         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2629         /* CD pin widget for input */
2630         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2631
2632         { }
2633 };
2634
2635 /*
2636  * W810 pin configuration:
2637  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2638  */
2639 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2640         /* hphone/speaker input selector: front DAC */
2641         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2642
2643         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2644         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2645         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2646         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2647         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2648         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2649
2650         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2651         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2652
2653         { }
2654 };
2655
2656 /*
2657  * Z71V pin configuration:
2658  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2659  */
2660 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2661         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2662         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2663         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2664         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2665
2666         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2667         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2668         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2669         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2670
2671         { }
2672 };
2673
2674 /*
2675  * 6-stack pin configuration:
2676  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2677  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2678  */
2679 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2680         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2681
2682         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2683         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2684         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2685         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2686         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2687         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2688         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2689         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2690
2691         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2692         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2693         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2694         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2695         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2696         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2697         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2698         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2699         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2700
2701         { }
2702 };
2703
2704 /*
2705  * Uniwill pin configuration:
2706  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2707  * line = 0x1a
2708  */
2709 static struct hda_verb alc880_uniwill_init_verbs[] = {
2710         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2711
2712         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2713         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2714         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2715         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2716         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2717         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2718         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2719         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2720         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2721         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2722         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2723         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2724         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2725         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2726
2727         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2728         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2729         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2730         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2731         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2732         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2733         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2734         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2735         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2736
2737         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2738         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2739
2740         { }
2741 };
2742
2743 /*
2744 * Uniwill P53
2745 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2746  */
2747 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2748         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2749
2750         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2751         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2752         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2753         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2754         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2755         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2756         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2757         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2758         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2759         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2760         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2761         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2762
2763         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2764         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2765         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2766         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2767         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2768         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2769
2770         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2771         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2772
2773         { }
2774 };
2775
2776 static struct hda_verb alc880_beep_init_verbs[] = {
2777         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2778         { }
2779 };
2780
2781 /* auto-toggle front mic */
2782 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2783 {
2784         unsigned int present;
2785         unsigned char bits;
2786
2787         present = snd_hda_codec_read(codec, 0x18, 0,
2788                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2789         bits = present ? HDA_AMP_MUTE : 0;
2790         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2791 }
2792
2793 static void alc880_uniwill_setup(struct hda_codec *codec)
2794 {
2795         struct alc_spec *spec = codec->spec;
2796
2797         spec->autocfg.hp_pins[0] = 0x14;
2798         spec->autocfg.speaker_pins[0] = 0x15;
2799         spec->autocfg.speaker_pins[0] = 0x16;
2800 }
2801
2802 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2803 {
2804         alc_automute_amp(codec);
2805         alc880_uniwill_mic_automute(codec);
2806 }
2807
2808 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2809                                        unsigned int res)
2810 {
2811         /* Looks like the unsol event is incompatible with the standard
2812          * definition.  4bit tag is placed at 28 bit!
2813          */
2814         switch (res >> 28) {
2815         case ALC880_MIC_EVENT:
2816                 alc880_uniwill_mic_automute(codec);
2817                 break;
2818         default:
2819                 alc_automute_amp_unsol_event(codec, res);
2820                 break;
2821         }
2822 }
2823
2824 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2825 {
2826         struct alc_spec *spec = codec->spec;
2827
2828         spec->autocfg.hp_pins[0] = 0x14;
2829         spec->autocfg.speaker_pins[0] = 0x15;
2830 }
2831
2832 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2833 {
2834         unsigned int present;
2835
2836         present = snd_hda_codec_read(codec, 0x21, 0,
2837                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2838         present &= HDA_AMP_VOLMASK;
2839         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2840                                  HDA_AMP_VOLMASK, present);
2841         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2842                                  HDA_AMP_VOLMASK, present);
2843 }
2844
2845 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2846                                            unsigned int res)
2847 {
2848         /* Looks like the unsol event is incompatible with the standard
2849          * definition.  4bit tag is placed at 28 bit!
2850          */
2851         if ((res >> 28) == ALC880_DCVOL_EVENT)
2852                 alc880_uniwill_p53_dcvol_automute(codec);
2853         else
2854                 alc_automute_amp_unsol_event(codec, res);
2855 }
2856
2857 /*
2858  * F1734 pin configuration:
2859  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2860  */
2861 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2862         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2863         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2864         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2865         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2866         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2867
2868         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2869         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2870         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2871         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2872
2873         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2874         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2875         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2876         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2877         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2878         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2879         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2880         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2881         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2882
2883         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2884         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2885
2886         { }
2887 };
2888
2889 /*
2890  * ASUS pin configuration:
2891  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2892  */
2893 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2894         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2895         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2896         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2897         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2898
2899         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2900         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2901         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2902         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2903         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2904         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2905         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2906         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2907
2908         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2909         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2910         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2911         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2912         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2913         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2914         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2915         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2916         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2917
2918         { }
2919 };
2920
2921 /* Enable GPIO mask and set output */
2922 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2923 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2924 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2925
2926 /* Clevo m520g init */
2927 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2928         /* headphone output */
2929         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2930         /* line-out */
2931         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2932         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2933         /* Line-in */
2934         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2935         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2936         /* CD */
2937         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2938         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2939         /* Mic1 (rear panel) */
2940         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2941         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2942         /* Mic2 (front panel) */
2943         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2944         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2945         /* headphone */
2946         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2947         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2948         /* change to EAPD mode */
2949         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2950         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2951
2952         { }
2953 };
2954
2955 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2956         /* change to EAPD mode */
2957         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2958         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2959
2960         /* Headphone output */
2961         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2962         /* Front output*/
2963         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2964         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2965
2966         /* Line In pin widget for input */
2967         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2968         /* CD pin widget for input */
2969         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2970         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2971         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2972
2973         /* change to EAPD mode */
2974         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2975         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2976
2977         { }
2978 };
2979
2980 /*
2981  * LG m1 express dual
2982  *
2983  * Pin assignment:
2984  *   Rear Line-In/Out (blue): 0x14
2985  *   Build-in Mic-In: 0x15
2986  *   Speaker-out: 0x17
2987  *   HP-Out (green): 0x1b
2988  *   Mic-In/Out (red): 0x19
2989  *   SPDIF-Out: 0x1e
2990  */
2991
2992 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2993 static hda_nid_t alc880_lg_dac_nids[3] = {
2994         0x05, 0x02, 0x03
2995 };
2996
2997 /* seems analog CD is not working */
2998 static struct hda_input_mux alc880_lg_capture_source = {
2999         .num_items = 3,
3000         .items = {
3001                 { "Mic", 0x1 },
3002                 { "Line", 0x5 },
3003                 { "Internal Mic", 0x6 },
3004         },
3005 };
3006
3007 /* 2,4,6 channel modes */
3008 static struct hda_verb alc880_lg_ch2_init[] = {
3009         /* set line-in and mic-in to input */
3010         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3011         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3012         { }
3013 };
3014
3015 static struct hda_verb alc880_lg_ch4_init[] = {
3016         /* set line-in to out and mic-in to input */
3017         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3018         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3019         { }
3020 };
3021
3022 static struct hda_verb alc880_lg_ch6_init[] = {
3023         /* set line-in and mic-in to output */
3024         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3025         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3026         { }
3027 };
3028
3029 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3030         { 2, alc880_lg_ch2_init },
3031         { 4, alc880_lg_ch4_init },
3032         { 6, alc880_lg_ch6_init },
3033 };
3034
3035 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3036         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3037         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3038         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3039         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3040         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3041         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3042         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3043         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3044         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3045         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3046         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3047         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3048         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3049         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3050         {
3051                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3052                 .name = "Channel Mode",
3053                 .info = alc_ch_mode_info,
3054                 .get = alc_ch_mode_get,
3055                 .put = alc_ch_mode_put,
3056         },
3057         { } /* end */
3058 };
3059
3060 static struct hda_verb alc880_lg_init_verbs[] = {
3061         /* set capture source to mic-in */
3062         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3063         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3064         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3065         /* mute all amp mixer inputs */
3066         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3067         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3068         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3069         /* line-in to input */
3070         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3071         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3072         /* built-in mic */
3073         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3074         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3075         /* speaker-out */
3076         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3077         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3078         /* mic-in to input */
3079         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3080         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3081         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3082         /* HP-out */
3083         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3084         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3085         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3086         /* jack sense */
3087         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3088         { }
3089 };
3090
3091 /* toggle speaker-output according to the hp-jack state */
3092 static void alc880_lg_setup(struct hda_codec *codec)
3093 {
3094         struct alc_spec *spec = codec->spec;
3095
3096         spec->autocfg.hp_pins[0] = 0x1b;
3097         spec->autocfg.speaker_pins[0] = 0x17;
3098 }
3099
3100 /*
3101  * LG LW20
3102  *
3103  * Pin assignment:
3104  *   Speaker-out: 0x14
3105  *   Mic-In: 0x18
3106  *   Built-in Mic-In: 0x19
3107  *   Line-In: 0x1b
3108  *   HP-Out: 0x1a
3109  *   SPDIF-Out: 0x1e
3110  */
3111
3112 static struct hda_input_mux alc880_lg_lw_capture_source = {
3113         .num_items = 3,
3114         .items = {
3115                 { "Mic", 0x0 },
3116                 { "Internal Mic", 0x1 },
3117                 { "Line In", 0x2 },
3118         },
3119 };
3120
3121 #define alc880_lg_lw_modes alc880_threestack_modes
3122
3123 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3124         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3125         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3126         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3127         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3128         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3129         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3130         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3131         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3132         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3133         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3134         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3135         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3136         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3137         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3138         {
3139                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3140                 .name = "Channel Mode",
3141                 .info = alc_ch_mode_info,
3142                 .get = alc_ch_mode_get,
3143                 .put = alc_ch_mode_put,
3144         },
3145         { } /* end */
3146 };
3147
3148 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3149         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3150         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3151         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3152
3153         /* set capture source to mic-in */
3154         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3155         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3156         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3157         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3158         /* speaker-out */
3159         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3160         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3161         /* HP-out */
3162         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3163         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3164         /* mic-in to input */
3165         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3166         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3167         /* built-in mic */
3168         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3169         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3170         /* jack sense */
3171         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3172         { }
3173 };
3174
3175 /* toggle speaker-output according to the hp-jack state */
3176 static void alc880_lg_lw_setup(struct hda_codec *codec)
3177 {
3178         struct alc_spec *spec = codec->spec;
3179
3180         spec->autocfg.hp_pins[0] = 0x1b;
3181         spec->autocfg.speaker_pins[0] = 0x14;
3182 }
3183
3184 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3185         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3186         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3187         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3188         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3189         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3190         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3191         { } /* end */
3192 };
3193
3194 static struct hda_input_mux alc880_medion_rim_capture_source = {
3195         .num_items = 2,
3196         .items = {
3197                 { "Mic", 0x0 },
3198                 { "Internal Mic", 0x1 },
3199         },
3200 };
3201
3202 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3203         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3204
3205         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3206         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3207
3208         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3209         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3210         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3211         /* Mic2 (as headphone out) for HP output */
3212         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3213         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3214         /* Internal Speaker */
3215         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3216         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3217
3218         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3219         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3220
3221         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3222         { }
3223 };
3224
3225 /* toggle speaker-output according to the hp-jack state */
3226 static void alc880_medion_rim_automute(struct hda_codec *codec)
3227 {
3228         struct alc_spec *spec = codec->spec;
3229         alc_automute_amp(codec);
3230         /* toggle EAPD */
3231         if (spec->jack_present)
3232                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3233         else
3234                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3235 }
3236
3237 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3238                                           unsigned int res)
3239 {
3240         /* Looks like the unsol event is incompatible with the standard
3241          * definition.  4bit tag is placed at 28 bit!
3242          */
3243         if ((res >> 28) == ALC880_HP_EVENT)
3244                 alc880_medion_rim_automute(codec);
3245 }
3246
3247 static void alc880_medion_rim_setup(struct hda_codec *codec)
3248 {
3249         struct alc_spec *spec = codec->spec;
3250
3251         spec->autocfg.hp_pins[0] = 0x14;
3252         spec->autocfg.speaker_pins[0] = 0x1b;
3253 }
3254
3255 #ifdef CONFIG_SND_HDA_POWER_SAVE
3256 static struct hda_amp_list alc880_loopbacks[] = {
3257         { 0x0b, HDA_INPUT, 0 },
3258         { 0x0b, HDA_INPUT, 1 },
3259         { 0x0b, HDA_INPUT, 2 },
3260         { 0x0b, HDA_INPUT, 3 },
3261         { 0x0b, HDA_INPUT, 4 },
3262         { } /* end */
3263 };
3264
3265 static struct hda_amp_list alc880_lg_loopbacks[] = {
3266         { 0x0b, HDA_INPUT, 1 },
3267         { 0x0b, HDA_INPUT, 6 },
3268         { 0x0b, HDA_INPUT, 7 },
3269         { } /* end */
3270 };
3271 #endif
3272
3273 /*
3274  * Common callbacks
3275  */
3276
3277 static int alc_init(struct hda_codec *codec)
3278 {
3279         struct alc_spec *spec = codec->spec;
3280         unsigned int i;
3281
3282         alc_fix_pll(codec);
3283         alc_auto_init_amp(codec, spec->init_amp);
3284
3285         for (i = 0; i < spec->num_init_verbs; i++)
3286                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3287
3288         if (spec->init_hook)
3289                 spec->init_hook(codec);
3290
3291         return 0;
3292 }
3293
3294 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3295 {
3296         struct alc_spec *spec = codec->spec;
3297
3298         if (spec->unsol_event)
3299                 spec->unsol_event(codec, res);
3300 }
3301
3302 #ifdef CONFIG_SND_HDA_POWER_SAVE
3303 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3304 {
3305         struct alc_spec *spec = codec->spec;
3306         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3307 }
3308 #endif
3309
3310 /*
3311  * Analog playback callbacks
3312  */
3313 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3314                                     struct hda_codec *codec,
3315                                     struct snd_pcm_substream *substream)
3316 {
3317         struct alc_spec *spec = codec->spec;
3318         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3319                                              hinfo);
3320 }
3321
3322 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3323                                        struct hda_codec *codec,
3324                                        unsigned int stream_tag,
3325                                        unsigned int format,
3326                                        struct snd_pcm_substream *substream)
3327 {
3328         struct alc_spec *spec = codec->spec;
3329         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3330                                                 stream_tag, format, substream);
3331 }
3332
3333 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3334                                        struct hda_codec *codec,
3335                                        struct snd_pcm_substream *substream)
3336 {
3337         struct alc_spec *spec = codec->spec;
3338         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3339 }
3340
3341 /*
3342  * Digital out
3343  */
3344 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3345                                         struct hda_codec *codec,
3346                                         struct snd_pcm_substream *substream)
3347 {
3348         struct alc_spec *spec = codec->spec;
3349         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3350 }
3351
3352 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3353                                            struct hda_codec *codec,
3354                                            unsigned int stream_tag,
3355                                            unsigned int format,
3356                                            struct snd_pcm_substream *substream)
3357 {
3358         struct alc_spec *spec = codec->spec;
3359         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3360                                              stream_tag, format, substream);
3361 }
3362
3363 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3364                                            struct hda_codec *codec,
3365                                            struct snd_pcm_substream *substream)
3366 {
3367         struct alc_spec *spec = codec->spec;
3368         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3369 }
3370
3371 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3372                                          struct hda_codec *codec,
3373                                          struct snd_pcm_substream *substream)
3374 {
3375         struct alc_spec *spec = codec->spec;
3376         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3377 }
3378
3379 /*
3380  * Analog capture
3381  */
3382 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3383                                       struct hda_codec *codec,
3384                                       unsigned int stream_tag,
3385                                       unsigned int format,
3386                                       struct snd_pcm_substream *substream)
3387 {
3388         struct alc_spec *spec = codec->spec;
3389
3390         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3391                                    stream_tag, 0, format);
3392         return 0;
3393 }
3394
3395 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3396                                       struct hda_codec *codec,
3397                                       struct snd_pcm_substream *substream)
3398 {
3399         struct alc_spec *spec = codec->spec;
3400
3401         snd_hda_codec_cleanup_stream(codec,
3402                                      spec->adc_nids[substream->number + 1]);
3403         return 0;
3404 }
3405
3406
3407 /*
3408  */
3409 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3410         .substreams = 1,
3411         .channels_min = 2,
3412         .channels_max = 8,
3413         /* NID is set in alc_build_pcms */
3414         .ops = {
3415                 .open = alc880_playback_pcm_open,
3416                 .prepare = alc880_playback_pcm_prepare,
3417                 .cleanup = alc880_playback_pcm_cleanup
3418         },
3419 };
3420
3421 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3422         .substreams = 1,
3423         .channels_min = 2,
3424         .channels_max = 2,
3425         /* NID is set in alc_build_pcms */
3426 };
3427
3428 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3429         .substreams = 1,
3430         .channels_min = 2,
3431         .channels_max = 2,
3432         /* NID is set in alc_build_pcms */
3433 };
3434
3435 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3436         .substreams = 2, /* can be overridden */
3437         .channels_min = 2,
3438         .channels_max = 2,
3439         /* NID is set in alc_build_pcms */
3440         .ops = {
3441                 .prepare = alc880_alt_capture_pcm_prepare,
3442                 .cleanup = alc880_alt_capture_pcm_cleanup
3443         },
3444 };
3445
3446 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3447         .substreams = 1,
3448         .channels_min = 2,
3449         .channels_max = 2,
3450         /* NID is set in alc_build_pcms */
3451         .ops = {
3452                 .open = alc880_dig_playback_pcm_open,
3453                 .close = alc880_dig_playback_pcm_close,
3454                 .prepare = alc880_dig_playback_pcm_prepare,
3455                 .cleanup = alc880_dig_playback_pcm_cleanup
3456         },
3457 };
3458
3459 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3460         .substreams = 1,
3461         .channels_min = 2,
3462         .channels_max = 2,
3463         /* NID is set in alc_build_pcms */
3464 };
3465
3466 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3467 static struct hda_pcm_stream alc_pcm_null_stream = {
3468         .substreams = 0,
3469         .channels_min = 0,
3470         .channels_max = 0,
3471 };
3472
3473 static int alc_build_pcms(struct hda_codec *codec)
3474 {
3475         struct alc_spec *spec = codec->spec;
3476         struct hda_pcm *info = spec->pcm_rec;
3477         int i;
3478
3479         codec->num_pcms = 1;
3480         codec->pcm_info = info;
3481
3482         if (spec->no_analog)
3483                 goto skip_analog;
3484
3485         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3486                  "%s Analog", codec->chip_name);
3487         info->name = spec->stream_name_analog;
3488         
3489         if (spec->stream_analog_playback) {
3490                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3491                         return -EINVAL;
3492                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3493                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3494         }
3495         if (spec->stream_analog_capture) {
3496                 if (snd_BUG_ON(!spec->adc_nids))
3497                         return -EINVAL;
3498                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3499                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3500         }
3501
3502         if (spec->channel_mode) {
3503                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3504                 for (i = 0; i < spec->num_channel_mode; i++) {
3505                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3506                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3507                         }
3508                 }
3509         }
3510
3511  skip_analog:
3512         /* SPDIF for stream index #1 */
3513         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3514                 snprintf(spec->stream_name_digital,
3515                          sizeof(spec->stream_name_digital),
3516                          "%s Digital", codec->chip_name);
3517                 codec->num_pcms = 2;
3518                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3519                 info = spec->pcm_rec + 1;
3520                 info->name = spec->stream_name_digital;
3521                 if (spec->dig_out_type)
3522                         info->pcm_type = spec->dig_out_type;
3523                 else
3524                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3525                 if (spec->multiout.dig_out_nid &&
3526                     spec->stream_digital_playback) {
3527                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3528                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3529                 }
3530                 if (spec->dig_in_nid &&
3531                     spec->stream_digital_capture) {
3532                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3533                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3534                 }
3535                 /* FIXME: do we need this for all Realtek codec models? */
3536                 codec->spdif_status_reset = 1;
3537         }
3538
3539         if (spec->no_analog)
3540                 return 0;
3541
3542         /* If the use of more than one ADC is requested for the current
3543          * model, configure a second analog capture-only PCM.
3544          */
3545         /* Additional Analaog capture for index #2 */
3546         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3547             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3548                 codec->num_pcms = 3;
3549                 info = spec->pcm_rec + 2;
3550                 info->name = spec->stream_name_analog;
3551                 if (spec->alt_dac_nid) {
3552                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3553                                 *spec->stream_analog_alt_playback;
3554                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3555                                 spec->alt_dac_nid;
3556                 } else {
3557                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3558                                 alc_pcm_null_stream;
3559                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3560                 }
3561                 if (spec->num_adc_nids > 1) {
3562                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3563                                 *spec->stream_analog_alt_capture;
3564                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3565                                 spec->adc_nids[1];
3566                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3567                                 spec->num_adc_nids - 1;
3568                 } else {
3569                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3570                                 alc_pcm_null_stream;
3571                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3572                 }
3573         }
3574
3575         return 0;
3576 }
3577
3578 static void alc_free_kctls(struct hda_codec *codec)
3579 {
3580         struct alc_spec *spec = codec->spec;
3581
3582         if (spec->kctls.list) {
3583                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3584                 int i;
3585                 for (i = 0; i < spec->kctls.used; i++)
3586                         kfree(kctl[i].name);
3587         }
3588         snd_array_free(&spec->kctls);
3589 }
3590
3591 static void alc_free(struct hda_codec *codec)
3592 {
3593         struct alc_spec *spec = codec->spec;
3594
3595         if (!spec)
3596                 return;
3597
3598         alc_free_kctls(codec);
3599         kfree(spec);
3600         snd_hda_detach_beep_device(codec);
3601 }
3602
3603 #ifdef SND_HDA_NEEDS_RESUME
3604 static int alc_resume(struct hda_codec *codec)
3605 {
3606         codec->patch_ops.init(codec);
3607         snd_hda_codec_resume_amp(codec);
3608         snd_hda_codec_resume_cache(codec);
3609         return 0;
3610 }
3611 #endif
3612
3613 /*
3614  */
3615 static struct hda_codec_ops alc_patch_ops = {
3616         .build_controls = alc_build_controls,
3617         .build_pcms = alc_build_pcms,
3618         .init = alc_init,
3619         .free = alc_free,
3620         .unsol_event = alc_unsol_event,
3621 #ifdef SND_HDA_NEEDS_RESUME
3622         .resume = alc_resume,
3623 #endif
3624 #ifdef CONFIG_SND_HDA_POWER_SAVE
3625         .check_power_status = alc_check_power_status,
3626 #endif
3627 };
3628
3629
3630 /*
3631  * Test configuration for debugging
3632  *
3633  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3634  * enum controls.
3635  */
3636 #ifdef CONFIG_SND_DEBUG
3637 static hda_nid_t alc880_test_dac_nids[4] = {
3638         0x02, 0x03, 0x04, 0x05
3639 };
3640
3641 static struct hda_input_mux alc880_test_capture_source = {
3642         .num_items = 7,
3643         .items = {
3644                 { "In-1", 0x0 },
3645                 { "In-2", 0x1 },
3646                 { "In-3", 0x2 },
3647                 { "In-4", 0x3 },
3648                 { "CD", 0x4 },
3649                 { "Front", 0x5 },
3650                 { "Surround", 0x6 },
3651         },
3652 };
3653
3654 static struct hda_channel_mode alc880_test_modes[4] = {
3655         { 2, NULL },
3656         { 4, NULL },
3657         { 6, NULL },
3658         { 8, NULL },
3659 };
3660
3661 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3662                                  struct snd_ctl_elem_info *uinfo)
3663 {
3664         static char *texts[] = {
3665                 "N/A", "Line Out", "HP Out",
3666                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3667         };
3668         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3669         uinfo->count = 1;
3670         uinfo->value.enumerated.items = 8;
3671         if (uinfo->value.enumerated.item >= 8)
3672                 uinfo->value.enumerated.item = 7;
3673         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3674         return 0;
3675 }
3676
3677 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3678                                 struct snd_ctl_elem_value *ucontrol)
3679 {
3680         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3681         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3682         unsigned int pin_ctl, item = 0;
3683
3684         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3685                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3686         if (pin_ctl & AC_PINCTL_OUT_EN) {
3687                 if (pin_ctl & AC_PINCTL_HP_EN)
3688                         item = 2;
3689                 else
3690                         item = 1;
3691         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3692                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3693                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3694                 case AC_PINCTL_VREF_50:  item = 4; break;
3695                 case AC_PINCTL_VREF_GRD: item = 5; break;
3696                 case AC_PINCTL_VREF_80:  item = 6; break;
3697                 case AC_PINCTL_VREF_100: item = 7; break;
3698                 }
3699         }
3700         ucontrol->value.enumerated.item[0] = item;
3701         return 0;
3702 }
3703
3704 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3705                                 struct snd_ctl_elem_value *ucontrol)
3706 {
3707         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3708         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3709         static unsigned int ctls[] = {
3710                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3711                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3712                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3713                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3714                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3715                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3716         };
3717         unsigned int old_ctl, new_ctl;
3718
3719         old_ctl = snd_hda_codec_read(codec, nid, 0,
3720                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3721         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3722         if (old_ctl != new_ctl) {
3723                 int val;
3724                 snd_hda_codec_write_cache(codec, nid, 0,
3725                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3726                                           new_ctl);
3727                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3728                         HDA_AMP_MUTE : 0;
3729                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3730                                          HDA_AMP_MUTE, val);
3731                 return 1;
3732         }
3733         return 0;
3734 }
3735
3736 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3737                                  struct snd_ctl_elem_info *uinfo)
3738 {
3739         static char *texts[] = {
3740                 "Front", "Surround", "CLFE", "Side"
3741         };
3742         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3743         uinfo->count = 1;
3744         uinfo->value.enumerated.items = 4;
3745         if (uinfo->value.enumerated.item >= 4)
3746                 uinfo->value.enumerated.item = 3;
3747         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3748         return 0;
3749 }
3750
3751 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3752                                 struct snd_ctl_elem_value *ucontrol)
3753 {
3754         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3755         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3756         unsigned int sel;
3757
3758         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3759         ucontrol->value.enumerated.item[0] = sel & 3;
3760         return 0;
3761 }
3762
3763 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3764                                 struct snd_ctl_elem_value *ucontrol)
3765 {
3766         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3767         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3768         unsigned int sel;
3769
3770         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3771         if (ucontrol->value.enumerated.item[0] != sel) {
3772                 sel = ucontrol->value.enumerated.item[0] & 3;
3773                 snd_hda_codec_write_cache(codec, nid, 0,
3774                                           AC_VERB_SET_CONNECT_SEL, sel);
3775                 return 1;
3776         }
3777         return 0;
3778 }
3779
3780 #define PIN_CTL_TEST(xname,nid) {                       \
3781                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3782                         .name = xname,                 \
3783                         .info = alc_test_pin_ctl_info, \
3784                         .get = alc_test_pin_ctl_get,   \
3785                         .put = alc_test_pin_ctl_put,   \
3786                         .private_value = nid           \
3787                         }
3788
3789 #define PIN_SRC_TEST(xname,nid) {                       \
3790                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3791                         .name = xname,                 \
3792                         .info = alc_test_pin_src_info, \
3793                         .get = alc_test_pin_src_get,   \
3794                         .put = alc_test_pin_src_put,   \
3795                         .private_value = nid           \
3796                         }
3797
3798 static struct snd_kcontrol_new alc880_test_mixer[] = {
3799         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3800         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3801         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3802         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3803         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3804         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3805         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3806         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3807         PIN_CTL_TEST("Front Pin Mode", 0x14),
3808         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3809         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3810         PIN_CTL_TEST("Side Pin Mode", 0x17),
3811         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3812         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3813         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3814         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3815         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3816         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3817         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3818         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3819         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3820         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3821         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3822         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3823         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3824         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3825         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3826         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3827         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3828         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3829         {
3830                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3831                 .name = "Channel Mode",
3832                 .info = alc_ch_mode_info,
3833                 .get = alc_ch_mode_get,
3834                 .put = alc_ch_mode_put,
3835         },
3836         { } /* end */
3837 };
3838
3839 static struct hda_verb alc880_test_init_verbs[] = {
3840         /* Unmute inputs of 0x0c - 0x0f */
3841         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3842         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3843         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3844         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3845         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3846         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3847         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3848         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3849         /* Vol output for 0x0c-0x0f */
3850         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3851         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3852         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3853         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3854         /* Set output pins 0x14-0x17 */
3855         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3856         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3857         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3858         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3859         /* Unmute output pins 0x14-0x17 */
3860         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3861         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3862         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3863         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3864         /* Set input pins 0x18-0x1c */
3865         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3866         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3867         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3868         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3869         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3870         /* Mute input pins 0x18-0x1b */
3871         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3872         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3873         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3874         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3875         /* ADC set up */
3876         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3877         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3878         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3879         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3880         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3881         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3882         /* Analog input/passthru */
3883         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3884         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3885         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3886         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3887         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3888         { }
3889 };
3890 #endif
3891
3892 /*
3893  */
3894
3895 static const char *alc880_models[ALC880_MODEL_LAST] = {
3896         [ALC880_3ST]            = "3stack",
3897         [ALC880_TCL_S700]       = "tcl",
3898         [ALC880_3ST_DIG]        = "3stack-digout",
3899         [ALC880_CLEVO]          = "clevo",
3900         [ALC880_5ST]            = "5stack",
3901         [ALC880_5ST_DIG]        = "5stack-digout",
3902         [ALC880_W810]           = "w810",
3903         [ALC880_Z71V]           = "z71v",
3904         [ALC880_6ST]            = "6stack",
3905         [ALC880_6ST_DIG]        = "6stack-digout",
3906         [ALC880_ASUS]           = "asus",
3907         [ALC880_ASUS_W1V]       = "asus-w1v",
3908         [ALC880_ASUS_DIG]       = "asus-dig",
3909         [ALC880_ASUS_DIG2]      = "asus-dig2",
3910         [ALC880_UNIWILL_DIG]    = "uniwill",
3911         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3912         [ALC880_FUJITSU]        = "fujitsu",
3913         [ALC880_F1734]          = "F1734",
3914         [ALC880_LG]             = "lg",
3915         [ALC880_LG_LW]          = "lg-lw",
3916         [ALC880_MEDION_RIM]     = "medion",
3917 #ifdef CONFIG_SND_DEBUG
3918         [ALC880_TEST]           = "test",
3919 #endif
3920         [ALC880_AUTO]           = "auto",
3921 };
3922
3923 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3924         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3925         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3926         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3927         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3928         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3929         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3930         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3931         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3932         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3933         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3934         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3935         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3936         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3937         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3938         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3939         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3940         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3941         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3942         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3943         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3944         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3945         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3946         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3947         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3948         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3949         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3950         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3951         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3952         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3953         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3954         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3955         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3956         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3957         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3958         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3959         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3960         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3961         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3962         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3963         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3964         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3965         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3966         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3967         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3968         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3969         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3970         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3971         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3972         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3973         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3974         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3975         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3976         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3977         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3978         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3979         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3980         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3981         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3982         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3983         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3984         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3985         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3986         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3987         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3988         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3989         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3990         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3991         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3992         /* default Intel */
3993         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3994         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3995         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3996         {}
3997 };
3998
3999 /*
4000  * ALC880 codec presets
4001  */
4002 static struct alc_config_preset alc880_presets[] = {
4003         [ALC880_3ST] = {
4004                 .mixers = { alc880_three_stack_mixer },
4005                 .init_verbs = { alc880_volume_init_verbs,
4006                                 alc880_pin_3stack_init_verbs },
4007                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4008                 .dac_nids = alc880_dac_nids,
4009                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4010                 .channel_mode = alc880_threestack_modes,
4011                 .need_dac_fix = 1,
4012                 .input_mux = &alc880_capture_source,
4013         },
4014         [ALC880_3ST_DIG] = {
4015                 .mixers = { alc880_three_stack_mixer },
4016                 .init_verbs = { alc880_volume_init_verbs,
4017                                 alc880_pin_3stack_init_verbs },
4018                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4019                 .dac_nids = alc880_dac_nids,
4020                 .dig_out_nid = ALC880_DIGOUT_NID,
4021                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4022                 .channel_mode = alc880_threestack_modes,
4023                 .need_dac_fix = 1,
4024                 .input_mux = &alc880_capture_source,
4025         },
4026         [ALC880_TCL_S700] = {
4027                 .mixers = { alc880_tcl_s700_mixer },
4028                 .init_verbs = { alc880_volume_init_verbs,
4029                                 alc880_pin_tcl_S700_init_verbs,
4030                                 alc880_gpio2_init_verbs },
4031                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4032                 .dac_nids = alc880_dac_nids,
4033                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4034                 .num_adc_nids = 1, /* single ADC */
4035                 .hp_nid = 0x03,
4036                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4037                 .channel_mode = alc880_2_jack_modes,
4038                 .input_mux = &alc880_capture_source,
4039         },
4040         [ALC880_5ST] = {
4041                 .mixers = { alc880_three_stack_mixer,
4042                             alc880_five_stack_mixer},
4043                 .init_verbs = { alc880_volume_init_verbs,
4044                                 alc880_pin_5stack_init_verbs },
4045                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4046                 .dac_nids = alc880_dac_nids,
4047                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4048                 .channel_mode = alc880_fivestack_modes,
4049                 .input_mux = &alc880_capture_source,
4050         },
4051         [ALC880_5ST_DIG] = {
4052                 .mixers = { alc880_three_stack_mixer,
4053                             alc880_five_stack_mixer },
4054                 .init_verbs = { alc880_volume_init_verbs,
4055                                 alc880_pin_5stack_init_verbs },
4056                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4057                 .dac_nids = alc880_dac_nids,
4058                 .dig_out_nid = ALC880_DIGOUT_NID,
4059                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4060                 .channel_mode = alc880_fivestack_modes,
4061                 .input_mux = &alc880_capture_source,
4062         },
4063         [ALC880_6ST] = {
4064                 .mixers = { alc880_six_stack_mixer },
4065                 .init_verbs = { alc880_volume_init_verbs,
4066                                 alc880_pin_6stack_init_verbs },
4067                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4068                 .dac_nids = alc880_6st_dac_nids,
4069                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4070                 .channel_mode = alc880_sixstack_modes,
4071                 .input_mux = &alc880_6stack_capture_source,
4072         },
4073         [ALC880_6ST_DIG] = {
4074                 .mixers = { alc880_six_stack_mixer },
4075                 .init_verbs = { alc880_volume_init_verbs,
4076                                 alc880_pin_6stack_init_verbs },
4077                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4078                 .dac_nids = alc880_6st_dac_nids,
4079                 .dig_out_nid = ALC880_DIGOUT_NID,
4080                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4081                 .channel_mode = alc880_sixstack_modes,
4082                 .input_mux = &alc880_6stack_capture_source,
4083         },
4084         [ALC880_W810] = {
4085                 .mixers = { alc880_w810_base_mixer },
4086                 .init_verbs = { alc880_volume_init_verbs,
4087                                 alc880_pin_w810_init_verbs,
4088                                 alc880_gpio2_init_verbs },
4089                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4090                 .dac_nids = alc880_w810_dac_nids,
4091                 .dig_out_nid = ALC880_DIGOUT_NID,
4092                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4093                 .channel_mode = alc880_w810_modes,
4094                 .input_mux = &alc880_capture_source,
4095         },
4096         [ALC880_Z71V] = {
4097                 .mixers = { alc880_z71v_mixer },
4098                 .init_verbs = { alc880_volume_init_verbs,
4099                                 alc880_pin_z71v_init_verbs },
4100                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4101                 .dac_nids = alc880_z71v_dac_nids,
4102                 .dig_out_nid = ALC880_DIGOUT_NID,
4103                 .hp_nid = 0x03,
4104                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4105                 .channel_mode = alc880_2_jack_modes,
4106                 .input_mux = &alc880_capture_source,
4107         },
4108         [ALC880_F1734] = {
4109                 .mixers = { alc880_f1734_mixer },
4110                 .init_verbs = { alc880_volume_init_verbs,
4111                                 alc880_pin_f1734_init_verbs },
4112                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4113                 .dac_nids = alc880_f1734_dac_nids,
4114                 .hp_nid = 0x02,
4115                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4116                 .channel_mode = alc880_2_jack_modes,
4117                 .input_mux = &alc880_f1734_capture_source,
4118                 .unsol_event = alc880_uniwill_p53_unsol_event,
4119                 .setup = alc880_uniwill_p53_setup,
4120                 .init_hook = alc_automute_amp,
4121         },
4122         [ALC880_ASUS] = {
4123                 .mixers = { alc880_asus_mixer },
4124                 .init_verbs = { alc880_volume_init_verbs,
4125                                 alc880_pin_asus_init_verbs,
4126                                 alc880_gpio1_init_verbs },
4127                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4128                 .dac_nids = alc880_asus_dac_nids,
4129                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4130                 .channel_mode = alc880_asus_modes,
4131                 .need_dac_fix = 1,
4132                 .input_mux = &alc880_capture_source,
4133         },
4134         [ALC880_ASUS_DIG] = {
4135                 .mixers = { alc880_asus_mixer },
4136                 .init_verbs = { alc880_volume_init_verbs,
4137                                 alc880_pin_asus_init_verbs,
4138                                 alc880_gpio1_init_verbs },
4139                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4140                 .dac_nids = alc880_asus_dac_nids,
4141                 .dig_out_nid = ALC880_DIGOUT_NID,
4142                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4143                 .channel_mode = alc880_asus_modes,
4144                 .need_dac_fix = 1,
4145                 .input_mux = &alc880_capture_source,
4146         },
4147         [ALC880_ASUS_DIG2] = {
4148                 .mixers = { alc880_asus_mixer },
4149                 .init_verbs = { alc880_volume_init_verbs,
4150                                 alc880_pin_asus_init_verbs,
4151                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4152                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4153                 .dac_nids = alc880_asus_dac_nids,
4154                 .dig_out_nid = ALC880_DIGOUT_NID,
4155                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4156                 .channel_mode = alc880_asus_modes,
4157                 .need_dac_fix = 1,
4158                 .input_mux = &alc880_capture_source,
4159         },
4160         [ALC880_ASUS_W1V] = {
4161                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4162                 .init_verbs = { alc880_volume_init_verbs,
4163                                 alc880_pin_asus_init_verbs,
4164                                 alc880_gpio1_init_verbs },
4165                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4166                 .dac_nids = alc880_asus_dac_nids,
4167                 .dig_out_nid = ALC880_DIGOUT_NID,
4168                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4169                 .channel_mode = alc880_asus_modes,
4170                 .need_dac_fix = 1,
4171                 .input_mux = &alc880_capture_source,
4172         },
4173         [ALC880_UNIWILL_DIG] = {
4174                 .mixers = { alc880_asus_mixer },
4175                 .init_verbs = { alc880_volume_init_verbs,
4176                                 alc880_pin_asus_init_verbs },
4177                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4178                 .dac_nids = alc880_asus_dac_nids,
4179                 .dig_out_nid = ALC880_DIGOUT_NID,
4180                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4181                 .channel_mode = alc880_asus_modes,
4182                 .need_dac_fix = 1,
4183                 .input_mux = &alc880_capture_source,
4184         },
4185         [ALC880_UNIWILL] = {
4186                 .mixers = { alc880_uniwill_mixer },
4187                 .init_verbs = { alc880_volume_init_verbs,
4188                                 alc880_uniwill_init_verbs },
4189                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4190                 .dac_nids = alc880_asus_dac_nids,
4191                 .dig_out_nid = ALC880_DIGOUT_NID,
4192                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4193                 .channel_mode = alc880_threestack_modes,
4194                 .need_dac_fix = 1,
4195                 .input_mux = &alc880_capture_source,
4196                 .unsol_event = alc880_uniwill_unsol_event,
4197                 .setup = alc880_uniwill_setup,
4198                 .init_hook = alc880_uniwill_init_hook,
4199         },
4200         [ALC880_UNIWILL_P53] = {
4201                 .mixers = { alc880_uniwill_p53_mixer },
4202                 .init_verbs = { alc880_volume_init_verbs,
4203                                 alc880_uniwill_p53_init_verbs },
4204                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4205                 .dac_nids = alc880_asus_dac_nids,
4206                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4207                 .channel_mode = alc880_threestack_modes,
4208                 .input_mux = &alc880_capture_source,
4209                 .unsol_event = alc880_uniwill_p53_unsol_event,
4210                 .setup = alc880_uniwill_p53_setup,
4211                 .init_hook = alc_automute_amp,
4212         },
4213         [ALC880_FUJITSU] = {
4214                 .mixers = { alc880_fujitsu_mixer },
4215                 .init_verbs = { alc880_volume_init_verbs,
4216                                 alc880_uniwill_p53_init_verbs,
4217                                 alc880_beep_init_verbs },
4218                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4219                 .dac_nids = alc880_dac_nids,
4220                 .dig_out_nid = ALC880_DIGOUT_NID,
4221                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4222                 .channel_mode = alc880_2_jack_modes,
4223                 .input_mux = &alc880_capture_source,
4224                 .unsol_event = alc880_uniwill_p53_unsol_event,
4225                 .setup = alc880_uniwill_p53_setup,
4226                 .init_hook = alc_automute_amp,
4227         },
4228         [ALC880_CLEVO] = {
4229                 .mixers = { alc880_three_stack_mixer },
4230                 .init_verbs = { alc880_volume_init_verbs,
4231                                 alc880_pin_clevo_init_verbs },
4232                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4233                 .dac_nids = alc880_dac_nids,
4234                 .hp_nid = 0x03,
4235                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4236                 .channel_mode = alc880_threestack_modes,
4237                 .need_dac_fix = 1,
4238                 .input_mux = &alc880_capture_source,
4239         },
4240         [ALC880_LG] = {
4241                 .mixers = { alc880_lg_mixer },
4242                 .init_verbs = { alc880_volume_init_verbs,
4243                                 alc880_lg_init_verbs },
4244                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4245                 .dac_nids = alc880_lg_dac_nids,
4246                 .dig_out_nid = ALC880_DIGOUT_NID,
4247                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4248                 .channel_mode = alc880_lg_ch_modes,
4249                 .need_dac_fix = 1,
4250                 .input_mux = &alc880_lg_capture_source,
4251                 .unsol_event = alc_automute_amp_unsol_event,
4252                 .setup = alc880_lg_setup,
4253                 .init_hook = alc_automute_amp,
4254 #ifdef CONFIG_SND_HDA_POWER_SAVE
4255                 .loopbacks = alc880_lg_loopbacks,
4256 #endif
4257         },
4258         [ALC880_LG_LW] = {
4259                 .mixers = { alc880_lg_lw_mixer },
4260                 .init_verbs = { alc880_volume_init_verbs,
4261                                 alc880_lg_lw_init_verbs },
4262                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4263                 .dac_nids = alc880_dac_nids,
4264                 .dig_out_nid = ALC880_DIGOUT_NID,
4265                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4266                 .channel_mode = alc880_lg_lw_modes,
4267                 .input_mux = &alc880_lg_lw_capture_source,
4268                 .unsol_event = alc_automute_amp_unsol_event,
4269                 .setup = alc880_lg_lw_setup,
4270                 .init_hook = alc_automute_amp,
4271         },
4272         [ALC880_MEDION_RIM] = {
4273                 .mixers = { alc880_medion_rim_mixer },
4274                 .init_verbs = { alc880_volume_init_verbs,
4275                                 alc880_medion_rim_init_verbs,
4276                                 alc_gpio2_init_verbs },
4277                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4278                 .dac_nids = alc880_dac_nids,
4279                 .dig_out_nid = ALC880_DIGOUT_NID,
4280                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4281                 .channel_mode = alc880_2_jack_modes,
4282                 .input_mux = &alc880_medion_rim_capture_source,
4283                 .unsol_event = alc880_medion_rim_unsol_event,
4284                 .setup = alc880_medion_rim_setup,
4285                 .init_hook = alc880_medion_rim_automute,
4286         },
4287 #ifdef CONFIG_SND_DEBUG
4288         [ALC880_TEST] = {
4289                 .mixers = { alc880_test_mixer },
4290                 .init_verbs = { alc880_test_init_verbs },
4291                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4292                 .dac_nids = alc880_test_dac_nids,
4293                 .dig_out_nid = ALC880_DIGOUT_NID,
4294                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4295                 .channel_mode = alc880_test_modes,
4296                 .input_mux = &alc880_test_capture_source,
4297         },
4298 #endif
4299 };
4300
4301 /*
4302  * Automatic parse of I/O pins from the BIOS configuration
4303  */
4304
4305 enum {
4306         ALC_CTL_WIDGET_VOL,
4307         ALC_CTL_WIDGET_MUTE,
4308         ALC_CTL_BIND_MUTE,
4309 };
4310 static struct snd_kcontrol_new alc880_control_templates[] = {
4311         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4312         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4313         HDA_BIND_MUTE(NULL, 0, 0, 0),
4314 };
4315
4316 /* add dynamic controls */
4317 static int add_control(struct alc_spec *spec, int type, const char *name,
4318                        unsigned long val)
4319 {
4320         struct snd_kcontrol_new *knew;
4321
4322         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4323         knew = snd_array_new(&spec->kctls);
4324         if (!knew)
4325                 return -ENOMEM;
4326         *knew = alc880_control_templates[type];
4327         knew->name = kstrdup(name, GFP_KERNEL);
4328         if (!knew->name)
4329                 return -ENOMEM;
4330         if (get_amp_nid_(val))
4331                 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
4332         knew->private_value = val;
4333         return 0;
4334 }
4335
4336 static int add_control_with_pfx(struct alc_spec *spec, int type,
4337                                 const char *pfx, const char *dir,
4338                                 const char *sfx, unsigned long val)
4339 {
4340         char name[32];
4341         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4342         return add_control(spec, type, name, val);
4343 }
4344
4345 #define add_pb_vol_ctrl(spec, type, pfx, val) \
4346         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4347 #define add_pb_sw_ctrl(spec, type, pfx, val) \
4348         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4349
4350 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4351 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4352 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4353 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4354 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4355 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4356 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4357 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4358 #define ALC880_PIN_CD_NID               0x1c
4359
4360 /* fill in the dac_nids table from the parsed pin configuration */
4361 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4362                                      const struct auto_pin_cfg *cfg)
4363 {
4364         hda_nid_t nid;
4365         int assigned[4];
4366         int i, j;
4367
4368         memset(assigned, 0, sizeof(assigned));
4369         spec->multiout.dac_nids = spec->private_dac_nids;
4370
4371         /* check the pins hardwired to audio widget */
4372         for (i = 0; i < cfg->line_outs; i++) {
4373                 nid = cfg->line_out_pins[i];
4374                 if (alc880_is_fixed_pin(nid)) {
4375                         int idx = alc880_fixed_pin_idx(nid);
4376                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4377                         assigned[idx] = 1;
4378                 }
4379         }
4380         /* left pins can be connect to any audio widget */
4381         for (i = 0; i < cfg->line_outs; i++) {
4382                 nid = cfg->line_out_pins[i];
4383                 if (alc880_is_fixed_pin(nid))
4384                         continue;
4385                 /* search for an empty channel */
4386                 for (j = 0; j < cfg->line_outs; j++) {
4387                         if (!assigned[j]) {
4388                                 spec->multiout.dac_nids[i] =
4389                                         alc880_idx_to_dac(j);
4390                                 assigned[j] = 1;
4391                                 break;
4392                         }
4393                 }
4394         }
4395         spec->multiout.num_dacs = cfg->line_outs;
4396         return 0;
4397 }
4398
4399 /* add playback controls from the parsed DAC table */
4400 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4401                                              const struct auto_pin_cfg *cfg)
4402 {
4403         static const char *chname[4] = {
4404                 "Front", "Surround", NULL /*CLFE*/, "Side"
4405         };
4406         hda_nid_t nid;
4407         int i, err;
4408
4409         for (i = 0; i < cfg->line_outs; i++) {
4410                 if (!spec->multiout.dac_nids[i])
4411                         continue;
4412                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4413                 if (i == 2) {
4414                         /* Center/LFE */
4415                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4416                                               "Center",
4417                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4418                                                               HDA_OUTPUT));
4419                         if (err < 0)
4420                                 return err;
4421                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4422                                               "LFE",
4423                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4424                                                               HDA_OUTPUT));
4425                         if (err < 0)
4426                                 return err;
4427                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4428                                              "Center",
4429                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4430                                                               HDA_INPUT));
4431                         if (err < 0)
4432                                 return err;
4433                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4434                                              "LFE",
4435                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4436                                                               HDA_INPUT));
4437                         if (err < 0)
4438                                 return err;
4439                 } else {
4440                         const char *pfx;
4441                         if (cfg->line_outs == 1 &&
4442                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4443                                 pfx = "Speaker";
4444                         else
4445                                 pfx = chname[i];
4446                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4447                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4448                                                               HDA_OUTPUT));
4449                         if (err < 0)
4450                                 return err;
4451                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4452                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4453                                                               HDA_INPUT));
4454                         if (err < 0)
4455                                 return err;
4456                 }
4457         }
4458         return 0;
4459 }
4460
4461 /* add playback controls for speaker and HP outputs */
4462 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4463                                         const char *pfx)
4464 {
4465         hda_nid_t nid;
4466         int err;
4467
4468         if (!pin)
4469                 return 0;
4470
4471         if (alc880_is_fixed_pin(pin)) {
4472                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4473                 /* specify the DAC as the extra output */
4474                 if (!spec->multiout.hp_nid)
4475                         spec->multiout.hp_nid = nid;
4476                 else
4477                         spec->multiout.extra_out_nid[0] = nid;
4478                 /* control HP volume/switch on the output mixer amp */
4479                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4480                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4481                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4482                 if (err < 0)
4483                         return err;
4484                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4485                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4486                 if (err < 0)
4487                         return err;
4488         } else if (alc880_is_multi_pin(pin)) {
4489                 /* set manual connection */
4490                 /* we have only a switch on HP-out PIN */
4491                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4492                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4493                 if (err < 0)
4494                         return err;
4495         }
4496         return 0;
4497 }
4498
4499 /* create input playback/capture controls for the given pin */
4500 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4501                             const char *ctlname,
4502                             int idx, hda_nid_t mix_nid)
4503 {
4504         int err;
4505
4506         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4507                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4508         if (err < 0)
4509                 return err;
4510         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4511                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4512         if (err < 0)
4513                 return err;
4514         return 0;
4515 }
4516
4517 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4518 {
4519         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4520         return (pincap & AC_PINCAP_IN) != 0;
4521 }
4522
4523 /* create playback/capture controls for input pins */
4524 static int alc_auto_create_input_ctls(struct hda_codec *codec,
4525                                       const struct auto_pin_cfg *cfg,
4526                                       hda_nid_t mixer,
4527                                       hda_nid_t cap1, hda_nid_t cap2)
4528 {
4529         struct alc_spec *spec = codec->spec;
4530         struct hda_input_mux *imux = &spec->private_imux[0];
4531         int i, err, idx;
4532
4533         for (i = 0; i < AUTO_PIN_LAST; i++) {
4534                 hda_nid_t pin;
4535
4536                 pin = cfg->input_pins[i];
4537                 if (!alc_is_input_pin(codec, pin))
4538                         continue;
4539
4540                 if (mixer) {
4541                         idx = get_connection_index(codec, mixer, pin);
4542                         if (idx >= 0) {
4543                                 err = new_analog_input(spec, pin,
4544                                                        auto_pin_cfg_labels[i],
4545                                                        idx, mixer);
4546                                 if (err < 0)
4547                                         return err;
4548                         }
4549                 }
4550
4551                 if (!cap1)
4552                         continue;
4553                 idx = get_connection_index(codec, cap1, pin);
4554                 if (idx < 0 && cap2)
4555                         idx = get_connection_index(codec, cap2, pin);
4556                 if (idx >= 0) {
4557                         imux->items[imux->num_items].label =
4558                                 auto_pin_cfg_labels[i];
4559                         imux->items[imux->num_items].index = idx;
4560                         imux->num_items++;
4561                 }
4562         }
4563         return 0;
4564 }
4565
4566 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4567                                                 const struct auto_pin_cfg *cfg)
4568 {
4569         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4570 }
4571
4572 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4573                                unsigned int pin_type)
4574 {
4575         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4576                             pin_type);
4577         /* unmute pin */
4578         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4579                             AMP_OUT_UNMUTE);
4580 }
4581
4582 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4583                                               hda_nid_t nid, int pin_type,
4584                                               int dac_idx)
4585 {
4586         alc_set_pin_output(codec, nid, pin_type);
4587         /* need the manual connection? */
4588         if (alc880_is_multi_pin(nid)) {
4589                 struct alc_spec *spec = codec->spec;
4590                 int idx = alc880_multi_pin_idx(nid);
4591                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4592                                     AC_VERB_SET_CONNECT_SEL,
4593                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4594         }
4595 }
4596
4597 static int get_pin_type(int line_out_type)
4598 {
4599         if (line_out_type == AUTO_PIN_HP_OUT)
4600                 return PIN_HP;
4601         else
4602                 return PIN_OUT;
4603 }
4604
4605 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4606 {
4607         struct alc_spec *spec = codec->spec;
4608         int i;
4609
4610         for (i = 0; i < spec->autocfg.line_outs; i++) {
4611                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4612                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4613                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4614         }
4615 }
4616
4617 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4618 {
4619         struct alc_spec *spec = codec->spec;
4620         hda_nid_t pin;
4621
4622         pin = spec->autocfg.speaker_pins[0];
4623         if (pin) /* connect to front */
4624                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4625         pin = spec->autocfg.hp_pins[0];
4626         if (pin) /* connect to front */
4627                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4628 }
4629
4630 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4631 {
4632         struct alc_spec *spec = codec->spec;
4633         int i;
4634
4635         for (i = 0; i < AUTO_PIN_LAST; i++) {
4636                 hda_nid_t nid = spec->autocfg.input_pins[i];
4637                 if (alc_is_input_pin(codec, nid)) {
4638                         alc_set_input_pin(codec, nid, i);
4639                         if (nid != ALC880_PIN_CD_NID &&
4640                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4641                                 snd_hda_codec_write(codec, nid, 0,
4642                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4643                                                     AMP_OUT_MUTE);
4644                 }
4645         }
4646 }
4647
4648 /* parse the BIOS configuration and set up the alc_spec */
4649 /* return 1 if successful, 0 if the proper config is not found,
4650  * or a negative error code
4651  */
4652 static int alc880_parse_auto_config(struct hda_codec *codec)
4653 {
4654         struct alc_spec *spec = codec->spec;
4655         int i, err;
4656         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4657
4658         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4659                                            alc880_ignore);
4660         if (err < 0)
4661                 return err;
4662         if (!spec->autocfg.line_outs)
4663                 return 0; /* can't find valid BIOS pin config */
4664
4665         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4666         if (err < 0)
4667                 return err;
4668         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4669         if (err < 0)
4670                 return err;
4671         err = alc880_auto_create_extra_out(spec,
4672                                            spec->autocfg.speaker_pins[0],
4673                                            "Speaker");
4674         if (err < 0)
4675                 return err;
4676         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4677                                            "Headphone");
4678         if (err < 0)
4679                 return err;
4680         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4681         if (err < 0)
4682                 return err;
4683
4684         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4685
4686         /* check multiple SPDIF-out (for recent codecs) */
4687         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4688                 hda_nid_t dig_nid;
4689                 err = snd_hda_get_connections(codec,
4690                                               spec->autocfg.dig_out_pins[i],
4691                                               &dig_nid, 1);
4692                 if (err < 0)
4693                         continue;
4694                 if (!i)
4695                         spec->multiout.dig_out_nid = dig_nid;
4696                 else {
4697                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4698                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4699                                 break;
4700                         spec->slave_dig_outs[i - 1] = dig_nid;
4701                 }
4702         }
4703         if (spec->autocfg.dig_in_pin)
4704                 spec->dig_in_nid = ALC880_DIGIN_NID;
4705
4706         if (spec->kctls.list)
4707                 add_mixer(spec, spec->kctls.list);
4708
4709         add_verb(spec, alc880_volume_init_verbs);
4710
4711         spec->num_mux_defs = 1;
4712         spec->input_mux = &spec->private_imux[0];
4713
4714         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4715
4716         return 1;
4717 }
4718
4719 /* additional initialization for auto-configuration model */
4720 static void alc880_auto_init(struct hda_codec *codec)
4721 {
4722         struct alc_spec *spec = codec->spec;
4723         alc880_auto_init_multi_out(codec);
4724         alc880_auto_init_extra_out(codec);
4725         alc880_auto_init_analog_input(codec);
4726         if (spec->unsol_event)
4727                 alc_inithook(codec);
4728 }
4729
4730 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4731  * one of two digital mic pins, e.g. on ALC272
4732  */
4733 static void fixup_automic_adc(struct hda_codec *codec)
4734 {
4735         struct alc_spec *spec = codec->spec;
4736         int i;
4737
4738         for (i = 0; i < spec->num_adc_nids; i++) {
4739                 hda_nid_t cap = spec->capsrc_nids ?
4740                         spec->capsrc_nids[i] : spec->adc_nids[i];
4741                 int iidx, eidx;
4742
4743                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4744                 if (iidx < 0)
4745                         continue;
4746                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4747                 if (eidx < 0)
4748                         continue;
4749                 spec->int_mic.mux_idx = iidx;
4750                 spec->ext_mic.mux_idx = eidx;
4751                 if (spec->capsrc_nids)
4752                         spec->capsrc_nids += i;
4753                 spec->adc_nids += i;
4754                 spec->num_adc_nids = 1;
4755                 return;
4756         }
4757         snd_printd(KERN_INFO "hda_codec: %s: "
4758                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4759                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4760         spec->auto_mic = 0; /* disable auto-mic to be sure */
4761 }
4762
4763 static void set_capture_mixer(struct hda_codec *codec)
4764 {
4765         struct alc_spec *spec = codec->spec;
4766         static struct snd_kcontrol_new *caps[2][3] = {
4767                 { alc_capture_mixer_nosrc1,
4768                   alc_capture_mixer_nosrc2,
4769                   alc_capture_mixer_nosrc3 },
4770                 { alc_capture_mixer1,
4771                   alc_capture_mixer2,
4772                   alc_capture_mixer3 },
4773         };
4774         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4775                 int mux;
4776                 if (spec->auto_mic) {
4777                         mux = 0;
4778                         fixup_automic_adc(codec);
4779                 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4780                         mux = 1;
4781                 else
4782                         mux = 0;
4783                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4784         }
4785 }
4786
4787 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4788 #define set_beep_amp(spec, nid, idx, dir) \
4789         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4790 #else
4791 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4792 #endif
4793
4794 /*
4795  * OK, here we have finally the patch for ALC880
4796  */
4797
4798 static int patch_alc880(struct hda_codec *codec)
4799 {
4800         struct alc_spec *spec;
4801         int board_config;
4802         int err;
4803
4804         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4805         if (spec == NULL)
4806                 return -ENOMEM;
4807
4808         codec->spec = spec;
4809
4810         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4811                                                   alc880_models,
4812                                                   alc880_cfg_tbl);
4813         if (board_config < 0) {
4814                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4815                        codec->chip_name);
4816                 board_config = ALC880_AUTO;
4817         }
4818
4819         if (board_config == ALC880_AUTO) {
4820                 /* automatic parse from the BIOS config */
4821                 err = alc880_parse_auto_config(codec);
4822                 if (err < 0) {
4823                         alc_free(codec);
4824                         return err;
4825                 } else if (!err) {
4826                         printk(KERN_INFO
4827                                "hda_codec: Cannot set up configuration "
4828                                "from BIOS.  Using 3-stack mode...\n");
4829                         board_config = ALC880_3ST;
4830                 }
4831         }
4832
4833         err = snd_hda_attach_beep_device(codec, 0x1);
4834         if (err < 0) {
4835                 alc_free(codec);
4836                 return err;
4837         }
4838
4839         if (board_config != ALC880_AUTO)
4840                 setup_preset(codec, &alc880_presets[board_config]);
4841
4842         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4843         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4844         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4845
4846         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4847         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4848
4849         if (!spec->adc_nids && spec->input_mux) {
4850                 /* check whether NID 0x07 is valid */
4851                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4852                 /* get type */
4853                 wcap = get_wcaps_type(wcap);
4854                 if (wcap != AC_WID_AUD_IN) {
4855                         spec->adc_nids = alc880_adc_nids_alt;
4856                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4857                 } else {
4858                         spec->adc_nids = alc880_adc_nids;
4859                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4860                 }
4861         }
4862         set_capture_mixer(codec);
4863         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4864
4865         spec->vmaster_nid = 0x0c;
4866
4867         codec->patch_ops = alc_patch_ops;
4868         if (board_config == ALC880_AUTO)
4869                 spec->init_hook = alc880_auto_init;
4870 #ifdef CONFIG_SND_HDA_POWER_SAVE
4871         if (!spec->loopback.amplist)
4872                 spec->loopback.amplist = alc880_loopbacks;
4873 #endif
4874         codec->proc_widget_hook = print_realtek_coef;
4875
4876         return 0;
4877 }
4878
4879
4880 /*
4881  * ALC260 support
4882  */
4883
4884 static hda_nid_t alc260_dac_nids[1] = {
4885         /* front */
4886         0x02,
4887 };
4888
4889 static hda_nid_t alc260_adc_nids[1] = {
4890         /* ADC0 */
4891         0x04,
4892 };
4893
4894 static hda_nid_t alc260_adc_nids_alt[1] = {
4895         /* ADC1 */
4896         0x05,
4897 };
4898
4899 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4900  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4901  */
4902 static hda_nid_t alc260_dual_adc_nids[2] = {
4903         /* ADC0, ADC1 */
4904         0x04, 0x05
4905 };
4906
4907 #define ALC260_DIGOUT_NID       0x03
4908 #define ALC260_DIGIN_NID        0x06
4909
4910 static struct hda_input_mux alc260_capture_source = {
4911         .num_items = 4,
4912         .items = {
4913                 { "Mic", 0x0 },
4914                 { "Front Mic", 0x1 },
4915                 { "Line", 0x2 },
4916                 { "CD", 0x4 },
4917         },
4918 };
4919
4920 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4921  * headphone jack and the internal CD lines since these are the only pins at
4922  * which audio can appear.  For flexibility, also allow the option of
4923  * recording the mixer output on the second ADC (ADC0 doesn't have a
4924  * connection to the mixer output).
4925  */
4926 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4927         {
4928                 .num_items = 3,
4929                 .items = {
4930                         { "Mic/Line", 0x0 },
4931                         { "CD", 0x4 },
4932                         { "Headphone", 0x2 },
4933                 },
4934         },
4935         {
4936                 .num_items = 4,
4937                 .items = {
4938                         { "Mic/Line", 0x0 },
4939                         { "CD", 0x4 },
4940                         { "Headphone", 0x2 },
4941                         { "Mixer", 0x5 },
4942                 },
4943         },
4944
4945 };
4946
4947 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4948  * the Fujitsu S702x, but jacks are marked differently.
4949  */
4950 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4951         {
4952                 .num_items = 4,
4953                 .items = {
4954                         { "Mic", 0x0 },
4955                         { "Line", 0x2 },
4956                         { "CD", 0x4 },
4957                         { "Headphone", 0x5 },
4958                 },
4959         },
4960         {
4961                 .num_items = 5,
4962                 .items = {
4963                         { "Mic", 0x0 },
4964                         { "Line", 0x2 },
4965                         { "CD", 0x4 },
4966                         { "Headphone", 0x6 },
4967                         { "Mixer", 0x5 },
4968                 },
4969         },
4970 };
4971
4972 /* Maxdata Favorit 100XS */
4973 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4974         {
4975                 .num_items = 2,
4976                 .items = {
4977                         { "Line/Mic", 0x0 },
4978                         { "CD", 0x4 },
4979                 },
4980         },
4981         {
4982                 .num_items = 3,
4983                 .items = {
4984                         { "Line/Mic", 0x0 },
4985                         { "CD", 0x4 },
4986                         { "Mixer", 0x5 },
4987                 },
4988         },
4989 };
4990
4991 /*
4992  * This is just place-holder, so there's something for alc_build_pcms to look
4993  * at when it calculates the maximum number of channels. ALC260 has no mixer
4994  * element which allows changing the channel mode, so the verb list is
4995  * never used.
4996  */
4997 static struct hda_channel_mode alc260_modes[1] = {
4998         { 2, NULL },
4999 };
5000
5001
5002 /* Mixer combinations
5003  *
5004  * basic: base_output + input + pc_beep + capture
5005  * HP: base_output + input + capture_alt
5006  * HP_3013: hp_3013 + input + capture
5007  * fujitsu: fujitsu + capture
5008  * acer: acer + capture
5009  */
5010
5011 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5012         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5013         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5014         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5015         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5016         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5017         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5018         { } /* end */
5019 };
5020
5021 static struct snd_kcontrol_new alc260_input_mixer[] = {
5022         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5023         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5024         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5025         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5027         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5028         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5029         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5030         { } /* end */
5031 };
5032
5033 /* update HP, line and mono out pins according to the master switch */
5034 static void alc260_hp_master_update(struct hda_codec *codec,
5035                                     hda_nid_t hp, hda_nid_t line,
5036                                     hda_nid_t mono)
5037 {
5038         struct alc_spec *spec = codec->spec;
5039         unsigned int val = spec->master_sw ? PIN_HP : 0;
5040         /* change HP and line-out pins */
5041         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5042                             val);
5043         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5044                             val);
5045         /* mono (speaker) depending on the HP jack sense */
5046         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5047         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5048                             val);
5049 }
5050
5051 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5052                                    struct snd_ctl_elem_value *ucontrol)
5053 {
5054         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5055         struct alc_spec *spec = codec->spec;
5056         *ucontrol->value.integer.value = spec->master_sw;
5057         return 0;
5058 }
5059
5060 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5061                                    struct snd_ctl_elem_value *ucontrol)
5062 {
5063         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5064         struct alc_spec *spec = codec->spec;
5065         int val = !!*ucontrol->value.integer.value;
5066         hda_nid_t hp, line, mono;
5067
5068         if (val == spec->master_sw)
5069                 return 0;
5070         spec->master_sw = val;
5071         hp = (kcontrol->private_value >> 16) & 0xff;
5072         line = (kcontrol->private_value >> 8) & 0xff;
5073         mono = kcontrol->private_value & 0xff;
5074         alc260_hp_master_update(codec, hp, line, mono);
5075         return 1;
5076 }
5077
5078 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5079         {
5080                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5081                 .name = "Master Playback Switch",
5082                 .info = snd_ctl_boolean_mono_info,
5083                 .get = alc260_hp_master_sw_get,
5084                 .put = alc260_hp_master_sw_put,
5085                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5086         },
5087         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5088         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5089         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5090         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5091         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5092                               HDA_OUTPUT),
5093         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5094         { } /* end */
5095 };
5096
5097 static struct hda_verb alc260_hp_unsol_verbs[] = {
5098         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5099         {},
5100 };
5101
5102 static void alc260_hp_automute(struct hda_codec *codec)
5103 {
5104         struct alc_spec *spec = codec->spec;
5105         unsigned int present;
5106
5107         present = snd_hda_codec_read(codec, 0x10, 0,
5108                                      AC_VERB_GET_PIN_SENSE, 0);
5109         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5110         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5111 }
5112
5113 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5114 {
5115         if ((res >> 26) == ALC880_HP_EVENT)
5116                 alc260_hp_automute(codec);
5117 }
5118
5119 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5120         {
5121                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5122                 .name = "Master Playback Switch",
5123                 .info = snd_ctl_boolean_mono_info,
5124                 .get = alc260_hp_master_sw_get,
5125                 .put = alc260_hp_master_sw_put,
5126                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5127         },
5128         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5129         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5130         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5131         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5132         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5134         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5135         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5136         { } /* end */
5137 };
5138
5139 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5140         .ops = &snd_hda_bind_vol,
5141         .values = {
5142                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5143                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5144                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5145                 0
5146         },
5147 };
5148
5149 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5150         .ops = &snd_hda_bind_sw,
5151         .values = {
5152                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5153                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5154                 0
5155         },
5156 };
5157
5158 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5159         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5160         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5161         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5162         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5163         { } /* end */
5164 };
5165
5166 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5167         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5168         {},
5169 };
5170
5171 static void alc260_hp_3013_automute(struct hda_codec *codec)
5172 {
5173         struct alc_spec *spec = codec->spec;
5174         unsigned int present;
5175
5176         present = snd_hda_codec_read(codec, 0x15, 0,
5177                                      AC_VERB_GET_PIN_SENSE, 0);
5178         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5179         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5180 }
5181
5182 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5183                                        unsigned int res)
5184 {
5185         if ((res >> 26) == ALC880_HP_EVENT)
5186                 alc260_hp_3013_automute(codec);
5187 }
5188
5189 static void alc260_hp_3012_automute(struct hda_codec *codec)
5190 {
5191         unsigned int present, bits;
5192
5193         present = snd_hda_codec_read(codec, 0x10, 0,
5194                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5195
5196         bits = present ? 0 : PIN_OUT;
5197         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5198                             bits);
5199         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5200                             bits);
5201         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5202                             bits);
5203 }
5204
5205 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5206                                        unsigned int res)
5207 {
5208         if ((res >> 26) == ALC880_HP_EVENT)
5209                 alc260_hp_3012_automute(codec);
5210 }
5211
5212 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5213  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5214  */
5215 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5216         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5217         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5218         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5219         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5220         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5221         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5222         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5223         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5224         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5225         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5226         { } /* end */
5227 };
5228
5229 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5230  * versions of the ALC260 don't act on requests to enable mic bias from NID
5231  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5232  * datasheet doesn't mention this restriction.  At this stage it's not clear
5233  * whether this behaviour is intentional or is a hardware bug in chip
5234  * revisions available in early 2006.  Therefore for now allow the
5235  * "Headphone Jack Mode" control to span all choices, but if it turns out
5236  * that the lack of mic bias for this NID is intentional we could change the
5237  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5238  *
5239  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5240  * don't appear to make the mic bias available from the "line" jack, even
5241  * though the NID used for this jack (0x14) can supply it.  The theory is
5242  * that perhaps Acer have included blocking capacitors between the ALC260
5243  * and the output jack.  If this turns out to be the case for all such
5244  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5245  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5246  *
5247  * The C20x Tablet series have a mono internal speaker which is controlled
5248  * via the chip's Mono sum widget and pin complex, so include the necessary
5249  * controls for such models.  On models without a "mono speaker" the control
5250  * won't do anything.
5251  */
5252 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5253         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5254         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5255         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5256         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5257                               HDA_OUTPUT),
5258         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5259                            HDA_INPUT),
5260         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5261         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5262         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5263         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5264         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5265         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5266         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5267         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5268         { } /* end */
5269 };
5270
5271 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5272  */
5273 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5274         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5275         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5276         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5277         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5278         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5279         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5280         { } /* end */
5281 };
5282
5283 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5284  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5285  */
5286 static struct snd_kcontrol_new alc260_will_mixer[] = {
5287         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5288         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5289         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5290         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5291         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5292         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5293         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5294         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5295         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5296         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5297         { } /* end */
5298 };
5299
5300 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5301  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5302  */
5303 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5304         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5305         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5306         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5307         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5308         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5309         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5310         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5311         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5312         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5313         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5314         { } /* end */
5315 };
5316
5317 /*
5318  * initialization verbs
5319  */
5320 static struct hda_verb alc260_init_verbs[] = {
5321         /* Line In pin widget for input */
5322         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5323         /* CD pin widget for input */
5324         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5325         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5326         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5327         /* Mic2 (front panel) pin widget for input and vref at 80% */
5328         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5329         /* LINE-2 is used for line-out in rear */
5330         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5331         /* select line-out */
5332         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5333         /* LINE-OUT pin */
5334         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5335         /* enable HP */
5336         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5337         /* enable Mono */
5338         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5339         /* mute capture amp left and right */
5340         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5341         /* set connection select to line in (default select for this ADC) */
5342         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5343         /* mute capture amp left and right */
5344         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5345         /* set connection select to line in (default select for this ADC) */
5346         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5347         /* set vol=0 Line-Out mixer amp left and right */
5348         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5349         /* unmute pin widget amp left and right (no gain on this amp) */
5350         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5351         /* set vol=0 HP mixer amp left and right */
5352         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5353         /* unmute pin widget amp left and right (no gain on this amp) */
5354         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5355         /* set vol=0 Mono mixer amp left and right */
5356         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5357         /* unmute pin widget amp left and right (no gain on this amp) */
5358         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5359         /* unmute LINE-2 out pin */
5360         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5361         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5362          * Line In 2 = 0x03
5363          */
5364         /* mute analog inputs */
5365         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5366         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5367         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5369         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5370         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5371         /* mute Front out path */
5372         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5373         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5374         /* mute Headphone out path */
5375         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5376         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5377         /* mute Mono out path */
5378         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5379         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5380         { }
5381 };
5382
5383 #if 0 /* should be identical with alc260_init_verbs? */
5384 static struct hda_verb alc260_hp_init_verbs[] = {
5385         /* Headphone and output */
5386         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5387         /* mono output */
5388         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5389         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5390         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5391         /* Mic2 (front panel) pin widget for input and vref at 80% */
5392         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5393         /* Line In pin widget for input */
5394         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5395         /* Line-2 pin widget for output */
5396         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5397         /* CD pin widget for input */
5398         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5399         /* unmute amp left and right */
5400         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5401         /* set connection select to line in (default select for this ADC) */
5402         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5403         /* unmute Line-Out mixer amp left and right (volume = 0) */
5404         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5405         /* mute pin widget amp left and right (no gain on this amp) */
5406         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5407         /* unmute HP mixer amp left and right (volume = 0) */
5408         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5409         /* mute pin widget amp left and right (no gain on this amp) */
5410         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5411         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5412          * Line In 2 = 0x03
5413          */
5414         /* mute analog inputs */
5415         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5416         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5417         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5418         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5419         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5420         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5421         /* Unmute Front out path */
5422         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5423         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5424         /* Unmute Headphone out path */
5425         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5426         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5427         /* Unmute Mono out path */
5428         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5429         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5430         { }
5431 };
5432 #endif
5433
5434 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5435         /* Line out and output */
5436         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5437         /* mono output */
5438         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5439         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5440         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5441         /* Mic2 (front panel) pin widget for input and vref at 80% */
5442         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5443         /* Line In pin widget for input */
5444         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5445         /* Headphone pin widget for output */
5446         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5447         /* CD pin widget for input */
5448         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5449         /* unmute amp left and right */
5450         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5451         /* set connection select to line in (default select for this ADC) */
5452         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5453         /* unmute Line-Out mixer amp left and right (volume = 0) */
5454         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5455         /* mute pin widget amp left and right (no gain on this amp) */
5456         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5457         /* unmute HP mixer amp left and right (volume = 0) */
5458         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5459         /* mute pin widget amp left and right (no gain on this amp) */
5460         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5461         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5462          * Line In 2 = 0x03
5463          */
5464         /* mute analog inputs */
5465         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5466         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5467         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5468         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5469         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5470         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5471         /* Unmute Front out path */
5472         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5473         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5474         /* Unmute Headphone out path */
5475         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5476         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5477         /* Unmute Mono out path */
5478         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5479         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5480         { }
5481 };
5482
5483 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5484  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5485  * audio = 0x16, internal speaker = 0x10.
5486  */
5487 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5488         /* Disable all GPIOs */
5489         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5490         /* Internal speaker is connected to headphone pin */
5491         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5492         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5493         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5494         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5495         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5496         /* Ensure all other unused pins are disabled and muted. */
5497         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5498         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5499         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5500         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5501         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5502         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5503         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5504         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5505
5506         /* Disable digital (SPDIF) pins */
5507         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5508         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5509
5510         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5511          * when acting as an output.
5512          */
5513         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5514
5515         /* Start with output sum widgets muted and their output gains at min */
5516         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5517         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5518         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5519         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5520         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5521         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5522         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5523         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5524         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5525
5526         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5527         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5528         /* Unmute Line1 pin widget output buffer since it starts as an output.
5529          * If the pin mode is changed by the user the pin mode control will
5530          * take care of enabling the pin's input/output buffers as needed.
5531          * Therefore there's no need to enable the input buffer at this
5532          * stage.
5533          */
5534         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5535         /* Unmute input buffer of pin widget used for Line-in (no equiv
5536          * mixer ctrl)
5537          */
5538         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5539
5540         /* Mute capture amp left and right */
5541         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5542         /* Set ADC connection select to match default mixer setting - line
5543          * in (on mic1 pin)
5544          */
5545         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5546
5547         /* Do the same for the second ADC: mute capture input amp and
5548          * set ADC connection to line in (on mic1 pin)
5549          */
5550         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5551         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5552
5553         /* Mute all inputs to mixer widget (even unconnected ones) */
5554         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5555         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5556         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5557         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5558         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5559         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5560         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5561         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5562
5563         { }
5564 };
5565
5566 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5567  * similar laptops (adapted from Fujitsu init verbs).
5568  */
5569 static struct hda_verb alc260_acer_init_verbs[] = {
5570         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5571          * the headphone jack.  Turn this on and rely on the standard mute
5572          * methods whenever the user wants to turn these outputs off.
5573          */
5574         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5575         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5576         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5577         /* Internal speaker/Headphone jack is connected to Line-out pin */
5578         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5579         /* Internal microphone/Mic jack is connected to Mic1 pin */
5580         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5581         /* Line In jack is connected to Line1 pin */
5582         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5583         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5584         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5585         /* Ensure all other unused pins are disabled and muted. */
5586         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5587         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5588         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5589         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5590         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5591         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5592         /* Disable digital (SPDIF) pins */
5593         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5594         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5595
5596         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5597          * bus when acting as outputs.
5598          */
5599         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5600         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5601
5602         /* Start with output sum widgets muted and their output gains at min */
5603         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5604         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5605         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5606         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5607         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5608         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5609         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5610         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5611         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5612
5613         /* Unmute Line-out pin widget amp left and right
5614          * (no equiv mixer ctrl)
5615          */
5616         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5617         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5618         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5619         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5620          * inputs. If the pin mode is changed by the user the pin mode control
5621          * will take care of enabling the pin's input/output buffers as needed.
5622          * Therefore there's no need to enable the input buffer at this
5623          * stage.
5624          */
5625         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5626         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5627
5628         /* Mute capture amp left and right */
5629         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5630         /* Set ADC connection select to match default mixer setting - mic
5631          * (on mic1 pin)
5632          */
5633         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5634
5635         /* Do similar with the second ADC: mute capture input amp and
5636          * set ADC connection to mic to match ALSA's default state.
5637          */
5638         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5639         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5640
5641         /* Mute all inputs to mixer widget (even unconnected ones) */
5642         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5643         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5644         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5645         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5646         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5647         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5648         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5649         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5650
5651         { }
5652 };
5653
5654 /* Initialisation sequence for Maxdata Favorit 100XS
5655  * (adapted from Acer init verbs).
5656  */
5657 static struct hda_verb alc260_favorit100_init_verbs[] = {
5658         /* GPIO 0 enables the output jack.
5659          * Turn this on and rely on the standard mute
5660          * methods whenever the user wants to turn these outputs off.
5661          */
5662         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5663         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5664         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5665         /* Line/Mic input jack is connected to Mic1 pin */
5666         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5667         /* Ensure all other unused pins are disabled and muted. */
5668         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5669         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5670         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5671         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5672         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5673         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5674         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5675         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5676         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5677         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5678         /* Disable digital (SPDIF) pins */
5679         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5680         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5681
5682         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5683          * bus when acting as outputs.
5684          */
5685         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5686         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5687
5688         /* Start with output sum widgets muted and their output gains at min */
5689         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5690         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5691         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5692         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5693         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5694         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5695         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5696         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5697         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5698
5699         /* Unmute Line-out pin widget amp left and right
5700          * (no equiv mixer ctrl)
5701          */
5702         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5703         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5704          * inputs. If the pin mode is changed by the user the pin mode control
5705          * will take care of enabling the pin's input/output buffers as needed.
5706          * Therefore there's no need to enable the input buffer at this
5707          * stage.
5708          */
5709         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5710
5711         /* Mute capture amp left and right */
5712         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5713         /* Set ADC connection select to match default mixer setting - mic
5714          * (on mic1 pin)
5715          */
5716         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5717
5718         /* Do similar with the second ADC: mute capture input amp and
5719          * set ADC connection to mic to match ALSA's default state.
5720          */
5721         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5722         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5723
5724         /* Mute all inputs to mixer widget (even unconnected ones) */
5725         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5726         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5727         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5728         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5729         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5730         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5731         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5732         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5733
5734         { }
5735 };
5736
5737 static struct hda_verb alc260_will_verbs[] = {
5738         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5739         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5740         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5741         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5742         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5743         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5744         {}
5745 };
5746
5747 static struct hda_verb alc260_replacer_672v_verbs[] = {
5748         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5749         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5750         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5751
5752         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5753         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5754         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5755
5756         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5757         {}
5758 };
5759
5760 /* toggle speaker-output according to the hp-jack state */
5761 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5762 {
5763         unsigned int present;
5764
5765         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5766         present = snd_hda_codec_read(codec, 0x0f, 0,
5767                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5768         if (present) {
5769                 snd_hda_codec_write_cache(codec, 0x01, 0,
5770                                           AC_VERB_SET_GPIO_DATA, 1);
5771                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5772                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5773                                           PIN_HP);
5774         } else {
5775                 snd_hda_codec_write_cache(codec, 0x01, 0,
5776                                           AC_VERB_SET_GPIO_DATA, 0);
5777                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5778                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5779                                           PIN_OUT);
5780         }
5781 }
5782
5783 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5784                                        unsigned int res)
5785 {
5786         if ((res >> 26) == ALC880_HP_EVENT)
5787                 alc260_replacer_672v_automute(codec);
5788 }
5789
5790 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5791         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5792         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5793         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5794         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5795         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5796         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5797         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5798         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5799         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5800         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5801         {}
5802 };
5803
5804 /* Test configuration for debugging, modelled after the ALC880 test
5805  * configuration.
5806  */
5807 #ifdef CONFIG_SND_DEBUG
5808 static hda_nid_t alc260_test_dac_nids[1] = {
5809         0x02,
5810 };
5811 static hda_nid_t alc260_test_adc_nids[2] = {
5812         0x04, 0x05,
5813 };
5814 /* For testing the ALC260, each input MUX needs its own definition since
5815  * the signal assignments are different.  This assumes that the first ADC
5816  * is NID 0x04.
5817  */
5818 static struct hda_input_mux alc260_test_capture_sources[2] = {
5819         {
5820                 .num_items = 7,
5821                 .items = {
5822                         { "MIC1 pin", 0x0 },
5823                         { "MIC2 pin", 0x1 },
5824                         { "LINE1 pin", 0x2 },
5825                         { "LINE2 pin", 0x3 },
5826                         { "CD pin", 0x4 },
5827                         { "LINE-OUT pin", 0x5 },
5828                         { "HP-OUT pin", 0x6 },
5829                 },
5830         },
5831         {
5832                 .num_items = 8,
5833                 .items = {
5834                         { "MIC1 pin", 0x0 },
5835                         { "MIC2 pin", 0x1 },
5836                         { "LINE1 pin", 0x2 },
5837                         { "LINE2 pin", 0x3 },
5838                         { "CD pin", 0x4 },
5839                         { "Mixer", 0x5 },
5840                         { "LINE-OUT pin", 0x6 },
5841                         { "HP-OUT pin", 0x7 },
5842                 },
5843         },
5844 };
5845 static struct snd_kcontrol_new alc260_test_mixer[] = {
5846         /* Output driver widgets */
5847         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5848         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5849         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5850         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5851         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5852         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5853
5854         /* Modes for retasking pin widgets
5855          * Note: the ALC260 doesn't seem to act on requests to enable mic
5856          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5857          * mention this restriction.  At this stage it's not clear whether
5858          * this behaviour is intentional or is a hardware bug in chip
5859          * revisions available at least up until early 2006.  Therefore for
5860          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5861          * choices, but if it turns out that the lack of mic bias for these
5862          * NIDs is intentional we could change their modes from
5863          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5864          */
5865         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5866         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5867         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5868         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5869         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5870         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5871
5872         /* Loopback mixer controls */
5873         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5874         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5875         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5876         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5877         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5878         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5879         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5880         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5881         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5882         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5883         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5884         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5885         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5886         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5887
5888         /* Controls for GPIO pins, assuming they are configured as outputs */
5889         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5890         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5891         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5892         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5893
5894         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5895          * is ambigious as to which NID is which; testing on laptops which
5896          * make this output available should provide clarification.
5897          */
5898         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5899         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5900
5901         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5902          * this output to turn on an external amplifier.
5903          */
5904         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5905         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5906
5907         { } /* end */
5908 };
5909 static struct hda_verb alc260_test_init_verbs[] = {
5910         /* Enable all GPIOs as outputs with an initial value of 0 */
5911         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5912         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5913         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5914
5915         /* Enable retasking pins as output, initially without power amp */
5916         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5917         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5918         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5919         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5920         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5921         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5922
5923         /* Disable digital (SPDIF) pins initially, but users can enable
5924          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5925          * payload also sets the generation to 0, output to be in "consumer"
5926          * PCM format, copyright asserted, no pre-emphasis and no validity
5927          * control.
5928          */
5929         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5930         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5931
5932         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5933          * OUT1 sum bus when acting as an output.
5934          */
5935         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5936         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5937         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5938         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5939
5940         /* Start with output sum widgets muted and their output gains at min */
5941         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5942         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5943         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5944         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5945         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5946         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5947         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5948         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5949         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5950
5951         /* Unmute retasking pin widget output buffers since the default
5952          * state appears to be output.  As the pin mode is changed by the
5953          * user the pin mode control will take care of enabling the pin's
5954          * input/output buffers as needed.
5955          */
5956         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5957         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5958         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5959         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5960         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5961         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5962         /* Also unmute the mono-out pin widget */
5963         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5964
5965         /* Mute capture amp left and right */
5966         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5967         /* Set ADC connection select to match default mixer setting (mic1
5968          * pin)
5969          */
5970         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5971
5972         /* Do the same for the second ADC: mute capture input amp and
5973          * set ADC connection to mic1 pin
5974          */
5975         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5976         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5977
5978         /* Mute all inputs to mixer widget (even unconnected ones) */
5979         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5980         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5981         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5982         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5983         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5984         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5985         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5986         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5987
5988         { }
5989 };
5990 #endif
5991
5992 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5993 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5994
5995 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5996 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5997
5998 /*
5999  * for BIOS auto-configuration
6000  */
6001
6002 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
6003                                         const char *pfx, int *vol_bits)
6004 {
6005         hda_nid_t nid_vol;
6006         unsigned long vol_val, sw_val;
6007         int err;
6008
6009         if (nid >= 0x0f && nid < 0x11) {
6010                 nid_vol = nid - 0x7;
6011                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6012                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6013         } else if (nid == 0x11) {
6014                 nid_vol = nid - 0x7;
6015                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
6016                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
6017         } else if (nid >= 0x12 && nid <= 0x15) {
6018                 nid_vol = 0x08;
6019                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6020                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6021         } else
6022                 return 0; /* N/A */
6023
6024         if (!(*vol_bits & (1 << nid_vol))) {
6025                 /* first control for the volume widget */
6026                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6027                 if (err < 0)
6028                         return err;
6029                 *vol_bits |= (1 << nid_vol);
6030         }
6031         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6032         if (err < 0)
6033                 return err;
6034         return 1;
6035 }
6036
6037 /* add playback controls from the parsed DAC table */
6038 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
6039                                              const struct auto_pin_cfg *cfg)
6040 {
6041         hda_nid_t nid;
6042         int err;
6043         int vols = 0;
6044
6045         spec->multiout.num_dacs = 1;
6046         spec->multiout.dac_nids = spec->private_dac_nids;
6047         spec->multiout.dac_nids[0] = 0x02;
6048
6049         nid = cfg->line_out_pins[0];
6050         if (nid) {
6051                 const char *pfx;
6052                 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
6053                         pfx = "Master";
6054                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
6055                         pfx = "Speaker";
6056                 else
6057                         pfx = "Front";
6058                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
6059                 if (err < 0)
6060                         return err;
6061         }
6062
6063         nid = cfg->speaker_pins[0];
6064         if (nid) {
6065                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
6066                 if (err < 0)
6067                         return err;
6068         }
6069
6070         nid = cfg->hp_pins[0];
6071         if (nid) {
6072                 err = alc260_add_playback_controls(spec, nid, "Headphone",
6073                                                    &vols);
6074                 if (err < 0)
6075                         return err;
6076         }
6077         return 0;
6078 }
6079
6080 /* create playback/capture controls for input pins */
6081 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
6082                                                 const struct auto_pin_cfg *cfg)
6083 {
6084         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
6085 }
6086
6087 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
6088                                               hda_nid_t nid, int pin_type,
6089                                               int sel_idx)
6090 {
6091         alc_set_pin_output(codec, nid, pin_type);
6092         /* need the manual connection? */
6093         if (nid >= 0x12) {
6094                 int idx = nid - 0x12;
6095                 snd_hda_codec_write(codec, idx + 0x0b, 0,
6096                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
6097         }
6098 }
6099
6100 static void alc260_auto_init_multi_out(struct hda_codec *codec)
6101 {
6102         struct alc_spec *spec = codec->spec;
6103         hda_nid_t nid;
6104
6105         nid = spec->autocfg.line_out_pins[0];
6106         if (nid) {
6107                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6108                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
6109         }
6110
6111         nid = spec->autocfg.speaker_pins[0];
6112         if (nid)
6113                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
6114
6115         nid = spec->autocfg.hp_pins[0];
6116         if (nid)
6117                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
6118 }
6119
6120 #define ALC260_PIN_CD_NID               0x16
6121 static void alc260_auto_init_analog_input(struct hda_codec *codec)
6122 {
6123         struct alc_spec *spec = codec->spec;
6124         int i;
6125
6126         for (i = 0; i < AUTO_PIN_LAST; i++) {
6127                 hda_nid_t nid = spec->autocfg.input_pins[i];
6128                 if (nid >= 0x12) {
6129                         alc_set_input_pin(codec, nid, i);
6130                         if (nid != ALC260_PIN_CD_NID &&
6131                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
6132                                 snd_hda_codec_write(codec, nid, 0,
6133                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6134                                                     AMP_OUT_MUTE);
6135                 }
6136         }
6137 }
6138
6139 /*
6140  * generic initialization of ADC, input mixers and output mixers
6141  */
6142 static struct hda_verb alc260_volume_init_verbs[] = {
6143         /*
6144          * Unmute ADC0-1 and set the default input to mic-in
6145          */
6146         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6147         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6148         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6149         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6150
6151         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6152          * mixer widget
6153          * Note: PASD motherboards uses the Line In 2 as the input for
6154          * front panel mic (mic 2)
6155          */
6156         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6157         /* mute analog inputs */
6158         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6159         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6160         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6161         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6162         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6163
6164         /*
6165          * Set up output mixers (0x08 - 0x0a)
6166          */
6167         /* set vol=0 to output mixers */
6168         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6169         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6170         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6171         /* set up input amps for analog loopback */
6172         /* Amp Indices: DAC = 0, mixer = 1 */
6173         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6174         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6175         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6176         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6177         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6178         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6179
6180         { }
6181 };
6182
6183 static int alc260_parse_auto_config(struct hda_codec *codec)
6184 {
6185         struct alc_spec *spec = codec->spec;
6186         int err;
6187         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
6188
6189         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6190                                            alc260_ignore);
6191         if (err < 0)
6192                 return err;
6193         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
6194         if (err < 0)
6195                 return err;
6196         if (!spec->kctls.list)
6197                 return 0; /* can't find valid BIOS pin config */
6198         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
6199         if (err < 0)
6200                 return err;
6201
6202         spec->multiout.max_channels = 2;
6203
6204         if (spec->autocfg.dig_outs)
6205                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6206         if (spec->kctls.list)
6207                 add_mixer(spec, spec->kctls.list);
6208
6209         add_verb(spec, alc260_volume_init_verbs);
6210
6211         spec->num_mux_defs = 1;
6212         spec->input_mux = &spec->private_imux[0];
6213
6214         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6215
6216         return 1;
6217 }
6218
6219 /* additional initialization for auto-configuration model */
6220 static void alc260_auto_init(struct hda_codec *codec)
6221 {
6222         struct alc_spec *spec = codec->spec;
6223         alc260_auto_init_multi_out(codec);
6224         alc260_auto_init_analog_input(codec);
6225         if (spec->unsol_event)
6226                 alc_inithook(codec);
6227 }
6228
6229 #ifdef CONFIG_SND_HDA_POWER_SAVE
6230 static struct hda_amp_list alc260_loopbacks[] = {
6231         { 0x07, HDA_INPUT, 0 },
6232         { 0x07, HDA_INPUT, 1 },
6233         { 0x07, HDA_INPUT, 2 },
6234         { 0x07, HDA_INPUT, 3 },
6235         { 0x07, HDA_INPUT, 4 },
6236         { } /* end */
6237 };
6238 #endif
6239
6240 /*
6241  * ALC260 configurations
6242  */
6243 static const char *alc260_models[ALC260_MODEL_LAST] = {
6244         [ALC260_BASIC]          = "basic",
6245         [ALC260_HP]             = "hp",
6246         [ALC260_HP_3013]        = "hp-3013",
6247         [ALC260_HP_DC7600]      = "hp-dc7600",
6248         [ALC260_FUJITSU_S702X]  = "fujitsu",
6249         [ALC260_ACER]           = "acer",
6250         [ALC260_WILL]           = "will",
6251         [ALC260_REPLACER_672V]  = "replacer",
6252         [ALC260_FAVORIT100]     = "favorit100",
6253 #ifdef CONFIG_SND_DEBUG
6254         [ALC260_TEST]           = "test",
6255 #endif
6256         [ALC260_AUTO]           = "auto",
6257 };
6258
6259 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6260         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6261         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6262         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6263         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6264         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
6265         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6266         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6267         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6268         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6269         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6270         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6271         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6272         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6273         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6274         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6275         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6276         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6277         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6278         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6279         {}
6280 };
6281
6282 static struct alc_config_preset alc260_presets[] = {
6283         [ALC260_BASIC] = {
6284                 .mixers = { alc260_base_output_mixer,
6285                             alc260_input_mixer },
6286                 .init_verbs = { alc260_init_verbs },
6287                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6288                 .dac_nids = alc260_dac_nids,
6289                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6290                 .adc_nids = alc260_adc_nids,
6291                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6292                 .channel_mode = alc260_modes,
6293                 .input_mux = &alc260_capture_source,
6294         },
6295         [ALC260_HP] = {
6296                 .mixers = { alc260_hp_output_mixer,
6297                             alc260_input_mixer },
6298                 .init_verbs = { alc260_init_verbs,
6299                                 alc260_hp_unsol_verbs },
6300                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6301                 .dac_nids = alc260_dac_nids,
6302                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6303                 .adc_nids = alc260_adc_nids_alt,
6304                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6305                 .channel_mode = alc260_modes,
6306                 .input_mux = &alc260_capture_source,
6307                 .unsol_event = alc260_hp_unsol_event,
6308                 .init_hook = alc260_hp_automute,
6309         },
6310         [ALC260_HP_DC7600] = {
6311                 .mixers = { alc260_hp_dc7600_mixer,
6312                             alc260_input_mixer },
6313                 .init_verbs = { alc260_init_verbs,
6314                                 alc260_hp_dc7600_verbs },
6315                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6316                 .dac_nids = alc260_dac_nids,
6317                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6318                 .adc_nids = alc260_adc_nids_alt,
6319                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6320                 .channel_mode = alc260_modes,
6321                 .input_mux = &alc260_capture_source,
6322                 .unsol_event = alc260_hp_3012_unsol_event,
6323                 .init_hook = alc260_hp_3012_automute,
6324         },
6325         [ALC260_HP_3013] = {
6326                 .mixers = { alc260_hp_3013_mixer,
6327                             alc260_input_mixer },
6328                 .init_verbs = { alc260_hp_3013_init_verbs,
6329                                 alc260_hp_3013_unsol_verbs },
6330                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6331                 .dac_nids = alc260_dac_nids,
6332                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6333                 .adc_nids = alc260_adc_nids_alt,
6334                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6335                 .channel_mode = alc260_modes,
6336                 .input_mux = &alc260_capture_source,
6337                 .unsol_event = alc260_hp_3013_unsol_event,
6338                 .init_hook = alc260_hp_3013_automute,
6339         },
6340         [ALC260_FUJITSU_S702X] = {
6341                 .mixers = { alc260_fujitsu_mixer },
6342                 .init_verbs = { alc260_fujitsu_init_verbs },
6343                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6344                 .dac_nids = alc260_dac_nids,
6345                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6346                 .adc_nids = alc260_dual_adc_nids,
6347                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6348                 .channel_mode = alc260_modes,
6349                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6350                 .input_mux = alc260_fujitsu_capture_sources,
6351         },
6352         [ALC260_ACER] = {
6353                 .mixers = { alc260_acer_mixer },
6354                 .init_verbs = { alc260_acer_init_verbs },
6355                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6356                 .dac_nids = alc260_dac_nids,
6357                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6358                 .adc_nids = alc260_dual_adc_nids,
6359                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6360                 .channel_mode = alc260_modes,
6361                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6362                 .input_mux = alc260_acer_capture_sources,
6363         },
6364         [ALC260_FAVORIT100] = {
6365                 .mixers = { alc260_favorit100_mixer },
6366                 .init_verbs = { alc260_favorit100_init_verbs },
6367                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6368                 .dac_nids = alc260_dac_nids,
6369                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6370                 .adc_nids = alc260_dual_adc_nids,
6371                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6372                 .channel_mode = alc260_modes,
6373                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6374                 .input_mux = alc260_favorit100_capture_sources,
6375         },
6376         [ALC260_WILL] = {
6377                 .mixers = { alc260_will_mixer },
6378                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6379                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6380                 .dac_nids = alc260_dac_nids,
6381                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6382                 .adc_nids = alc260_adc_nids,
6383                 .dig_out_nid = ALC260_DIGOUT_NID,
6384                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6385                 .channel_mode = alc260_modes,
6386                 .input_mux = &alc260_capture_source,
6387         },
6388         [ALC260_REPLACER_672V] = {
6389                 .mixers = { alc260_replacer_672v_mixer },
6390                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6391                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6392                 .dac_nids = alc260_dac_nids,
6393                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6394                 .adc_nids = alc260_adc_nids,
6395                 .dig_out_nid = ALC260_DIGOUT_NID,
6396                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6397                 .channel_mode = alc260_modes,
6398                 .input_mux = &alc260_capture_source,
6399                 .unsol_event = alc260_replacer_672v_unsol_event,
6400                 .init_hook = alc260_replacer_672v_automute,
6401         },
6402 #ifdef CONFIG_SND_DEBUG
6403         [ALC260_TEST] = {
6404                 .mixers = { alc260_test_mixer },
6405                 .init_verbs = { alc260_test_init_verbs },
6406                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6407                 .dac_nids = alc260_test_dac_nids,
6408                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6409                 .adc_nids = alc260_test_adc_nids,
6410                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6411                 .channel_mode = alc260_modes,
6412                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6413                 .input_mux = alc260_test_capture_sources,
6414         },
6415 #endif
6416 };
6417
6418 static int patch_alc260(struct hda_codec *codec)
6419 {
6420         struct alc_spec *spec;
6421         int err, board_config;
6422
6423         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6424         if (spec == NULL)
6425                 return -ENOMEM;
6426
6427         codec->spec = spec;
6428
6429         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6430                                                   alc260_models,
6431                                                   alc260_cfg_tbl);
6432         if (board_config < 0) {
6433                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6434                            codec->chip_name);
6435                 board_config = ALC260_AUTO;
6436         }
6437
6438         if (board_config == ALC260_AUTO) {
6439                 /* automatic parse from the BIOS config */
6440                 err = alc260_parse_auto_config(codec);
6441                 if (err < 0) {
6442                         alc_free(codec);
6443                         return err;
6444                 } else if (!err) {
6445                         printk(KERN_INFO
6446                                "hda_codec: Cannot set up configuration "
6447                                "from BIOS.  Using base mode...\n");
6448                         board_config = ALC260_BASIC;
6449                 }
6450         }
6451
6452         err = snd_hda_attach_beep_device(codec, 0x1);
6453         if (err < 0) {
6454                 alc_free(codec);
6455                 return err;
6456         }
6457
6458         if (board_config != ALC260_AUTO)
6459                 setup_preset(codec, &alc260_presets[board_config]);
6460
6461         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6462         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6463
6464         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6465         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6466
6467         if (!spec->adc_nids && spec->input_mux) {
6468                 /* check whether NID 0x04 is valid */
6469                 unsigned int wcap = get_wcaps(codec, 0x04);
6470                 wcap = get_wcaps_type(wcap);
6471                 /* get type */
6472                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6473                         spec->adc_nids = alc260_adc_nids_alt;
6474                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6475                 } else {
6476                         spec->adc_nids = alc260_adc_nids;
6477                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6478                 }
6479         }
6480         set_capture_mixer(codec);
6481         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6482
6483         spec->vmaster_nid = 0x08;
6484
6485         codec->patch_ops = alc_patch_ops;
6486         if (board_config == ALC260_AUTO)
6487                 spec->init_hook = alc260_auto_init;
6488 #ifdef CONFIG_SND_HDA_POWER_SAVE
6489         if (!spec->loopback.amplist)
6490                 spec->loopback.amplist = alc260_loopbacks;
6491 #endif
6492         codec->proc_widget_hook = print_realtek_coef;
6493
6494         return 0;
6495 }
6496
6497
6498 /*
6499  * ALC882/883/885/888/889 support
6500  *
6501  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6502  * configuration.  Each pin widget can choose any input DACs and a mixer.
6503  * Each ADC is connected from a mixer of all inputs.  This makes possible
6504  * 6-channel independent captures.
6505  *
6506  * In addition, an independent DAC for the multi-playback (not used in this
6507  * driver yet).
6508  */
6509 #define ALC882_DIGOUT_NID       0x06
6510 #define ALC882_DIGIN_NID        0x0a
6511 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
6512 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
6513 #define ALC1200_DIGOUT_NID      0x10
6514
6515
6516 static struct hda_channel_mode alc882_ch_modes[1] = {
6517         { 8, NULL }
6518 };
6519
6520 /* DACs */
6521 static hda_nid_t alc882_dac_nids[4] = {
6522         /* front, rear, clfe, rear_surr */
6523         0x02, 0x03, 0x04, 0x05
6524 };
6525 #define alc883_dac_nids         alc882_dac_nids
6526
6527 /* ADCs */
6528 #define alc882_adc_nids         alc880_adc_nids
6529 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6530 #define alc883_adc_nids         alc882_adc_nids_alt
6531 static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
6532 static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
6533 #define alc889_adc_nids         alc880_adc_nids
6534
6535 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6536 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6537 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
6538 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
6539 #define alc889_capsrc_nids      alc882_capsrc_nids
6540
6541 /* input MUX */
6542 /* FIXME: should be a matrix-type input source selection */
6543
6544 static struct hda_input_mux alc882_capture_source = {
6545         .num_items = 4,
6546         .items = {
6547                 { "Mic", 0x0 },
6548                 { "Front Mic", 0x1 },
6549                 { "Line", 0x2 },
6550                 { "CD", 0x4 },
6551         },
6552 };
6553
6554 #define alc883_capture_source   alc882_capture_source
6555
6556 static struct hda_input_mux alc889_capture_source = {
6557         .num_items = 3,
6558         .items = {
6559                 { "Front Mic", 0x0 },
6560                 { "Mic", 0x3 },
6561                 { "Line", 0x2 },
6562         },
6563 };
6564
6565 static struct hda_input_mux mb5_capture_source = {
6566         .num_items = 3,
6567         .items = {
6568                 { "Mic", 0x1 },
6569                 { "Line", 0x2 },
6570                 { "CD", 0x4 },
6571         },
6572 };
6573
6574 static struct hda_input_mux alc883_3stack_6ch_intel = {
6575         .num_items = 4,
6576         .items = {
6577                 { "Mic", 0x1 },
6578                 { "Front Mic", 0x0 },
6579                 { "Line", 0x2 },
6580                 { "CD", 0x4 },
6581         },
6582 };
6583
6584 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6585         .num_items = 2,
6586         .items = {
6587                 { "Mic", 0x1 },
6588                 { "Line", 0x2 },
6589         },
6590 };
6591
6592 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6593         .num_items = 4,
6594         .items = {
6595                 { "Mic", 0x0 },
6596                 { "iMic", 0x1 },
6597                 { "Line", 0x2 },
6598                 { "CD", 0x4 },
6599         },
6600 };
6601
6602 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6603         .num_items = 2,
6604         .items = {
6605                 { "Mic", 0x0 },
6606                 { "Int Mic", 0x1 },
6607         },
6608 };
6609
6610 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6611         .num_items = 3,
6612         .items = {
6613                 { "Mic", 0x0 },
6614                 { "Front Mic", 0x1 },
6615                 { "Line", 0x4 },
6616         },
6617 };
6618
6619 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6620         .num_items = 2,
6621         .items = {
6622                 { "Mic", 0x0 },
6623                 { "Line", 0x2 },
6624         },
6625 };
6626
6627 static struct hda_input_mux alc889A_mb31_capture_source = {
6628         .num_items = 2,
6629         .items = {
6630                 { "Mic", 0x0 },
6631                 /* Front Mic (0x01) unused */
6632                 { "Line", 0x2 },
6633                 /* Line 2 (0x03) unused */
6634                 /* CD (0x04) unsused? */
6635         },
6636 };
6637
6638 /*
6639  * 2ch mode
6640  */
6641 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6642         { 2, NULL }
6643 };
6644
6645 /*
6646  * 2ch mode
6647  */
6648 static struct hda_verb alc882_3ST_ch2_init[] = {
6649         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6650         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6651         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6652         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6653         { } /* end */
6654 };
6655
6656 /*
6657  * 4ch mode
6658  */
6659 static struct hda_verb alc882_3ST_ch4_init[] = {
6660         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6661         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6662         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6663         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6664         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6665         { } /* end */
6666 };
6667
6668 /*
6669  * 6ch mode
6670  */
6671 static struct hda_verb alc882_3ST_ch6_init[] = {
6672         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6673         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6674         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6675         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6676         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6677         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6678         { } /* end */
6679 };
6680
6681 static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6682         { 2, alc882_3ST_ch2_init },
6683         { 4, alc882_3ST_ch4_init },
6684         { 6, alc882_3ST_ch6_init },
6685 };
6686
6687 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
6688
6689 /*
6690  * 2ch mode
6691  */
6692 static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
6693         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
6694         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6695         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6696         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6697         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6698         { } /* end */
6699 };
6700
6701 /*
6702  * 4ch mode
6703  */
6704 static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
6705         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6706         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6707         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6708         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6709         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6710         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6711         { } /* end */
6712 };
6713
6714 /*
6715  * 6ch mode
6716  */
6717 static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
6718         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6719         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6720         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6721         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6722         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6723         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6724         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6725         { } /* end */
6726 };
6727
6728 static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
6729         { 2, alc883_3ST_ch2_clevo_init },
6730         { 4, alc883_3ST_ch4_clevo_init },
6731         { 6, alc883_3ST_ch6_clevo_init },
6732 };
6733
6734
6735 /*
6736  * 6ch mode
6737  */
6738 static struct hda_verb alc882_sixstack_ch6_init[] = {
6739         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6740         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6741         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6742         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6743         { } /* end */
6744 };
6745
6746 /*
6747  * 8ch mode
6748  */
6749 static struct hda_verb alc882_sixstack_ch8_init[] = {
6750         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6751         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6752         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6753         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6754         { } /* end */
6755 };
6756
6757 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6758         { 6, alc882_sixstack_ch6_init },
6759         { 8, alc882_sixstack_ch8_init },
6760 };
6761
6762 /*
6763  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6764  */
6765
6766 /*
6767  * 2ch mode
6768  */
6769 static struct hda_verb alc885_mbp_ch2_init[] = {
6770         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6771         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6772         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6773         { } /* end */
6774 };
6775
6776 /*
6777  * 4ch mode
6778  */
6779 static struct hda_verb alc885_mbp_ch4_init[] = {
6780         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6781         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6782         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6783         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6784         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6785         { } /* end */
6786 };
6787
6788 static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6789         { 2, alc885_mbp_ch2_init },
6790         { 4, alc885_mbp_ch4_init },
6791 };
6792
6793 /*
6794  * 2ch
6795  * Speakers/Woofer/HP = Front
6796  * LineIn = Input
6797  */
6798 static struct hda_verb alc885_mb5_ch2_init[] = {
6799         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6800         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6801         { } /* end */
6802 };
6803
6804 /*
6805  * 6ch mode
6806  * Speakers/HP = Front
6807  * Woofer = LFE
6808  * LineIn = Surround
6809  */
6810 static struct hda_verb alc885_mb5_ch6_init[] = {
6811         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6813         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6814         { } /* end */
6815 };
6816
6817 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6818         { 2, alc885_mb5_ch2_init },
6819         { 6, alc885_mb5_ch6_init },
6820 };
6821
6822
6823 /*
6824  * 2ch mode
6825  */
6826 static struct hda_verb alc883_4ST_ch2_init[] = {
6827         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6828         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6829         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6830         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6831         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6832         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6833         { } /* end */
6834 };
6835
6836 /*
6837  * 4ch mode
6838  */
6839 static struct hda_verb alc883_4ST_ch4_init[] = {
6840         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6841         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6842         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6843         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6844         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6845         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6846         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6847         { } /* end */
6848 };
6849
6850 /*
6851  * 6ch mode
6852  */
6853 static struct hda_verb alc883_4ST_ch6_init[] = {
6854         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6855         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6856         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6857         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6858         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6859         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6860         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6861         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6862         { } /* end */
6863 };
6864
6865 /*
6866  * 8ch mode
6867  */
6868 static struct hda_verb alc883_4ST_ch8_init[] = {
6869         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6870         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6871         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6872         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6873         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6874         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6875         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6876         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6877         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6878         { } /* end */
6879 };
6880
6881 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
6882         { 2, alc883_4ST_ch2_init },
6883         { 4, alc883_4ST_ch4_init },
6884         { 6, alc883_4ST_ch6_init },
6885         { 8, alc883_4ST_ch8_init },
6886 };
6887
6888
6889 /*
6890  * 2ch mode
6891  */
6892 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6893         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6894         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6895         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6896         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6897         { } /* end */
6898 };
6899
6900 /*
6901  * 4ch mode
6902  */
6903 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6904         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6905         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6906         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6907         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6908         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6909         { } /* end */
6910 };
6911
6912 /*
6913  * 6ch mode
6914  */
6915 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6916         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6917         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6918         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6919         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6920         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6921         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6922         { } /* end */
6923 };
6924
6925 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6926         { 2, alc883_3ST_ch2_intel_init },
6927         { 4, alc883_3ST_ch4_intel_init },
6928         { 6, alc883_3ST_ch6_intel_init },
6929 };
6930
6931 /*
6932  * 2ch mode
6933  */
6934 static struct hda_verb alc889_ch2_intel_init[] = {
6935         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6936         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
6937         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
6938         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
6939         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6940         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6941         { } /* end */
6942 };
6943
6944 /*
6945  * 6ch mode
6946  */
6947 static struct hda_verb alc889_ch6_intel_init[] = {
6948         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6949         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6950         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6951         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6952         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6953         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6954         { } /* end */
6955 };
6956
6957 /*
6958  * 8ch mode
6959  */
6960 static struct hda_verb alc889_ch8_intel_init[] = {
6961         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6962         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6963         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6964         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6965         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
6966         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6967         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6968         { } /* end */
6969 };
6970
6971 static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
6972         { 2, alc889_ch2_intel_init },
6973         { 6, alc889_ch6_intel_init },
6974         { 8, alc889_ch8_intel_init },
6975 };
6976
6977 /*
6978  * 6ch mode
6979  */
6980 static struct hda_verb alc883_sixstack_ch6_init[] = {
6981         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6982         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6983         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6984         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6985         { } /* end */
6986 };
6987
6988 /*
6989  * 8ch mode
6990  */
6991 static struct hda_verb alc883_sixstack_ch8_init[] = {
6992         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6993         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6994         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6995         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6996         { } /* end */
6997 };
6998
6999 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7000         { 6, alc883_sixstack_ch6_init },
7001         { 8, alc883_sixstack_ch8_init },
7002 };
7003
7004
7005 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7006  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7007  */
7008 static struct snd_kcontrol_new alc882_base_mixer[] = {
7009         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7010         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7011         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7012         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7013         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7014         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7015         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7016         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7017         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7018         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7019         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7020         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7021         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7022         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7023         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7024         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7025         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7026         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7028         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7029         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7030         { } /* end */
7031 };
7032
7033 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7034         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7035         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
7036         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7037         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
7038         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7039         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7040         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7041         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7042         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7043         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
7044         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7045         { } /* end */
7046 };
7047
7048 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7049         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7050         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
7051         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7052         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7053         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7054         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7055         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7056         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
7057         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7058         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7059         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7060         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7061         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
7062         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
7063         { } /* end */
7064 };
7065
7066 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7067         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7068         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7069         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7070         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7071         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7072         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7073         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7075         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7076         { } /* end */
7077 };
7078
7079 static struct snd_kcontrol_new alc882_targa_mixer[] = {
7080         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7081         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7082         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7083         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7084         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7085         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7086         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7087         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7088         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7089         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7090         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7091         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7092         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7093         { } /* end */
7094 };
7095
7096 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
7097  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
7098  */
7099 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
7100         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7101         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7102         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7103         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
7104         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7105         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7106         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7107         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7108         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
7109         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
7110         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7111         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7112         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7113         { } /* end */
7114 };
7115
7116 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
7117         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7118         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7119         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7120         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7121         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7122         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7123         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7124         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7125         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7126         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7127         { } /* end */
7128 };
7129
7130 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
7131         {
7132                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7133                 .name = "Channel Mode",
7134                 .info = alc_ch_mode_info,
7135                 .get = alc_ch_mode_get,
7136                 .put = alc_ch_mode_put,
7137         },
7138         { } /* end */
7139 };
7140
7141 static struct hda_verb alc882_base_init_verbs[] = {
7142         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7143         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7144         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7145         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7146         /* Rear mixer */
7147         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7148         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7149         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7150         /* CLFE mixer */
7151         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7152         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7153         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7154         /* Side mixer */
7155         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7156         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7157         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7158
7159         /* mute analog input loopbacks */
7160         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7161         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7162         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7163         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7164         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7165
7166         /* Front Pin: output 0 (0x0c) */
7167         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7168         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7169         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7170         /* Rear Pin: output 1 (0x0d) */
7171         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7172         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7173         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7174         /* CLFE Pin: output 2 (0x0e) */
7175         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7176         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7177         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7178         /* Side Pin: output 3 (0x0f) */
7179         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7180         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7181         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7182         /* Mic (rear) pin: input vref at 80% */
7183         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7184         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7185         /* Front Mic pin: input vref at 80% */
7186         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7187         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7188         /* Line In pin: input */
7189         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7190         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7191         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7192         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7193         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7194         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7195         /* CD pin widget for input */
7196         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7197
7198         /* FIXME: use matrix-type input source selection */
7199         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7200         /* Input mixer2 */
7201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7203         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7204         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7205         /* Input mixer3 */
7206         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7207         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7208         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7209         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7210         /* ADC2: mute amp left and right */
7211         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7212         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7213         /* ADC3: mute amp left and right */
7214         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7215         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7216
7217         { }
7218 };
7219
7220 static struct hda_verb alc882_adc1_init_verbs[] = {
7221         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7222         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7223         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7224         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7225         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7226         /* ADC1: mute amp left and right */
7227         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7228         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7229         { }
7230 };
7231
7232 static struct hda_verb alc882_eapd_verbs[] = {
7233         /* change to EAPD mode */
7234         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7235         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
7236         { }
7237 };
7238
7239 static struct hda_verb alc889_eapd_verbs[] = {
7240         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
7241         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
7242         { }
7243 };
7244
7245 static struct hda_verb alc_hp15_unsol_verbs[] = {
7246         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7247         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7248         {}
7249 };
7250
7251 static struct hda_verb alc885_init_verbs[] = {
7252         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7255         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7256         /* Rear mixer */
7257         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7258         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7259         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7260         /* CLFE mixer */
7261         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7262         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7263         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7264         /* Side mixer */
7265         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7266         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7267         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7268
7269         /* mute analog input loopbacks */
7270         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7272         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7273
7274         /* Front HP Pin: output 0 (0x0c) */
7275         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7276         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7277         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7278         /* Front Pin: output 0 (0x0c) */
7279         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7280         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7281         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7282         /* Rear Pin: output 1 (0x0d) */
7283         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7284         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7285         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
7286         /* CLFE Pin: output 2 (0x0e) */
7287         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7288         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7289         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7290         /* Side Pin: output 3 (0x0f) */
7291         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7292         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7293         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7294         /* Mic (rear) pin: input vref at 80% */
7295         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7296         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7297         /* Front Mic pin: input vref at 80% */
7298         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7299         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7300         /* Line In pin: input */
7301         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7302         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7303
7304         /* Mixer elements: 0x18, , 0x1a, 0x1b */
7305         /* Input mixer1 */
7306         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7307         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7308         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7309         /* Input mixer2 */
7310         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7311         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7312         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7313         /* Input mixer3 */
7314         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7316         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7317         /* ADC2: mute amp left and right */
7318         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7319         /* ADC3: mute amp left and right */
7320         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7321
7322         { }
7323 };
7324
7325 static struct hda_verb alc885_init_input_verbs[] = {
7326         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7327         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7328         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7329         { }
7330 };
7331
7332
7333 /* Unmute Selector 24h and set the default input to front mic */
7334 static struct hda_verb alc889_init_input_verbs[] = {
7335         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
7336         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7337         { }
7338 };
7339
7340
7341 #define alc883_init_verbs       alc882_base_init_verbs
7342
7343 /* Mac Pro test */
7344 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7345         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7346         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7347         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
7348         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7349         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7350         /* FIXME: this looks suspicious...
7351         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
7352         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7353         */
7354         { } /* end */
7355 };
7356
7357 static struct hda_verb alc882_macpro_init_verbs[] = {
7358         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7359         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7360         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7361         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7362         /* Front Pin: output 0 (0x0c) */
7363         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7364         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7365         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7366         /* Front Mic pin: input vref at 80% */
7367         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7368         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7369         /* Speaker:  output */
7370         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7371         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7372         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
7373         /* Headphone output (output 0 - 0x0c) */
7374         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7375         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7376         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7377
7378         /* FIXME: use matrix-type input source selection */
7379         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7380         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7381         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7382         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7383         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7384         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7385         /* Input mixer2 */
7386         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7387         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7388         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7389         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7390         /* Input mixer3 */
7391         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7392         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7393         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7394         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7395         /* ADC1: mute amp left and right */
7396         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7397         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7398         /* ADC2: mute amp left and right */
7399         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7400         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7401         /* ADC3: mute amp left and right */
7402         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7403         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7404
7405         { }
7406 };
7407
7408 /* Macbook 5,1 */
7409 static struct hda_verb alc885_mb5_init_verbs[] = {
7410         /* DACs */
7411         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7412         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7413         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7414         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7415         /* Front mixer */
7416         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7417         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7418         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7419         /* Surround mixer */
7420         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7421         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7422         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7423         /* LFE mixer */
7424         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7425         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7426         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7427         /* HP mixer */
7428         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7429         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7430         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7431         /* Front Pin (0x0c) */
7432         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7433         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7434         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7435         /* LFE Pin (0x0e) */
7436         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7437         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7438         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
7439         /* HP Pin (0x0f) */
7440         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7441         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7442         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7443         /* Front Mic pin: input vref at 80% */
7444         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7445         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7446         /* Line In pin */
7447         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7448         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7449
7450         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7451         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7452         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7453         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7454         { }
7455 };
7456
7457 /* Macbook Pro rev3 */
7458 static struct hda_verb alc885_mbp3_init_verbs[] = {
7459         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7461         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7462         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7463         /* Rear mixer */
7464         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7465         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7466         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7467         /* HP mixer */
7468         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7469         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7470         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7471         /* Front Pin: output 0 (0x0c) */
7472         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7473         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7474         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7475         /* HP Pin: output 0 (0x0e) */
7476         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7477         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7478         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
7479         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7480         /* Mic (rear) pin: input vref at 80% */
7481         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7482         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7483         /* Front Mic pin: input vref at 80% */
7484         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7485         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7486         /* Line In pin: use output 1 when in LineOut mode */
7487         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7488         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7489         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7490
7491         /* FIXME: use matrix-type input source selection */
7492         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7493         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7494         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7495         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7496         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7497         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7498         /* Input mixer2 */
7499         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7500         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7501         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7502         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7503         /* Input mixer3 */
7504         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7505         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7506         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7507         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7508         /* ADC1: mute amp left and right */
7509         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7510         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7511         /* ADC2: mute amp left and right */
7512         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7513         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7514         /* ADC3: mute amp left and right */
7515         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7516         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7517
7518         { }
7519 };
7520
7521 /* iMac 24 mixer. */
7522 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7523         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7524         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
7525         { } /* end */
7526 };
7527
7528 /* iMac 24 init verbs. */
7529 static struct hda_verb alc885_imac24_init_verbs[] = {
7530         /* Internal speakers: output 0 (0x0c) */
7531         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7532         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7533         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7534         /* Internal speakers: output 0 (0x0c) */
7535         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7536         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7537         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7538         /* Headphone: output 0 (0x0c) */
7539         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7540         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7541         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7542         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7543         /* Front Mic: input vref at 80% */
7544         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7545         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7546         { }
7547 };
7548
7549 /* Toggle speaker-output according to the hp-jack state */
7550 static void alc885_imac24_setup(struct hda_codec *codec)
7551 {
7552         struct alc_spec *spec = codec->spec;
7553
7554         spec->autocfg.hp_pins[0] = 0x14;
7555         spec->autocfg.speaker_pins[0] = 0x18;
7556         spec->autocfg.speaker_pins[1] = 0x1a;
7557 }
7558
7559 static void alc885_mbp3_setup(struct hda_codec *codec)
7560 {
7561         struct alc_spec *spec = codec->spec;
7562
7563         spec->autocfg.hp_pins[0] = 0x15;
7564         spec->autocfg.speaker_pins[0] = 0x14;
7565 }
7566
7567
7568 static struct hda_verb alc882_targa_verbs[] = {
7569         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7570         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7571
7572         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7573         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7574
7575         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7576         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7577         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7578
7579         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7580         { } /* end */
7581 };
7582
7583 /* toggle speaker-output according to the hp-jack state */
7584 static void alc882_targa_automute(struct hda_codec *codec)
7585 {
7586         struct alc_spec *spec = codec->spec;
7587         alc_automute_amp(codec);
7588         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7589                                   spec->jack_present ? 1 : 3);
7590 }
7591
7592 static void alc882_targa_setup(struct hda_codec *codec)
7593 {
7594         struct alc_spec *spec = codec->spec;
7595
7596         spec->autocfg.hp_pins[0] = 0x14;
7597         spec->autocfg.speaker_pins[0] = 0x1b;
7598 }
7599
7600 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
7601 {
7602         if ((res >> 26) == ALC880_HP_EVENT)
7603                 alc882_targa_automute(codec);
7604 }
7605
7606 static struct hda_verb alc882_asus_a7j_verbs[] = {
7607         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7608         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7609
7610         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7611         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7612         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7613
7614         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7615         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7616         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7617
7618         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7619         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7620         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7621         { } /* end */
7622 };
7623
7624 static struct hda_verb alc882_asus_a7m_verbs[] = {
7625         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7626         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7627
7628         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7629         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7630         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7631
7632         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7633         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7634         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7635
7636         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7637         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7638         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7639         { } /* end */
7640 };
7641
7642 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
7643 {
7644         unsigned int gpiostate, gpiomask, gpiodir;
7645
7646         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
7647                                        AC_VERB_GET_GPIO_DATA, 0);
7648
7649         if (!muted)
7650                 gpiostate |= (1 << pin);
7651         else
7652                 gpiostate &= ~(1 << pin);
7653
7654         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7655                                       AC_VERB_GET_GPIO_MASK, 0);
7656         gpiomask |= (1 << pin);
7657
7658         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7659                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7660         gpiodir |= (1 << pin);
7661
7662
7663         snd_hda_codec_write(codec, codec->afg, 0,
7664                             AC_VERB_SET_GPIO_MASK, gpiomask);
7665         snd_hda_codec_write(codec, codec->afg, 0,
7666                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7667
7668         msleep(1);
7669
7670         snd_hda_codec_write(codec, codec->afg, 0,
7671                             AC_VERB_SET_GPIO_DATA, gpiostate);
7672 }
7673
7674 /* set up GPIO at initialization */
7675 static void alc885_macpro_init_hook(struct hda_codec *codec)
7676 {
7677         alc882_gpio_mute(codec, 0, 0);
7678         alc882_gpio_mute(codec, 1, 0);
7679 }
7680
7681 /* set up GPIO and update auto-muting at initialization */
7682 static void alc885_imac24_init_hook(struct hda_codec *codec)
7683 {
7684         alc885_macpro_init_hook(codec);
7685         alc_automute_amp(codec);
7686 }
7687
7688 /*
7689  * generic initialization of ADC, input mixers and output mixers
7690  */
7691 static struct hda_verb alc883_auto_init_verbs[] = {
7692         /*
7693          * Unmute ADC0-2 and set the default input to mic-in
7694          */
7695         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7696         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7697         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7698         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7699
7700         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7701          * mixer widget
7702          * Note: PASD motherboards uses the Line In 2 as the input for
7703          * front panel mic (mic 2)
7704          */
7705         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7706         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7707         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7708         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7709         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7710         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7711
7712         /*
7713          * Set up output mixers (0x0c - 0x0f)
7714          */
7715         /* set vol=0 to output mixers */
7716         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7717         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7718         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7719         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7720         /* set up input amps for analog loopback */
7721         /* Amp Indices: DAC = 0, mixer = 1 */
7722         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7723         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7724         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7725         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7726         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7727         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7728         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7729         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7730         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7731         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7732
7733         /* FIXME: use matrix-type input source selection */
7734         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7735         /* Input mixer2 */
7736         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7737         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7738         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7739         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7740         /* Input mixer3 */
7741         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7742         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7743         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7744         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7745
7746         { }
7747 };
7748
7749 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7750 static struct hda_verb alc889A_mb31_ch2_init[] = {
7751         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7752         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7753         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7754         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7755         { } /* end */
7756 };
7757
7758 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7759 static struct hda_verb alc889A_mb31_ch4_init[] = {
7760         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7761         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7762         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7763         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7764         { } /* end */
7765 };
7766
7767 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7768 static struct hda_verb alc889A_mb31_ch5_init[] = {
7769         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7770         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7771         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7772         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7773         { } /* end */
7774 };
7775
7776 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7777 static struct hda_verb alc889A_mb31_ch6_init[] = {
7778         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7779         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7780         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7781         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7782         { } /* end */
7783 };
7784
7785 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7786         { 2, alc889A_mb31_ch2_init },
7787         { 4, alc889A_mb31_ch4_init },
7788         { 5, alc889A_mb31_ch5_init },
7789         { 6, alc889A_mb31_ch6_init },
7790 };
7791
7792 static struct hda_verb alc883_medion_eapd_verbs[] = {
7793         /* eanable EAPD on medion laptop */
7794         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7795         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7796         { }
7797 };
7798
7799 #define alc883_base_mixer       alc882_base_mixer
7800
7801 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7802         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7803         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7804         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7805         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7806         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7807         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7808         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7809         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7810         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7811         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7812         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7813         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7814         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7815         { } /* end */
7816 };
7817
7818 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7819         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7820         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7821         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7822         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7823         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7824         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7825         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7826         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7827         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7828         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7829         { } /* end */
7830 };
7831
7832 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7833         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7834         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7835         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7836         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7837         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7838         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7839         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7840         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7841         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7842         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7843         { } /* end */
7844 };
7845
7846 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7847         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7848         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7849         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7850         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7851         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7852         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7853         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7854         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7855         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7856         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7857         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7858         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7859         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7860         { } /* end */
7861 };
7862
7863 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7864         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7865         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7866         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7867         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7868         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7869         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7870         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7871         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7872         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7873         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7874         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7875         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7876         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7877         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7878         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7880         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7881         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7882         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7883         { } /* end */
7884 };
7885
7886 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7887         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7888         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7889         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7890         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7891         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7892                               HDA_OUTPUT),
7893         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7894         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7895         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7897         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7898         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7899         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7900         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7901         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7902         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7903         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7904         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7905         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7906         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7907         { } /* end */
7908 };
7909
7910 static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
7911         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7912         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7913         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7914         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7915         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7916                               HDA_OUTPUT),
7917         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7918         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7919         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7920         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7921         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
7922         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7923         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7924         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7925         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
7926         HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
7927         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
7928         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7929         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7930         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7931         { } /* end */
7932 };
7933
7934 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7935         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7936         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7937         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7938         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7939         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7940         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7941         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7942         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7943         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7944         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7945         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7946         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7947         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7948         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7949         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7950         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7951         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7952         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7953         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7954         { } /* end */
7955 };
7956
7957 static struct snd_kcontrol_new alc883_targa_mixer[] = {
7958         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7959         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7960         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7961         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7962         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7963         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7964         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7965         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7966         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7967         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7968         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7969         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7970         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7971         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7972         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7973         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7974         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7975         { } /* end */
7976 };
7977
7978 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
7979         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7980         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7981         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7982         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7983         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7984         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7985         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7986         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7987         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7988         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7989         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7990         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7991         { } /* end */
7992 };
7993
7994 static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
7995         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7996         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7997         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7998         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7999         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8000         { } /* end */
8001 };
8002
8003 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8004         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8005         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8006         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8007         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8008         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8009         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8010         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8011         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8012         { } /* end */
8013 };
8014
8015 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8016         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8017         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8018         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8019         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8020         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8021         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8022         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8023         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8024         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8025         { } /* end */
8026 };
8027
8028 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8029         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8030         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8031         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8032         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8033         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8034         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8035         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8036         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8037         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8038         { } /* end */
8039 };
8040
8041 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8042         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8043         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8044         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8045         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8046         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8048         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8049         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8050         { } /* end */
8051 };
8052
8053 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8054         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8055         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8056         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8057         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8058         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8059         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8060         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8061         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8063         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8064         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8065         { } /* end */
8066 };
8067
8068 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8069         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8070         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8071         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8072         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8073         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8074                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8075         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8076         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8077         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8078         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8079         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8080         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8081         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8082         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8083         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8084         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8085         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8086         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8087         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8088         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8089         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8090         { } /* end */
8091 };
8092
8093 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8094         /* Output mixers */
8095         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8096         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8097         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8098         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8099         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8100                 HDA_OUTPUT),
8101         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8102         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8103         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8104         /* Output switches */
8105         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8106         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8107         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8108         /* Boost mixers */
8109         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8110         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8111         /* Input mixers */
8112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8113         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8114         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8115         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8116         { } /* end */
8117 };
8118
8119 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8120         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8121         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8123         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8124         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8125         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8126         { } /* end */
8127 };
8128
8129 static struct hda_bind_ctls alc883_bind_cap_vol = {
8130         .ops = &snd_hda_bind_vol,
8131         .values = {
8132                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8133                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8134                 0
8135         },
8136 };
8137
8138 static struct hda_bind_ctls alc883_bind_cap_switch = {
8139         .ops = &snd_hda_bind_sw,
8140         .values = {
8141                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8142                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8143                 0
8144         },
8145 };
8146
8147 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8148         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8149         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8150         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8151         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8152         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8153         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8154         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8155         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8156         { } /* end */
8157 };
8158
8159 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8160         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8161         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8162         {
8163                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8164                 /* .name = "Capture Source", */
8165                 .name = "Input Source",
8166                 .count = 1,
8167                 .info = alc_mux_enum_info,
8168                 .get = alc_mux_enum_get,
8169                 .put = alc_mux_enum_put,
8170         },
8171         { } /* end */
8172 };
8173
8174 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8175         {
8176                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8177                 .name = "Channel Mode",
8178                 .info = alc_ch_mode_info,
8179                 .get = alc_ch_mode_get,
8180                 .put = alc_ch_mode_put,
8181         },
8182         { } /* end */
8183 };
8184
8185 /* toggle speaker-output according to the hp-jack state */
8186 static void alc883_mitac_setup(struct hda_codec *codec)
8187 {
8188         struct alc_spec *spec = codec->spec;
8189
8190         spec->autocfg.hp_pins[0] = 0x15;
8191         spec->autocfg.speaker_pins[0] = 0x14;
8192         spec->autocfg.speaker_pins[1] = 0x17;
8193 }
8194
8195 /* auto-toggle front mic */
8196 /*
8197 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8198 {
8199         unsigned int present;
8200         unsigned char bits;
8201
8202         present = snd_hda_codec_read(codec, 0x18, 0,
8203                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8204         bits = present ? HDA_AMP_MUTE : 0;
8205         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8206 }
8207 */
8208
8209 static struct hda_verb alc883_mitac_verbs[] = {
8210         /* HP */
8211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8213         /* Subwoofer */
8214         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8215         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8216
8217         /* enable unsolicited event */
8218         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8219         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8220
8221         { } /* end */
8222 };
8223
8224 static struct hda_verb alc883_clevo_m540r_verbs[] = {
8225         /* HP */
8226         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8227         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8228         /* Int speaker */
8229         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
8230
8231         /* enable unsolicited event */
8232         /*
8233         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8234         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8235         */
8236
8237         { } /* end */
8238 };
8239
8240 static struct hda_verb alc883_clevo_m720_verbs[] = {
8241         /* HP */
8242         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8243         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8244         /* Int speaker */
8245         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8246         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8247
8248         /* enable unsolicited event */
8249         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8250         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8251
8252         { } /* end */
8253 };
8254
8255 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8256         /* HP */
8257         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8259         /* Subwoofer */
8260         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8261         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8262
8263         /* enable unsolicited event */
8264         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8265
8266         { } /* end */
8267 };
8268
8269 static struct hda_verb alc883_targa_verbs[] = {
8270         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8271         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8272
8273         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8274         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8275
8276 /* Connect Line-Out side jack (SPDIF) to Side */
8277         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8278         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8279         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8280 /* Connect Mic jack to CLFE */
8281         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8282         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8283         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8284 /* Connect Line-in jack to Surround */
8285         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8286         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8287         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8288 /* Connect HP out jack to Front */
8289         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8290         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8291         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8292
8293         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8294
8295         { } /* end */
8296 };
8297
8298 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8299         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8300         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8301         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8302         { } /* end */
8303 };
8304
8305 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8306         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8307         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8308         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8309         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8310         { } /* end */
8311 };
8312
8313 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8315         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8316         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8317         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8318         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8319         { } /* end */
8320 };
8321
8322 static struct hda_verb alc883_haier_w66_verbs[] = {
8323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8325
8326         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8327
8328         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8329         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8330         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8331         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8332         { } /* end */
8333 };
8334
8335 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8336         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8337         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8338         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8339         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8340         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8341         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8342         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8343         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8344         { } /* end */
8345 };
8346
8347 static struct hda_verb alc888_6st_dell_verbs[] = {
8348         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8349         { }
8350 };
8351
8352 static struct hda_verb alc883_vaiott_verbs[] = {
8353         /* HP */
8354         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8355         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8356
8357         /* enable unsolicited event */
8358         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8359
8360         { } /* end */
8361 };
8362
8363 static void alc888_3st_hp_setup(struct hda_codec *codec)
8364 {
8365         struct alc_spec *spec = codec->spec;
8366
8367         spec->autocfg.hp_pins[0] = 0x1b;
8368         spec->autocfg.speaker_pins[0] = 0x14;
8369         spec->autocfg.speaker_pins[1] = 0x16;
8370         spec->autocfg.speaker_pins[2] = 0x18;
8371 }
8372
8373 static struct hda_verb alc888_3st_hp_verbs[] = {
8374         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8375         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8376         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8377         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8378         { } /* end */
8379 };
8380
8381 /*
8382  * 2ch mode
8383  */
8384 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8385         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8386         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8387         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8388         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8389         { } /* end */
8390 };
8391
8392 /*
8393  * 4ch mode
8394  */
8395 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8396         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8397         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8398         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8399         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8400         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8401         { } /* end */
8402 };
8403
8404 /*
8405  * 6ch mode
8406  */
8407 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8408         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8409         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8410         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8411         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8412         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8413         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8414         { } /* end */
8415 };
8416
8417 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8418         { 2, alc888_3st_hp_2ch_init },
8419         { 4, alc888_3st_hp_4ch_init },
8420         { 6, alc888_3st_hp_6ch_init },
8421 };
8422
8423 /* toggle front-jack and RCA according to the hp-jack state */
8424 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8425 {
8426         unsigned int present;
8427
8428         present = snd_hda_codec_read(codec, 0x1b, 0,
8429                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8430         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8431                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8432         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8433                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8434 }
8435
8436 /* toggle RCA according to the front-jack state */
8437 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8438 {
8439         unsigned int present;
8440
8441         present = snd_hda_codec_read(codec, 0x14, 0,
8442                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8443         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8444                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8445 }
8446
8447 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8448                                              unsigned int res)
8449 {
8450         if ((res >> 26) == ALC880_HP_EVENT)
8451                 alc888_lenovo_ms7195_front_automute(codec);
8452         if ((res >> 26) == ALC880_FRONT_EVENT)
8453                 alc888_lenovo_ms7195_rca_automute(codec);
8454 }
8455
8456 static struct hda_verb alc883_medion_md2_verbs[] = {
8457         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8458         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8459
8460         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8461
8462         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8463         { } /* end */
8464 };
8465
8466 /* toggle speaker-output according to the hp-jack state */
8467 static void alc883_medion_md2_setup(struct hda_codec *codec)
8468 {
8469         struct alc_spec *spec = codec->spec;
8470
8471         spec->autocfg.hp_pins[0] = 0x14;
8472         spec->autocfg.speaker_pins[0] = 0x15;
8473 }
8474
8475 /* toggle speaker-output according to the hp-jack state */
8476 #define alc883_targa_init_hook          alc882_targa_init_hook
8477 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8478
8479 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8480 {
8481         unsigned int present;
8482
8483         present = snd_hda_codec_read(codec, 0x18, 0,
8484                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8485         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8486                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8487 }
8488
8489 static void alc883_clevo_m720_setup(struct hda_codec *codec)
8490 {
8491         struct alc_spec *spec = codec->spec;
8492
8493         spec->autocfg.hp_pins[0] = 0x15;
8494         spec->autocfg.speaker_pins[0] = 0x14;
8495 }
8496
8497 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8498 {
8499         alc_automute_amp(codec);
8500         alc883_clevo_m720_mic_automute(codec);
8501 }
8502
8503 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8504                                            unsigned int res)
8505 {
8506         switch (res >> 26) {
8507         case ALC880_MIC_EVENT:
8508                 alc883_clevo_m720_mic_automute(codec);
8509                 break;
8510         default:
8511                 alc_automute_amp_unsol_event(codec, res);
8512                 break;
8513         }
8514 }
8515
8516 /* toggle speaker-output according to the hp-jack state */
8517 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8518 {
8519         struct alc_spec *spec = codec->spec;
8520
8521         spec->autocfg.hp_pins[0] = 0x14;
8522         spec->autocfg.speaker_pins[0] = 0x15;
8523 }
8524
8525 static void alc883_haier_w66_setup(struct hda_codec *codec)
8526 {
8527         struct alc_spec *spec = codec->spec;
8528
8529         spec->autocfg.hp_pins[0] = 0x1b;
8530         spec->autocfg.speaker_pins[0] = 0x14;
8531 }
8532
8533 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8534 {
8535         unsigned int present;
8536         unsigned char bits;
8537
8538         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8539                 & AC_PINSENSE_PRESENCE;
8540         bits = present ? HDA_AMP_MUTE : 0;
8541         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8542                                  HDA_AMP_MUTE, bits);
8543 }
8544
8545 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8546 {
8547         unsigned int present;
8548         unsigned char bits;
8549
8550         present = snd_hda_codec_read(codec, 0x1b, 0,
8551                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8552         bits = present ? HDA_AMP_MUTE : 0;
8553         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8554                                  HDA_AMP_MUTE, bits);
8555         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8556                                  HDA_AMP_MUTE, bits);
8557 }
8558
8559 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8560                                            unsigned int res)
8561 {
8562         if ((res >> 26) == ALC880_HP_EVENT)
8563                 alc883_lenovo_101e_all_automute(codec);
8564         if ((res >> 26) == ALC880_FRONT_EVENT)
8565                 alc883_lenovo_101e_ispeaker_automute(codec);
8566 }
8567
8568 /* toggle speaker-output according to the hp-jack state */
8569 static void alc883_acer_aspire_setup(struct hda_codec *codec)
8570 {
8571         struct alc_spec *spec = codec->spec;
8572
8573         spec->autocfg.hp_pins[0] = 0x14;
8574         spec->autocfg.speaker_pins[0] = 0x15;
8575         spec->autocfg.speaker_pins[1] = 0x16;
8576 }
8577
8578 static struct hda_verb alc883_acer_eapd_verbs[] = {
8579         /* HP Pin: output 0 (0x0c) */
8580         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8581         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8582         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8583         /* Front Pin: output 0 (0x0c) */
8584         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8585         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8586         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8587         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8588         /* eanable EAPD on medion laptop */
8589         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8590         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8591         /* enable unsolicited event */
8592         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8593         { }
8594 };
8595
8596 static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
8597         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8598         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8599         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8600         { } /* end */
8601 };
8602
8603 static void alc888_6st_dell_setup(struct hda_codec *codec)
8604 {
8605         struct alc_spec *spec = codec->spec;
8606
8607         spec->autocfg.hp_pins[0] = 0x1b;
8608         spec->autocfg.speaker_pins[0] = 0x14;
8609         spec->autocfg.speaker_pins[1] = 0x15;
8610         spec->autocfg.speaker_pins[2] = 0x16;
8611         spec->autocfg.speaker_pins[3] = 0x17;
8612 }
8613
8614 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
8615 {
8616         struct alc_spec *spec = codec->spec;
8617
8618         spec->autocfg.hp_pins[0] = 0x1b;
8619         spec->autocfg.speaker_pins[0] = 0x14;
8620         spec->autocfg.speaker_pins[1] = 0x15;
8621         spec->autocfg.speaker_pins[2] = 0x16;
8622         spec->autocfg.speaker_pins[3] = 0x17;
8623         spec->autocfg.speaker_pins[4] = 0x1a;
8624 }
8625
8626 static void alc883_vaiott_setup(struct hda_codec *codec)
8627 {
8628         struct alc_spec *spec = codec->spec;
8629
8630         spec->autocfg.hp_pins[0] = 0x15;
8631         spec->autocfg.speaker_pins[0] = 0x14;
8632         spec->autocfg.speaker_pins[1] = 0x17;
8633 }
8634
8635 static struct hda_verb alc888_asus_m90v_verbs[] = {
8636         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8637         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8638         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8639         /* enable unsolicited event */
8640         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8641         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8642         { } /* end */
8643 };
8644
8645 static void alc883_mode2_setup(struct hda_codec *codec)
8646 {
8647         struct alc_spec *spec = codec->spec;
8648
8649         spec->autocfg.hp_pins[0] = 0x1b;
8650         spec->autocfg.speaker_pins[0] = 0x14;
8651         spec->autocfg.speaker_pins[1] = 0x15;
8652         spec->autocfg.speaker_pins[2] = 0x16;
8653         spec->ext_mic.pin = 0x18;
8654         spec->int_mic.pin = 0x19;
8655         spec->ext_mic.mux_idx = 0;
8656         spec->int_mic.mux_idx = 1;
8657         spec->auto_mic = 1;
8658 }
8659
8660 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8661         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8662         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8663         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8665         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8666         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8667         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8668         /* enable unsolicited event */
8669         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8670         { } /* end */
8671 };
8672
8673 static void alc883_eee1601_inithook(struct hda_codec *codec)
8674 {
8675         struct alc_spec *spec = codec->spec;
8676
8677         spec->autocfg.hp_pins[0] = 0x14;
8678         spec->autocfg.speaker_pins[0] = 0x1b;
8679         alc_automute_pin(codec);
8680 }
8681
8682 static struct hda_verb alc889A_mb31_verbs[] = {
8683         /* Init rear pin (used as headphone output) */
8684         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8685         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8686         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8687         /* Init line pin (used as output in 4ch and 6ch mode) */
8688         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8689         /* Init line 2 pin (used as headphone out by default) */
8690         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8691         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
8692         { } /* end */
8693 };
8694
8695 /* Mute speakers according to the headphone jack state */
8696 static void alc889A_mb31_automute(struct hda_codec *codec)
8697 {
8698         unsigned int present;
8699
8700         /* Mute only in 2ch or 4ch mode */
8701         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8702             == 0x00) {
8703                 present = snd_hda_codec_read(codec, 0x15, 0,
8704                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8705                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
8706                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8707                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8708                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8709         }
8710 }
8711
8712 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8713 {
8714         if ((res >> 26) == ALC880_HP_EVENT)
8715                 alc889A_mb31_automute(codec);
8716 }
8717
8718
8719 #ifdef CONFIG_SND_HDA_POWER_SAVE
8720 #define alc882_loopbacks        alc880_loopbacks
8721 #endif
8722
8723 /* pcm configuration: identical with ALC880 */
8724 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
8725 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
8726 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
8727 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
8728
8729 static hda_nid_t alc883_slave_dig_outs[] = {
8730         ALC1200_DIGOUT_NID, 0,
8731 };
8732
8733 static hda_nid_t alc1200_slave_dig_outs[] = {
8734         ALC883_DIGOUT_NID, 0,
8735 };
8736
8737 /*
8738  * configuration and preset
8739  */
8740 static const char *alc882_models[ALC882_MODEL_LAST] = {
8741         [ALC882_3ST_DIG]        = "3stack-dig",
8742         [ALC882_6ST_DIG]        = "6stack-dig",
8743         [ALC882_ARIMA]          = "arima",
8744         [ALC882_W2JC]           = "w2jc",
8745         [ALC882_TARGA]          = "targa",
8746         [ALC882_ASUS_A7J]       = "asus-a7j",
8747         [ALC882_ASUS_A7M]       = "asus-a7m",
8748         [ALC885_MACPRO]         = "macpro",
8749         [ALC885_MB5]            = "mb5",
8750         [ALC885_MBP3]           = "mbp3",
8751         [ALC885_IMAC24]         = "imac24",
8752         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
8753         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8754         [ALC883_3ST_6ch]        = "3stack-6ch",
8755         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
8756         [ALC883_TARGA_DIG]      = "targa-dig",
8757         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8758         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
8759         [ALC883_ACER]           = "acer",
8760         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8761         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8762         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
8763         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
8764         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
8765         [ALC883_MEDION]         = "medion",
8766         [ALC883_MEDION_MD2]     = "medion-md2",
8767         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8768         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8769         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8770         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8771         [ALC888_LENOVO_SKY] = "lenovo-sky",
8772         [ALC883_HAIER_W66]      = "haier-w66",
8773         [ALC888_3ST_HP]         = "3stack-hp",
8774         [ALC888_6ST_DELL]       = "6stack-dell",
8775         [ALC883_MITAC]          = "mitac",
8776         [ALC883_CLEVO_M540R]    = "clevo-m540r",
8777         [ALC883_CLEVO_M720]     = "clevo-m720",
8778         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8779         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8780         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8781         [ALC889A_INTEL]         = "intel-alc889a",
8782         [ALC889_INTEL]          = "intel-x58",
8783         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8784         [ALC889A_MB31]          = "mb31",
8785         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
8786         [ALC882_AUTO]           = "auto",
8787 };
8788
8789 static struct snd_pci_quirk alc882_cfg_tbl[] = {
8790         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8791
8792         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8793         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8794         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8795         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8796         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8797         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8798         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8799                 ALC888_ACER_ASPIRE_4930G),
8800         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8801                 ALC888_ACER_ASPIRE_4930G),
8802         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
8803                 ALC888_ACER_ASPIRE_8930G),
8804         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
8805                 ALC888_ACER_ASPIRE_8930G),
8806         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
8807         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
8808         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8809                 ALC888_ACER_ASPIRE_6530G),
8810         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8811                 ALC888_ACER_ASPIRE_6530G),
8812         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8813                 ALC888_ACER_ASPIRE_7730G),
8814         /* default Acer -- disabled as it causes more problems.
8815          *    model=auto should work fine now
8816          */
8817         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8818
8819         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8820
8821         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8822         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8823         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8824         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8825         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8826         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8827
8828         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
8829         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
8830         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
8831         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8832         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
8833         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
8834         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
8835         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8836         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8837         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8838         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8839
8840         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
8841         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8842         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
8843         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8844         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8845         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8846         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8847         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8848         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8849
8850         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8851         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8852         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8853         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
8854         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8855         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8856         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8857         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8858         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8859         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8860         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8861         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8862         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8863         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8864         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
8865         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8866         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8867         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8868         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
8869         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8870         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8871         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8872         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8873         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8874         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8875         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8876         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
8877         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8878         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8879
8880         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8881         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8882         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8883         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
8884         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8885         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8886         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
8887         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8888         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8889                       ALC883_FUJITSU_PI2515),
8890         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8891                 ALC888_FUJITSU_XA3530),
8892         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8893         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8894         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8895         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8896         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8897         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8898         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8899         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8900         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8901
8902         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8903         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8904         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8905         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8906         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8907         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
8908         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8909
8910         {}
8911 };
8912
8913 /* codec SSID table for Intel Mac */
8914 static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8915         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
8916         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
8917         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
8918         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
8919         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
8920         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
8921         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
8922         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8923         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8924         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
8925         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8926         /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
8927          * so apparently no perfect solution yet
8928          */
8929         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8930         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
8931         {} /* terminator */
8932 };
8933
8934 static struct alc_config_preset alc882_presets[] = {
8935         [ALC882_3ST_DIG] = {
8936                 .mixers = { alc882_base_mixer },
8937                 .init_verbs = { alc882_base_init_verbs,
8938                                 alc882_adc1_init_verbs },
8939                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8940                 .dac_nids = alc882_dac_nids,
8941                 .dig_out_nid = ALC882_DIGOUT_NID,
8942                 .dig_in_nid = ALC882_DIGIN_NID,
8943                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8944                 .channel_mode = alc882_ch_modes,
8945                 .need_dac_fix = 1,
8946                 .input_mux = &alc882_capture_source,
8947         },
8948         [ALC882_6ST_DIG] = {
8949                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8950                 .init_verbs = { alc882_base_init_verbs,
8951                                 alc882_adc1_init_verbs },
8952                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8953                 .dac_nids = alc882_dac_nids,
8954                 .dig_out_nid = ALC882_DIGOUT_NID,
8955                 .dig_in_nid = ALC882_DIGIN_NID,
8956                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8957                 .channel_mode = alc882_sixstack_modes,
8958                 .input_mux = &alc882_capture_source,
8959         },
8960         [ALC882_ARIMA] = {
8961                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8962                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8963                                 alc882_eapd_verbs },
8964                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8965                 .dac_nids = alc882_dac_nids,
8966                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8967                 .channel_mode = alc882_sixstack_modes,
8968                 .input_mux = &alc882_capture_source,
8969         },
8970         [ALC882_W2JC] = {
8971                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
8972                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8973                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
8974                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8975                 .dac_nids = alc882_dac_nids,
8976                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
8977                 .channel_mode = alc880_threestack_modes,
8978                 .need_dac_fix = 1,
8979                 .input_mux = &alc882_capture_source,
8980                 .dig_out_nid = ALC882_DIGOUT_NID,
8981         },
8982         [ALC885_MBP3] = {
8983                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8984                 .init_verbs = { alc885_mbp3_init_verbs,
8985                                 alc880_gpio1_init_verbs },
8986                 .num_dacs = 2,
8987                 .dac_nids = alc882_dac_nids,
8988                 .hp_nid = 0x04,
8989                 .channel_mode = alc885_mbp_4ch_modes,
8990                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
8991                 .input_mux = &alc882_capture_source,
8992                 .dig_out_nid = ALC882_DIGOUT_NID,
8993                 .dig_in_nid = ALC882_DIGIN_NID,
8994                 .unsol_event = alc_automute_amp_unsol_event,
8995                 .setup = alc885_mbp3_setup,
8996                 .init_hook = alc_automute_amp,
8997         },
8998         [ALC885_MB5] = {
8999                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
9000                 .init_verbs = { alc885_mb5_init_verbs,
9001                                 alc880_gpio1_init_verbs },
9002                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9003                 .dac_nids = alc882_dac_nids,
9004                 .channel_mode = alc885_mb5_6ch_modes,
9005                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
9006                 .input_mux = &mb5_capture_source,
9007                 .dig_out_nid = ALC882_DIGOUT_NID,
9008                 .dig_in_nid = ALC882_DIGIN_NID,
9009         },
9010         [ALC885_MACPRO] = {
9011                 .mixers = { alc882_macpro_mixer },
9012                 .init_verbs = { alc882_macpro_init_verbs },
9013                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9014                 .dac_nids = alc882_dac_nids,
9015                 .dig_out_nid = ALC882_DIGOUT_NID,
9016                 .dig_in_nid = ALC882_DIGIN_NID,
9017                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9018                 .channel_mode = alc882_ch_modes,
9019                 .input_mux = &alc882_capture_source,
9020                 .init_hook = alc885_macpro_init_hook,
9021         },
9022         [ALC885_IMAC24] = {
9023                 .mixers = { alc885_imac24_mixer },
9024                 .init_verbs = { alc885_imac24_init_verbs },
9025                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9026                 .dac_nids = alc882_dac_nids,
9027                 .dig_out_nid = ALC882_DIGOUT_NID,
9028                 .dig_in_nid = ALC882_DIGIN_NID,
9029                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9030                 .channel_mode = alc882_ch_modes,
9031                 .input_mux = &alc882_capture_source,
9032                 .unsol_event = alc_automute_amp_unsol_event,
9033                 .setup = alc885_imac24_setup,
9034                 .init_hook = alc885_imac24_init_hook,
9035         },
9036         [ALC882_TARGA] = {
9037                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9038                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9039                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
9040                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9041                 .dac_nids = alc882_dac_nids,
9042                 .dig_out_nid = ALC882_DIGOUT_NID,
9043                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9044                 .adc_nids = alc882_adc_nids,
9045                 .capsrc_nids = alc882_capsrc_nids,
9046                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9047                 .channel_mode = alc882_3ST_6ch_modes,
9048                 .need_dac_fix = 1,
9049                 .input_mux = &alc882_capture_source,
9050                 .unsol_event = alc882_targa_unsol_event,
9051                 .setup = alc882_targa_setup,
9052                 .init_hook = alc882_targa_automute,
9053         },
9054         [ALC882_ASUS_A7J] = {
9055                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9056                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9057                                 alc882_asus_a7j_verbs},
9058                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9059                 .dac_nids = alc882_dac_nids,
9060                 .dig_out_nid = ALC882_DIGOUT_NID,
9061                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9062                 .adc_nids = alc882_adc_nids,
9063                 .capsrc_nids = alc882_capsrc_nids,
9064                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9065                 .channel_mode = alc882_3ST_6ch_modes,
9066                 .need_dac_fix = 1,
9067                 .input_mux = &alc882_capture_source,
9068         },
9069         [ALC882_ASUS_A7M] = {
9070                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9071                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9072                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
9073                                 alc882_asus_a7m_verbs },
9074                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9075                 .dac_nids = alc882_dac_nids,
9076                 .dig_out_nid = ALC882_DIGOUT_NID,
9077                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
9078                 .channel_mode = alc880_threestack_modes,
9079                 .need_dac_fix = 1,
9080                 .input_mux = &alc882_capture_source,
9081         },
9082         [ALC883_3ST_2ch_DIG] = {
9083                 .mixers = { alc883_3ST_2ch_mixer },
9084                 .init_verbs = { alc883_init_verbs },
9085                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9086                 .dac_nids = alc883_dac_nids,
9087                 .dig_out_nid = ALC883_DIGOUT_NID,
9088                 .dig_in_nid = ALC883_DIGIN_NID,
9089                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9090                 .channel_mode = alc883_3ST_2ch_modes,
9091                 .input_mux = &alc883_capture_source,
9092         },
9093         [ALC883_3ST_6ch_DIG] = {
9094                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9095                 .init_verbs = { alc883_init_verbs },
9096                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9097                 .dac_nids = alc883_dac_nids,
9098                 .dig_out_nid = ALC883_DIGOUT_NID,
9099                 .dig_in_nid = ALC883_DIGIN_NID,
9100                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9101                 .channel_mode = alc883_3ST_6ch_modes,
9102                 .need_dac_fix = 1,
9103                 .input_mux = &alc883_capture_source,
9104         },
9105         [ALC883_3ST_6ch] = {
9106                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9107                 .init_verbs = { alc883_init_verbs },
9108                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9109                 .dac_nids = alc883_dac_nids,
9110                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9111                 .channel_mode = alc883_3ST_6ch_modes,
9112                 .need_dac_fix = 1,
9113                 .input_mux = &alc883_capture_source,
9114         },
9115         [ALC883_3ST_6ch_INTEL] = {
9116                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9117                 .init_verbs = { alc883_init_verbs },
9118                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9119                 .dac_nids = alc883_dac_nids,
9120                 .dig_out_nid = ALC883_DIGOUT_NID,
9121                 .dig_in_nid = ALC883_DIGIN_NID,
9122                 .slave_dig_outs = alc883_slave_dig_outs,
9123                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9124                 .channel_mode = alc883_3ST_6ch_intel_modes,
9125                 .need_dac_fix = 1,
9126                 .input_mux = &alc883_3stack_6ch_intel,
9127         },
9128         [ALC889A_INTEL] = {
9129                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9130                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
9131                                 alc_hp15_unsol_verbs },
9132                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9133                 .dac_nids = alc883_dac_nids,
9134                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9135                 .adc_nids = alc889_adc_nids,
9136                 .dig_out_nid = ALC883_DIGOUT_NID,
9137                 .dig_in_nid = ALC883_DIGIN_NID,
9138                 .slave_dig_outs = alc883_slave_dig_outs,
9139                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9140                 .channel_mode = alc889_8ch_intel_modes,
9141                 .capsrc_nids = alc889_capsrc_nids,
9142                 .input_mux = &alc889_capture_source,
9143                 .setup = alc889_automute_setup,
9144                 .init_hook = alc_automute_amp,
9145                 .unsol_event = alc_automute_amp_unsol_event,
9146                 .need_dac_fix = 1,
9147         },
9148         [ALC889_INTEL] = {
9149                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9150                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9151                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
9152                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9153                 .dac_nids = alc883_dac_nids,
9154                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9155                 .adc_nids = alc889_adc_nids,
9156                 .dig_out_nid = ALC883_DIGOUT_NID,
9157                 .dig_in_nid = ALC883_DIGIN_NID,
9158                 .slave_dig_outs = alc883_slave_dig_outs,
9159                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9160                 .channel_mode = alc889_8ch_intel_modes,
9161                 .capsrc_nids = alc889_capsrc_nids,
9162                 .input_mux = &alc889_capture_source,
9163                 .setup = alc889_automute_setup,
9164                 .init_hook = alc889_intel_init_hook,
9165                 .unsol_event = alc_automute_amp_unsol_event,
9166                 .need_dac_fix = 1,
9167         },
9168         [ALC883_6ST_DIG] = {
9169                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9170                 .init_verbs = { alc883_init_verbs },
9171                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9172                 .dac_nids = alc883_dac_nids,
9173                 .dig_out_nid = ALC883_DIGOUT_NID,
9174                 .dig_in_nid = ALC883_DIGIN_NID,
9175                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9176                 .channel_mode = alc883_sixstack_modes,
9177                 .input_mux = &alc883_capture_source,
9178         },
9179         [ALC883_TARGA_DIG] = {
9180                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9181                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9182                                 alc883_targa_verbs},
9183                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9184                 .dac_nids = alc883_dac_nids,
9185                 .dig_out_nid = ALC883_DIGOUT_NID,
9186                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9187                 .channel_mode = alc883_3ST_6ch_modes,
9188                 .need_dac_fix = 1,
9189                 .input_mux = &alc883_capture_source,
9190                 .unsol_event = alc883_targa_unsol_event,
9191                 .setup = alc882_targa_setup,
9192                 .init_hook = alc882_targa_automute,
9193         },
9194         [ALC883_TARGA_2ch_DIG] = {
9195                 .mixers = { alc883_targa_2ch_mixer},
9196                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9197                                 alc883_targa_verbs},
9198                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9199                 .dac_nids = alc883_dac_nids,
9200                 .adc_nids = alc883_adc_nids_alt,
9201                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9202                 .dig_out_nid = ALC883_DIGOUT_NID,
9203                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9204                 .channel_mode = alc883_3ST_2ch_modes,
9205                 .input_mux = &alc883_capture_source,
9206                 .unsol_event = alc883_targa_unsol_event,
9207                 .setup = alc882_targa_setup,
9208                 .init_hook = alc882_targa_automute,
9209         },
9210         [ALC883_TARGA_8ch_DIG] = {
9211                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9212                             alc883_chmode_mixer },
9213                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9214                                 alc883_targa_verbs },
9215                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9216                 .dac_nids = alc883_dac_nids,
9217                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9218                 .adc_nids = alc883_adc_nids_rev,
9219                 .capsrc_nids = alc883_capsrc_nids_rev,
9220                 .dig_out_nid = ALC883_DIGOUT_NID,
9221                 .dig_in_nid = ALC883_DIGIN_NID,
9222                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9223                 .channel_mode = alc883_4ST_8ch_modes,
9224                 .need_dac_fix = 1,
9225                 .input_mux = &alc883_capture_source,
9226                 .unsol_event = alc883_targa_unsol_event,
9227                 .setup = alc882_targa_setup,
9228                 .init_hook = alc882_targa_automute,
9229         },
9230         [ALC883_ACER] = {
9231                 .mixers = { alc883_base_mixer },
9232                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9233                  * and the headphone jack.  Turn this on and rely on the
9234                  * standard mute methods whenever the user wants to turn
9235                  * these outputs off.
9236                  */
9237                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9238                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9239                 .dac_nids = alc883_dac_nids,
9240                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9241                 .channel_mode = alc883_3ST_2ch_modes,
9242                 .input_mux = &alc883_capture_source,
9243         },
9244         [ALC883_ACER_ASPIRE] = {
9245                 .mixers = { alc883_acer_aspire_mixer },
9246                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9247                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9248                 .dac_nids = alc883_dac_nids,
9249                 .dig_out_nid = ALC883_DIGOUT_NID,
9250                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9251                 .channel_mode = alc883_3ST_2ch_modes,
9252                 .input_mux = &alc883_capture_source,
9253                 .unsol_event = alc_automute_amp_unsol_event,
9254                 .setup = alc883_acer_aspire_setup,
9255                 .init_hook = alc_automute_amp,
9256         },
9257         [ALC888_ACER_ASPIRE_4930G] = {
9258                 .mixers = { alc888_base_mixer,
9259                                 alc883_chmode_mixer },
9260                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9261                                 alc888_acer_aspire_4930g_verbs },
9262                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9263                 .dac_nids = alc883_dac_nids,
9264                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9265                 .adc_nids = alc883_adc_nids_rev,
9266                 .capsrc_nids = alc883_capsrc_nids_rev,
9267                 .dig_out_nid = ALC883_DIGOUT_NID,
9268                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9269                 .channel_mode = alc883_3ST_6ch_modes,
9270                 .need_dac_fix = 1,
9271                 .num_mux_defs =
9272                         ARRAY_SIZE(alc888_2_capture_sources),
9273                 .input_mux = alc888_2_capture_sources,
9274                 .unsol_event = alc_automute_amp_unsol_event,
9275                 .setup = alc888_acer_aspire_4930g_setup,
9276                 .init_hook = alc_automute_amp,
9277         },
9278         [ALC888_ACER_ASPIRE_6530G] = {
9279                 .mixers = { alc888_acer_aspire_6530_mixer },
9280                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9281                                 alc888_acer_aspire_6530g_verbs },
9282                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9283                 .dac_nids = alc883_dac_nids,
9284                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9285                 .adc_nids = alc883_adc_nids_rev,
9286                 .capsrc_nids = alc883_capsrc_nids_rev,
9287                 .dig_out_nid = ALC883_DIGOUT_NID,
9288                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9289                 .channel_mode = alc883_3ST_2ch_modes,
9290                 .num_mux_defs =
9291                         ARRAY_SIZE(alc888_2_capture_sources),
9292                 .input_mux = alc888_acer_aspire_6530_sources,
9293                 .unsol_event = alc_automute_amp_unsol_event,
9294                 .setup = alc888_acer_aspire_6530g_setup,
9295                 .init_hook = alc_automute_amp,
9296         },
9297         [ALC888_ACER_ASPIRE_8930G] = {
9298                 .mixers = { alc888_base_mixer,
9299                                 alc883_chmode_mixer },
9300                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9301                                 alc889_acer_aspire_8930g_verbs },
9302                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9303                 .dac_nids = alc883_dac_nids,
9304                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9305                 .adc_nids = alc889_adc_nids,
9306                 .capsrc_nids = alc889_capsrc_nids,
9307                 .dig_out_nid = ALC883_DIGOUT_NID,
9308                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9309                 .channel_mode = alc883_3ST_6ch_modes,
9310                 .need_dac_fix = 1,
9311                 .const_channel_count = 6,
9312                 .num_mux_defs =
9313                         ARRAY_SIZE(alc889_capture_sources),
9314                 .input_mux = alc889_capture_sources,
9315                 .unsol_event = alc_automute_amp_unsol_event,
9316                 .setup = alc889_acer_aspire_8930g_setup,
9317                 .init_hook = alc_automute_amp,
9318         },
9319         [ALC888_ACER_ASPIRE_7730G] = {
9320                 .mixers = { alc883_3ST_6ch_mixer,
9321                                 alc883_chmode_mixer },
9322                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9323                                 alc888_acer_aspire_7730G_verbs },
9324                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9325                 .dac_nids = alc883_dac_nids,
9326                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9327                 .adc_nids = alc883_adc_nids_rev,
9328                 .capsrc_nids = alc883_capsrc_nids_rev,
9329                 .dig_out_nid = ALC883_DIGOUT_NID,
9330                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9331                 .channel_mode = alc883_3ST_6ch_modes,
9332                 .need_dac_fix = 1,
9333                 .const_channel_count = 6,
9334                 .input_mux = &alc883_capture_source,
9335                 .unsol_event = alc_automute_amp_unsol_event,
9336                 .setup = alc888_acer_aspire_6530g_setup,
9337                 .init_hook = alc_automute_amp,
9338         },
9339         [ALC883_MEDION] = {
9340                 .mixers = { alc883_fivestack_mixer,
9341                             alc883_chmode_mixer },
9342                 .init_verbs = { alc883_init_verbs,
9343                                 alc883_medion_eapd_verbs },
9344                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9345                 .dac_nids = alc883_dac_nids,
9346                 .adc_nids = alc883_adc_nids_alt,
9347                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9348                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9349                 .channel_mode = alc883_sixstack_modes,
9350                 .input_mux = &alc883_capture_source,
9351         },
9352         [ALC883_MEDION_MD2] = {
9353                 .mixers = { alc883_medion_md2_mixer},
9354                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9355                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9356                 .dac_nids = alc883_dac_nids,
9357                 .dig_out_nid = ALC883_DIGOUT_NID,
9358                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9359                 .channel_mode = alc883_3ST_2ch_modes,
9360                 .input_mux = &alc883_capture_source,
9361                 .unsol_event = alc_automute_amp_unsol_event,
9362                 .setup = alc883_medion_md2_setup,
9363                 .init_hook = alc_automute_amp,
9364         },
9365         [ALC883_LAPTOP_EAPD] = {
9366                 .mixers = { alc883_base_mixer },
9367                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9368                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9369                 .dac_nids = alc883_dac_nids,
9370                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9371                 .channel_mode = alc883_3ST_2ch_modes,
9372                 .input_mux = &alc883_capture_source,
9373         },
9374         [ALC883_CLEVO_M540R] = {
9375                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9376                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
9377                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9378                 .dac_nids = alc883_dac_nids,
9379                 .dig_out_nid = ALC883_DIGOUT_NID,
9380                 .dig_in_nid = ALC883_DIGIN_NID,
9381                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
9382                 .channel_mode = alc883_3ST_6ch_clevo_modes,
9383                 .need_dac_fix = 1,
9384                 .input_mux = &alc883_capture_source,
9385                 /* This machine has the hardware HP auto-muting, thus
9386                  * we need no software mute via unsol event
9387                  */
9388         },
9389         [ALC883_CLEVO_M720] = {
9390                 .mixers = { alc883_clevo_m720_mixer },
9391                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9392                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9393                 .dac_nids = alc883_dac_nids,
9394                 .dig_out_nid = ALC883_DIGOUT_NID,
9395                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9396                 .channel_mode = alc883_3ST_2ch_modes,
9397                 .input_mux = &alc883_capture_source,
9398                 .unsol_event = alc883_clevo_m720_unsol_event,
9399                 .setup = alc883_clevo_m720_setup,
9400                 .init_hook = alc883_clevo_m720_init_hook,
9401         },
9402         [ALC883_LENOVO_101E_2ch] = {
9403                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9404                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9405                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9406                 .dac_nids = alc883_dac_nids,
9407                 .adc_nids = alc883_adc_nids_alt,
9408                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9409                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9410                 .channel_mode = alc883_3ST_2ch_modes,
9411                 .input_mux = &alc883_lenovo_101e_capture_source,
9412                 .unsol_event = alc883_lenovo_101e_unsol_event,
9413                 .init_hook = alc883_lenovo_101e_all_automute,
9414         },
9415         [ALC883_LENOVO_NB0763] = {
9416                 .mixers = { alc883_lenovo_nb0763_mixer },
9417                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9418                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9419                 .dac_nids = alc883_dac_nids,
9420                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9421                 .channel_mode = alc883_3ST_2ch_modes,
9422                 .need_dac_fix = 1,
9423                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9424                 .unsol_event = alc_automute_amp_unsol_event,
9425                 .setup = alc883_medion_md2_setup,
9426                 .init_hook = alc_automute_amp,
9427         },
9428         [ALC888_LENOVO_MS7195_DIG] = {
9429                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9430                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9431                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9432                 .dac_nids = alc883_dac_nids,
9433                 .dig_out_nid = ALC883_DIGOUT_NID,
9434                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9435                 .channel_mode = alc883_3ST_6ch_modes,
9436                 .need_dac_fix = 1,
9437                 .input_mux = &alc883_capture_source,
9438                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9439                 .init_hook = alc888_lenovo_ms7195_front_automute,
9440         },
9441         [ALC883_HAIER_W66] = {
9442                 .mixers = { alc883_targa_2ch_mixer},
9443                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9444                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9445                 .dac_nids = alc883_dac_nids,
9446                 .dig_out_nid = ALC883_DIGOUT_NID,
9447                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9448                 .channel_mode = alc883_3ST_2ch_modes,
9449                 .input_mux = &alc883_capture_source,
9450                 .unsol_event = alc_automute_amp_unsol_event,
9451                 .setup = alc883_haier_w66_setup,
9452                 .init_hook = alc_automute_amp,
9453         },
9454         [ALC888_3ST_HP] = {
9455                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9456                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9457                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9458                 .dac_nids = alc883_dac_nids,
9459                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9460                 .channel_mode = alc888_3st_hp_modes,
9461                 .need_dac_fix = 1,
9462                 .input_mux = &alc883_capture_source,
9463                 .unsol_event = alc_automute_amp_unsol_event,
9464                 .setup = alc888_3st_hp_setup,
9465                 .init_hook = alc_automute_amp,
9466         },
9467         [ALC888_6ST_DELL] = {
9468                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9469                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9470                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9471                 .dac_nids = alc883_dac_nids,
9472                 .dig_out_nid = ALC883_DIGOUT_NID,
9473                 .dig_in_nid = ALC883_DIGIN_NID,
9474                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9475                 .channel_mode = alc883_sixstack_modes,
9476                 .input_mux = &alc883_capture_source,
9477                 .unsol_event = alc_automute_amp_unsol_event,
9478                 .setup = alc888_6st_dell_setup,
9479                 .init_hook = alc_automute_amp,
9480         },
9481         [ALC883_MITAC] = {
9482                 .mixers = { alc883_mitac_mixer },
9483                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9484                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9485                 .dac_nids = alc883_dac_nids,
9486                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9487                 .channel_mode = alc883_3ST_2ch_modes,
9488                 .input_mux = &alc883_capture_source,
9489                 .unsol_event = alc_automute_amp_unsol_event,
9490                 .setup = alc883_mitac_setup,
9491                 .init_hook = alc_automute_amp,
9492         },
9493         [ALC883_FUJITSU_PI2515] = {
9494                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9495                 .init_verbs = { alc883_init_verbs,
9496                                 alc883_2ch_fujitsu_pi2515_verbs},
9497                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9498                 .dac_nids = alc883_dac_nids,
9499                 .dig_out_nid = ALC883_DIGOUT_NID,
9500                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9501                 .channel_mode = alc883_3ST_2ch_modes,
9502                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9503                 .unsol_event = alc_automute_amp_unsol_event,
9504                 .setup = alc883_2ch_fujitsu_pi2515_setup,
9505                 .init_hook = alc_automute_amp,
9506         },
9507         [ALC888_FUJITSU_XA3530] = {
9508                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9509                 .init_verbs = { alc883_init_verbs,
9510                         alc888_fujitsu_xa3530_verbs },
9511                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9512                 .dac_nids = alc883_dac_nids,
9513                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9514                 .adc_nids = alc883_adc_nids_rev,
9515                 .capsrc_nids = alc883_capsrc_nids_rev,
9516                 .dig_out_nid = ALC883_DIGOUT_NID,
9517                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9518                 .channel_mode = alc888_4ST_8ch_intel_modes,
9519                 .num_mux_defs =
9520                         ARRAY_SIZE(alc888_2_capture_sources),
9521                 .input_mux = alc888_2_capture_sources,
9522                 .unsol_event = alc_automute_amp_unsol_event,
9523                 .setup = alc888_fujitsu_xa3530_setup,
9524                 .init_hook = alc_automute_amp,
9525         },
9526         [ALC888_LENOVO_SKY] = {
9527                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9528                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9529                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9530                 .dac_nids = alc883_dac_nids,
9531                 .dig_out_nid = ALC883_DIGOUT_NID,
9532                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9533                 .channel_mode = alc883_sixstack_modes,
9534                 .need_dac_fix = 1,
9535                 .input_mux = &alc883_lenovo_sky_capture_source,
9536                 .unsol_event = alc_automute_amp_unsol_event,
9537                 .setup = alc888_lenovo_sky_setup,
9538                 .init_hook = alc_automute_amp,
9539         },
9540         [ALC888_ASUS_M90V] = {
9541                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9542                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9543                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9544                 .dac_nids = alc883_dac_nids,
9545                 .dig_out_nid = ALC883_DIGOUT_NID,
9546                 .dig_in_nid = ALC883_DIGIN_NID,
9547                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9548                 .channel_mode = alc883_3ST_6ch_modes,
9549                 .need_dac_fix = 1,
9550                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9551                 .unsol_event = alc_sku_unsol_event,
9552                 .setup = alc883_mode2_setup,
9553                 .init_hook = alc_inithook,
9554         },
9555         [ALC888_ASUS_EEE1601] = {
9556                 .mixers = { alc883_asus_eee1601_mixer },
9557                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9558                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9559                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9560                 .dac_nids = alc883_dac_nids,
9561                 .dig_out_nid = ALC883_DIGOUT_NID,
9562                 .dig_in_nid = ALC883_DIGIN_NID,
9563                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9564                 .channel_mode = alc883_3ST_2ch_modes,
9565                 .need_dac_fix = 1,
9566                 .input_mux = &alc883_asus_eee1601_capture_source,
9567                 .unsol_event = alc_sku_unsol_event,
9568                 .init_hook = alc883_eee1601_inithook,
9569         },
9570         [ALC1200_ASUS_P5Q] = {
9571                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9572                 .init_verbs = { alc883_init_verbs },
9573                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9574                 .dac_nids = alc883_dac_nids,
9575                 .dig_out_nid = ALC1200_DIGOUT_NID,
9576                 .dig_in_nid = ALC883_DIGIN_NID,
9577                 .slave_dig_outs = alc1200_slave_dig_outs,
9578                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9579                 .channel_mode = alc883_sixstack_modes,
9580                 .input_mux = &alc883_capture_source,
9581         },
9582         [ALC889A_MB31] = {
9583                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9584                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9585                         alc880_gpio1_init_verbs },
9586                 .adc_nids = alc883_adc_nids,
9587                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9588                 .dac_nids = alc883_dac_nids,
9589                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9590                 .channel_mode = alc889A_mb31_6ch_modes,
9591                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9592                 .input_mux = &alc889A_mb31_capture_source,
9593                 .dig_out_nid = ALC883_DIGOUT_NID,
9594                 .unsol_event = alc889A_mb31_unsol_event,
9595                 .init_hook = alc889A_mb31_automute,
9596         },
9597         [ALC883_SONY_VAIO_TT] = {
9598                 .mixers = { alc883_vaiott_mixer },
9599                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9600                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9601                 .dac_nids = alc883_dac_nids,
9602                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9603                 .channel_mode = alc883_3ST_2ch_modes,
9604                 .input_mux = &alc883_capture_source,
9605                 .unsol_event = alc_automute_amp_unsol_event,
9606                 .setup = alc883_vaiott_setup,
9607                 .init_hook = alc_automute_amp,
9608         },
9609 };
9610
9611
9612 /*
9613  * Pin config fixes
9614  */
9615 enum {
9616         PINFIX_ABIT_AW9D_MAX
9617 };
9618
9619 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
9620         { 0x15, 0x01080104 }, /* side */
9621         { 0x16, 0x01011012 }, /* rear */
9622         { 0x17, 0x01016011 }, /* clfe */
9623         { }
9624 };
9625
9626 static const struct alc_fixup alc882_fixups[] = {
9627         [PINFIX_ABIT_AW9D_MAX] = {
9628                 .pins = alc882_abit_aw9d_pinfix
9629         },
9630 };
9631
9632 static struct snd_pci_quirk alc882_fixup_tbl[] = {
9633         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
9634         {}
9635 };
9636
9637 /*
9638  * BIOS auto configuration
9639  */
9640 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
9641                                                 const struct auto_pin_cfg *cfg)
9642 {
9643         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
9644 }
9645
9646 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9647                                               hda_nid_t nid, int pin_type,
9648                                               int dac_idx)
9649 {
9650         /* set as output */
9651         struct alc_spec *spec = codec->spec;
9652         int idx;
9653
9654         alc_set_pin_output(codec, nid, pin_type);
9655         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9656                 idx = 4;
9657         else
9658                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9659         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9660
9661 }
9662
9663 static void alc882_auto_init_multi_out(struct hda_codec *codec)
9664 {
9665         struct alc_spec *spec = codec->spec;
9666         int i;
9667
9668         for (i = 0; i <= HDA_SIDE; i++) {
9669                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9670                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9671                 if (nid)
9672                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9673                                                           i);
9674         }
9675 }
9676
9677 static void alc882_auto_init_hp_out(struct hda_codec *codec)
9678 {
9679         struct alc_spec *spec = codec->spec;
9680         hda_nid_t pin;
9681
9682         pin = spec->autocfg.hp_pins[0];
9683         if (pin) /* connect to front */
9684                 /* use dac 0 */
9685                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9686         pin = spec->autocfg.speaker_pins[0];
9687         if (pin)
9688                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9689 }
9690
9691 static void alc882_auto_init_analog_input(struct hda_codec *codec)
9692 {
9693         struct alc_spec *spec = codec->spec;
9694         int i;
9695
9696         for (i = 0; i < AUTO_PIN_LAST; i++) {
9697                 hda_nid_t nid = spec->autocfg.input_pins[i];
9698                 if (!nid)
9699                         continue;
9700                 alc_set_input_pin(codec, nid, i);
9701                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
9702                         snd_hda_codec_write(codec, nid, 0,
9703                                             AC_VERB_SET_AMP_GAIN_MUTE,
9704                                             AMP_OUT_MUTE);
9705         }
9706 }
9707
9708 static void alc882_auto_init_input_src(struct hda_codec *codec)
9709 {
9710         struct alc_spec *spec = codec->spec;
9711         int c;
9712
9713         for (c = 0; c < spec->num_adc_nids; c++) {
9714                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
9715                 hda_nid_t nid = spec->capsrc_nids[c];
9716                 unsigned int mux_idx;
9717                 const struct hda_input_mux *imux;
9718                 int conns, mute, idx, item;
9719
9720                 conns = snd_hda_get_connections(codec, nid, conn_list,
9721                                                 ARRAY_SIZE(conn_list));
9722                 if (conns < 0)
9723                         continue;
9724                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9725                 imux = &spec->input_mux[mux_idx];
9726                 for (idx = 0; idx < conns; idx++) {
9727                         /* if the current connection is the selected one,
9728                          * unmute it as default - otherwise mute it
9729                          */
9730                         mute = AMP_IN_MUTE(idx);
9731                         for (item = 0; item < imux->num_items; item++) {
9732                                 if (imux->items[item].index == idx) {
9733                                         if (spec->cur_mux[c] == item)
9734                                                 mute = AMP_IN_UNMUTE(idx);
9735                                         break;
9736                                 }
9737                         }
9738                         /* check if we have a selector or mixer
9739                          * we could check for the widget type instead, but
9740                          * just check for Amp-In presence (in case of mixer
9741                          * without amp-in there is something wrong, this
9742                          * function shouldn't be used or capsrc nid is wrong)
9743                          */
9744                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
9745                                 snd_hda_codec_write(codec, nid, 0,
9746                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9747                                                     mute);
9748                         else if (mute != AMP_IN_MUTE(idx))
9749                                 snd_hda_codec_write(codec, nid, 0,
9750                                                     AC_VERB_SET_CONNECT_SEL,
9751                                                     idx);
9752                 }
9753         }
9754 }
9755
9756 /* add mic boosts if needed */
9757 static int alc_auto_add_mic_boost(struct hda_codec *codec)
9758 {
9759         struct alc_spec *spec = codec->spec;
9760         int err;
9761         hda_nid_t nid;
9762
9763         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
9764         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9765                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9766                                   "Mic Boost",
9767                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9768                 if (err < 0)
9769                         return err;
9770         }
9771         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
9772         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9773                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9774                                   "Front Mic Boost",
9775                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9776                 if (err < 0)
9777                         return err;
9778         }
9779         return 0;
9780 }
9781
9782 /* almost identical with ALC880 parser... */
9783 static int alc882_parse_auto_config(struct hda_codec *codec)
9784 {
9785         struct alc_spec *spec = codec->spec;
9786         static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9787         int i, err;
9788
9789         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9790                                            alc882_ignore);
9791         if (err < 0)
9792                 return err;
9793         if (!spec->autocfg.line_outs)
9794                 return 0; /* can't find valid BIOS pin config */
9795
9796         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
9797         if (err < 0)
9798                 return err;
9799         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
9800         if (err < 0)
9801                 return err;
9802         err = alc880_auto_create_extra_out(spec,
9803                                            spec->autocfg.speaker_pins[0],
9804                                            "Speaker");
9805         if (err < 0)
9806                 return err;
9807         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
9808                                            "Headphone");
9809         if (err < 0)
9810                 return err;
9811         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
9812         if (err < 0)
9813                 return err;
9814
9815         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9816
9817         /* check multiple SPDIF-out (for recent codecs) */
9818         for (i = 0; i < spec->autocfg.dig_outs; i++) {
9819                 hda_nid_t dig_nid;
9820                 err = snd_hda_get_connections(codec,
9821                                               spec->autocfg.dig_out_pins[i],
9822                                               &dig_nid, 1);
9823                 if (err < 0)
9824                         continue;
9825                 if (!i)
9826                         spec->multiout.dig_out_nid = dig_nid;
9827                 else {
9828                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9829                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
9830                                 break;
9831                         spec->slave_dig_outs[i - 1] = dig_nid;
9832                 }
9833         }
9834         if (spec->autocfg.dig_in_pin)
9835                 spec->dig_in_nid = ALC880_DIGIN_NID;
9836
9837         if (spec->kctls.list)
9838                 add_mixer(spec, spec->kctls.list);
9839
9840         add_verb(spec, alc883_auto_init_verbs);
9841         /* if ADC 0x07 is available, initialize it, too */
9842         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
9843                 add_verb(spec, alc882_adc1_init_verbs);
9844
9845         spec->num_mux_defs = 1;
9846         spec->input_mux = &spec->private_imux[0];
9847
9848         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
9849
9850         err = alc_auto_add_mic_boost(codec);
9851         if (err < 0)
9852                 return err;
9853
9854         return 1; /* config found */
9855 }
9856
9857 /* additional initialization for auto-configuration model */
9858 static void alc882_auto_init(struct hda_codec *codec)
9859 {
9860         struct alc_spec *spec = codec->spec;
9861         alc882_auto_init_multi_out(codec);
9862         alc882_auto_init_hp_out(codec);
9863         alc882_auto_init_analog_input(codec);
9864         alc882_auto_init_input_src(codec);
9865         if (spec->unsol_event)
9866                 alc_inithook(codec);
9867 }
9868
9869 static int patch_alc882(struct hda_codec *codec)
9870 {
9871         struct alc_spec *spec;
9872         int err, board_config;
9873
9874         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9875         if (spec == NULL)
9876                 return -ENOMEM;
9877
9878         codec->spec = spec;
9879
9880         switch (codec->vendor_id) {
9881         case 0x10ec0882:
9882         case 0x10ec0885:
9883                 break;
9884         default:
9885                 /* ALC883 and variants */
9886                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9887                 break;
9888         }
9889
9890         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9891                                                   alc882_models,
9892                                                   alc882_cfg_tbl);
9893
9894         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9895                 board_config = snd_hda_check_board_codec_sid_config(codec,
9896                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9897
9898         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9899                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9900                        codec->chip_name);
9901                 board_config = ALC882_AUTO;
9902         }
9903
9904         alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups);
9905
9906         if (board_config == ALC882_AUTO) {
9907                 /* automatic parse from the BIOS config */
9908                 err = alc882_parse_auto_config(codec);
9909                 if (err < 0) {
9910                         alc_free(codec);
9911                         return err;
9912                 } else if (!err) {
9913                         printk(KERN_INFO
9914                                "hda_codec: Cannot set up configuration "
9915                                "from BIOS.  Using base mode...\n");
9916                         board_config = ALC882_3ST_DIG;
9917                 }
9918         }
9919
9920         err = snd_hda_attach_beep_device(codec, 0x1);
9921         if (err < 0) {
9922                 alc_free(codec);
9923                 return err;
9924         }
9925
9926         if (board_config != ALC882_AUTO)
9927                 setup_preset(codec, &alc882_presets[board_config]);
9928
9929         spec->stream_analog_playback = &alc882_pcm_analog_playback;
9930         spec->stream_analog_capture = &alc882_pcm_analog_capture;
9931         /* FIXME: setup DAC5 */
9932         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9933         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9934
9935         spec->stream_digital_playback = &alc882_pcm_digital_playback;
9936         spec->stream_digital_capture = &alc882_pcm_digital_capture;
9937
9938         if (codec->vendor_id == 0x10ec0888)
9939                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9940
9941         if (!spec->adc_nids && spec->input_mux) {
9942                 int i;
9943                 spec->num_adc_nids = 0;
9944                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9945                         hda_nid_t cap;
9946                         hda_nid_t nid = alc882_adc_nids[i];
9947                         unsigned int wcap = get_wcaps(codec, nid);
9948                         /* get type */
9949                         wcap = get_wcaps_type(wcap);
9950                         if (wcap != AC_WID_AUD_IN)
9951                                 continue;
9952                         spec->private_adc_nids[spec->num_adc_nids] = nid;
9953                         err = snd_hda_get_connections(codec, nid, &cap, 1);
9954                         if (err < 0)
9955                                 continue;
9956                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9957                         spec->num_adc_nids++;
9958                 }
9959                 spec->adc_nids = spec->private_adc_nids;
9960                 spec->capsrc_nids = spec->private_capsrc_nids;
9961         }
9962
9963         set_capture_mixer(codec);
9964         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9965
9966         spec->vmaster_nid = 0x0c;
9967
9968         codec->patch_ops = alc_patch_ops;
9969         if (board_config == ALC882_AUTO)
9970                 spec->init_hook = alc882_auto_init;
9971 #ifdef CONFIG_SND_HDA_POWER_SAVE
9972         if (!spec->loopback.amplist)
9973                 spec->loopback.amplist = alc882_loopbacks;
9974 #endif
9975         codec->proc_widget_hook = print_realtek_coef;
9976
9977         return 0;
9978 }
9979
9980
9981 /*
9982  * ALC262 support
9983  */
9984
9985 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9986 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9987
9988 #define alc262_dac_nids         alc260_dac_nids
9989 #define alc262_adc_nids         alc882_adc_nids
9990 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9991 #define alc262_capsrc_nids      alc882_capsrc_nids
9992 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9993
9994 #define alc262_modes            alc260_modes
9995 #define alc262_capture_source   alc882_capture_source
9996
9997 static hda_nid_t alc262_dmic_adc_nids[1] = {
9998         /* ADC0 */
9999         0x09
10000 };
10001
10002 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
10003
10004 static struct snd_kcontrol_new alc262_base_mixer[] = {
10005         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10006         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10007         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10008         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10009         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10010         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10011         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10012         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10013         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10014         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10015         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10016         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10017         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
10018         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10019         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
10020         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10021         { } /* end */
10022 };
10023
10024 /* update HP, line and mono-out pins according to the master switch */
10025 static void alc262_hp_master_update(struct hda_codec *codec)
10026 {
10027         struct alc_spec *spec = codec->spec;
10028         int val = spec->master_sw;
10029
10030         /* HP & line-out */
10031         snd_hda_codec_write_cache(codec, 0x1b, 0,
10032                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10033                                   val ? PIN_HP : 0);
10034         snd_hda_codec_write_cache(codec, 0x15, 0,
10035                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10036                                   val ? PIN_HP : 0);
10037         /* mono (speaker) depending on the HP jack sense */
10038         val = val && !spec->jack_present;
10039         snd_hda_codec_write_cache(codec, 0x16, 0,
10040                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10041                                   val ? PIN_OUT : 0);
10042 }
10043
10044 static void alc262_hp_bpc_automute(struct hda_codec *codec)
10045 {
10046         struct alc_spec *spec = codec->spec;
10047         unsigned int presence;
10048         presence = snd_hda_codec_read(codec, 0x1b, 0,
10049                                       AC_VERB_GET_PIN_SENSE, 0);
10050         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10051         alc262_hp_master_update(codec);
10052 }
10053
10054 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10055 {
10056         if ((res >> 26) != ALC880_HP_EVENT)
10057                 return;
10058         alc262_hp_bpc_automute(codec);
10059 }
10060
10061 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10062 {
10063         struct alc_spec *spec = codec->spec;
10064         unsigned int presence;
10065         presence = snd_hda_codec_read(codec, 0x15, 0,
10066                                       AC_VERB_GET_PIN_SENSE, 0);
10067         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10068         alc262_hp_master_update(codec);
10069 }
10070
10071 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
10072                                            unsigned int res)
10073 {
10074         if ((res >> 26) != ALC880_HP_EVENT)
10075                 return;
10076         alc262_hp_wildwest_automute(codec);
10077 }
10078
10079 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
10080
10081 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
10082                                    struct snd_ctl_elem_value *ucontrol)
10083 {
10084         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10085         struct alc_spec *spec = codec->spec;
10086         int val = !!*ucontrol->value.integer.value;
10087
10088         if (val == spec->master_sw)
10089                 return 0;
10090         spec->master_sw = val;
10091         alc262_hp_master_update(codec);
10092         return 1;
10093 }
10094
10095 #define ALC262_HP_MASTER_SWITCH                                 \
10096         {                                                       \
10097                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10098                 .name = "Master Playback Switch",               \
10099                 .info = snd_ctl_boolean_mono_info,              \
10100                 .get = alc262_hp_master_sw_get,                 \
10101                 .put = alc262_hp_master_sw_put,                 \
10102         }
10103
10104 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10105         ALC262_HP_MASTER_SWITCH,
10106         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10107         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10108         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10109         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10110                               HDA_OUTPUT),
10111         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10112                             HDA_OUTPUT),
10113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10115         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10116         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10117         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10118         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10119         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10120         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10121         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10122         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10123         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
10124         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
10125         { } /* end */
10126 };
10127
10128 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10129         ALC262_HP_MASTER_SWITCH,
10130         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10131         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10132         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10134         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10135                               HDA_OUTPUT),
10136         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10137                             HDA_OUTPUT),
10138         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10139         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10140         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10141         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10142         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10143         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10144         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10145         { } /* end */
10146 };
10147
10148 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10149         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10150         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10151         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10152         { } /* end */
10153 };
10154
10155 /* mute/unmute internal speaker according to the hp jack and mute state */
10156 static void alc262_hp_t5735_setup(struct hda_codec *codec)
10157 {
10158         struct alc_spec *spec = codec->spec;
10159
10160         spec->autocfg.hp_pins[0] = 0x15;
10161         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10162 }
10163
10164 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10165         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10166         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10167         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10168         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10169         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10170         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10171         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10172         { } /* end */
10173 };
10174
10175 static struct hda_verb alc262_hp_t5735_verbs[] = {
10176         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10177         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10178
10179         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10180         { }
10181 };
10182
10183 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10184         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10185         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10186         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10187         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10188         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10189         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10190         { } /* end */
10191 };
10192
10193 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10194         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10195         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10196         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10197         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10198         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10199         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10201         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10203         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10204         {}
10205 };
10206
10207 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10208         .num_items = 1,
10209         .items = {
10210                 { "Line", 0x1 },
10211         },
10212 };
10213
10214 /* bind hp and internal speaker mute (with plug check) as master switch */
10215 static void alc262_hippo_master_update(struct hda_codec *codec)
10216 {
10217         struct alc_spec *spec = codec->spec;
10218         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10219         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10220         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10221         unsigned int mute;
10222
10223         /* HP */
10224         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10225         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10226                                  HDA_AMP_MUTE, mute);
10227         /* mute internal speaker per jack sense */
10228         if (spec->jack_present)
10229                 mute = HDA_AMP_MUTE;
10230         if (line_nid)
10231                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10232                                          HDA_AMP_MUTE, mute);
10233         if (speaker_nid && speaker_nid != line_nid)
10234                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10235                                          HDA_AMP_MUTE, mute);
10236 }
10237
10238 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10239
10240 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10241                                       struct snd_ctl_elem_value *ucontrol)
10242 {
10243         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10244         struct alc_spec *spec = codec->spec;
10245         int val = !!*ucontrol->value.integer.value;
10246
10247         if (val == spec->master_sw)
10248                 return 0;
10249         spec->master_sw = val;
10250         alc262_hippo_master_update(codec);
10251         return 1;
10252 }
10253
10254 #define ALC262_HIPPO_MASTER_SWITCH                              \
10255         {                                                       \
10256                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10257                 .name = "Master Playback Switch",               \
10258                 .info = snd_ctl_boolean_mono_info,              \
10259                 .get = alc262_hippo_master_sw_get,              \
10260                 .put = alc262_hippo_master_sw_put,              \
10261         }
10262
10263 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10264         ALC262_HIPPO_MASTER_SWITCH,
10265         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10266         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10267         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10268         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10269         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10270         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10271         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10272         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10273         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10274         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10275         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10276         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10277         { } /* end */
10278 };
10279
10280 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10281         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10282         ALC262_HIPPO_MASTER_SWITCH,
10283         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10284         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10285         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10286         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10287         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10288         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10289         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10290         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10291         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10292         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10293         { } /* end */
10294 };
10295
10296 /* mute/unmute internal speaker according to the hp jack and mute state */
10297 static void alc262_hippo_automute(struct hda_codec *codec)
10298 {
10299         struct alc_spec *spec = codec->spec;
10300         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10301         unsigned int present;
10302
10303         /* need to execute and sync at first */
10304         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10305         present = snd_hda_codec_read(codec, hp_nid, 0,
10306                                      AC_VERB_GET_PIN_SENSE, 0);
10307         spec->jack_present = (present & 0x80000000) != 0;
10308         alc262_hippo_master_update(codec);
10309 }
10310
10311 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10312 {
10313         if ((res >> 26) != ALC880_HP_EVENT)
10314                 return;
10315         alc262_hippo_automute(codec);
10316 }
10317
10318 static void alc262_hippo_setup(struct hda_codec *codec)
10319 {
10320         struct alc_spec *spec = codec->spec;
10321
10322         spec->autocfg.hp_pins[0] = 0x15;
10323         spec->autocfg.speaker_pins[0] = 0x14;
10324 }
10325
10326 static void alc262_hippo1_setup(struct hda_codec *codec)
10327 {
10328         struct alc_spec *spec = codec->spec;
10329
10330         spec->autocfg.hp_pins[0] = 0x1b;
10331         spec->autocfg.speaker_pins[0] = 0x14;
10332 }
10333
10334
10335 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10336         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10337         ALC262_HIPPO_MASTER_SWITCH,
10338         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10339         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10340         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10341         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10342         { } /* end */
10343 };
10344
10345 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10346         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10347         ALC262_HIPPO_MASTER_SWITCH,
10348         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10349         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10350         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10351         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10352         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10353         { } /* end */
10354 };
10355
10356 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10357         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10358         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10359         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10360         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10361         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10362         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10363         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10364         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10365         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10366         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10367         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10368         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10369         { } /* end */
10370 };
10371
10372 static struct hda_verb alc262_tyan_verbs[] = {
10373         /* Headphone automute */
10374         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10375         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10376         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10377
10378         /* P11 AUX_IN, white 4-pin connector */
10379         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10380         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10381         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10382         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10383
10384         {}
10385 };
10386
10387 /* unsolicited event for HP jack sensing */
10388 static void alc262_tyan_setup(struct hda_codec *codec)
10389 {
10390         struct alc_spec *spec = codec->spec;
10391
10392         spec->autocfg.hp_pins[0] = 0x1b;
10393         spec->autocfg.speaker_pins[0] = 0x15;
10394 }
10395
10396
10397 #define alc262_capture_mixer            alc882_capture_mixer
10398 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10399
10400 /*
10401  * generic initialization of ADC, input mixers and output mixers
10402  */
10403 static struct hda_verb alc262_init_verbs[] = {
10404         /*
10405          * Unmute ADC0-2 and set the default input to mic-in
10406          */
10407         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10409         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10410         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10411         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10412         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10413
10414         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10415          * mixer widget
10416          * Note: PASD motherboards uses the Line In 2 as the input for
10417          * front panel mic (mic 2)
10418          */
10419         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10420         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10421         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10422         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10423         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10424         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10425
10426         /*
10427          * Set up output mixers (0x0c - 0x0e)
10428          */
10429         /* set vol=0 to output mixers */
10430         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10431         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10432         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10433         /* set up input amps for analog loopback */
10434         /* Amp Indices: DAC = 0, mixer = 1 */
10435         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10436         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10437         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10438         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10439         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10440         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10441
10442         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10443         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10444         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10445         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10446         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10447         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10448
10449         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10450         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10451         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10452         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10453         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10454
10455         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10456         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10457
10458         /* FIXME: use matrix-type input source selection */
10459         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10460         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10461         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10462         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10463         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10464         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10465         /* Input mixer2 */
10466         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10467         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10468         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10469         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10470         /* Input mixer3 */
10471         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10472         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10473         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10474         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10475
10476         { }
10477 };
10478
10479 static struct hda_verb alc262_eapd_verbs[] = {
10480         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10481         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10482         { }
10483 };
10484
10485 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10486         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10487         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10488         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10489
10490         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10491         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10492         {}
10493 };
10494
10495 static struct hda_verb alc262_sony_unsol_verbs[] = {
10496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10497         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10498         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10499
10500         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10501         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10502         {}
10503 };
10504
10505 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10506         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10507         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10508         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10509         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10510         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10511         { } /* end */
10512 };
10513
10514 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10515         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10516         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10517         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10518         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10519         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10520         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10521         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10522         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10523         {}
10524 };
10525
10526 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10527 {
10528         struct alc_spec *spec = codec->spec;
10529
10530         spec->autocfg.hp_pins[0] = 0x15;
10531         spec->autocfg.speaker_pins[0] = 0x14;
10532         spec->ext_mic.pin = 0x18;
10533         spec->ext_mic.mux_idx = 0;
10534         spec->int_mic.pin = 0x12;
10535         spec->int_mic.mux_idx = 9;
10536         spec->auto_mic = 1;
10537 }
10538
10539 /*
10540  * nec model
10541  *  0x15 = headphone
10542  *  0x16 = internal speaker
10543  *  0x18 = external mic
10544  */
10545
10546 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10547         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10548         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10549
10550         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10551         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10552         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10553
10554         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10555         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10556         { } /* end */
10557 };
10558
10559 static struct hda_verb alc262_nec_verbs[] = {
10560         /* Unmute Speaker */
10561         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10562
10563         /* Headphone */
10564         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10565         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10566
10567         /* External mic to headphone */
10568         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10569         /* External mic to speaker */
10570         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10571         {}
10572 };
10573
10574 /*
10575  * fujitsu model
10576  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10577  *  0x1b = port replicator headphone out
10578  */
10579
10580 #define ALC_HP_EVENT    0x37
10581
10582 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10583         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10584         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10585         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10586         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10587         {}
10588 };
10589
10590 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10591         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10592         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10593         {}
10594 };
10595
10596 static struct hda_input_mux alc262_fujitsu_capture_source = {
10597         .num_items = 3,
10598         .items = {
10599                 { "Mic", 0x0 },
10600                 { "Int Mic", 0x1 },
10601                 { "CD", 0x4 },
10602         },
10603 };
10604
10605 static struct hda_input_mux alc262_HP_capture_source = {
10606         .num_items = 5,
10607         .items = {
10608                 { "Mic", 0x0 },
10609                 { "Front Mic", 0x1 },
10610                 { "Line", 0x2 },
10611                 { "CD", 0x4 },
10612                 { "AUX IN", 0x6 },
10613         },
10614 };
10615
10616 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10617         .num_items = 4,
10618         .items = {
10619                 { "Mic", 0x0 },
10620                 { "Front Mic", 0x2 },
10621                 { "Line", 0x1 },
10622                 { "CD", 0x4 },
10623         },
10624 };
10625
10626 /* mute/unmute internal speaker according to the hp jacks and mute state */
10627 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10628 {
10629         struct alc_spec *spec = codec->spec;
10630         unsigned int mute;
10631
10632         if (force || !spec->sense_updated) {
10633                 unsigned int present;
10634                 /* need to execute and sync at first */
10635                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10636                 /* check laptop HP jack */
10637                 present = snd_hda_codec_read(codec, 0x14, 0,
10638                                              AC_VERB_GET_PIN_SENSE, 0);
10639                 /* need to execute and sync at first */
10640                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10641                 /* check docking HP jack */
10642                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10643                                               AC_VERB_GET_PIN_SENSE, 0);
10644                 if (present & AC_PINSENSE_PRESENCE)
10645                         spec->jack_present = 1;
10646                 else
10647                         spec->jack_present = 0;
10648                 spec->sense_updated = 1;
10649         }
10650         /* unmute internal speaker only if both HPs are unplugged and
10651          * master switch is on
10652          */
10653         if (spec->jack_present)
10654                 mute = HDA_AMP_MUTE;
10655         else
10656                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10657         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10658                                  HDA_AMP_MUTE, mute);
10659 }
10660
10661 /* unsolicited event for HP jack sensing */
10662 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10663                                        unsigned int res)
10664 {
10665         if ((res >> 26) != ALC_HP_EVENT)
10666                 return;
10667         alc262_fujitsu_automute(codec, 1);
10668 }
10669
10670 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10671 {
10672         alc262_fujitsu_automute(codec, 1);
10673 }
10674
10675 /* bind volumes of both NID 0x0c and 0x0d */
10676 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10677         .ops = &snd_hda_bind_vol,
10678         .values = {
10679                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10680                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10681                 0
10682         },
10683 };
10684
10685 /* mute/unmute internal speaker according to the hp jack and mute state */
10686 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10687 {
10688         struct alc_spec *spec = codec->spec;
10689         unsigned int mute;
10690
10691         if (force || !spec->sense_updated) {
10692                 unsigned int present_int_hp;
10693                 /* need to execute and sync at first */
10694                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10695                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10696                                         AC_VERB_GET_PIN_SENSE, 0);
10697                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10698                 spec->sense_updated = 1;
10699         }
10700         if (spec->jack_present) {
10701                 /* mute internal speaker */
10702                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10703                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10704                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10705                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10706         } else {
10707                 /* unmute internal speaker if necessary */
10708                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10709                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10710                                          HDA_AMP_MUTE, mute);
10711                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10712                                          HDA_AMP_MUTE, mute);
10713         }
10714 }
10715
10716 /* unsolicited event for HP jack sensing */
10717 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10718                                        unsigned int res)
10719 {
10720         if ((res >> 26) != ALC_HP_EVENT)
10721                 return;
10722         alc262_lenovo_3000_automute(codec, 1);
10723 }
10724
10725 static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
10726                                   int dir, int idx, long *valp)
10727 {
10728         int i, change = 0;
10729
10730         for (i = 0; i < 2; i++, valp++)
10731                 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
10732                                                    HDA_AMP_MUTE,
10733                                                    *valp ? 0 : HDA_AMP_MUTE);
10734         return change;
10735 }
10736
10737 /* bind hp and internal speaker mute (with plug check) */
10738 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10739                                          struct snd_ctl_elem_value *ucontrol)
10740 {
10741         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10742         long *valp = ucontrol->value.integer.value;
10743         int change;
10744
10745         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10746         change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10747         if (change)
10748                 alc262_fujitsu_automute(codec, 0);
10749         return change;
10750 }
10751
10752 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10753         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10754         {
10755                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10756                 .name = "Master Playback Switch",
10757                 .info = snd_hda_mixer_amp_switch_info,
10758                 .get = snd_hda_mixer_amp_switch_get,
10759                 .put = alc262_fujitsu_master_sw_put,
10760                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10761         },
10762         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10763         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10764         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10765         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10766         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10767         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10768         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10769         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10770         { } /* end */
10771 };
10772
10773 /* bind hp and internal speaker mute (with plug check) */
10774 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10775                                          struct snd_ctl_elem_value *ucontrol)
10776 {
10777         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10778         long *valp = ucontrol->value.integer.value;
10779         int change;
10780
10781         change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10782         if (change)
10783                 alc262_lenovo_3000_automute(codec, 0);
10784         return change;
10785 }
10786
10787 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10788         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10789         {
10790                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10791                 .name = "Master Playback Switch",
10792                 .info = snd_hda_mixer_amp_switch_info,
10793                 .get = snd_hda_mixer_amp_switch_get,
10794                 .put = alc262_lenovo_3000_master_sw_put,
10795                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10796         },
10797         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10798         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10799         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10800         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10801         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10802         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10803         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10804         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10805         { } /* end */
10806 };
10807
10808 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10809         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10810         ALC262_HIPPO_MASTER_SWITCH,
10811         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10812         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10813         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10814         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10815         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10816         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10817         { } /* end */
10818 };
10819
10820 /* additional init verbs for Benq laptops */
10821 static struct hda_verb alc262_EAPD_verbs[] = {
10822         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10823         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10824         {}
10825 };
10826
10827 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10828         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10829         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10830
10831         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10832         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10833         {}
10834 };
10835
10836 /* Samsung Q1 Ultra Vista model setup */
10837 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10838         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10839         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10840         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10841         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10842         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10843         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10844         { } /* end */
10845 };
10846
10847 static struct hda_verb alc262_ultra_verbs[] = {
10848         /* output mixer */
10849         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10850         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10851         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10852         /* speaker */
10853         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10854         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10855         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10856         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10857         /* HP */
10858         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10859         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10860         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10861         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10862         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10863         /* internal mic */
10864         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10865         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10866         /* ADC, choose mic */
10867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10868         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10869         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10870         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10871         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10872         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10873         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10874         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10875         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10876         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10877         {}
10878 };
10879
10880 /* mute/unmute internal speaker according to the hp jack and mute state */
10881 static void alc262_ultra_automute(struct hda_codec *codec)
10882 {
10883         struct alc_spec *spec = codec->spec;
10884         unsigned int mute;
10885
10886         mute = 0;
10887         /* auto-mute only when HP is used as HP */
10888         if (!spec->cur_mux[0]) {
10889                 unsigned int present;
10890                 /* need to execute and sync at first */
10891                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10892                 present = snd_hda_codec_read(codec, 0x15, 0,
10893                                              AC_VERB_GET_PIN_SENSE, 0);
10894                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10895                 if (spec->jack_present)
10896                         mute = HDA_AMP_MUTE;
10897         }
10898         /* mute/unmute internal speaker */
10899         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10900                                  HDA_AMP_MUTE, mute);
10901         /* mute/unmute HP */
10902         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10903                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10904 }
10905
10906 /* unsolicited event for HP jack sensing */
10907 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10908                                        unsigned int res)
10909 {
10910         if ((res >> 26) != ALC880_HP_EVENT)
10911                 return;
10912         alc262_ultra_automute(codec);
10913 }
10914
10915 static struct hda_input_mux alc262_ultra_capture_source = {
10916         .num_items = 2,
10917         .items = {
10918                 { "Mic", 0x1 },
10919                 { "Headphone", 0x7 },
10920         },
10921 };
10922
10923 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10924                                      struct snd_ctl_elem_value *ucontrol)
10925 {
10926         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10927         struct alc_spec *spec = codec->spec;
10928         int ret;
10929
10930         ret = alc_mux_enum_put(kcontrol, ucontrol);
10931         if (!ret)
10932                 return 0;
10933         /* reprogram the HP pin as mic or HP according to the input source */
10934         snd_hda_codec_write_cache(codec, 0x15, 0,
10935                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10936                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10937         alc262_ultra_automute(codec); /* mute/unmute HP */
10938         return ret;
10939 }
10940
10941 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10942         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10943         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10944         {
10945                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10946                 .name = "Capture Source",
10947                 .info = alc_mux_enum_info,
10948                 .get = alc_mux_enum_get,
10949                 .put = alc262_ultra_mux_enum_put,
10950         },
10951         { } /* end */
10952 };
10953
10954 /* We use two mixers depending on the output pin; 0x16 is a mono output
10955  * and thus it's bound with a different mixer.
10956  * This function returns which mixer amp should be used.
10957  */
10958 static int alc262_check_volbit(hda_nid_t nid)
10959 {
10960         if (!nid)
10961                 return 0;
10962         else if (nid == 0x16)
10963                 return 2;
10964         else
10965                 return 1;
10966 }
10967
10968 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10969                                   const char *pfx, int *vbits)
10970 {
10971         unsigned long val;
10972         int vbit;
10973
10974         vbit = alc262_check_volbit(nid);
10975         if (!vbit)
10976                 return 0;
10977         if (*vbits & vbit) /* a volume control for this mixer already there */
10978                 return 0;
10979         *vbits |= vbit;
10980         if (vbit == 2)
10981                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10982         else
10983                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10984         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10985 }
10986
10987 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10988                                  const char *pfx)
10989 {
10990         unsigned long val;
10991
10992         if (!nid)
10993                 return 0;
10994         if (nid == 0x16)
10995                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10996         else
10997                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10998         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10999 }
11000
11001 /* add playback controls from the parsed DAC table */
11002 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
11003                                              const struct auto_pin_cfg *cfg)
11004 {
11005         const char *pfx;
11006         int vbits;
11007         int err;
11008
11009         spec->multiout.num_dacs = 1;    /* only use one dac */
11010         spec->multiout.dac_nids = spec->private_dac_nids;
11011         spec->multiout.dac_nids[0] = 2;
11012
11013         if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
11014                 pfx = "Master";
11015         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11016                 pfx = "Speaker";
11017         else
11018                 pfx = "Front";
11019         err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
11020         if (err < 0)
11021                 return err;
11022         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
11023         if (err < 0)
11024                 return err;
11025         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
11026         if (err < 0)
11027                 return err;
11028
11029         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
11030                 alc262_check_volbit(cfg->speaker_pins[0]) |
11031                 alc262_check_volbit(cfg->hp_pins[0]);
11032         if (vbits == 1 || vbits == 2)
11033                 pfx = "Master"; /* only one mixer is used */
11034         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11035                 pfx = "Speaker";
11036         else
11037                 pfx = "Front";
11038         vbits = 0;
11039         err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
11040         if (err < 0)
11041                 return err;
11042         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
11043                                      &vbits);
11044         if (err < 0)
11045                 return err;
11046         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
11047                                      &vbits);
11048         if (err < 0)
11049                 return err;
11050         return 0;
11051 }
11052
11053 #define alc262_auto_create_input_ctls \
11054         alc880_auto_create_input_ctls
11055
11056 /*
11057  * generic initialization of ADC, input mixers and output mixers
11058  */
11059 static struct hda_verb alc262_volume_init_verbs[] = {
11060         /*
11061          * Unmute ADC0-2 and set the default input to mic-in
11062          */
11063         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11064         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11065         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11066         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11067         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11068         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11069
11070         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11071          * mixer widget
11072          * Note: PASD motherboards uses the Line In 2 as the input for
11073          * front panel mic (mic 2)
11074          */
11075         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11076         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11077         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11078         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11079         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11081
11082         /*
11083          * Set up output mixers (0x0c - 0x0f)
11084          */
11085         /* set vol=0 to output mixers */
11086         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11087         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11088         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11089
11090         /* set up input amps for analog loopback */
11091         /* Amp Indices: DAC = 0, mixer = 1 */
11092         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11093         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11094         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11095         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11096         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11097         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11098
11099         /* FIXME: use matrix-type input source selection */
11100         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11101         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11102         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11103         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11104         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11105         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11106         /* Input mixer2 */
11107         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11108         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11109         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11110         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11111         /* Input mixer3 */
11112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11113         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11115         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11116
11117         { }
11118 };
11119
11120 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11121         /*
11122          * Unmute ADC0-2 and set the default input to mic-in
11123          */
11124         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11125         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11126         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11127         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11128         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11129         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11130
11131         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11132          * mixer widget
11133          * Note: PASD motherboards uses the Line In 2 as the input for
11134          * front panel mic (mic 2)
11135          */
11136         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11138         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11139         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11140         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11141         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11142         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11143         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11144
11145         /*
11146          * Set up output mixers (0x0c - 0x0e)
11147          */
11148         /* set vol=0 to output mixers */
11149         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11150         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11151         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11152
11153         /* set up input amps for analog loopback */
11154         /* Amp Indices: DAC = 0, mixer = 1 */
11155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11156         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11157         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11158         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11159         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11160         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11161
11162         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11163         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11164         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11165
11166         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11167         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11168
11169         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11170         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11171
11172         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11173         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11174         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11175         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11176         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11177
11178         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11179         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11180         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11181         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11182         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11183         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11184
11185
11186         /* FIXME: use matrix-type input source selection */
11187         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11188         /* Input mixer1: only unmute Mic */
11189         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11190         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11192         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11195         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11196         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11197         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11198         /* Input mixer2 */
11199         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11203         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11204         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11205         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11206         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11207         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11208         /* Input mixer3 */
11209         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11210         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11211         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11212         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11213         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11218
11219         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11220
11221         { }
11222 };
11223
11224 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11225         /*
11226          * Unmute ADC0-2 and set the default input to mic-in
11227          */
11228         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11230         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11231         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11232         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11233         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11234
11235         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11236          * mixer widget
11237          * Note: PASD motherboards uses the Line In 2 as the input for front
11238          * panel mic (mic 2)
11239          */
11240         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11241         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11242         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11243         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11244         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11245         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11246         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11247         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11248         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11249         /*
11250          * Set up output mixers (0x0c - 0x0e)
11251          */
11252         /* set vol=0 to output mixers */
11253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11254         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11255         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11256
11257         /* set up input amps for analog loopback */
11258         /* Amp Indices: DAC = 0, mixer = 1 */
11259         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11260         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11261         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11262         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11263         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11264         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11265
11266
11267         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11268         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11269         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11270         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11271         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11272         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11273         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11274
11275         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11276         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11277
11278         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11279         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11280
11281         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11282         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11283         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11284         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11285         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11286         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11287
11288         /* FIXME: use matrix-type input source selection */
11289         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11290         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11291         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11292         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11293         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11294         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11296         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11297         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11298         /* Input mixer2 */
11299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11302         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11303         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11304         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11305         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11306         /* Input mixer3 */
11307         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11308         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11309         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11312         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11314
11315         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11316
11317         { }
11318 };
11319
11320 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11321
11322         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11323         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11324         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11325
11326         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11327         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11328         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11329         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11330
11331         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11332         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11333         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11334         {}
11335 };
11336
11337
11338 #ifdef CONFIG_SND_HDA_POWER_SAVE
11339 #define alc262_loopbacks        alc880_loopbacks
11340 #endif
11341
11342 /* pcm configuration: identical with ALC880 */
11343 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11344 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11345 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11346 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11347
11348 /*
11349  * BIOS auto configuration
11350  */
11351 static int alc262_parse_auto_config(struct hda_codec *codec)
11352 {
11353         struct alc_spec *spec = codec->spec;
11354         int err;
11355         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11356
11357         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11358                                            alc262_ignore);
11359         if (err < 0)
11360                 return err;
11361         if (!spec->autocfg.line_outs) {
11362                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11363                         spec->multiout.max_channels = 2;
11364                         spec->no_analog = 1;
11365                         goto dig_only;
11366                 }
11367                 return 0; /* can't find valid BIOS pin config */
11368         }
11369         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11370         if (err < 0)
11371                 return err;
11372         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11373         if (err < 0)
11374                 return err;
11375
11376         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11377
11378  dig_only:
11379         if (spec->autocfg.dig_outs) {
11380                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11381                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11382         }
11383         if (spec->autocfg.dig_in_pin)
11384                 spec->dig_in_nid = ALC262_DIGIN_NID;
11385
11386         if (spec->kctls.list)
11387                 add_mixer(spec, spec->kctls.list);
11388
11389         add_verb(spec, alc262_volume_init_verbs);
11390         spec->num_mux_defs = 1;
11391         spec->input_mux = &spec->private_imux[0];
11392
11393         err = alc_auto_add_mic_boost(codec);
11394         if (err < 0)
11395                 return err;
11396
11397         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11398
11399         return 1;
11400 }
11401
11402 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11403 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11404 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11405 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11406
11407
11408 /* init callback for auto-configuration model -- overriding the default init */
11409 static void alc262_auto_init(struct hda_codec *codec)
11410 {
11411         struct alc_spec *spec = codec->spec;
11412         alc262_auto_init_multi_out(codec);
11413         alc262_auto_init_hp_out(codec);
11414         alc262_auto_init_analog_input(codec);
11415         alc262_auto_init_input_src(codec);
11416         if (spec->unsol_event)
11417                 alc_inithook(codec);
11418 }
11419
11420 /*
11421  * configuration and preset
11422  */
11423 static const char *alc262_models[ALC262_MODEL_LAST] = {
11424         [ALC262_BASIC]          = "basic",
11425         [ALC262_HIPPO]          = "hippo",
11426         [ALC262_HIPPO_1]        = "hippo_1",
11427         [ALC262_FUJITSU]        = "fujitsu",
11428         [ALC262_HP_BPC]         = "hp-bpc",
11429         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11430         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11431         [ALC262_HP_RP5700]      = "hp-rp5700",
11432         [ALC262_BENQ_ED8]       = "benq",
11433         [ALC262_BENQ_T31]       = "benq-t31",
11434         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11435         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11436         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11437         [ALC262_ULTRA]          = "ultra",
11438         [ALC262_LENOVO_3000]    = "lenovo-3000",
11439         [ALC262_NEC]            = "nec",
11440         [ALC262_TYAN]           = "tyan",
11441         [ALC262_AUTO]           = "auto",
11442 };
11443
11444 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11445         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11446         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11447         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11448                            ALC262_HP_BPC),
11449         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11450                            ALC262_HP_BPC),
11451         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11452                            ALC262_HP_BPC),
11453         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11454         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11455         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11456         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11457         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11458         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11459         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11460         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11461         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11462         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11463         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11464         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11465                       ALC262_HP_TC_T5735),
11466         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11467         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11468         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11469         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11470         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11471         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11472         SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11473         SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
11474         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11475                            ALC262_SONY_ASSAMD),
11476         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11477                       ALC262_TOSHIBA_RX1),
11478         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11479         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11480         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11481         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11482         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11483                            ALC262_ULTRA),
11484         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11485         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11486         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11487         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11488         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11489         {}
11490 };
11491
11492 static struct alc_config_preset alc262_presets[] = {
11493         [ALC262_BASIC] = {
11494                 .mixers = { alc262_base_mixer },
11495                 .init_verbs = { alc262_init_verbs },
11496                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11497                 .dac_nids = alc262_dac_nids,
11498                 .hp_nid = 0x03,
11499                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11500                 .channel_mode = alc262_modes,
11501                 .input_mux = &alc262_capture_source,
11502         },
11503         [ALC262_HIPPO] = {
11504                 .mixers = { alc262_hippo_mixer },
11505                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11506                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11507                 .dac_nids = alc262_dac_nids,
11508                 .hp_nid = 0x03,
11509                 .dig_out_nid = ALC262_DIGOUT_NID,
11510                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11511                 .channel_mode = alc262_modes,
11512                 .input_mux = &alc262_capture_source,
11513                 .unsol_event = alc262_hippo_unsol_event,
11514                 .setup = alc262_hippo_setup,
11515                 .init_hook = alc262_hippo_automute,
11516         },
11517         [ALC262_HIPPO_1] = {
11518                 .mixers = { alc262_hippo1_mixer },
11519                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11520                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11521                 .dac_nids = alc262_dac_nids,
11522                 .hp_nid = 0x02,
11523                 .dig_out_nid = ALC262_DIGOUT_NID,
11524                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11525                 .channel_mode = alc262_modes,
11526                 .input_mux = &alc262_capture_source,
11527                 .unsol_event = alc262_hippo_unsol_event,
11528                 .setup = alc262_hippo1_setup,
11529                 .init_hook = alc262_hippo_automute,
11530         },
11531         [ALC262_FUJITSU] = {
11532                 .mixers = { alc262_fujitsu_mixer },
11533                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11534                                 alc262_fujitsu_unsol_verbs },
11535                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11536                 .dac_nids = alc262_dac_nids,
11537                 .hp_nid = 0x03,
11538                 .dig_out_nid = ALC262_DIGOUT_NID,
11539                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11540                 .channel_mode = alc262_modes,
11541                 .input_mux = &alc262_fujitsu_capture_source,
11542                 .unsol_event = alc262_fujitsu_unsol_event,
11543                 .init_hook = alc262_fujitsu_init_hook,
11544         },
11545         [ALC262_HP_BPC] = {
11546                 .mixers = { alc262_HP_BPC_mixer },
11547                 .init_verbs = { alc262_HP_BPC_init_verbs },
11548                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11549                 .dac_nids = alc262_dac_nids,
11550                 .hp_nid = 0x03,
11551                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11552                 .channel_mode = alc262_modes,
11553                 .input_mux = &alc262_HP_capture_source,
11554                 .unsol_event = alc262_hp_bpc_unsol_event,
11555                 .init_hook = alc262_hp_bpc_automute,
11556         },
11557         [ALC262_HP_BPC_D7000_WF] = {
11558                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11559                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11560                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11561                 .dac_nids = alc262_dac_nids,
11562                 .hp_nid = 0x03,
11563                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11564                 .channel_mode = alc262_modes,
11565                 .input_mux = &alc262_HP_D7000_capture_source,
11566                 .unsol_event = alc262_hp_wildwest_unsol_event,
11567                 .init_hook = alc262_hp_wildwest_automute,
11568         },
11569         [ALC262_HP_BPC_D7000_WL] = {
11570                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11571                             alc262_HP_BPC_WildWest_option_mixer },
11572                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11573                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11574                 .dac_nids = alc262_dac_nids,
11575                 .hp_nid = 0x03,
11576                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11577                 .channel_mode = alc262_modes,
11578                 .input_mux = &alc262_HP_D7000_capture_source,
11579                 .unsol_event = alc262_hp_wildwest_unsol_event,
11580                 .init_hook = alc262_hp_wildwest_automute,
11581         },
11582         [ALC262_HP_TC_T5735] = {
11583                 .mixers = { alc262_hp_t5735_mixer },
11584                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11585                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11586                 .dac_nids = alc262_dac_nids,
11587                 .hp_nid = 0x03,
11588                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11589                 .channel_mode = alc262_modes,
11590                 .input_mux = &alc262_capture_source,
11591                 .unsol_event = alc_automute_amp_unsol_event,
11592                 .setup = alc262_hp_t5735_setup,
11593                 .init_hook = alc_automute_amp,
11594         },
11595         [ALC262_HP_RP5700] = {
11596                 .mixers = { alc262_hp_rp5700_mixer },
11597                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11598                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11599                 .dac_nids = alc262_dac_nids,
11600                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11601                 .channel_mode = alc262_modes,
11602                 .input_mux = &alc262_hp_rp5700_capture_source,
11603         },
11604         [ALC262_BENQ_ED8] = {
11605                 .mixers = { alc262_base_mixer },
11606                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11607                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11608                 .dac_nids = alc262_dac_nids,
11609                 .hp_nid = 0x03,
11610                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11611                 .channel_mode = alc262_modes,
11612                 .input_mux = &alc262_capture_source,
11613         },
11614         [ALC262_SONY_ASSAMD] = {
11615                 .mixers = { alc262_sony_mixer },
11616                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11617                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11618                 .dac_nids = alc262_dac_nids,
11619                 .hp_nid = 0x02,
11620                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11621                 .channel_mode = alc262_modes,
11622                 .input_mux = &alc262_capture_source,
11623                 .unsol_event = alc262_hippo_unsol_event,
11624                 .setup = alc262_hippo_setup,
11625                 .init_hook = alc262_hippo_automute,
11626         },
11627         [ALC262_BENQ_T31] = {
11628                 .mixers = { alc262_benq_t31_mixer },
11629                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
11630                                 alc_hp15_unsol_verbs },
11631                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11632                 .dac_nids = alc262_dac_nids,
11633                 .hp_nid = 0x03,
11634                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11635                 .channel_mode = alc262_modes,
11636                 .input_mux = &alc262_capture_source,
11637                 .unsol_event = alc262_hippo_unsol_event,
11638                 .setup = alc262_hippo_setup,
11639                 .init_hook = alc262_hippo_automute,
11640         },
11641         [ALC262_ULTRA] = {
11642                 .mixers = { alc262_ultra_mixer },
11643                 .cap_mixer = alc262_ultra_capture_mixer,
11644                 .init_verbs = { alc262_ultra_verbs },
11645                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11646                 .dac_nids = alc262_dac_nids,
11647                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11648                 .channel_mode = alc262_modes,
11649                 .input_mux = &alc262_ultra_capture_source,
11650                 .adc_nids = alc262_adc_nids, /* ADC0 */
11651                 .capsrc_nids = alc262_capsrc_nids,
11652                 .num_adc_nids = 1, /* single ADC */
11653                 .unsol_event = alc262_ultra_unsol_event,
11654                 .init_hook = alc262_ultra_automute,
11655         },
11656         [ALC262_LENOVO_3000] = {
11657                 .mixers = { alc262_lenovo_3000_mixer },
11658                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11659                                 alc262_lenovo_3000_unsol_verbs },
11660                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11661                 .dac_nids = alc262_dac_nids,
11662                 .hp_nid = 0x03,
11663                 .dig_out_nid = ALC262_DIGOUT_NID,
11664                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11665                 .channel_mode = alc262_modes,
11666                 .input_mux = &alc262_fujitsu_capture_source,
11667                 .unsol_event = alc262_lenovo_3000_unsol_event,
11668         },
11669         [ALC262_NEC] = {
11670                 .mixers = { alc262_nec_mixer },
11671                 .init_verbs = { alc262_nec_verbs },
11672                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11673                 .dac_nids = alc262_dac_nids,
11674                 .hp_nid = 0x03,
11675                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11676                 .channel_mode = alc262_modes,
11677                 .input_mux = &alc262_capture_source,
11678         },
11679         [ALC262_TOSHIBA_S06] = {
11680                 .mixers = { alc262_toshiba_s06_mixer },
11681                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11682                                                         alc262_eapd_verbs },
11683                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11684                 .capsrc_nids = alc262_dmic_capsrc_nids,
11685                 .dac_nids = alc262_dac_nids,
11686                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11687                 .num_adc_nids = 1, /* single ADC */
11688                 .dig_out_nid = ALC262_DIGOUT_NID,
11689                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11690                 .channel_mode = alc262_modes,
11691                 .unsol_event = alc_sku_unsol_event,
11692                 .setup = alc262_toshiba_s06_setup,
11693                 .init_hook = alc_inithook,
11694         },
11695         [ALC262_TOSHIBA_RX1] = {
11696                 .mixers = { alc262_toshiba_rx1_mixer },
11697                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11698                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11699                 .dac_nids = alc262_dac_nids,
11700                 .hp_nid = 0x03,
11701                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11702                 .channel_mode = alc262_modes,
11703                 .input_mux = &alc262_capture_source,
11704                 .unsol_event = alc262_hippo_unsol_event,
11705                 .setup = alc262_hippo_setup,
11706                 .init_hook = alc262_hippo_automute,
11707         },
11708         [ALC262_TYAN] = {
11709                 .mixers = { alc262_tyan_mixer },
11710                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11711                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11712                 .dac_nids = alc262_dac_nids,
11713                 .hp_nid = 0x02,
11714                 .dig_out_nid = ALC262_DIGOUT_NID,
11715                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11716                 .channel_mode = alc262_modes,
11717                 .input_mux = &alc262_capture_source,
11718                 .unsol_event = alc_automute_amp_unsol_event,
11719                 .setup = alc262_tyan_setup,
11720                 .init_hook = alc_automute_amp,
11721         },
11722 };
11723
11724 static int patch_alc262(struct hda_codec *codec)
11725 {
11726         struct alc_spec *spec;
11727         int board_config;
11728         int err;
11729
11730         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11731         if (spec == NULL)
11732                 return -ENOMEM;
11733
11734         codec->spec = spec;
11735 #if 0
11736         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11737          * under-run
11738          */
11739         {
11740         int tmp;
11741         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11742         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11743         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11744         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11745         }
11746 #endif
11747
11748         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11749
11750         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11751                                                   alc262_models,
11752                                                   alc262_cfg_tbl);
11753
11754         if (board_config < 0) {
11755                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11756                        codec->chip_name);
11757                 board_config = ALC262_AUTO;
11758         }
11759
11760         if (board_config == ALC262_AUTO) {
11761                 /* automatic parse from the BIOS config */
11762                 err = alc262_parse_auto_config(codec);
11763                 if (err < 0) {
11764                         alc_free(codec);
11765                         return err;
11766                 } else if (!err) {
11767                         printk(KERN_INFO
11768                                "hda_codec: Cannot set up configuration "
11769                                "from BIOS.  Using base mode...\n");
11770                         board_config = ALC262_BASIC;
11771                 }
11772         }
11773
11774         if (!spec->no_analog) {
11775                 err = snd_hda_attach_beep_device(codec, 0x1);
11776                 if (err < 0) {
11777                         alc_free(codec);
11778                         return err;
11779                 }
11780         }
11781
11782         if (board_config != ALC262_AUTO)
11783                 setup_preset(codec, &alc262_presets[board_config]);
11784
11785         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11786         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11787
11788         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11789         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11790
11791         if (!spec->adc_nids && spec->input_mux) {
11792                 int i;
11793                 /* check whether the digital-mic has to be supported */
11794                 for (i = 0; i < spec->input_mux->num_items; i++) {
11795                         if (spec->input_mux->items[i].index >= 9)
11796                                 break;
11797                 }
11798                 if (i < spec->input_mux->num_items) {
11799                         /* use only ADC0 */
11800                         spec->adc_nids = alc262_dmic_adc_nids;
11801                         spec->num_adc_nids = 1;
11802                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11803                 } else {
11804                         /* all analog inputs */
11805                         /* check whether NID 0x07 is valid */
11806                         unsigned int wcap = get_wcaps(codec, 0x07);
11807
11808                         /* get type */
11809                         wcap = get_wcaps_type(wcap);
11810                         if (wcap != AC_WID_AUD_IN) {
11811                                 spec->adc_nids = alc262_adc_nids_alt;
11812                                 spec->num_adc_nids =
11813                                         ARRAY_SIZE(alc262_adc_nids_alt);
11814                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11815                         } else {
11816                                 spec->adc_nids = alc262_adc_nids;
11817                                 spec->num_adc_nids =
11818                                         ARRAY_SIZE(alc262_adc_nids);
11819                                 spec->capsrc_nids = alc262_capsrc_nids;
11820                         }
11821                 }
11822         }
11823         if (!spec->cap_mixer && !spec->no_analog)
11824                 set_capture_mixer(codec);
11825         if (!spec->no_analog)
11826                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11827
11828         spec->vmaster_nid = 0x0c;
11829
11830         codec->patch_ops = alc_patch_ops;
11831         if (board_config == ALC262_AUTO)
11832                 spec->init_hook = alc262_auto_init;
11833 #ifdef CONFIG_SND_HDA_POWER_SAVE
11834         if (!spec->loopback.amplist)
11835                 spec->loopback.amplist = alc262_loopbacks;
11836 #endif
11837         codec->proc_widget_hook = print_realtek_coef;
11838
11839         return 0;
11840 }
11841
11842 /*
11843  *  ALC268 channel source setting (2 channel)
11844  */
11845 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11846 #define alc268_modes            alc260_modes
11847
11848 static hda_nid_t alc268_dac_nids[2] = {
11849         /* front, hp */
11850         0x02, 0x03
11851 };
11852
11853 static hda_nid_t alc268_adc_nids[2] = {
11854         /* ADC0-1 */
11855         0x08, 0x07
11856 };
11857
11858 static hda_nid_t alc268_adc_nids_alt[1] = {
11859         /* ADC0 */
11860         0x08
11861 };
11862
11863 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11864
11865 static struct snd_kcontrol_new alc268_base_mixer[] = {
11866         /* output mixer control */
11867         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11868         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11869         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11870         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11871         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11872         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11873         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11874         { }
11875 };
11876
11877 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11878         /* output mixer control */
11879         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11880         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11881         ALC262_HIPPO_MASTER_SWITCH,
11882         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11883         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11884         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11885         { }
11886 };
11887
11888 /* bind Beep switches of both NID 0x0f and 0x10 */
11889 static struct hda_bind_ctls alc268_bind_beep_sw = {
11890         .ops = &snd_hda_bind_sw,
11891         .values = {
11892                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11893                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11894                 0
11895         },
11896 };
11897
11898 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11899         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11900         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11901         { }
11902 };
11903
11904 static struct hda_verb alc268_eapd_verbs[] = {
11905         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11906         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11907         { }
11908 };
11909
11910 /* Toshiba specific */
11911 static struct hda_verb alc268_toshiba_verbs[] = {
11912         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11913         { } /* end */
11914 };
11915
11916 /* Acer specific */
11917 /* bind volumes of both NID 0x02 and 0x03 */
11918 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11919         .ops = &snd_hda_bind_vol,
11920         .values = {
11921                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11922                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11923                 0
11924         },
11925 };
11926
11927 /* mute/unmute internal speaker according to the hp jack and mute state */
11928 static void alc268_acer_automute(struct hda_codec *codec, int force)
11929 {
11930         struct alc_spec *spec = codec->spec;
11931         unsigned int mute;
11932
11933         if (force || !spec->sense_updated) {
11934                 unsigned int present;
11935                 present = snd_hda_codec_read(codec, 0x14, 0,
11936                                          AC_VERB_GET_PIN_SENSE, 0);
11937                 spec->jack_present = (present & 0x80000000) != 0;
11938                 spec->sense_updated = 1;
11939         }
11940         if (spec->jack_present)
11941                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11942         else /* unmute internal speaker if necessary */
11943                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11944         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11945                                  HDA_AMP_MUTE, mute);
11946 }
11947
11948
11949 /* bind hp and internal speaker mute (with plug check) */
11950 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11951                                      struct snd_ctl_elem_value *ucontrol)
11952 {
11953         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11954         long *valp = ucontrol->value.integer.value;
11955         int change;
11956
11957         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11958         if (change)
11959                 alc268_acer_automute(codec, 0);
11960         return change;
11961 }
11962
11963 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11964         /* output mixer control */
11965         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11966         {
11967                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11968                 .name = "Master Playback Switch",
11969                 .info = snd_hda_mixer_amp_switch_info,
11970                 .get = snd_hda_mixer_amp_switch_get,
11971                 .put = alc268_acer_master_sw_put,
11972                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11973         },
11974         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11975         { }
11976 };
11977
11978 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11979         /* output mixer control */
11980         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11981         {
11982                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11983                 .name = "Master Playback Switch",
11984                 .info = snd_hda_mixer_amp_switch_info,
11985                 .get = snd_hda_mixer_amp_switch_get,
11986                 .put = alc268_acer_master_sw_put,
11987                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11988         },
11989         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11990         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11991         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11992         { }
11993 };
11994
11995 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11996         /* output mixer control */
11997         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11998         {
11999                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12000                 .name = "Master Playback Switch",
12001                 .info = snd_hda_mixer_amp_switch_info,
12002                 .get = snd_hda_mixer_amp_switch_get,
12003                 .put = alc268_acer_master_sw_put,
12004                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12005         },
12006         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12007         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
12008         { }
12009 };
12010
12011 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
12012         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12013         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12014         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12015         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12016         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
12017         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
12018         { }
12019 };
12020
12021 static struct hda_verb alc268_acer_verbs[] = {
12022         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
12023         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12024         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12025         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12026         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12027         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12028         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12029         { }
12030 };
12031
12032 /* unsolicited event for HP jack sensing */
12033 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
12034 #define alc268_toshiba_setup            alc262_hippo_setup
12035 #define alc268_toshiba_automute         alc262_hippo_automute
12036
12037 static void alc268_acer_unsol_event(struct hda_codec *codec,
12038                                        unsigned int res)
12039 {
12040         if ((res >> 26) != ALC880_HP_EVENT)
12041                 return;
12042         alc268_acer_automute(codec, 1);
12043 }
12044
12045 static void alc268_acer_init_hook(struct hda_codec *codec)
12046 {
12047         alc268_acer_automute(codec, 1);
12048 }
12049
12050 /* toggle speaker-output according to the hp-jack state */
12051 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12052 {
12053         unsigned int present;
12054         unsigned char bits;
12055
12056         present = snd_hda_codec_read(codec, 0x15, 0,
12057                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12058         bits = present ? AMP_IN_MUTE(0) : 0;
12059         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12060                                 AMP_IN_MUTE(0), bits);
12061         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12062                                 AMP_IN_MUTE(0), bits);
12063 }
12064
12065 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
12066                                     unsigned int res)
12067 {
12068         switch (res >> 26) {
12069         case ALC880_HP_EVENT:
12070                 alc268_aspire_one_speaker_automute(codec);
12071                 break;
12072         case ALC880_MIC_EVENT:
12073                 alc_mic_automute(codec);
12074                 break;
12075         }
12076 }
12077
12078 static void alc268_acer_lc_setup(struct hda_codec *codec)
12079 {
12080         struct alc_spec *spec = codec->spec;
12081         spec->ext_mic.pin = 0x18;
12082         spec->ext_mic.mux_idx = 0;
12083         spec->int_mic.pin = 0x12;
12084         spec->int_mic.mux_idx = 6;
12085         spec->auto_mic = 1;
12086 }
12087
12088 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
12089 {
12090         alc268_aspire_one_speaker_automute(codec);
12091         alc_mic_automute(codec);
12092 }
12093
12094 static struct snd_kcontrol_new alc268_dell_mixer[] = {
12095         /* output mixer control */
12096         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12097         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12098         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12099         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12100         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12101         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12102         { }
12103 };
12104
12105 static struct hda_verb alc268_dell_verbs[] = {
12106         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12107         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12108         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12109         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12110         { }
12111 };
12112
12113 /* mute/unmute internal speaker according to the hp jack and mute state */
12114 static void alc268_dell_setup(struct hda_codec *codec)
12115 {
12116         struct alc_spec *spec = codec->spec;
12117
12118         spec->autocfg.hp_pins[0] = 0x15;
12119         spec->autocfg.speaker_pins[0] = 0x14;
12120         spec->ext_mic.pin = 0x18;
12121         spec->ext_mic.mux_idx = 0;
12122         spec->int_mic.pin = 0x19;
12123         spec->int_mic.mux_idx = 1;
12124         spec->auto_mic = 1;
12125 }
12126
12127 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12128         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12129         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12130         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12131         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12132         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12133         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12134         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12135         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12136         { }
12137 };
12138
12139 static struct hda_verb alc267_quanta_il1_verbs[] = {
12140         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12141         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12142         { }
12143 };
12144
12145 static void alc267_quanta_il1_setup(struct hda_codec *codec)
12146 {
12147         struct alc_spec *spec = codec->spec;
12148         spec->autocfg.hp_pins[0] = 0x15;
12149         spec->autocfg.speaker_pins[0] = 0x14;
12150         spec->ext_mic.pin = 0x18;
12151         spec->ext_mic.mux_idx = 0;
12152         spec->int_mic.pin = 0x19;
12153         spec->int_mic.mux_idx = 1;
12154         spec->auto_mic = 1;
12155 }
12156
12157 /*
12158  * generic initialization of ADC, input mixers and output mixers
12159  */
12160 static struct hda_verb alc268_base_init_verbs[] = {
12161         /* Unmute DAC0-1 and set vol = 0 */
12162         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12163         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12164
12165         /*
12166          * Set up output mixers (0x0c - 0x0e)
12167          */
12168         /* set vol=0 to output mixers */
12169         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12170         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12171
12172         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12173         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12174
12175         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12176         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12177         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12178         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12179         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12180         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12181         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12182         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12183
12184         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12185         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12186         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12187         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12188         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12189
12190         /* set PCBEEP vol = 0, mute connections */
12191         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12192         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12193         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12194
12195         /* Unmute Selector 23h,24h and set the default input to mic-in */
12196
12197         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12198         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12199         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12200         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12201
12202         { }
12203 };
12204
12205 /*
12206  * generic initialization of ADC, input mixers and output mixers
12207  */
12208 static struct hda_verb alc268_volume_init_verbs[] = {
12209         /* set output DAC */
12210         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12211         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12212
12213         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12214         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12215         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12216         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12217         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12218
12219         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12220         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12221         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12222
12223         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12224         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12225
12226         /* set PCBEEP vol = 0, mute connections */
12227         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12228         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12229         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12230
12231         { }
12232 };
12233
12234 static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
12235         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12236         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12237         { } /* end */
12238 };
12239
12240 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12241         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12242         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12243         _DEFINE_CAPSRC(1),
12244         { } /* end */
12245 };
12246
12247 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12248         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12249         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12250         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12251         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12252         _DEFINE_CAPSRC(2),
12253         { } /* end */
12254 };
12255
12256 static struct hda_input_mux alc268_capture_source = {
12257         .num_items = 4,
12258         .items = {
12259                 { "Mic", 0x0 },
12260                 { "Front Mic", 0x1 },
12261                 { "Line", 0x2 },
12262                 { "CD", 0x3 },
12263         },
12264 };
12265
12266 static struct hda_input_mux alc268_acer_capture_source = {
12267         .num_items = 3,
12268         .items = {
12269                 { "Mic", 0x0 },
12270                 { "Internal Mic", 0x1 },
12271                 { "Line", 0x2 },
12272         },
12273 };
12274
12275 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12276         .num_items = 3,
12277         .items = {
12278                 { "Mic", 0x0 },
12279                 { "Internal Mic", 0x6 },
12280                 { "Line", 0x2 },
12281         },
12282 };
12283
12284 #ifdef CONFIG_SND_DEBUG
12285 static struct snd_kcontrol_new alc268_test_mixer[] = {
12286         /* Volume widgets */
12287         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12288         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12289         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12290         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12291         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12292         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12293         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12294         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12295         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12296         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12297         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12298         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12299         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12300         /* The below appears problematic on some hardwares */
12301         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12302         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12303         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12304         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12305         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12306
12307         /* Modes for retasking pin widgets */
12308         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12309         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12310         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12311         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12312
12313         /* Controls for GPIO pins, assuming they are configured as outputs */
12314         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12315         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12316         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12317         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12318
12319         /* Switches to allow the digital SPDIF output pin to be enabled.
12320          * The ALC268 does not have an SPDIF input.
12321          */
12322         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12323
12324         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12325          * this output to turn on an external amplifier.
12326          */
12327         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12328         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12329
12330         { } /* end */
12331 };
12332 #endif
12333
12334 /* create input playback/capture controls for the given pin */
12335 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12336                                     const char *ctlname, int idx)
12337 {
12338         hda_nid_t dac;
12339         int err;
12340
12341         switch (nid) {
12342         case 0x14:
12343         case 0x16:
12344                 dac = 0x02;
12345                 break;
12346         case 0x15:
12347                 dac = 0x03;
12348                 break;
12349         default:
12350                 return 0;
12351         }
12352         if (spec->multiout.dac_nids[0] != dac &&
12353             spec->multiout.dac_nids[1] != dac) {
12354                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12355                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12356                                                       HDA_OUTPUT));
12357                 if (err < 0)
12358                         return err;
12359                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12360         }
12361
12362         if (nid != 0x16)
12363                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12364                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12365         else /* mono */
12366                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12367                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12368         if (err < 0)
12369                 return err;
12370         return 0;
12371 }
12372
12373 /* add playback controls from the parsed DAC table */
12374 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12375                                              const struct auto_pin_cfg *cfg)
12376 {
12377         hda_nid_t nid;
12378         int err;
12379
12380         spec->multiout.dac_nids = spec->private_dac_nids;
12381
12382         nid = cfg->line_out_pins[0];
12383         if (nid) {
12384                 const char *name;
12385                 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12386                         name = "Speaker";
12387                 else
12388                         name = "Front";
12389                 err = alc268_new_analog_output(spec, nid, name, 0);
12390                 if (err < 0)
12391                         return err;
12392         }
12393
12394         nid = cfg->speaker_pins[0];
12395         if (nid == 0x1d) {
12396                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12397                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12398                 if (err < 0)
12399                         return err;
12400         } else {
12401                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12402                 if (err < 0)
12403                         return err;
12404         }
12405         nid = cfg->hp_pins[0];
12406         if (nid) {
12407                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
12408                 if (err < 0)
12409                         return err;
12410         }
12411
12412         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12413         if (nid == 0x16) {
12414                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12415                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12416                 if (err < 0)
12417                         return err;
12418         }
12419         return 0;
12420 }
12421
12422 /* create playback/capture controls for input pins */
12423 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12424                                                 const struct auto_pin_cfg *cfg)
12425 {
12426         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12427 }
12428
12429 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12430                                               hda_nid_t nid, int pin_type)
12431 {
12432         int idx;
12433
12434         alc_set_pin_output(codec, nid, pin_type);
12435         if (nid == 0x14 || nid == 0x16)
12436                 idx = 0;
12437         else
12438                 idx = 1;
12439         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12440 }
12441
12442 static void alc268_auto_init_multi_out(struct hda_codec *codec)
12443 {
12444         struct alc_spec *spec = codec->spec;
12445         hda_nid_t nid = spec->autocfg.line_out_pins[0];
12446         if (nid) {
12447                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12448                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12449         }
12450 }
12451
12452 static void alc268_auto_init_hp_out(struct hda_codec *codec)
12453 {
12454         struct alc_spec *spec = codec->spec;
12455         hda_nid_t pin;
12456
12457         pin = spec->autocfg.hp_pins[0];
12458         if (pin)
12459                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
12460         pin = spec->autocfg.speaker_pins[0];
12461         if (pin)
12462                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
12463 }
12464
12465 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12466 {
12467         struct alc_spec *spec = codec->spec;
12468         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12469         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12470         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12471         unsigned int    dac_vol1, dac_vol2;
12472
12473         if (line_nid == 0x1d || speaker_nid == 0x1d) {
12474                 snd_hda_codec_write(codec, speaker_nid, 0,
12475                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12476                 /* mute mixer inputs from 0x1d */
12477                 snd_hda_codec_write(codec, 0x0f, 0,
12478                                     AC_VERB_SET_AMP_GAIN_MUTE,
12479                                     AMP_IN_UNMUTE(1));
12480                 snd_hda_codec_write(codec, 0x10, 0,
12481                                     AC_VERB_SET_AMP_GAIN_MUTE,
12482                                     AMP_IN_UNMUTE(1));
12483         } else {
12484                 /* unmute mixer inputs from 0x1d */
12485                 snd_hda_codec_write(codec, 0x0f, 0,
12486                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12487                 snd_hda_codec_write(codec, 0x10, 0,
12488                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12489         }
12490
12491         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12492         if (line_nid == 0x14)
12493                 dac_vol2 = AMP_OUT_ZERO;
12494         else if (line_nid == 0x15)
12495                 dac_vol1 = AMP_OUT_ZERO;
12496         if (hp_nid == 0x14)
12497                 dac_vol2 = AMP_OUT_ZERO;
12498         else if (hp_nid == 0x15)
12499                 dac_vol1 = AMP_OUT_ZERO;
12500         if (line_nid != 0x16 || hp_nid != 0x16 ||
12501             spec->autocfg.line_out_pins[1] != 0x16 ||
12502             spec->autocfg.line_out_pins[2] != 0x16)
12503                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12504
12505         snd_hda_codec_write(codec, 0x02, 0,
12506                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12507         snd_hda_codec_write(codec, 0x03, 0,
12508                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12509 }
12510
12511 /* pcm configuration: identical with ALC880 */
12512 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12513 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12514 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12515 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12516
12517 /*
12518  * BIOS auto configuration
12519  */
12520 static int alc268_parse_auto_config(struct hda_codec *codec)
12521 {
12522         struct alc_spec *spec = codec->spec;
12523         int err;
12524         static hda_nid_t alc268_ignore[] = { 0 };
12525
12526         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12527                                            alc268_ignore);
12528         if (err < 0)
12529                 return err;
12530         if (!spec->autocfg.line_outs) {
12531                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12532                         spec->multiout.max_channels = 2;
12533                         spec->no_analog = 1;
12534                         goto dig_only;
12535                 }
12536                 return 0; /* can't find valid BIOS pin config */
12537         }
12538         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12539         if (err < 0)
12540                 return err;
12541         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12542         if (err < 0)
12543                 return err;
12544
12545         spec->multiout.max_channels = 2;
12546
12547  dig_only:
12548         /* digital only support output */
12549         if (spec->autocfg.dig_outs) {
12550                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12551                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12552         }
12553         if (spec->kctls.list)
12554                 add_mixer(spec, spec->kctls.list);
12555
12556         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12557                 add_mixer(spec, alc268_beep_mixer);
12558
12559         add_verb(spec, alc268_volume_init_verbs);
12560         spec->num_mux_defs = 2;
12561         spec->input_mux = &spec->private_imux[0];
12562
12563         err = alc_auto_add_mic_boost(codec);
12564         if (err < 0)
12565                 return err;
12566
12567         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12568
12569         return 1;
12570 }
12571
12572 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12573
12574 /* init callback for auto-configuration model -- overriding the default init */
12575 static void alc268_auto_init(struct hda_codec *codec)
12576 {
12577         struct alc_spec *spec = codec->spec;
12578         alc268_auto_init_multi_out(codec);
12579         alc268_auto_init_hp_out(codec);
12580         alc268_auto_init_mono_speaker_out(codec);
12581         alc268_auto_init_analog_input(codec);
12582         if (spec->unsol_event)
12583                 alc_inithook(codec);
12584 }
12585
12586 /*
12587  * configuration and preset
12588  */
12589 static const char *alc268_models[ALC268_MODEL_LAST] = {
12590         [ALC267_QUANTA_IL1]     = "quanta-il1",
12591         [ALC268_3ST]            = "3stack",
12592         [ALC268_TOSHIBA]        = "toshiba",
12593         [ALC268_ACER]           = "acer",
12594         [ALC268_ACER_DMIC]      = "acer-dmic",
12595         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12596         [ALC268_DELL]           = "dell",
12597         [ALC268_ZEPTO]          = "zepto",
12598 #ifdef CONFIG_SND_DEBUG
12599         [ALC268_TEST]           = "test",
12600 #endif
12601         [ALC268_AUTO]           = "auto",
12602 };
12603
12604 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12605         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12606         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12607         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12608         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12609         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12610         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12611                                                 ALC268_ACER_ASPIRE_ONE),
12612         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12613         SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
12614                         "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
12615         /* almost compatible with toshiba but with optional digital outs;
12616          * auto-probing seems working fine
12617          */
12618         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12619                            ALC268_AUTO),
12620         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12621         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12622         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12623         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12624         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12625         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12626         {}
12627 };
12628
12629 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
12630 static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
12631         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
12632         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
12633         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12634                            ALC268_TOSHIBA),
12635         {}
12636 };
12637
12638 static struct alc_config_preset alc268_presets[] = {
12639         [ALC267_QUANTA_IL1] = {
12640                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12641                             alc268_capture_nosrc_mixer },
12642                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12643                                 alc267_quanta_il1_verbs },
12644                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12645                 .dac_nids = alc268_dac_nids,
12646                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12647                 .adc_nids = alc268_adc_nids_alt,
12648                 .hp_nid = 0x03,
12649                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12650                 .channel_mode = alc268_modes,
12651                 .unsol_event = alc_sku_unsol_event,
12652                 .setup = alc267_quanta_il1_setup,
12653                 .init_hook = alc_inithook,
12654         },
12655         [ALC268_3ST] = {
12656                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12657                             alc268_beep_mixer },
12658                 .init_verbs = { alc268_base_init_verbs },
12659                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12660                 .dac_nids = alc268_dac_nids,
12661                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12662                 .adc_nids = alc268_adc_nids_alt,
12663                 .capsrc_nids = alc268_capsrc_nids,
12664                 .hp_nid = 0x03,
12665                 .dig_out_nid = ALC268_DIGOUT_NID,
12666                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12667                 .channel_mode = alc268_modes,
12668                 .input_mux = &alc268_capture_source,
12669         },
12670         [ALC268_TOSHIBA] = {
12671                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12672                             alc268_beep_mixer },
12673                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12674                                 alc268_toshiba_verbs },
12675                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12676                 .dac_nids = alc268_dac_nids,
12677                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12678                 .adc_nids = alc268_adc_nids_alt,
12679                 .capsrc_nids = alc268_capsrc_nids,
12680                 .hp_nid = 0x03,
12681                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12682                 .channel_mode = alc268_modes,
12683                 .input_mux = &alc268_capture_source,
12684                 .unsol_event = alc268_toshiba_unsol_event,
12685                 .setup = alc268_toshiba_setup,
12686                 .init_hook = alc268_toshiba_automute,
12687         },
12688         [ALC268_ACER] = {
12689                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12690                             alc268_beep_mixer },
12691                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12692                                 alc268_acer_verbs },
12693                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12694                 .dac_nids = alc268_dac_nids,
12695                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12696                 .adc_nids = alc268_adc_nids_alt,
12697                 .capsrc_nids = alc268_capsrc_nids,
12698                 .hp_nid = 0x02,
12699                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12700                 .channel_mode = alc268_modes,
12701                 .input_mux = &alc268_acer_capture_source,
12702                 .unsol_event = alc268_acer_unsol_event,
12703                 .init_hook = alc268_acer_init_hook,
12704         },
12705         [ALC268_ACER_DMIC] = {
12706                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12707                             alc268_beep_mixer },
12708                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12709                                 alc268_acer_verbs },
12710                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12711                 .dac_nids = alc268_dac_nids,
12712                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12713                 .adc_nids = alc268_adc_nids_alt,
12714                 .capsrc_nids = alc268_capsrc_nids,
12715                 .hp_nid = 0x02,
12716                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12717                 .channel_mode = alc268_modes,
12718                 .input_mux = &alc268_acer_dmic_capture_source,
12719                 .unsol_event = alc268_acer_unsol_event,
12720                 .init_hook = alc268_acer_init_hook,
12721         },
12722         [ALC268_ACER_ASPIRE_ONE] = {
12723                 .mixers = { alc268_acer_aspire_one_mixer,
12724                             alc268_beep_mixer,
12725                             alc268_capture_nosrc_mixer },
12726                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12727                                 alc268_acer_aspire_one_verbs },
12728                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12729                 .dac_nids = alc268_dac_nids,
12730                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12731                 .adc_nids = alc268_adc_nids_alt,
12732                 .capsrc_nids = alc268_capsrc_nids,
12733                 .hp_nid = 0x03,
12734                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12735                 .channel_mode = alc268_modes,
12736                 .unsol_event = alc268_acer_lc_unsol_event,
12737                 .setup = alc268_acer_lc_setup,
12738                 .init_hook = alc268_acer_lc_init_hook,
12739         },
12740         [ALC268_DELL] = {
12741                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12742                             alc268_capture_nosrc_mixer },
12743                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12744                                 alc268_dell_verbs },
12745                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12746                 .dac_nids = alc268_dac_nids,
12747                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12748                 .adc_nids = alc268_adc_nids_alt,
12749                 .capsrc_nids = alc268_capsrc_nids,
12750                 .hp_nid = 0x02,
12751                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12752                 .channel_mode = alc268_modes,
12753                 .unsol_event = alc_sku_unsol_event,
12754                 .setup = alc268_dell_setup,
12755                 .init_hook = alc_inithook,
12756         },
12757         [ALC268_ZEPTO] = {
12758                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12759                             alc268_beep_mixer },
12760                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12761                                 alc268_toshiba_verbs },
12762                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12763                 .dac_nids = alc268_dac_nids,
12764                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12765                 .adc_nids = alc268_adc_nids_alt,
12766                 .capsrc_nids = alc268_capsrc_nids,
12767                 .hp_nid = 0x03,
12768                 .dig_out_nid = ALC268_DIGOUT_NID,
12769                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12770                 .channel_mode = alc268_modes,
12771                 .input_mux = &alc268_capture_source,
12772                 .setup = alc268_toshiba_setup,
12773                 .init_hook = alc268_toshiba_automute,
12774         },
12775 #ifdef CONFIG_SND_DEBUG
12776         [ALC268_TEST] = {
12777                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12778                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12779                                 alc268_volume_init_verbs },
12780                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12781                 .dac_nids = alc268_dac_nids,
12782                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12783                 .adc_nids = alc268_adc_nids_alt,
12784                 .capsrc_nids = alc268_capsrc_nids,
12785                 .hp_nid = 0x03,
12786                 .dig_out_nid = ALC268_DIGOUT_NID,
12787                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12788                 .channel_mode = alc268_modes,
12789                 .input_mux = &alc268_capture_source,
12790         },
12791 #endif
12792 };
12793
12794 static int patch_alc268(struct hda_codec *codec)
12795 {
12796         struct alc_spec *spec;
12797         int board_config;
12798         int i, has_beep, err;
12799
12800         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12801         if (spec == NULL)
12802                 return -ENOMEM;
12803
12804         codec->spec = spec;
12805
12806         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12807                                                   alc268_models,
12808                                                   alc268_cfg_tbl);
12809
12810         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12811                 board_config = snd_hda_check_board_codec_sid_config(codec,
12812                         ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12813
12814         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12815                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12816                        codec->chip_name);
12817                 board_config = ALC268_AUTO;
12818         }
12819
12820         if (board_config == ALC268_AUTO) {
12821                 /* automatic parse from the BIOS config */
12822                 err = alc268_parse_auto_config(codec);
12823                 if (err < 0) {
12824                         alc_free(codec);
12825                         return err;
12826                 } else if (!err) {
12827                         printk(KERN_INFO
12828                                "hda_codec: Cannot set up configuration "
12829                                "from BIOS.  Using base mode...\n");
12830                         board_config = ALC268_3ST;
12831                 }
12832         }
12833
12834         if (board_config != ALC268_AUTO)
12835                 setup_preset(codec, &alc268_presets[board_config]);
12836
12837         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12838         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12839         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12840
12841         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12842
12843         has_beep = 0;
12844         for (i = 0; i < spec->num_mixers; i++) {
12845                 if (spec->mixers[i] == alc268_beep_mixer) {
12846                         has_beep = 1;
12847                         break;
12848                 }
12849         }
12850
12851         if (has_beep) {
12852                 err = snd_hda_attach_beep_device(codec, 0x1);
12853                 if (err < 0) {
12854                         alc_free(codec);
12855                         return err;
12856                 }
12857                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12858                         /* override the amp caps for beep generator */
12859                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12860                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12861                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12862                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12863                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12864         }
12865
12866         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12867                 /* check whether NID 0x07 is valid */
12868                 unsigned int wcap = get_wcaps(codec, 0x07);
12869                 int i;
12870
12871                 spec->capsrc_nids = alc268_capsrc_nids;
12872                 /* get type */
12873                 wcap = get_wcaps_type(wcap);
12874                 if (spec->auto_mic ||
12875                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12876                         spec->adc_nids = alc268_adc_nids_alt;
12877                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12878                         if (spec->auto_mic)
12879                                 fixup_automic_adc(codec);
12880                         if (spec->auto_mic || spec->input_mux->num_items == 1)
12881                                 add_mixer(spec, alc268_capture_nosrc_mixer);
12882                         else
12883                                 add_mixer(spec, alc268_capture_alt_mixer);
12884                 } else {
12885                         spec->adc_nids = alc268_adc_nids;
12886                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12887                         add_mixer(spec, alc268_capture_mixer);
12888                 }
12889                 /* set default input source */
12890                 for (i = 0; i < spec->num_adc_nids; i++)
12891                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12892                                 0, AC_VERB_SET_CONNECT_SEL,
12893                                 i < spec->num_mux_defs ?
12894                                 spec->input_mux[i].items[0].index :
12895                                 spec->input_mux->items[0].index);
12896         }
12897
12898         spec->vmaster_nid = 0x02;
12899
12900         codec->patch_ops = alc_patch_ops;
12901         if (board_config == ALC268_AUTO)
12902                 spec->init_hook = alc268_auto_init;
12903
12904         codec->proc_widget_hook = print_realtek_coef;
12905
12906         return 0;
12907 }
12908
12909 /*
12910  *  ALC269 channel source setting (2 channel)
12911  */
12912 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12913
12914 #define alc269_dac_nids         alc260_dac_nids
12915
12916 static hda_nid_t alc269_adc_nids[1] = {
12917         /* ADC1 */
12918         0x08,
12919 };
12920
12921 static hda_nid_t alc269_capsrc_nids[1] = {
12922         0x23,
12923 };
12924
12925 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12926  *       not a mux!
12927  */
12928
12929 #define alc269_modes            alc260_modes
12930 #define alc269_capture_source   alc880_lg_lw_capture_source
12931
12932 static struct snd_kcontrol_new alc269_base_mixer[] = {
12933         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12934         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12935         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12936         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12939         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12940         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12941         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12942         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12943         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12944         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12945         { } /* end */
12946 };
12947
12948 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12949         /* output mixer control */
12950         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12951         {
12952                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12953                 .name = "Master Playback Switch",
12954                 .info = snd_hda_mixer_amp_switch_info,
12955                 .get = snd_hda_mixer_amp_switch_get,
12956                 .put = alc268_acer_master_sw_put,
12957                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12958         },
12959         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12960         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12961         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12962         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12963         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12964         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12965         { }
12966 };
12967
12968 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12969         /* output mixer control */
12970         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12971         {
12972                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12973                 .name = "Master Playback Switch",
12974                 .info = snd_hda_mixer_amp_switch_info,
12975                 .get = snd_hda_mixer_amp_switch_get,
12976                 .put = alc268_acer_master_sw_put,
12977                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12978         },
12979         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12980         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12981         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12982         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12983         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12984         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12985         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12986         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12987         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12988         { }
12989 };
12990
12991 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12992         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12993         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12994         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12995         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12996         { } /* end */
12997 };
12998
12999 /* capture mixer elements */
13000 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
13001         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
13002         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13003         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13004         { } /* end */
13005 };
13006
13007 /* FSC amilo */
13008 #define alc269_fujitsu_mixer    alc269_eeepc_mixer
13009
13010 static struct hda_verb alc269_quanta_fl1_verbs[] = {
13011         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13012         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13013         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13014         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13015         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13016         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13017         { }
13018 };
13019
13020 static struct hda_verb alc269_lifebook_verbs[] = {
13021         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13022         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
13023         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13024         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13025         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13026         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13027         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13028         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13029         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13030         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13031         { }
13032 };
13033
13034 /* toggle speaker-output according to the hp-jack state */
13035 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13036 {
13037         unsigned int present;
13038         unsigned char bits;
13039
13040         present = snd_hda_codec_read(codec, 0x15, 0,
13041                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13042         bits = present ? AMP_IN_MUTE(0) : 0;
13043         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13044                         AMP_IN_MUTE(0), bits);
13045         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13046                         AMP_IN_MUTE(0), bits);
13047
13048         snd_hda_codec_write(codec, 0x20, 0,
13049                         AC_VERB_SET_COEF_INDEX, 0x0c);
13050         snd_hda_codec_write(codec, 0x20, 0,
13051                         AC_VERB_SET_PROC_COEF, 0x680);
13052
13053         snd_hda_codec_write(codec, 0x20, 0,
13054                         AC_VERB_SET_COEF_INDEX, 0x0c);
13055         snd_hda_codec_write(codec, 0x20, 0,
13056                         AC_VERB_SET_PROC_COEF, 0x480);
13057 }
13058
13059 /* toggle speaker-output according to the hp-jacks state */
13060 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13061 {
13062         unsigned int present;
13063         unsigned char bits;
13064
13065         /* Check laptop headphone socket */
13066         present = snd_hda_codec_read(codec, 0x15, 0,
13067                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13068
13069         /* Check port replicator headphone socket */
13070         present |= snd_hda_codec_read(codec, 0x1a, 0,
13071                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13072
13073         bits = present ? AMP_IN_MUTE(0) : 0;
13074         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13075                         AMP_IN_MUTE(0), bits);
13076         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13077                         AMP_IN_MUTE(0), bits);
13078
13079         snd_hda_codec_write(codec, 0x20, 0,
13080                         AC_VERB_SET_COEF_INDEX, 0x0c);
13081         snd_hda_codec_write(codec, 0x20, 0,
13082                         AC_VERB_SET_PROC_COEF, 0x680);
13083
13084         snd_hda_codec_write(codec, 0x20, 0,
13085                         AC_VERB_SET_COEF_INDEX, 0x0c);
13086         snd_hda_codec_write(codec, 0x20, 0,
13087                         AC_VERB_SET_PROC_COEF, 0x480);
13088 }
13089
13090 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13091 {
13092         unsigned int present_laptop;
13093         unsigned int present_dock;
13094
13095         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13096                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13097
13098         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13099                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13100
13101         /* Laptop mic port overrides dock mic port, design decision */
13102         if (present_dock)
13103                 snd_hda_codec_write(codec, 0x23, 0,
13104                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13105         if (present_laptop)
13106                 snd_hda_codec_write(codec, 0x23, 0,
13107                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13108         if (!present_dock && !present_laptop)
13109                 snd_hda_codec_write(codec, 0x23, 0,
13110                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13111 }
13112
13113 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13114                                     unsigned int res)
13115 {
13116         switch (res >> 26) {
13117         case ALC880_HP_EVENT:
13118                 alc269_quanta_fl1_speaker_automute(codec);
13119                 break;
13120         case ALC880_MIC_EVENT:
13121                 alc_mic_automute(codec);
13122                 break;
13123         }
13124 }
13125
13126 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13127                                         unsigned int res)
13128 {
13129         if ((res >> 26) == ALC880_HP_EVENT)
13130                 alc269_lifebook_speaker_automute(codec);
13131         if ((res >> 26) == ALC880_MIC_EVENT)
13132                 alc269_lifebook_mic_autoswitch(codec);
13133 }
13134
13135 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13136 {
13137         struct alc_spec *spec = codec->spec;
13138         spec->ext_mic.pin = 0x18;
13139         spec->ext_mic.mux_idx = 0;
13140         spec->int_mic.pin = 0x19;
13141         spec->int_mic.mux_idx = 1;
13142         spec->auto_mic = 1;
13143 }
13144
13145 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13146 {
13147         alc269_quanta_fl1_speaker_automute(codec);
13148         alc_mic_automute(codec);
13149 }
13150
13151 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13152 {
13153         alc269_lifebook_speaker_automute(codec);
13154         alc269_lifebook_mic_autoswitch(codec);
13155 }
13156
13157 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13158         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13159         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13160         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13161         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13162         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13163         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13164         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13165         {}
13166 };
13167
13168 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13169         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13170         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13171         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13172         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13173         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13174         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13175         {}
13176 };
13177
13178 /* toggle speaker-output according to the hp-jack state */
13179 static void alc269_speaker_automute(struct hda_codec *codec)
13180 {
13181         unsigned int present;
13182         unsigned char bits;
13183
13184         present = snd_hda_codec_read(codec, 0x15, 0,
13185                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13186         bits = present ? AMP_IN_MUTE(0) : 0;
13187         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13188                                 AMP_IN_MUTE(0), bits);
13189         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13190                                 AMP_IN_MUTE(0), bits);
13191 }
13192
13193 /* unsolicited event for HP jack sensing */
13194 static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13195                                      unsigned int res)
13196 {
13197         switch (res >> 26) {
13198         case ALC880_HP_EVENT:
13199                 alc269_speaker_automute(codec);
13200                 break;
13201         case ALC880_MIC_EVENT:
13202                 alc_mic_automute(codec);
13203                 break;
13204         }
13205 }
13206
13207 static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13208 {
13209         struct alc_spec *spec = codec->spec;
13210         spec->ext_mic.pin = 0x18;
13211         spec->ext_mic.mux_idx = 0;
13212         spec->int_mic.pin = 0x12;
13213         spec->int_mic.mux_idx = 5;
13214         spec->auto_mic = 1;
13215 }
13216
13217 static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13218 {
13219         struct alc_spec *spec = codec->spec;
13220         spec->ext_mic.pin = 0x18;
13221         spec->ext_mic.mux_idx = 0;
13222         spec->int_mic.pin = 0x19;
13223         spec->int_mic.mux_idx = 1;
13224         spec->auto_mic = 1;
13225 }
13226
13227 static void alc269_eeepc_inithook(struct hda_codec *codec)
13228 {
13229         alc269_speaker_automute(codec);
13230         alc_mic_automute(codec);
13231 }
13232
13233 /*
13234  * generic initialization of ADC, input mixers and output mixers
13235  */
13236 static struct hda_verb alc269_init_verbs[] = {
13237         /*
13238          * Unmute ADC0 and set the default input to mic-in
13239          */
13240         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13241
13242         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13243          * analog-loopback mixer widget
13244          * Note: PASD motherboards uses the Line In 2 as the input for
13245          * front panel mic (mic 2)
13246          */
13247         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13248         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13249         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13250         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13251         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13252         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13253
13254         /*
13255          * Set up output mixers (0x0c - 0x0e)
13256          */
13257         /* set vol=0 to output mixers */
13258         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13259         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13260
13261         /* set up input amps for analog loopback */
13262         /* Amp Indices: DAC = 0, mixer = 1 */
13263         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13264         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13265         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13266         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13267         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13268         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13269
13270         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13271         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13272         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13273         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13274         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13275         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13276         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13277
13278         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13279         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13280         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13281         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13282         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13283         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13284         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13285
13286         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13287         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13288
13289         /* FIXME: use matrix-type input source selection */
13290         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13291         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13292         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13293         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13294         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13296
13297         /* set EAPD */
13298         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13299         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13300         { }
13301 };
13302
13303 #define alc269_auto_create_multi_out_ctls \
13304         alc268_auto_create_multi_out_ctls
13305 #define alc269_auto_create_input_ctls \
13306         alc268_auto_create_input_ctls
13307
13308 #ifdef CONFIG_SND_HDA_POWER_SAVE
13309 #define alc269_loopbacks        alc880_loopbacks
13310 #endif
13311
13312 /* pcm configuration: identical with ALC880 */
13313 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13314 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13315 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13316 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13317
13318 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13319         .substreams = 1,
13320         .channels_min = 2,
13321         .channels_max = 8,
13322         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13323         /* NID is set in alc_build_pcms */
13324         .ops = {
13325                 .open = alc880_playback_pcm_open,
13326                 .prepare = alc880_playback_pcm_prepare,
13327                 .cleanup = alc880_playback_pcm_cleanup
13328         },
13329 };
13330
13331 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13332         .substreams = 1,
13333         .channels_min = 2,
13334         .channels_max = 2,
13335         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13336         /* NID is set in alc_build_pcms */
13337 };
13338
13339 /*
13340  * BIOS auto configuration
13341  */
13342 static int alc269_parse_auto_config(struct hda_codec *codec)
13343 {
13344         struct alc_spec *spec = codec->spec;
13345         int err;
13346         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13347
13348         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13349                                            alc269_ignore);
13350         if (err < 0)
13351                 return err;
13352
13353         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13354         if (err < 0)
13355                 return err;
13356         err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13357         if (err < 0)
13358                 return err;
13359
13360         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13361
13362         if (spec->autocfg.dig_outs)
13363                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13364
13365         if (spec->kctls.list)
13366                 add_mixer(spec, spec->kctls.list);
13367
13368         add_verb(spec, alc269_init_verbs);
13369         spec->num_mux_defs = 1;
13370         spec->input_mux = &spec->private_imux[0];
13371         /* set default input source */
13372         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13373                                   0, AC_VERB_SET_CONNECT_SEL,
13374                                   spec->input_mux->items[0].index);
13375
13376         err = alc_auto_add_mic_boost(codec);
13377         if (err < 0)
13378                 return err;
13379
13380         if (!spec->cap_mixer && !spec->no_analog)
13381                 set_capture_mixer(codec);
13382
13383         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13384
13385         return 1;
13386 }
13387
13388 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
13389 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
13390 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13391
13392
13393 /* init callback for auto-configuration model -- overriding the default init */
13394 static void alc269_auto_init(struct hda_codec *codec)
13395 {
13396         struct alc_spec *spec = codec->spec;
13397         alc269_auto_init_multi_out(codec);
13398         alc269_auto_init_hp_out(codec);
13399         alc269_auto_init_analog_input(codec);
13400         if (spec->unsol_event)
13401                 alc_inithook(codec);
13402 }
13403
13404 /*
13405  * configuration and preset
13406  */
13407 static const char *alc269_models[ALC269_MODEL_LAST] = {
13408         [ALC269_BASIC]                  = "basic",
13409         [ALC269_QUANTA_FL1]             = "quanta",
13410         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13411         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13412         [ALC269_FUJITSU]                = "fujitsu",
13413         [ALC269_LIFEBOOK]               = "lifebook",
13414         [ALC269_AUTO]                   = "auto",
13415 };
13416
13417 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13418         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13419         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13420                       ALC269_ASUS_EEEPC_P703),
13421         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13422         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13423         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13424         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13425         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13426         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13427         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13428                       ALC269_ASUS_EEEPC_P901),
13429         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13430                       ALC269_ASUS_EEEPC_P901),
13431         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13432         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13433         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13434         {}
13435 };
13436
13437 static struct alc_config_preset alc269_presets[] = {
13438         [ALC269_BASIC] = {
13439                 .mixers = { alc269_base_mixer },
13440                 .init_verbs = { alc269_init_verbs },
13441                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13442                 .dac_nids = alc269_dac_nids,
13443                 .hp_nid = 0x03,
13444                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13445                 .channel_mode = alc269_modes,
13446                 .input_mux = &alc269_capture_source,
13447         },
13448         [ALC269_QUANTA_FL1] = {
13449                 .mixers = { alc269_quanta_fl1_mixer },
13450                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13451                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13452                 .dac_nids = alc269_dac_nids,
13453                 .hp_nid = 0x03,
13454                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13455                 .channel_mode = alc269_modes,
13456                 .input_mux = &alc269_capture_source,
13457                 .unsol_event = alc269_quanta_fl1_unsol_event,
13458                 .setup = alc269_quanta_fl1_setup,
13459                 .init_hook = alc269_quanta_fl1_init_hook,
13460         },
13461         [ALC269_ASUS_EEEPC_P703] = {
13462                 .mixers = { alc269_eeepc_mixer },
13463                 .cap_mixer = alc269_epc_capture_mixer,
13464                 .init_verbs = { alc269_init_verbs,
13465                                 alc269_eeepc_amic_init_verbs },
13466                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13467                 .dac_nids = alc269_dac_nids,
13468                 .hp_nid = 0x03,
13469                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13470                 .channel_mode = alc269_modes,
13471                 .unsol_event = alc269_eeepc_unsol_event,
13472                 .setup = alc269_eeepc_amic_setup,
13473                 .init_hook = alc269_eeepc_inithook,
13474         },
13475         [ALC269_ASUS_EEEPC_P901] = {
13476                 .mixers = { alc269_eeepc_mixer },
13477                 .cap_mixer = alc269_epc_capture_mixer,
13478                 .init_verbs = { alc269_init_verbs,
13479                                 alc269_eeepc_dmic_init_verbs },
13480                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13481                 .dac_nids = alc269_dac_nids,
13482                 .hp_nid = 0x03,
13483                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13484                 .channel_mode = alc269_modes,
13485                 .unsol_event = alc269_eeepc_unsol_event,
13486                 .setup = alc269_eeepc_dmic_setup,
13487                 .init_hook = alc269_eeepc_inithook,
13488         },
13489         [ALC269_FUJITSU] = {
13490                 .mixers = { alc269_fujitsu_mixer },
13491                 .cap_mixer = alc269_epc_capture_mixer,
13492                 .init_verbs = { alc269_init_verbs,
13493                                 alc269_eeepc_dmic_init_verbs },
13494                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13495                 .dac_nids = alc269_dac_nids,
13496                 .hp_nid = 0x03,
13497                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13498                 .channel_mode = alc269_modes,
13499                 .unsol_event = alc269_eeepc_unsol_event,
13500                 .setup = alc269_eeepc_dmic_setup,
13501                 .init_hook = alc269_eeepc_inithook,
13502         },
13503         [ALC269_LIFEBOOK] = {
13504                 .mixers = { alc269_lifebook_mixer },
13505                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13506                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13507                 .dac_nids = alc269_dac_nids,
13508                 .hp_nid = 0x03,
13509                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13510                 .channel_mode = alc269_modes,
13511                 .input_mux = &alc269_capture_source,
13512                 .unsol_event = alc269_lifebook_unsol_event,
13513                 .init_hook = alc269_lifebook_init_hook,
13514         },
13515 };
13516
13517 static int patch_alc269(struct hda_codec *codec)
13518 {
13519         struct alc_spec *spec;
13520         int board_config;
13521         int err;
13522
13523         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13524         if (spec == NULL)
13525                 return -ENOMEM;
13526
13527         codec->spec = spec;
13528
13529         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13530
13531         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13532                                                   alc269_models,
13533                                                   alc269_cfg_tbl);
13534
13535         if (board_config < 0) {
13536                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13537                        codec->chip_name);
13538                 board_config = ALC269_AUTO;
13539         }
13540
13541         if (board_config == ALC269_AUTO) {
13542                 /* automatic parse from the BIOS config */
13543                 err = alc269_parse_auto_config(codec);
13544                 if (err < 0) {
13545                         alc_free(codec);
13546                         return err;
13547                 } else if (!err) {
13548                         printk(KERN_INFO
13549                                "hda_codec: Cannot set up configuration "
13550                                "from BIOS.  Using base mode...\n");
13551                         board_config = ALC269_BASIC;
13552                 }
13553         }
13554
13555         err = snd_hda_attach_beep_device(codec, 0x1);
13556         if (err < 0) {
13557                 alc_free(codec);
13558                 return err;
13559         }
13560
13561         if (board_config != ALC269_AUTO)
13562                 setup_preset(codec, &alc269_presets[board_config]);
13563
13564         if (codec->subsystem_id == 0x17aa3bf8) {
13565                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13566                  * fix the sample rate of analog I/O to 44.1kHz
13567                  */
13568                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13569                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13570         } else {
13571                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13572                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13573         }
13574         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13575         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13576
13577         spec->adc_nids = alc269_adc_nids;
13578         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13579         spec->capsrc_nids = alc269_capsrc_nids;
13580         if (!spec->cap_mixer)
13581                 set_capture_mixer(codec);
13582         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13583
13584         spec->vmaster_nid = 0x02;
13585
13586         codec->patch_ops = alc_patch_ops;
13587         if (board_config == ALC269_AUTO)
13588                 spec->init_hook = alc269_auto_init;
13589 #ifdef CONFIG_SND_HDA_POWER_SAVE
13590         if (!spec->loopback.amplist)
13591                 spec->loopback.amplist = alc269_loopbacks;
13592 #endif
13593         codec->proc_widget_hook = print_realtek_coef;
13594
13595         return 0;
13596 }
13597
13598 /*
13599  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13600  */
13601
13602 /*
13603  * set the path ways for 2 channel output
13604  * need to set the codec line out and mic 1 pin widgets to inputs
13605  */
13606 static struct hda_verb alc861_threestack_ch2_init[] = {
13607         /* set pin widget 1Ah (line in) for input */
13608         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13609         /* set pin widget 18h (mic1/2) for input, for mic also enable
13610          * the vref
13611          */
13612         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13613
13614         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13615 #if 0
13616         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13617         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13618 #endif
13619         { } /* end */
13620 };
13621 /*
13622  * 6ch mode
13623  * need to set the codec line out and mic 1 pin widgets to outputs
13624  */
13625 static struct hda_verb alc861_threestack_ch6_init[] = {
13626         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13627         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13628         /* set pin widget 18h (mic1) for output (CLFE)*/
13629         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13630
13631         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13632         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13633
13634         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13635 #if 0
13636         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13637         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13638 #endif
13639         { } /* end */
13640 };
13641
13642 static struct hda_channel_mode alc861_threestack_modes[2] = {
13643         { 2, alc861_threestack_ch2_init },
13644         { 6, alc861_threestack_ch6_init },
13645 };
13646 /* Set mic1 as input and unmute the mixer */
13647 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13648         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13649         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13650         { } /* end */
13651 };
13652 /* Set mic1 as output and mute mixer */
13653 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13654         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13655         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13656         { } /* end */
13657 };
13658
13659 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13660         { 2, alc861_uniwill_m31_ch2_init },
13661         { 4, alc861_uniwill_m31_ch4_init },
13662 };
13663
13664 /* Set mic1 and line-in as input and unmute the mixer */
13665 static struct hda_verb alc861_asus_ch2_init[] = {
13666         /* set pin widget 1Ah (line in) for input */
13667         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13668         /* set pin widget 18h (mic1/2) for input, for mic also enable
13669          * the vref
13670          */
13671         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13672
13673         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13674 #if 0
13675         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13676         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13677 #endif
13678         { } /* end */
13679 };
13680 /* Set mic1 nad line-in as output and mute mixer */
13681 static struct hda_verb alc861_asus_ch6_init[] = {
13682         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13683         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13684         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13685         /* set pin widget 18h (mic1) for output (CLFE)*/
13686         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13687         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13688         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13689         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13690
13691         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13692 #if 0
13693         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13694         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13695 #endif
13696         { } /* end */
13697 };
13698
13699 static struct hda_channel_mode alc861_asus_modes[2] = {
13700         { 2, alc861_asus_ch2_init },
13701         { 6, alc861_asus_ch6_init },
13702 };
13703
13704 /* patch-ALC861 */
13705
13706 static struct snd_kcontrol_new alc861_base_mixer[] = {
13707         /* output mixer control */
13708         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13709         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13710         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13711         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13712         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13713
13714         /*Input mixer control */
13715         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13716            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13717         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13718         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13719         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13720         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13721         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13722         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13723         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13724         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13725
13726         { } /* end */
13727 };
13728
13729 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13730         /* output mixer control */
13731         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13732         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13733         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13734         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13735         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13736
13737         /* Input mixer control */
13738         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13739            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13740         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13741         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13742         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13743         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13744         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13745         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13746         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13747         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13748
13749         {
13750                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13751                 .name = "Channel Mode",
13752                 .info = alc_ch_mode_info,
13753                 .get = alc_ch_mode_get,
13754                 .put = alc_ch_mode_put,
13755                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13756         },
13757         { } /* end */
13758 };
13759
13760 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13761         /* output mixer control */
13762         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13763         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13764         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13765
13766         { } /* end */
13767 };
13768
13769 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13770         /* output mixer control */
13771         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13772         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13773         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13774         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13775         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13776
13777         /* Input mixer control */
13778         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13779            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13780         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13781         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13782         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13783         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13784         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13785         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13786         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13787         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13788
13789         {
13790                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13791                 .name = "Channel Mode",
13792                 .info = alc_ch_mode_info,
13793                 .get = alc_ch_mode_get,
13794                 .put = alc_ch_mode_put,
13795                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13796         },
13797         { } /* end */
13798 };
13799
13800 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13801         /* output mixer control */
13802         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13803         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13804         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13805         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13806         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13807
13808         /* Input mixer control */
13809         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13810         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13811         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13812         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13813         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13814         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13815         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13816         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13817         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13818         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13819
13820         {
13821                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13822                 .name = "Channel Mode",
13823                 .info = alc_ch_mode_info,
13824                 .get = alc_ch_mode_get,
13825                 .put = alc_ch_mode_put,
13826                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13827         },
13828         { }
13829 };
13830
13831 /* additional mixer */
13832 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13833         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13834         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13835         { }
13836 };
13837
13838 /*
13839  * generic initialization of ADC, input mixers and output mixers
13840  */
13841 static struct hda_verb alc861_base_init_verbs[] = {
13842         /*
13843          * Unmute ADC0 and set the default input to mic-in
13844          */
13845         /* port-A for surround (rear panel) */
13846         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13847         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13848         /* port-B for mic-in (rear panel) with vref */
13849         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13850         /* port-C for line-in (rear panel) */
13851         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13852         /* port-D for Front */
13853         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13854         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13855         /* port-E for HP out (front panel) */
13856         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13857         /* route front PCM to HP */
13858         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13859         /* port-F for mic-in (front panel) with vref */
13860         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13861         /* port-G for CLFE (rear panel) */
13862         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13863         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13864         /* port-H for side (rear panel) */
13865         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13866         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13867         /* CD-in */
13868         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13869         /* route front mic to ADC1*/
13870         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13871         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13872
13873         /* Unmute DAC0~3 & spdif out*/
13874         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13875         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13876         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13877         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13878         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13879
13880         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13881         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13882         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13883         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13884         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13885
13886         /* Unmute Stereo Mixer 15 */
13887         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13888         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13889         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13890         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13891
13892         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13893         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13894         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13895         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13896         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13897         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13898         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13899         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13900         /* hp used DAC 3 (Front) */
13901         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13902         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13903
13904         { }
13905 };
13906
13907 static struct hda_verb alc861_threestack_init_verbs[] = {
13908         /*
13909          * Unmute ADC0 and set the default input to mic-in
13910          */
13911         /* port-A for surround (rear panel) */
13912         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13913         /* port-B for mic-in (rear panel) with vref */
13914         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13915         /* port-C for line-in (rear panel) */
13916         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13917         /* port-D for Front */
13918         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13919         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13920         /* port-E for HP out (front panel) */
13921         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13922         /* route front PCM to HP */
13923         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13924         /* port-F for mic-in (front panel) with vref */
13925         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13926         /* port-G for CLFE (rear panel) */
13927         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13928         /* port-H for side (rear panel) */
13929         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13930         /* CD-in */
13931         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13932         /* route front mic to ADC1*/
13933         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13934         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13935         /* Unmute DAC0~3 & spdif out*/
13936         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13937         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13938         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13939         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13941
13942         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13943         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13944         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13945         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13946         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13947
13948         /* Unmute Stereo Mixer 15 */
13949         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13950         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13951         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13952         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13953
13954         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13955         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13956         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13957         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13958         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13959         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13960         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13961         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13962         /* hp used DAC 3 (Front) */
13963         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13964         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13965         { }
13966 };
13967
13968 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13969         /*
13970          * Unmute ADC0 and set the default input to mic-in
13971          */
13972         /* port-A for surround (rear panel) */
13973         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13974         /* port-B for mic-in (rear panel) with vref */
13975         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13976         /* port-C for line-in (rear panel) */
13977         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13978         /* port-D for Front */
13979         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13980         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13981         /* port-E for HP out (front panel) */
13982         /* this has to be set to VREF80 */
13983         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13984         /* route front PCM to HP */
13985         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13986         /* port-F for mic-in (front panel) with vref */
13987         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13988         /* port-G for CLFE (rear panel) */
13989         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13990         /* port-H for side (rear panel) */
13991         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13992         /* CD-in */
13993         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13994         /* route front mic to ADC1*/
13995         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13996         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13997         /* Unmute DAC0~3 & spdif out*/
13998         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13999         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14000         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14001         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14002         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14003
14004         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14005         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14006         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14007         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14008         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14009
14010         /* Unmute Stereo Mixer 15 */
14011         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14012         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14013         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14014         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14015
14016         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14017         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14018         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14019         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14020         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14021         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14022         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14023         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14024         /* hp used DAC 3 (Front) */
14025         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14026         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14027         { }
14028 };
14029
14030 static struct hda_verb alc861_asus_init_verbs[] = {
14031         /*
14032          * Unmute ADC0 and set the default input to mic-in
14033          */
14034         /* port-A for surround (rear panel)
14035          * according to codec#0 this is the HP jack
14036          */
14037         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14038         /* route front PCM to HP */
14039         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14040         /* port-B for mic-in (rear panel) with vref */
14041         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14042         /* port-C for line-in (rear panel) */
14043         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14044         /* port-D for Front */
14045         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14046         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14047         /* port-E for HP out (front panel) */
14048         /* this has to be set to VREF80 */
14049         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14050         /* route front PCM to HP */
14051         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14052         /* port-F for mic-in (front panel) with vref */
14053         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14054         /* port-G for CLFE (rear panel) */
14055         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14056         /* port-H for side (rear panel) */
14057         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14058         /* CD-in */
14059         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14060         /* route front mic to ADC1*/
14061         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14062         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14063         /* Unmute DAC0~3 & spdif out*/
14064         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14065         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14066         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14067         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14068         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14069         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14070         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14071         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14072         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14073         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14074
14075         /* Unmute Stereo Mixer 15 */
14076         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14077         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14078         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14079         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14080
14081         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14082         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14083         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14084         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14085         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14086         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14087         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14088         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14089         /* hp used DAC 3 (Front) */
14090         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14091         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14092         { }
14093 };
14094
14095 /* additional init verbs for ASUS laptops */
14096 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14097         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14098         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14099         { }
14100 };
14101
14102 /*
14103  * generic initialization of ADC, input mixers and output mixers
14104  */
14105 static struct hda_verb alc861_auto_init_verbs[] = {
14106         /*
14107          * Unmute ADC0 and set the default input to mic-in
14108          */
14109         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14110         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14111
14112         /* Unmute DAC0~3 & spdif out*/
14113         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14114         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14115         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14116         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14117         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14118
14119         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14120         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14121         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14122         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14123         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14124
14125         /* Unmute Stereo Mixer 15 */
14126         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14127         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14128         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14129         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14130
14131         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14132         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14133         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14134         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14135         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14136         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14137         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14138         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14139
14140         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14141         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14142         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14143         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14144         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14145         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14146         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14147         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14148
14149         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14150
14151         { }
14152 };
14153
14154 static struct hda_verb alc861_toshiba_init_verbs[] = {
14155         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14156
14157         { }
14158 };
14159
14160 /* toggle speaker-output according to the hp-jack state */
14161 static void alc861_toshiba_automute(struct hda_codec *codec)
14162 {
14163         unsigned int present;
14164
14165         present = snd_hda_codec_read(codec, 0x0f, 0,
14166                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14167         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14168                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14169         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14170                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14171 }
14172
14173 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14174                                        unsigned int res)
14175 {
14176         if ((res >> 26) == ALC880_HP_EVENT)
14177                 alc861_toshiba_automute(codec);
14178 }
14179
14180 /* pcm configuration: identical with ALC880 */
14181 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14182 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14183 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14184 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14185
14186
14187 #define ALC861_DIGOUT_NID       0x07
14188
14189 static struct hda_channel_mode alc861_8ch_modes[1] = {
14190         { 8, NULL }
14191 };
14192
14193 static hda_nid_t alc861_dac_nids[4] = {
14194         /* front, surround, clfe, side */
14195         0x03, 0x06, 0x05, 0x04
14196 };
14197
14198 static hda_nid_t alc660_dac_nids[3] = {
14199         /* front, clfe, surround */
14200         0x03, 0x05, 0x06
14201 };
14202
14203 static hda_nid_t alc861_adc_nids[1] = {
14204         /* ADC0-2 */
14205         0x08,
14206 };
14207
14208 static struct hda_input_mux alc861_capture_source = {
14209         .num_items = 5,
14210         .items = {
14211                 { "Mic", 0x0 },
14212                 { "Front Mic", 0x3 },
14213                 { "Line", 0x1 },
14214                 { "CD", 0x4 },
14215                 { "Mixer", 0x5 },
14216         },
14217 };
14218
14219 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
14220 {
14221         struct alc_spec *spec = codec->spec;
14222         hda_nid_t mix, srcs[5];
14223         int i, j, num;
14224
14225         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
14226                 return 0;
14227         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14228         if (num < 0)
14229                 return 0;
14230         for (i = 0; i < num; i++) {
14231                 unsigned int type;
14232                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14233                 if (type != AC_WID_AUD_OUT)
14234                         continue;
14235                 for (j = 0; j < spec->multiout.num_dacs; j++)
14236                         if (spec->multiout.dac_nids[j] == srcs[i])
14237                                 break;
14238                 if (j >= spec->multiout.num_dacs)
14239                         return srcs[i];
14240         }
14241         return 0;
14242 }
14243
14244 /* fill in the dac_nids table from the parsed pin configuration */
14245 static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14246                                      const struct auto_pin_cfg *cfg)
14247 {
14248         struct alc_spec *spec = codec->spec;
14249         int i;
14250         hda_nid_t nid, dac;
14251
14252         spec->multiout.dac_nids = spec->private_dac_nids;
14253         for (i = 0; i < cfg->line_outs; i++) {
14254                 nid = cfg->line_out_pins[i];
14255                 dac = alc861_look_for_dac(codec, nid);
14256                 if (!dac)
14257                         continue;
14258                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14259         }
14260         return 0;
14261 }
14262
14263 static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14264                                 hda_nid_t nid, unsigned int chs)
14265 {
14266         return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14267                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14268 }
14269
14270 /* add playback controls from the parsed DAC table */
14271 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14272                                              const struct auto_pin_cfg *cfg)
14273 {
14274         struct alc_spec *spec = codec->spec;
14275         static const char *chname[4] = {
14276                 "Front", "Surround", NULL /*CLFE*/, "Side"
14277         };
14278         hda_nid_t nid;
14279         int i, err;
14280
14281         if (cfg->line_outs == 1) {
14282                 const char *pfx = NULL;
14283                 if (!cfg->hp_outs)
14284                         pfx = "Master";
14285                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
14286                         pfx = "Speaker";
14287                 if (pfx) {
14288                         nid = spec->multiout.dac_nids[0];
14289                         return alc861_create_out_sw(codec, pfx, nid, 3);
14290                 }
14291         }
14292
14293         for (i = 0; i < cfg->line_outs; i++) {
14294                 nid = spec->multiout.dac_nids[i];
14295                 if (!nid)
14296                         continue;
14297                 if (i == 2) {
14298                         /* Center/LFE */
14299                         err = alc861_create_out_sw(codec, "Center", nid, 1);
14300                         if (err < 0)
14301                                 return err;
14302                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
14303                         if (err < 0)
14304                                 return err;
14305                 } else {
14306                         err = alc861_create_out_sw(codec, chname[i], nid, 3);
14307                         if (err < 0)
14308                                 return err;
14309                 }
14310         }
14311         return 0;
14312 }
14313
14314 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14315 {
14316         struct alc_spec *spec = codec->spec;
14317         int err;
14318         hda_nid_t nid;
14319
14320         if (!pin)
14321                 return 0;
14322
14323         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14324                 nid = alc861_look_for_dac(codec, pin);
14325                 if (nid) {
14326                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14327                         if (err < 0)
14328                                 return err;
14329                         spec->multiout.hp_nid = nid;
14330                 }
14331         }
14332         return 0;
14333 }
14334
14335 /* create playback/capture controls for input pins */
14336 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14337                                                 const struct auto_pin_cfg *cfg)
14338 {
14339         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14340 }
14341
14342 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14343                                               hda_nid_t nid,
14344                                               int pin_type, hda_nid_t dac)
14345 {
14346         hda_nid_t mix, srcs[5];
14347         int i, num;
14348
14349         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14350                             pin_type);
14351         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14352                             AMP_OUT_UNMUTE);
14353         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
14354                 return;
14355         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14356         if (num < 0)
14357                 return;
14358         for (i = 0; i < num; i++) {
14359                 unsigned int mute;
14360                 if (srcs[i] == dac || srcs[i] == 0x15)
14361                         mute = AMP_IN_UNMUTE(i);
14362                 else
14363                         mute = AMP_IN_MUTE(i);
14364                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14365                                     mute);
14366         }
14367 }
14368
14369 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14370 {
14371         struct alc_spec *spec = codec->spec;
14372         int i;
14373
14374         for (i = 0; i < spec->autocfg.line_outs; i++) {
14375                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14376                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14377                 if (nid)
14378                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14379                                                           spec->multiout.dac_nids[i]);
14380         }
14381 }
14382
14383 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14384 {
14385         struct alc_spec *spec = codec->spec;
14386
14387         if (spec->autocfg.hp_outs)
14388                 alc861_auto_set_output_and_unmute(codec,
14389                                                   spec->autocfg.hp_pins[0],
14390                                                   PIN_HP,
14391                                                   spec->multiout.hp_nid);
14392         if (spec->autocfg.speaker_outs)
14393                 alc861_auto_set_output_and_unmute(codec,
14394                                                   spec->autocfg.speaker_pins[0],
14395                                                   PIN_OUT,
14396                                                   spec->multiout.dac_nids[0]);
14397 }
14398
14399 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14400 {
14401         struct alc_spec *spec = codec->spec;
14402         int i;
14403
14404         for (i = 0; i < AUTO_PIN_LAST; i++) {
14405                 hda_nid_t nid = spec->autocfg.input_pins[i];
14406                 if (nid >= 0x0c && nid <= 0x11)
14407                         alc_set_input_pin(codec, nid, i);
14408         }
14409 }
14410
14411 /* parse the BIOS configuration and set up the alc_spec */
14412 /* return 1 if successful, 0 if the proper config is not found,
14413  * or a negative error code
14414  */
14415 static int alc861_parse_auto_config(struct hda_codec *codec)
14416 {
14417         struct alc_spec *spec = codec->spec;
14418         int err;
14419         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14420
14421         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14422                                            alc861_ignore);
14423         if (err < 0)
14424                 return err;
14425         if (!spec->autocfg.line_outs)
14426                 return 0; /* can't find valid BIOS pin config */
14427
14428         err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14429         if (err < 0)
14430                 return err;
14431         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14432         if (err < 0)
14433                 return err;
14434         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
14435         if (err < 0)
14436                 return err;
14437         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14438         if (err < 0)
14439                 return err;
14440
14441         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14442
14443         if (spec->autocfg.dig_outs)
14444                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14445
14446         if (spec->kctls.list)
14447                 add_mixer(spec, spec->kctls.list);
14448
14449         add_verb(spec, alc861_auto_init_verbs);
14450
14451         spec->num_mux_defs = 1;
14452         spec->input_mux = &spec->private_imux[0];
14453
14454         spec->adc_nids = alc861_adc_nids;
14455         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14456         set_capture_mixer(codec);
14457
14458         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14459
14460         return 1;
14461 }
14462
14463 /* additional initialization for auto-configuration model */
14464 static void alc861_auto_init(struct hda_codec *codec)
14465 {
14466         struct alc_spec *spec = codec->spec;
14467         alc861_auto_init_multi_out(codec);
14468         alc861_auto_init_hp_out(codec);
14469         alc861_auto_init_analog_input(codec);
14470         if (spec->unsol_event)
14471                 alc_inithook(codec);
14472 }
14473
14474 #ifdef CONFIG_SND_HDA_POWER_SAVE
14475 static struct hda_amp_list alc861_loopbacks[] = {
14476         { 0x15, HDA_INPUT, 0 },
14477         { 0x15, HDA_INPUT, 1 },
14478         { 0x15, HDA_INPUT, 2 },
14479         { 0x15, HDA_INPUT, 3 },
14480         { } /* end */
14481 };
14482 #endif
14483
14484
14485 /*
14486  * configuration and preset
14487  */
14488 static const char *alc861_models[ALC861_MODEL_LAST] = {
14489         [ALC861_3ST]            = "3stack",
14490         [ALC660_3ST]            = "3stack-660",
14491         [ALC861_3ST_DIG]        = "3stack-dig",
14492         [ALC861_6ST_DIG]        = "6stack-dig",
14493         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14494         [ALC861_TOSHIBA]        = "toshiba",
14495         [ALC861_ASUS]           = "asus",
14496         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14497         [ALC861_AUTO]           = "auto",
14498 };
14499
14500 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14501         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14502         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14503         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14504         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14505         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14506         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14507         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14508         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14509          *        Any other models that need this preset?
14510          */
14511         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14512         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14513         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14514         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14515         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14516         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14517         /* FIXME: the below seems conflict */
14518         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14519         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14520         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14521         {}
14522 };
14523
14524 static struct alc_config_preset alc861_presets[] = {
14525         [ALC861_3ST] = {
14526                 .mixers = { alc861_3ST_mixer },
14527                 .init_verbs = { alc861_threestack_init_verbs },
14528                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14529                 .dac_nids = alc861_dac_nids,
14530                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14531                 .channel_mode = alc861_threestack_modes,
14532                 .need_dac_fix = 1,
14533                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14534                 .adc_nids = alc861_adc_nids,
14535                 .input_mux = &alc861_capture_source,
14536         },
14537         [ALC861_3ST_DIG] = {
14538                 .mixers = { alc861_base_mixer },
14539                 .init_verbs = { alc861_threestack_init_verbs },
14540                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14541                 .dac_nids = alc861_dac_nids,
14542                 .dig_out_nid = ALC861_DIGOUT_NID,
14543                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14544                 .channel_mode = alc861_threestack_modes,
14545                 .need_dac_fix = 1,
14546                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14547                 .adc_nids = alc861_adc_nids,
14548                 .input_mux = &alc861_capture_source,
14549         },
14550         [ALC861_6ST_DIG] = {
14551                 .mixers = { alc861_base_mixer },
14552                 .init_verbs = { alc861_base_init_verbs },
14553                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14554                 .dac_nids = alc861_dac_nids,
14555                 .dig_out_nid = ALC861_DIGOUT_NID,
14556                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14557                 .channel_mode = alc861_8ch_modes,
14558                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14559                 .adc_nids = alc861_adc_nids,
14560                 .input_mux = &alc861_capture_source,
14561         },
14562         [ALC660_3ST] = {
14563                 .mixers = { alc861_3ST_mixer },
14564                 .init_verbs = { alc861_threestack_init_verbs },
14565                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14566                 .dac_nids = alc660_dac_nids,
14567                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14568                 .channel_mode = alc861_threestack_modes,
14569                 .need_dac_fix = 1,
14570                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14571                 .adc_nids = alc861_adc_nids,
14572                 .input_mux = &alc861_capture_source,
14573         },
14574         [ALC861_UNIWILL_M31] = {
14575                 .mixers = { alc861_uniwill_m31_mixer },
14576                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14577                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14578                 .dac_nids = alc861_dac_nids,
14579                 .dig_out_nid = ALC861_DIGOUT_NID,
14580                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14581                 .channel_mode = alc861_uniwill_m31_modes,
14582                 .need_dac_fix = 1,
14583                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14584                 .adc_nids = alc861_adc_nids,
14585                 .input_mux = &alc861_capture_source,
14586         },
14587         [ALC861_TOSHIBA] = {
14588                 .mixers = { alc861_toshiba_mixer },
14589                 .init_verbs = { alc861_base_init_verbs,
14590                                 alc861_toshiba_init_verbs },
14591                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14592                 .dac_nids = alc861_dac_nids,
14593                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14594                 .channel_mode = alc883_3ST_2ch_modes,
14595                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14596                 .adc_nids = alc861_adc_nids,
14597                 .input_mux = &alc861_capture_source,
14598                 .unsol_event = alc861_toshiba_unsol_event,
14599                 .init_hook = alc861_toshiba_automute,
14600         },
14601         [ALC861_ASUS] = {
14602                 .mixers = { alc861_asus_mixer },
14603                 .init_verbs = { alc861_asus_init_verbs },
14604                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14605                 .dac_nids = alc861_dac_nids,
14606                 .dig_out_nid = ALC861_DIGOUT_NID,
14607                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14608                 .channel_mode = alc861_asus_modes,
14609                 .need_dac_fix = 1,
14610                 .hp_nid = 0x06,
14611                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14612                 .adc_nids = alc861_adc_nids,
14613                 .input_mux = &alc861_capture_source,
14614         },
14615         [ALC861_ASUS_LAPTOP] = {
14616                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14617                 .init_verbs = { alc861_asus_init_verbs,
14618                                 alc861_asus_laptop_init_verbs },
14619                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14620                 .dac_nids = alc861_dac_nids,
14621                 .dig_out_nid = ALC861_DIGOUT_NID,
14622                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14623                 .channel_mode = alc883_3ST_2ch_modes,
14624                 .need_dac_fix = 1,
14625                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14626                 .adc_nids = alc861_adc_nids,
14627                 .input_mux = &alc861_capture_source,
14628         },
14629 };
14630
14631
14632 static int patch_alc861(struct hda_codec *codec)
14633 {
14634         struct alc_spec *spec;
14635         int board_config;
14636         int err;
14637
14638         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14639         if (spec == NULL)
14640                 return -ENOMEM;
14641
14642         codec->spec = spec;
14643
14644         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14645                                                   alc861_models,
14646                                                   alc861_cfg_tbl);
14647
14648         if (board_config < 0) {
14649                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14650                        codec->chip_name);
14651                 board_config = ALC861_AUTO;
14652         }
14653
14654         if (board_config == ALC861_AUTO) {
14655                 /* automatic parse from the BIOS config */
14656                 err = alc861_parse_auto_config(codec);
14657                 if (err < 0) {
14658                         alc_free(codec);
14659                         return err;
14660                 } else if (!err) {
14661                         printk(KERN_INFO
14662                                "hda_codec: Cannot set up configuration "
14663                                "from BIOS.  Using base mode...\n");
14664                    board_config = ALC861_3ST_DIG;
14665                 }
14666         }
14667
14668         err = snd_hda_attach_beep_device(codec, 0x23);
14669         if (err < 0) {
14670                 alc_free(codec);
14671                 return err;
14672         }
14673
14674         if (board_config != ALC861_AUTO)
14675                 setup_preset(codec, &alc861_presets[board_config]);
14676
14677         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14678         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14679
14680         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14681         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14682
14683         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14684
14685         spec->vmaster_nid = 0x03;
14686
14687         codec->patch_ops = alc_patch_ops;
14688         if (board_config == ALC861_AUTO)
14689                 spec->init_hook = alc861_auto_init;
14690 #ifdef CONFIG_SND_HDA_POWER_SAVE
14691         if (!spec->loopback.amplist)
14692                 spec->loopback.amplist = alc861_loopbacks;
14693 #endif
14694         codec->proc_widget_hook = print_realtek_coef;
14695
14696         return 0;
14697 }
14698
14699 /*
14700  * ALC861-VD support
14701  *
14702  * Based on ALC882
14703  *
14704  * In addition, an independent DAC
14705  */
14706 #define ALC861VD_DIGOUT_NID     0x06
14707
14708 static hda_nid_t alc861vd_dac_nids[4] = {
14709         /* front, surr, clfe, side surr */
14710         0x02, 0x03, 0x04, 0x05
14711 };
14712
14713 /* dac_nids for ALC660vd are in a different order - according to
14714  * Realtek's driver.
14715  * This should probably result in a different mixer for 6stack models
14716  * of ALC660vd codecs, but for now there is only 3stack mixer
14717  * - and it is the same as in 861vd.
14718  * adc_nids in ALC660vd are (is) the same as in 861vd
14719  */
14720 static hda_nid_t alc660vd_dac_nids[3] = {
14721         /* front, rear, clfe, rear_surr */
14722         0x02, 0x04, 0x03
14723 };
14724
14725 static hda_nid_t alc861vd_adc_nids[1] = {
14726         /* ADC0 */
14727         0x09,
14728 };
14729
14730 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14731
14732 /* input MUX */
14733 /* FIXME: should be a matrix-type input source selection */
14734 static struct hda_input_mux alc861vd_capture_source = {
14735         .num_items = 4,
14736         .items = {
14737                 { "Mic", 0x0 },
14738                 { "Front Mic", 0x1 },
14739                 { "Line", 0x2 },
14740                 { "CD", 0x4 },
14741         },
14742 };
14743
14744 static struct hda_input_mux alc861vd_dallas_capture_source = {
14745         .num_items = 2,
14746         .items = {
14747                 { "Ext Mic", 0x0 },
14748                 { "Int Mic", 0x1 },
14749         },
14750 };
14751
14752 static struct hda_input_mux alc861vd_hp_capture_source = {
14753         .num_items = 2,
14754         .items = {
14755                 { "Front Mic", 0x0 },
14756                 { "ATAPI Mic", 0x1 },
14757         },
14758 };
14759
14760 /*
14761  * 2ch mode
14762  */
14763 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14764         { 2, NULL }
14765 };
14766
14767 /*
14768  * 6ch mode
14769  */
14770 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14771         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14772         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14773         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14774         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14775         { } /* end */
14776 };
14777
14778 /*
14779  * 8ch mode
14780  */
14781 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14782         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14783         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14784         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14785         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14786         { } /* end */
14787 };
14788
14789 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14790         { 6, alc861vd_6stack_ch6_init },
14791         { 8, alc861vd_6stack_ch8_init },
14792 };
14793
14794 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14795         {
14796                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14797                 .name = "Channel Mode",
14798                 .info = alc_ch_mode_info,
14799                 .get = alc_ch_mode_get,
14800                 .put = alc_ch_mode_put,
14801         },
14802         { } /* end */
14803 };
14804
14805 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14806  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14807  */
14808 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14809         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14810         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14811
14812         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14813         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14814
14815         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14816                                 HDA_OUTPUT),
14817         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14818                                 HDA_OUTPUT),
14819         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14820         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14821
14822         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14823         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14824
14825         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14826
14827         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14828         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14829         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14830
14831         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14832         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14833         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14834
14835         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14836         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14837
14838         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14839         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14840
14841         { } /* end */
14842 };
14843
14844 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14845         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14846         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14847
14848         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14849
14850         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14851         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14852         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14853
14854         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14855         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14856         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14857
14858         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14859         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14860
14861         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14862         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14863
14864         { } /* end */
14865 };
14866
14867 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14868         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14869         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14870         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14871
14872         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14873
14874         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14875         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14876         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14877
14878         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14879         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14880         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14881
14882         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14883         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14884
14885         { } /* end */
14886 };
14887
14888 /* Pin assignment: Speaker=0x14, HP = 0x15,
14889  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14890  */
14891 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14892         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14893         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14894         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14895         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14896         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14897         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14898         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14899         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14900         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14901         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14902         { } /* end */
14903 };
14904
14905 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14906  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14907  */
14908 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14909         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14910         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14911         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14912         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14913         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14914         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14915         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14916         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14917
14918         { } /* end */
14919 };
14920
14921 /*
14922  * generic initialization of ADC, input mixers and output mixers
14923  */
14924 static struct hda_verb alc861vd_volume_init_verbs[] = {
14925         /*
14926          * Unmute ADC0 and set the default input to mic-in
14927          */
14928         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14929         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14930
14931         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14932          * the analog-loopback mixer widget
14933          */
14934         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14935         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14936         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14937         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14938         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14939         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14940
14941         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14942         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14943         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14944         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14945         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14946
14947         /*
14948          * Set up output mixers (0x02 - 0x05)
14949          */
14950         /* set vol=0 to output mixers */
14951         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14952         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14953         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14954         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14955
14956         /* set up input amps for analog loopback */
14957         /* Amp Indices: DAC = 0, mixer = 1 */
14958         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14959         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14960         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14961         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14962         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14963         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14964         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14965         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14966
14967         { }
14968 };
14969
14970 /*
14971  * 3-stack pin configuration:
14972  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14973  */
14974 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14975         /*
14976          * Set pin mode and muting
14977          */
14978         /* set front pin widgets 0x14 for output */
14979         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14980         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14981         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14982
14983         /* Mic (rear) pin: input vref at 80% */
14984         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14985         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14986         /* Front Mic pin: input vref at 80% */
14987         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14988         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14989         /* Line In pin: input */
14990         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14991         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14992         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14993         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14994         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14995         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14996         /* CD pin widget for input */
14997         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14998
14999         { }
15000 };
15001
15002 /*
15003  * 6-stack pin configuration:
15004  */
15005 static struct hda_verb alc861vd_6stack_init_verbs[] = {
15006         /*
15007          * Set pin mode and muting
15008          */
15009         /* set front pin widgets 0x14 for output */
15010         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15011         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15012         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
15013
15014         /* Rear Pin: output 1 (0x0d) */
15015         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15016         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15017         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
15018         /* CLFE Pin: output 2 (0x0e) */
15019         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15020         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15021         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
15022         /* Side Pin: output 3 (0x0f) */
15023         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15024         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15025         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
15026
15027         /* Mic (rear) pin: input vref at 80% */
15028         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15029         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15030         /* Front Mic pin: input vref at 80% */
15031         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15032         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15033         /* Line In pin: input */
15034         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15035         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15036         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15037         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15038         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15039         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15040         /* CD pin widget for input */
15041         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15042
15043         { }
15044 };
15045
15046 static struct hda_verb alc861vd_eapd_verbs[] = {
15047         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15048         { }
15049 };
15050
15051 static struct hda_verb alc660vd_eapd_verbs[] = {
15052         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15053         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15054         { }
15055 };
15056
15057 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15058         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15059         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15060         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15061         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15062         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15063         {}
15064 };
15065
15066 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15067 {
15068         unsigned int present;
15069         unsigned char bits;
15070
15071         present = snd_hda_codec_read(codec, 0x18, 0,
15072                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15073         bits = present ? HDA_AMP_MUTE : 0;
15074         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15075                                  HDA_AMP_MUTE, bits);
15076 }
15077
15078 static void alc861vd_lenovo_setup(struct hda_codec *codec)
15079 {
15080         struct alc_spec *spec = codec->spec;
15081         spec->autocfg.hp_pins[0] = 0x1b;
15082         spec->autocfg.speaker_pins[0] = 0x14;
15083 }
15084
15085 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15086 {
15087         alc_automute_amp(codec);
15088         alc861vd_lenovo_mic_automute(codec);
15089 }
15090
15091 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15092                                         unsigned int res)
15093 {
15094         switch (res >> 26) {
15095         case ALC880_MIC_EVENT:
15096                 alc861vd_lenovo_mic_automute(codec);
15097                 break;
15098         default:
15099                 alc_automute_amp_unsol_event(codec, res);
15100                 break;
15101         }
15102 }
15103
15104 static struct hda_verb alc861vd_dallas_verbs[] = {
15105         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15106         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15107         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15108         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15109
15110         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15111         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15112         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15113         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15114         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15115         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15116         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15117         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15118
15119         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15120         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15121         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15122         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15123         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15124         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15125         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15126         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15127
15128         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15129         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15130         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15131         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15132         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15133         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15134         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15135         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15136
15137         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15138         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15139         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15140         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15141
15142         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15143         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15144         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15145
15146         { } /* end */
15147 };
15148
15149 /* toggle speaker-output according to the hp-jack state */
15150 static void alc861vd_dallas_setup(struct hda_codec *codec)
15151 {
15152         struct alc_spec *spec = codec->spec;
15153
15154         spec->autocfg.hp_pins[0] = 0x15;
15155         spec->autocfg.speaker_pins[0] = 0x14;
15156 }
15157
15158 #ifdef CONFIG_SND_HDA_POWER_SAVE
15159 #define alc861vd_loopbacks      alc880_loopbacks
15160 #endif
15161
15162 /* pcm configuration: identical with ALC880 */
15163 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15164 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15165 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15166 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15167
15168 /*
15169  * configuration and preset
15170  */
15171 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15172         [ALC660VD_3ST]          = "3stack-660",
15173         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15174         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15175         [ALC861VD_3ST]          = "3stack",
15176         [ALC861VD_3ST_DIG]      = "3stack-digout",
15177         [ALC861VD_6ST_DIG]      = "6stack-digout",
15178         [ALC861VD_LENOVO]       = "lenovo",
15179         [ALC861VD_DALLAS]       = "dallas",
15180         [ALC861VD_HP]           = "hp",
15181         [ALC861VD_AUTO]         = "auto",
15182 };
15183
15184 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15185         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15186         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15187         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15188         /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
15189         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15190         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15191         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15192         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15193         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15194         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15195         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15196         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15197         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15198         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15199         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15200         {}
15201 };
15202
15203 static struct alc_config_preset alc861vd_presets[] = {
15204         [ALC660VD_3ST] = {
15205                 .mixers = { alc861vd_3st_mixer },
15206                 .init_verbs = { alc861vd_volume_init_verbs,
15207                                  alc861vd_3stack_init_verbs },
15208                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15209                 .dac_nids = alc660vd_dac_nids,
15210                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15211                 .channel_mode = alc861vd_3stack_2ch_modes,
15212                 .input_mux = &alc861vd_capture_source,
15213         },
15214         [ALC660VD_3ST_DIG] = {
15215                 .mixers = { alc861vd_3st_mixer },
15216                 .init_verbs = { alc861vd_volume_init_verbs,
15217                                  alc861vd_3stack_init_verbs },
15218                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15219                 .dac_nids = alc660vd_dac_nids,
15220                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15221                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15222                 .channel_mode = alc861vd_3stack_2ch_modes,
15223                 .input_mux = &alc861vd_capture_source,
15224         },
15225         [ALC861VD_3ST] = {
15226                 .mixers = { alc861vd_3st_mixer },
15227                 .init_verbs = { alc861vd_volume_init_verbs,
15228                                  alc861vd_3stack_init_verbs },
15229                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15230                 .dac_nids = alc861vd_dac_nids,
15231                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15232                 .channel_mode = alc861vd_3stack_2ch_modes,
15233                 .input_mux = &alc861vd_capture_source,
15234         },
15235         [ALC861VD_3ST_DIG] = {
15236                 .mixers = { alc861vd_3st_mixer },
15237                 .init_verbs = { alc861vd_volume_init_verbs,
15238                                  alc861vd_3stack_init_verbs },
15239                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15240                 .dac_nids = alc861vd_dac_nids,
15241                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15242                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15243                 .channel_mode = alc861vd_3stack_2ch_modes,
15244                 .input_mux = &alc861vd_capture_source,
15245         },
15246         [ALC861VD_6ST_DIG] = {
15247                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15248                 .init_verbs = { alc861vd_volume_init_verbs,
15249                                 alc861vd_6stack_init_verbs },
15250                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15251                 .dac_nids = alc861vd_dac_nids,
15252                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15253                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15254                 .channel_mode = alc861vd_6stack_modes,
15255                 .input_mux = &alc861vd_capture_source,
15256         },
15257         [ALC861VD_LENOVO] = {
15258                 .mixers = { alc861vd_lenovo_mixer },
15259                 .init_verbs = { alc861vd_volume_init_verbs,
15260                                 alc861vd_3stack_init_verbs,
15261                                 alc861vd_eapd_verbs,
15262                                 alc861vd_lenovo_unsol_verbs },
15263                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15264                 .dac_nids = alc660vd_dac_nids,
15265                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15266                 .channel_mode = alc861vd_3stack_2ch_modes,
15267                 .input_mux = &alc861vd_capture_source,
15268                 .unsol_event = alc861vd_lenovo_unsol_event,
15269                 .setup = alc861vd_lenovo_setup,
15270                 .init_hook = alc861vd_lenovo_init_hook,
15271         },
15272         [ALC861VD_DALLAS] = {
15273                 .mixers = { alc861vd_dallas_mixer },
15274                 .init_verbs = { alc861vd_dallas_verbs },
15275                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15276                 .dac_nids = alc861vd_dac_nids,
15277                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15278                 .channel_mode = alc861vd_3stack_2ch_modes,
15279                 .input_mux = &alc861vd_dallas_capture_source,
15280                 .unsol_event = alc_automute_amp_unsol_event,
15281                 .setup = alc861vd_dallas_setup,
15282                 .init_hook = alc_automute_amp,
15283         },
15284         [ALC861VD_HP] = {
15285                 .mixers = { alc861vd_hp_mixer },
15286                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15287                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15288                 .dac_nids = alc861vd_dac_nids,
15289                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15290                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15291                 .channel_mode = alc861vd_3stack_2ch_modes,
15292                 .input_mux = &alc861vd_hp_capture_source,
15293                 .unsol_event = alc_automute_amp_unsol_event,
15294                 .setup = alc861vd_dallas_setup,
15295                 .init_hook = alc_automute_amp,
15296         },
15297         [ALC660VD_ASUS_V1S] = {
15298                 .mixers = { alc861vd_lenovo_mixer },
15299                 .init_verbs = { alc861vd_volume_init_verbs,
15300                                 alc861vd_3stack_init_verbs,
15301                                 alc861vd_eapd_verbs,
15302                                 alc861vd_lenovo_unsol_verbs },
15303                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15304                 .dac_nids = alc660vd_dac_nids,
15305                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15306                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15307                 .channel_mode = alc861vd_3stack_2ch_modes,
15308                 .input_mux = &alc861vd_capture_source,
15309                 .unsol_event = alc861vd_lenovo_unsol_event,
15310                 .setup = alc861vd_lenovo_setup,
15311                 .init_hook = alc861vd_lenovo_init_hook,
15312         },
15313 };
15314
15315 /*
15316  * BIOS auto configuration
15317  */
15318 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
15319                                                 const struct auto_pin_cfg *cfg)
15320 {
15321         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
15322 }
15323
15324
15325 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15326                                 hda_nid_t nid, int pin_type, int dac_idx)
15327 {
15328         alc_set_pin_output(codec, nid, pin_type);
15329 }
15330
15331 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15332 {
15333         struct alc_spec *spec = codec->spec;
15334         int i;
15335
15336         for (i = 0; i <= HDA_SIDE; i++) {
15337                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15338                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15339                 if (nid)
15340                         alc861vd_auto_set_output_and_unmute(codec, nid,
15341                                                             pin_type, i);
15342         }
15343 }
15344
15345
15346 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15347 {
15348         struct alc_spec *spec = codec->spec;
15349         hda_nid_t pin;
15350
15351         pin = spec->autocfg.hp_pins[0];
15352         if (pin) /* connect to front and use dac 0 */
15353                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15354         pin = spec->autocfg.speaker_pins[0];
15355         if (pin)
15356                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15357 }
15358
15359 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15360
15361 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15362 {
15363         struct alc_spec *spec = codec->spec;
15364         int i;
15365
15366         for (i = 0; i < AUTO_PIN_LAST; i++) {
15367                 hda_nid_t nid = spec->autocfg.input_pins[i];
15368                 if (alc_is_input_pin(codec, nid)) {
15369                         alc_set_input_pin(codec, nid, i);
15370                         if (nid != ALC861VD_PIN_CD_NID &&
15371                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15372                                 snd_hda_codec_write(codec, nid, 0,
15373                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15374                                                 AMP_OUT_MUTE);
15375                 }
15376         }
15377 }
15378
15379 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15380
15381 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15382 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15383
15384 /* add playback controls from the parsed DAC table */
15385 /* Based on ALC880 version. But ALC861VD has separate,
15386  * different NIDs for mute/unmute switch and volume control */
15387 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15388                                              const struct auto_pin_cfg *cfg)
15389 {
15390         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15391         hda_nid_t nid_v, nid_s;
15392         int i, err;
15393
15394         for (i = 0; i < cfg->line_outs; i++) {
15395                 if (!spec->multiout.dac_nids[i])
15396                         continue;
15397                 nid_v = alc861vd_idx_to_mixer_vol(
15398                                 alc880_dac_to_idx(
15399                                         spec->multiout.dac_nids[i]));
15400                 nid_s = alc861vd_idx_to_mixer_switch(
15401                                 alc880_dac_to_idx(
15402                                         spec->multiout.dac_nids[i]));
15403
15404                 if (i == 2) {
15405                         /* Center/LFE */
15406                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15407                                               "Center",
15408                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15409                                                               HDA_OUTPUT));
15410                         if (err < 0)
15411                                 return err;
15412                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15413                                               "LFE",
15414                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15415                                                               HDA_OUTPUT));
15416                         if (err < 0)
15417                                 return err;
15418                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15419                                              "Center",
15420                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15421                                                               HDA_INPUT));
15422                         if (err < 0)
15423                                 return err;
15424                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15425                                              "LFE",
15426                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15427                                                               HDA_INPUT));
15428                         if (err < 0)
15429                                 return err;
15430                 } else {
15431                         const char *pfx;
15432                         if (cfg->line_outs == 1 &&
15433                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
15434                                 if (!cfg->hp_pins)
15435                                         pfx = "Speaker";
15436                                 else
15437                                         pfx = "PCM";
15438                         } else
15439                                 pfx = chname[i];
15440                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15441                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15442                                                               HDA_OUTPUT));
15443                         if (err < 0)
15444                                 return err;
15445                         if (cfg->line_outs == 1 &&
15446                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15447                                 pfx = "Speaker";
15448                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15449                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15450                                                               HDA_INPUT));
15451                         if (err < 0)
15452                                 return err;
15453                 }
15454         }
15455         return 0;
15456 }
15457
15458 /* add playback controls for speaker and HP outputs */
15459 /* Based on ALC880 version. But ALC861VD has separate,
15460  * different NIDs for mute/unmute switch and volume control */
15461 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15462                                         hda_nid_t pin, const char *pfx)
15463 {
15464         hda_nid_t nid_v, nid_s;
15465         int err;
15466
15467         if (!pin)
15468                 return 0;
15469
15470         if (alc880_is_fixed_pin(pin)) {
15471                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15472                 /* specify the DAC as the extra output */
15473                 if (!spec->multiout.hp_nid)
15474                         spec->multiout.hp_nid = nid_v;
15475                 else
15476                         spec->multiout.extra_out_nid[0] = nid_v;
15477                 /* control HP volume/switch on the output mixer amp */
15478                 nid_v = alc861vd_idx_to_mixer_vol(
15479                                 alc880_fixed_pin_idx(pin));
15480                 nid_s = alc861vd_idx_to_mixer_switch(
15481                                 alc880_fixed_pin_idx(pin));
15482
15483                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15484                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15485                 if (err < 0)
15486                         return err;
15487                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15488                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15489                 if (err < 0)
15490                         return err;
15491         } else if (alc880_is_multi_pin(pin)) {
15492                 /* set manual connection */
15493                 /* we have only a switch on HP-out PIN */
15494                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15495                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15496                 if (err < 0)
15497                         return err;
15498         }
15499         return 0;
15500 }
15501
15502 /* parse the BIOS configuration and set up the alc_spec
15503  * return 1 if successful, 0 if the proper config is not found,
15504  * or a negative error code
15505  * Based on ALC880 version - had to change it to override
15506  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15507 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15508 {
15509         struct alc_spec *spec = codec->spec;
15510         int err;
15511         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15512
15513         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15514                                            alc861vd_ignore);
15515         if (err < 0)
15516                 return err;
15517         if (!spec->autocfg.line_outs)
15518                 return 0; /* can't find valid BIOS pin config */
15519
15520         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15521         if (err < 0)
15522                 return err;
15523         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15524         if (err < 0)
15525                 return err;
15526         err = alc861vd_auto_create_extra_out(spec,
15527                                              spec->autocfg.speaker_pins[0],
15528                                              "Speaker");
15529         if (err < 0)
15530                 return err;
15531         err = alc861vd_auto_create_extra_out(spec,
15532                                              spec->autocfg.hp_pins[0],
15533                                              "Headphone");
15534         if (err < 0)
15535                 return err;
15536         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15537         if (err < 0)
15538                 return err;
15539
15540         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15541
15542         if (spec->autocfg.dig_outs)
15543                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15544
15545         if (spec->kctls.list)
15546                 add_mixer(spec, spec->kctls.list);
15547
15548         add_verb(spec, alc861vd_volume_init_verbs);
15549
15550         spec->num_mux_defs = 1;
15551         spec->input_mux = &spec->private_imux[0];
15552
15553         err = alc_auto_add_mic_boost(codec);
15554         if (err < 0)
15555                 return err;
15556
15557         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15558
15559         return 1;
15560 }
15561
15562 /* additional initialization for auto-configuration model */
15563 static void alc861vd_auto_init(struct hda_codec *codec)
15564 {
15565         struct alc_spec *spec = codec->spec;
15566         alc861vd_auto_init_multi_out(codec);
15567         alc861vd_auto_init_hp_out(codec);
15568         alc861vd_auto_init_analog_input(codec);
15569         alc861vd_auto_init_input_src(codec);
15570         if (spec->unsol_event)
15571                 alc_inithook(codec);
15572 }
15573
15574 enum {
15575         ALC660VD_FIX_ASUS_GPIO1
15576 };
15577
15578 /* reset GPIO1 */
15579 static const struct hda_verb alc660vd_fix_asus_gpio1_verbs[] = {
15580         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
15581         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
15582         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
15583         { }
15584 };
15585
15586 static const struct alc_fixup alc861vd_fixups[] = {
15587         [ALC660VD_FIX_ASUS_GPIO1] = {
15588                 .verbs = alc660vd_fix_asus_gpio1_verbs,
15589         },
15590 };
15591
15592 static struct snd_pci_quirk alc861vd_fixup_tbl[] = {
15593         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
15594         {}
15595 };
15596
15597 static int patch_alc861vd(struct hda_codec *codec)
15598 {
15599         struct alc_spec *spec;
15600         int err, board_config;
15601
15602         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15603         if (spec == NULL)
15604                 return -ENOMEM;
15605
15606         codec->spec = spec;
15607
15608         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15609                                                   alc861vd_models,
15610                                                   alc861vd_cfg_tbl);
15611
15612         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15613                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15614                        codec->chip_name);
15615                 board_config = ALC861VD_AUTO;
15616         }
15617
15618         alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups);
15619
15620         if (board_config == ALC861VD_AUTO) {
15621                 /* automatic parse from the BIOS config */
15622                 err = alc861vd_parse_auto_config(codec);
15623                 if (err < 0) {
15624                         alc_free(codec);
15625                         return err;
15626                 } else if (!err) {
15627                         printk(KERN_INFO
15628                                "hda_codec: Cannot set up configuration "
15629                                "from BIOS.  Using base mode...\n");
15630                         board_config = ALC861VD_3ST;
15631                 }
15632         }
15633
15634         err = snd_hda_attach_beep_device(codec, 0x23);
15635         if (err < 0) {
15636                 alc_free(codec);
15637                 return err;
15638         }
15639
15640         if (board_config != ALC861VD_AUTO)
15641                 setup_preset(codec, &alc861vd_presets[board_config]);
15642
15643         if (codec->vendor_id == 0x10ec0660) {
15644                 /* always turn on EAPD */
15645                 add_verb(spec, alc660vd_eapd_verbs);
15646         }
15647
15648         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15649         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15650
15651         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15652         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15653
15654         if (!spec->adc_nids) {
15655                 spec->adc_nids = alc861vd_adc_nids;
15656                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15657         }
15658         if (!spec->capsrc_nids)
15659                 spec->capsrc_nids = alc861vd_capsrc_nids;
15660
15661         set_capture_mixer(codec);
15662         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15663
15664         spec->vmaster_nid = 0x02;
15665
15666         codec->patch_ops = alc_patch_ops;
15667
15668         if (board_config == ALC861VD_AUTO)
15669                 spec->init_hook = alc861vd_auto_init;
15670 #ifdef CONFIG_SND_HDA_POWER_SAVE
15671         if (!spec->loopback.amplist)
15672                 spec->loopback.amplist = alc861vd_loopbacks;
15673 #endif
15674         codec->proc_widget_hook = print_realtek_coef;
15675
15676         return 0;
15677 }
15678
15679 /*
15680  * ALC662 support
15681  *
15682  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15683  * configuration.  Each pin widget can choose any input DACs and a mixer.
15684  * Each ADC is connected from a mixer of all inputs.  This makes possible
15685  * 6-channel independent captures.
15686  *
15687  * In addition, an independent DAC for the multi-playback (not used in this
15688  * driver yet).
15689  */
15690 #define ALC662_DIGOUT_NID       0x06
15691 #define ALC662_DIGIN_NID        0x0a
15692
15693 static hda_nid_t alc662_dac_nids[4] = {
15694         /* front, rear, clfe, rear_surr */
15695         0x02, 0x03, 0x04
15696 };
15697
15698 static hda_nid_t alc272_dac_nids[2] = {
15699         0x02, 0x03
15700 };
15701
15702 static hda_nid_t alc662_adc_nids[2] = {
15703         /* ADC1-2 */
15704         0x09, 0x08
15705 };
15706
15707 static hda_nid_t alc272_adc_nids[1] = {
15708         /* ADC1-2 */
15709         0x08,
15710 };
15711
15712 static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15713 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15714
15715
15716 /* input MUX */
15717 /* FIXME: should be a matrix-type input source selection */
15718 static struct hda_input_mux alc662_capture_source = {
15719         .num_items = 4,
15720         .items = {
15721                 { "Mic", 0x0 },
15722                 { "Front Mic", 0x1 },
15723                 { "Line", 0x2 },
15724                 { "CD", 0x4 },
15725         },
15726 };
15727
15728 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15729         .num_items = 2,
15730         .items = {
15731                 { "Mic", 0x1 },
15732                 { "Line", 0x2 },
15733         },
15734 };
15735
15736 static struct hda_input_mux alc663_capture_source = {
15737         .num_items = 3,
15738         .items = {
15739                 { "Mic", 0x0 },
15740                 { "Front Mic", 0x1 },
15741                 { "Line", 0x2 },
15742         },
15743 };
15744
15745 #if 0 /* set to 1 for testing other input sources below */
15746 static struct hda_input_mux alc272_nc10_capture_source = {
15747         .num_items = 16,
15748         .items = {
15749                 { "Autoselect Mic", 0x0 },
15750                 { "Internal Mic", 0x1 },
15751                 { "In-0x02", 0x2 },
15752                 { "In-0x03", 0x3 },
15753                 { "In-0x04", 0x4 },
15754                 { "In-0x05", 0x5 },
15755                 { "In-0x06", 0x6 },
15756                 { "In-0x07", 0x7 },
15757                 { "In-0x08", 0x8 },
15758                 { "In-0x09", 0x9 },
15759                 { "In-0x0a", 0x0a },
15760                 { "In-0x0b", 0x0b },
15761                 { "In-0x0c", 0x0c },
15762                 { "In-0x0d", 0x0d },
15763                 { "In-0x0e", 0x0e },
15764                 { "In-0x0f", 0x0f },
15765         },
15766 };
15767 #endif
15768
15769 /*
15770  * 2ch mode
15771  */
15772 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15773         { 2, NULL }
15774 };
15775
15776 /*
15777  * 2ch mode
15778  */
15779 static struct hda_verb alc662_3ST_ch2_init[] = {
15780         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15781         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15782         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15783         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15784         { } /* end */
15785 };
15786
15787 /*
15788  * 6ch mode
15789  */
15790 static struct hda_verb alc662_3ST_ch6_init[] = {
15791         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15792         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15793         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15794         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15795         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15796         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15797         { } /* end */
15798 };
15799
15800 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15801         { 2, alc662_3ST_ch2_init },
15802         { 6, alc662_3ST_ch6_init },
15803 };
15804
15805 /*
15806  * 2ch mode
15807  */
15808 static struct hda_verb alc662_sixstack_ch6_init[] = {
15809         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15810         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15811         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15812         { } /* end */
15813 };
15814
15815 /*
15816  * 6ch mode
15817  */
15818 static struct hda_verb alc662_sixstack_ch8_init[] = {
15819         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15820         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15821         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15822         { } /* end */
15823 };
15824
15825 static struct hda_channel_mode alc662_5stack_modes[2] = {
15826         { 2, alc662_sixstack_ch6_init },
15827         { 6, alc662_sixstack_ch8_init },
15828 };
15829
15830 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15831  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15832  */
15833
15834 static struct snd_kcontrol_new alc662_base_mixer[] = {
15835         /* output mixer control */
15836         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15837         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15838         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15839         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15840         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15841         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15842         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15843         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15844         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15845
15846         /*Input mixer control */
15847         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15848         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15849         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15850         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15851         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15852         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15853         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15854         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15855         { } /* end */
15856 };
15857
15858 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15859         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15860         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15861         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15862         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15863         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15864         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15865         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15866         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15867         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15868         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15869         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15870         { } /* end */
15871 };
15872
15873 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15874         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15875         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15876         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15877         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15878         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15879         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15880         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15881         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15882         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15883         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15884         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15885         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15886         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15887         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15888         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15889         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15890         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15891         { } /* end */
15892 };
15893
15894 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15895         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15896         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15897         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15898         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15899         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15900         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15901         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15902         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15903         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15904         { } /* end */
15905 };
15906
15907 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15908         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15909         ALC262_HIPPO_MASTER_SWITCH,
15910
15911         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15912         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15913         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15914
15915         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15916         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15917         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15918         { } /* end */
15919 };
15920
15921 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15922         ALC262_HIPPO_MASTER_SWITCH,
15923         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15924         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15925         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15926         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15927         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15928         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15929         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15930         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15931         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15932         { } /* end */
15933 };
15934
15935 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15936         .ops = &snd_hda_bind_vol,
15937         .values = {
15938                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15939                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15940                 0
15941         },
15942 };
15943
15944 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15945         .ops = &snd_hda_bind_sw,
15946         .values = {
15947                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15948                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15949                 0
15950         },
15951 };
15952
15953 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15954         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15955         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15956         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15957         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15958         { } /* end */
15959 };
15960
15961 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15962         .ops = &snd_hda_bind_sw,
15963         .values = {
15964                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15965                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15966                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15967                 0
15968         },
15969 };
15970
15971 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15972         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15973         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15974         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15975         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15976         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15977         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15978
15979         { } /* end */
15980 };
15981
15982 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15983         .ops = &snd_hda_bind_sw,
15984         .values = {
15985                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15986                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15987                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15988                 0
15989         },
15990 };
15991
15992 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15993         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15994         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15995         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15996         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15997         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15998         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15999         { } /* end */
16000 };
16001
16002 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
16003         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16004         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16005         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
16006         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16007         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16008         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16009         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16010         { } /* end */
16011 };
16012
16013 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
16014         .ops = &snd_hda_bind_vol,
16015         .values = {
16016                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
16017                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
16018                 0
16019         },
16020 };
16021
16022 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
16023         .ops = &snd_hda_bind_sw,
16024         .values = {
16025                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16026                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
16027                 0
16028         },
16029 };
16030
16031 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
16032         HDA_BIND_VOL("Master Playback Volume",
16033                                 &alc663_asus_two_bind_master_vol),
16034         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16035         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16036         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16037         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16038         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16039         { } /* end */
16040 };
16041
16042 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
16043         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
16044         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16045         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16046         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16048         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16049         { } /* end */
16050 };
16051
16052 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
16053         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16054         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16055         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16056         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16057         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16058
16059         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16060         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16061         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16062         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16063         { } /* end */
16064 };
16065
16066 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16067         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16068         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16069         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16070
16071         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16072         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16073         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16074         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16075         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16076         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16077         { } /* end */
16078 };
16079
16080 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16081         {
16082                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16083                 .name = "Channel Mode",
16084                 .info = alc_ch_mode_info,
16085                 .get = alc_ch_mode_get,
16086                 .put = alc_ch_mode_put,
16087         },
16088         { } /* end */
16089 };
16090
16091 static struct hda_verb alc662_init_verbs[] = {
16092         /* ADC: mute amp left and right */
16093         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16094         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16095         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16096
16097         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16098         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16101         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16102
16103         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16104         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16105         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16106         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16107         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16108         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16109
16110         /* Front Pin: output 0 (0x0c) */
16111         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16112         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16113
16114         /* Rear Pin: output 1 (0x0d) */
16115         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16116         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16117
16118         /* CLFE Pin: output 2 (0x0e) */
16119         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16120         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16121
16122         /* Mic (rear) pin: input vref at 80% */
16123         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16124         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16125         /* Front Mic pin: input vref at 80% */
16126         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16127         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16128         /* Line In pin: input */
16129         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16130         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16131         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16132         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16133         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16134         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16135         /* CD pin widget for input */
16136         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16137
16138         /* FIXME: use matrix-type input source selection */
16139         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16140         /* Input mixer */
16141         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16142         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16143
16144         /* always trun on EAPD */
16145         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16146         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16147
16148         { }
16149 };
16150
16151 static struct hda_verb alc662_sue_init_verbs[] = {
16152         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16153         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16154         {}
16155 };
16156
16157 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16158         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16159         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16160         {}
16161 };
16162
16163 /* Set Unsolicited Event*/
16164 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16165         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16166         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16167         {}
16168 };
16169
16170 /*
16171  * generic initialization of ADC, input mixers and output mixers
16172  */
16173 static struct hda_verb alc662_auto_init_verbs[] = {
16174         /*
16175          * Unmute ADC and set the default input to mic-in
16176          */
16177         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16178         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16179
16180         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16181          * mixer widget
16182          * Note: PASD motherboards uses the Line In 2 as the input for front
16183          * panel mic (mic 2)
16184          */
16185         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16186         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16187         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16188         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16189         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16190         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16191
16192         /*
16193          * Set up output mixers (0x0c - 0x0f)
16194          */
16195         /* set vol=0 to output mixers */
16196         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16197         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16198         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16199
16200         /* set up input amps for analog loopback */
16201         /* Amp Indices: DAC = 0, mixer = 1 */
16202         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16203         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16204         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16205         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16206         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16207         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16208
16209
16210         /* FIXME: use matrix-type input source selection */
16211         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16212         /* Input mixer */
16213         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16214         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16215         { }
16216 };
16217
16218 /* additional verbs for ALC663 */
16219 static struct hda_verb alc663_auto_init_verbs[] = {
16220         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16221         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16222         { }
16223 };
16224
16225 static struct hda_verb alc663_m51va_init_verbs[] = {
16226         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16227         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16228         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16229         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16230         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16231         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16232         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16233         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16234         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16235         {}
16236 };
16237
16238 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16239         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16240         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16241         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16242         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16243         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16244         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16245         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16246         {}
16247 };
16248
16249 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16250         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16251         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16252         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16253         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16254         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16255         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16256         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16257         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16258         {}
16259 };
16260
16261 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16262         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16263         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16264         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16265         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16266         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16267         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16268         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16269         {}
16270 };
16271
16272 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16273         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16274         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16275         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16276         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16277         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16278         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16279         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16280         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16281         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16282         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16283         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16284         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16285         {}
16286 };
16287
16288 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16289         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16290         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16291         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16292         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16293         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16294         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16295         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16296         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16297         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16298         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16299         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16300         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16301         {}
16302 };
16303
16304 static struct hda_verb alc663_g71v_init_verbs[] = {
16305         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16306         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16307         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16308
16309         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16310         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16311         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16312
16313         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16314         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16315         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16316         {}
16317 };
16318
16319 static struct hda_verb alc663_g50v_init_verbs[] = {
16320         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16321         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16322         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16323
16324         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16325         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16326         {}
16327 };
16328
16329 static struct hda_verb alc662_ecs_init_verbs[] = {
16330         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16331         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16332         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16333         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16334         {}
16335 };
16336
16337 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16338         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16339         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16340         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16341         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16342         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16343         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16344         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16347         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16348         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16349         {}
16350 };
16351
16352 static struct hda_verb alc272_dell_init_verbs[] = {
16353         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16354         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16355         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16356         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16357         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16358         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16359         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16360         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16361         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16362         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16363         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16364         {}
16365 };
16366
16367 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16368         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16369         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16370         { } /* end */
16371 };
16372
16373 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16374         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16375         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16376         { } /* end */
16377 };
16378
16379 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16380 {
16381         unsigned int present;
16382         unsigned char bits;
16383
16384         present = snd_hda_codec_read(codec, 0x14, 0,
16385                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16386         bits = present ? HDA_AMP_MUTE : 0;
16387         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16388                                  HDA_AMP_MUTE, bits);
16389 }
16390
16391 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16392 {
16393         unsigned int present;
16394         unsigned char bits;
16395
16396         present = snd_hda_codec_read(codec, 0x1b, 0,
16397                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16398         bits = present ? HDA_AMP_MUTE : 0;
16399         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16400                                  HDA_AMP_MUTE, bits);
16401         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16402                                  HDA_AMP_MUTE, bits);
16403 }
16404
16405 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16406                                            unsigned int res)
16407 {
16408         if ((res >> 26) == ALC880_HP_EVENT)
16409                 alc662_lenovo_101e_all_automute(codec);
16410         if ((res >> 26) == ALC880_FRONT_EVENT)
16411                 alc662_lenovo_101e_ispeaker_automute(codec);
16412 }
16413
16414 /* unsolicited event for HP jack sensing */
16415 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16416                                      unsigned int res)
16417 {
16418         if ((res >> 26) == ALC880_MIC_EVENT)
16419                 alc_mic_automute(codec);
16420         else
16421                 alc262_hippo_unsol_event(codec, res);
16422 }
16423
16424 static void alc662_eeepc_setup(struct hda_codec *codec)
16425 {
16426         struct alc_spec *spec = codec->spec;
16427
16428         alc262_hippo1_setup(codec);
16429         spec->ext_mic.pin = 0x18;
16430         spec->ext_mic.mux_idx = 0;
16431         spec->int_mic.pin = 0x19;
16432         spec->int_mic.mux_idx = 1;
16433         spec->auto_mic = 1;
16434 }
16435
16436 static void alc662_eeepc_inithook(struct hda_codec *codec)
16437 {
16438         alc262_hippo_automute(codec);
16439         alc_mic_automute(codec);
16440 }
16441
16442 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16443 {
16444         struct alc_spec *spec = codec->spec;
16445
16446         spec->autocfg.hp_pins[0] = 0x14;
16447         spec->autocfg.speaker_pins[0] = 0x1b;
16448 }
16449
16450 #define alc662_eeepc_ep20_inithook      alc262_hippo_master_update
16451
16452 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16453 {
16454         unsigned int present;
16455         unsigned char bits;
16456
16457         present = snd_hda_codec_read(codec, 0x21, 0,
16458                         AC_VERB_GET_PIN_SENSE, 0)
16459                         & AC_PINSENSE_PRESENCE;
16460         bits = present ? HDA_AMP_MUTE : 0;
16461         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16462                                 AMP_IN_MUTE(0), bits);
16463         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16464                                 AMP_IN_MUTE(0), bits);
16465 }
16466
16467 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16468 {
16469         unsigned int present;
16470         unsigned char bits;
16471
16472         present = snd_hda_codec_read(codec, 0x21, 0,
16473                         AC_VERB_GET_PIN_SENSE, 0)
16474                         & AC_PINSENSE_PRESENCE;
16475         bits = present ? HDA_AMP_MUTE : 0;
16476         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16477                                 AMP_IN_MUTE(0), bits);
16478         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16479                                 AMP_IN_MUTE(0), bits);
16480         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16481                                 AMP_IN_MUTE(0), bits);
16482         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16483                                 AMP_IN_MUTE(0), bits);
16484 }
16485
16486 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16487 {
16488         unsigned int present;
16489         unsigned char bits;
16490
16491         present = snd_hda_codec_read(codec, 0x15, 0,
16492                         AC_VERB_GET_PIN_SENSE, 0)
16493                         & AC_PINSENSE_PRESENCE;
16494         bits = present ? HDA_AMP_MUTE : 0;
16495         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16496                                 AMP_IN_MUTE(0), bits);
16497         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16498                                 AMP_IN_MUTE(0), bits);
16499         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16500                                 AMP_IN_MUTE(0), bits);
16501         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16502                                 AMP_IN_MUTE(0), bits);
16503 }
16504
16505 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16506 {
16507         unsigned int present;
16508         unsigned char bits;
16509
16510         present = snd_hda_codec_read(codec, 0x1b, 0,
16511                         AC_VERB_GET_PIN_SENSE, 0)
16512                         & AC_PINSENSE_PRESENCE;
16513         bits = present ? 0 : PIN_OUT;
16514         snd_hda_codec_write(codec, 0x14, 0,
16515                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16516 }
16517
16518 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16519 {
16520         unsigned int present1, present2;
16521
16522         present1 = snd_hda_codec_read(codec, 0x21, 0,
16523                         AC_VERB_GET_PIN_SENSE, 0)
16524                         & AC_PINSENSE_PRESENCE;
16525         present2 = snd_hda_codec_read(codec, 0x15, 0,
16526                         AC_VERB_GET_PIN_SENSE, 0)
16527                         & AC_PINSENSE_PRESENCE;
16528
16529         if (present1 || present2) {
16530                 snd_hda_codec_write_cache(codec, 0x14, 0,
16531                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16532         } else {
16533                 snd_hda_codec_write_cache(codec, 0x14, 0,
16534                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16535         }
16536 }
16537
16538 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16539 {
16540         unsigned int present1, present2;
16541
16542         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16543                                 AC_VERB_GET_PIN_SENSE, 0)
16544                                 & AC_PINSENSE_PRESENCE;
16545         present2 = snd_hda_codec_read(codec, 0x15, 0,
16546                                 AC_VERB_GET_PIN_SENSE, 0)
16547                                 & AC_PINSENSE_PRESENCE;
16548
16549         if (present1 || present2) {
16550                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16551                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16552                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16553                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16554         } else {
16555                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16556                                 AMP_IN_MUTE(0), 0);
16557                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16558                                 AMP_IN_MUTE(0), 0);
16559         }
16560 }
16561
16562 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16563                                            unsigned int res)
16564 {
16565         switch (res >> 26) {
16566         case ALC880_HP_EVENT:
16567                 alc663_m51va_speaker_automute(codec);
16568                 break;
16569         case ALC880_MIC_EVENT:
16570                 alc_mic_automute(codec);
16571                 break;
16572         }
16573 }
16574
16575 static void alc663_m51va_setup(struct hda_codec *codec)
16576 {
16577         struct alc_spec *spec = codec->spec;
16578         spec->ext_mic.pin = 0x18;
16579         spec->ext_mic.mux_idx = 0;
16580         spec->int_mic.pin = 0x12;
16581         spec->int_mic.mux_idx = 1;
16582         spec->auto_mic = 1;
16583 }
16584
16585 static void alc663_m51va_inithook(struct hda_codec *codec)
16586 {
16587         alc663_m51va_speaker_automute(codec);
16588         alc_mic_automute(codec);
16589 }
16590
16591 /* ***************** Mode1 ******************************/
16592 #define alc663_mode1_unsol_event        alc663_m51va_unsol_event
16593 #define alc663_mode1_setup              alc663_m51va_setup
16594 #define alc663_mode1_inithook           alc663_m51va_inithook
16595
16596 /* ***************** Mode2 ******************************/
16597 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16598                                            unsigned int res)
16599 {
16600         switch (res >> 26) {
16601         case ALC880_HP_EVENT:
16602                 alc662_f5z_speaker_automute(codec);
16603                 break;
16604         case ALC880_MIC_EVENT:
16605                 alc_mic_automute(codec);
16606                 break;
16607         }
16608 }
16609
16610 #define alc662_mode2_setup      alc663_m51va_setup
16611
16612 static void alc662_mode2_inithook(struct hda_codec *codec)
16613 {
16614         alc662_f5z_speaker_automute(codec);
16615         alc_mic_automute(codec);
16616 }
16617 /* ***************** Mode3 ******************************/
16618 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16619                                            unsigned int res)
16620 {
16621         switch (res >> 26) {
16622         case ALC880_HP_EVENT:
16623                 alc663_two_hp_m1_speaker_automute(codec);
16624                 break;
16625         case ALC880_MIC_EVENT:
16626                 alc_mic_automute(codec);
16627                 break;
16628         }
16629 }
16630
16631 #define alc663_mode3_setup      alc663_m51va_setup
16632
16633 static void alc663_mode3_inithook(struct hda_codec *codec)
16634 {
16635         alc663_two_hp_m1_speaker_automute(codec);
16636         alc_mic_automute(codec);
16637 }
16638 /* ***************** Mode4 ******************************/
16639 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16640                                            unsigned int res)
16641 {
16642         switch (res >> 26) {
16643         case ALC880_HP_EVENT:
16644                 alc663_21jd_two_speaker_automute(codec);
16645                 break;
16646         case ALC880_MIC_EVENT:
16647                 alc_mic_automute(codec);
16648                 break;
16649         }
16650 }
16651
16652 #define alc663_mode4_setup      alc663_m51va_setup
16653
16654 static void alc663_mode4_inithook(struct hda_codec *codec)
16655 {
16656         alc663_21jd_two_speaker_automute(codec);
16657         alc_mic_automute(codec);
16658 }
16659 /* ***************** Mode5 ******************************/
16660 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16661                                            unsigned int res)
16662 {
16663         switch (res >> 26) {
16664         case ALC880_HP_EVENT:
16665                 alc663_15jd_two_speaker_automute(codec);
16666                 break;
16667         case ALC880_MIC_EVENT:
16668                 alc_mic_automute(codec);
16669                 break;
16670         }
16671 }
16672
16673 #define alc663_mode5_setup      alc663_m51va_setup
16674
16675 static void alc663_mode5_inithook(struct hda_codec *codec)
16676 {
16677         alc663_15jd_two_speaker_automute(codec);
16678         alc_mic_automute(codec);
16679 }
16680 /* ***************** Mode6 ******************************/
16681 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16682                                            unsigned int res)
16683 {
16684         switch (res >> 26) {
16685         case ALC880_HP_EVENT:
16686                 alc663_two_hp_m2_speaker_automute(codec);
16687                 break;
16688         case ALC880_MIC_EVENT:
16689                 alc_mic_automute(codec);
16690                 break;
16691         }
16692 }
16693
16694 #define alc663_mode6_setup      alc663_m51va_setup
16695
16696 static void alc663_mode6_inithook(struct hda_codec *codec)
16697 {
16698         alc663_two_hp_m2_speaker_automute(codec);
16699         alc_mic_automute(codec);
16700 }
16701
16702 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16703 {
16704         unsigned int present;
16705         unsigned char bits;
16706
16707         present = snd_hda_codec_read(codec, 0x21, 0,
16708                                      AC_VERB_GET_PIN_SENSE, 0)
16709                 & AC_PINSENSE_PRESENCE;
16710         bits = present ? HDA_AMP_MUTE : 0;
16711         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16712                                  HDA_AMP_MUTE, bits);
16713         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16714                                  HDA_AMP_MUTE, bits);
16715 }
16716
16717 static void alc663_g71v_front_automute(struct hda_codec *codec)
16718 {
16719         unsigned int present;
16720         unsigned char bits;
16721
16722         present = snd_hda_codec_read(codec, 0x15, 0,
16723                                      AC_VERB_GET_PIN_SENSE, 0)
16724                 & AC_PINSENSE_PRESENCE;
16725         bits = present ? HDA_AMP_MUTE : 0;
16726         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16727                                  HDA_AMP_MUTE, bits);
16728 }
16729
16730 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16731                                            unsigned int res)
16732 {
16733         switch (res >> 26) {
16734         case ALC880_HP_EVENT:
16735                 alc663_g71v_hp_automute(codec);
16736                 break;
16737         case ALC880_FRONT_EVENT:
16738                 alc663_g71v_front_automute(codec);
16739                 break;
16740         case ALC880_MIC_EVENT:
16741                 alc_mic_automute(codec);
16742                 break;
16743         }
16744 }
16745
16746 #define alc663_g71v_setup       alc663_m51va_setup
16747
16748 static void alc663_g71v_inithook(struct hda_codec *codec)
16749 {
16750         alc663_g71v_front_automute(codec);
16751         alc663_g71v_hp_automute(codec);
16752         alc_mic_automute(codec);
16753 }
16754
16755 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16756                                            unsigned int res)
16757 {
16758         switch (res >> 26) {
16759         case ALC880_HP_EVENT:
16760                 alc663_m51va_speaker_automute(codec);
16761                 break;
16762         case ALC880_MIC_EVENT:
16763                 alc_mic_automute(codec);
16764                 break;
16765         }
16766 }
16767
16768 #define alc663_g50v_setup       alc663_m51va_setup
16769
16770 static void alc663_g50v_inithook(struct hda_codec *codec)
16771 {
16772         alc663_m51va_speaker_automute(codec);
16773         alc_mic_automute(codec);
16774 }
16775
16776 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16777         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16778         ALC262_HIPPO_MASTER_SWITCH,
16779
16780         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16781         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16782         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16783
16784         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16785         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16786         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16787         { } /* end */
16788 };
16789
16790 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16791         /* Master Playback automatically created from Speaker and Headphone */
16792         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16793         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16794         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16795         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16796
16797         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16798         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16799         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16800
16801         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16802         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16803         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16804         { } /* end */
16805 };
16806
16807 #ifdef CONFIG_SND_HDA_POWER_SAVE
16808 #define alc662_loopbacks        alc880_loopbacks
16809 #endif
16810
16811
16812 /* pcm configuration: identical with ALC880 */
16813 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16814 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16815 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16816 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16817
16818 /*
16819  * configuration and preset
16820  */
16821 static const char *alc662_models[ALC662_MODEL_LAST] = {
16822         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16823         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16824         [ALC662_3ST_6ch]        = "3stack-6ch",
16825         [ALC662_5ST_DIG]        = "6stack-dig",
16826         [ALC662_LENOVO_101E]    = "lenovo-101e",
16827         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16828         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16829         [ALC662_ECS] = "ecs",
16830         [ALC663_ASUS_M51VA] = "m51va",
16831         [ALC663_ASUS_G71V] = "g71v",
16832         [ALC663_ASUS_H13] = "h13",
16833         [ALC663_ASUS_G50V] = "g50v",
16834         [ALC663_ASUS_MODE1] = "asus-mode1",
16835         [ALC662_ASUS_MODE2] = "asus-mode2",
16836         [ALC663_ASUS_MODE3] = "asus-mode3",
16837         [ALC663_ASUS_MODE4] = "asus-mode4",
16838         [ALC663_ASUS_MODE5] = "asus-mode5",
16839         [ALC663_ASUS_MODE6] = "asus-mode6",
16840         [ALC272_DELL]           = "dell",
16841         [ALC272_DELL_ZM1]       = "dell-zm1",
16842         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16843         [ALC662_AUTO]           = "auto",
16844 };
16845
16846 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16847         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16848         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16849         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16850         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16851         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16852         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16853         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16854         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16855         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16856         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16857         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16858         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16859         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16860         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16861         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16862         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16863         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16864         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16865         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16866         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16867         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16868         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16869         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16870         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16871         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16872         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16873         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16874         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16875         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16876         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16877         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16878         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16879         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16880         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16881         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16882         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16883         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16884         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16885         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16886         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16887         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16888         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16889         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16890         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16891         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16892         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16893         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16894         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16895         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16896         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16897         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16898         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16899                       ALC662_3ST_6ch_DIG),
16900         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4),
16901         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16902         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16903                       ALC662_3ST_6ch_DIG),
16904         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16905         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16906         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16907         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16908                                         ALC662_3ST_6ch_DIG),
16909         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16910                            ALC663_ASUS_H13),
16911         {}
16912 };
16913
16914 static struct alc_config_preset alc662_presets[] = {
16915         [ALC662_3ST_2ch_DIG] = {
16916                 .mixers = { alc662_3ST_2ch_mixer },
16917                 .init_verbs = { alc662_init_verbs },
16918                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16919                 .dac_nids = alc662_dac_nids,
16920                 .dig_out_nid = ALC662_DIGOUT_NID,
16921                 .dig_in_nid = ALC662_DIGIN_NID,
16922                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16923                 .channel_mode = alc662_3ST_2ch_modes,
16924                 .input_mux = &alc662_capture_source,
16925         },
16926         [ALC662_3ST_6ch_DIG] = {
16927                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16928                 .init_verbs = { alc662_init_verbs },
16929                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16930                 .dac_nids = alc662_dac_nids,
16931                 .dig_out_nid = ALC662_DIGOUT_NID,
16932                 .dig_in_nid = ALC662_DIGIN_NID,
16933                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16934                 .channel_mode = alc662_3ST_6ch_modes,
16935                 .need_dac_fix = 1,
16936                 .input_mux = &alc662_capture_source,
16937         },
16938         [ALC662_3ST_6ch] = {
16939                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16940                 .init_verbs = { alc662_init_verbs },
16941                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16942                 .dac_nids = alc662_dac_nids,
16943                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16944                 .channel_mode = alc662_3ST_6ch_modes,
16945                 .need_dac_fix = 1,
16946                 .input_mux = &alc662_capture_source,
16947         },
16948         [ALC662_5ST_DIG] = {
16949                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16950                 .init_verbs = { alc662_init_verbs },
16951                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16952                 .dac_nids = alc662_dac_nids,
16953                 .dig_out_nid = ALC662_DIGOUT_NID,
16954                 .dig_in_nid = ALC662_DIGIN_NID,
16955                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16956                 .channel_mode = alc662_5stack_modes,
16957                 .input_mux = &alc662_capture_source,
16958         },
16959         [ALC662_LENOVO_101E] = {
16960                 .mixers = { alc662_lenovo_101e_mixer },
16961                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16962                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16963                 .dac_nids = alc662_dac_nids,
16964                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16965                 .channel_mode = alc662_3ST_2ch_modes,
16966                 .input_mux = &alc662_lenovo_101e_capture_source,
16967                 .unsol_event = alc662_lenovo_101e_unsol_event,
16968                 .init_hook = alc662_lenovo_101e_all_automute,
16969         },
16970         [ALC662_ASUS_EEEPC_P701] = {
16971                 .mixers = { alc662_eeepc_p701_mixer },
16972                 .init_verbs = { alc662_init_verbs,
16973                                 alc662_eeepc_sue_init_verbs },
16974                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16975                 .dac_nids = alc662_dac_nids,
16976                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16977                 .channel_mode = alc662_3ST_2ch_modes,
16978                 .unsol_event = alc662_eeepc_unsol_event,
16979                 .setup = alc662_eeepc_setup,
16980                 .init_hook = alc662_eeepc_inithook,
16981         },
16982         [ALC662_ASUS_EEEPC_EP20] = {
16983                 .mixers = { alc662_eeepc_ep20_mixer,
16984                             alc662_chmode_mixer },
16985                 .init_verbs = { alc662_init_verbs,
16986                                 alc662_eeepc_ep20_sue_init_verbs },
16987                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16988                 .dac_nids = alc662_dac_nids,
16989                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16990                 .channel_mode = alc662_3ST_6ch_modes,
16991                 .input_mux = &alc662_lenovo_101e_capture_source,
16992                 .unsol_event = alc662_eeepc_unsol_event,
16993                 .setup = alc662_eeepc_ep20_setup,
16994                 .init_hook = alc662_eeepc_ep20_inithook,
16995         },
16996         [ALC662_ECS] = {
16997                 .mixers = { alc662_ecs_mixer },
16998                 .init_verbs = { alc662_init_verbs,
16999                                 alc662_ecs_init_verbs },
17000                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17001                 .dac_nids = alc662_dac_nids,
17002                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17003                 .channel_mode = alc662_3ST_2ch_modes,
17004                 .unsol_event = alc662_eeepc_unsol_event,
17005                 .setup = alc662_eeepc_setup,
17006                 .init_hook = alc662_eeepc_inithook,
17007         },
17008         [ALC663_ASUS_M51VA] = {
17009                 .mixers = { alc663_m51va_mixer },
17010                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
17011                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17012                 .dac_nids = alc662_dac_nids,
17013                 .dig_out_nid = ALC662_DIGOUT_NID,
17014                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17015                 .channel_mode = alc662_3ST_2ch_modes,
17016                 .unsol_event = alc663_m51va_unsol_event,
17017                 .setup = alc663_m51va_setup,
17018                 .init_hook = alc663_m51va_inithook,
17019         },
17020         [ALC663_ASUS_G71V] = {
17021                 .mixers = { alc663_g71v_mixer },
17022                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
17023                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17024                 .dac_nids = alc662_dac_nids,
17025                 .dig_out_nid = ALC662_DIGOUT_NID,
17026                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17027                 .channel_mode = alc662_3ST_2ch_modes,
17028                 .unsol_event = alc663_g71v_unsol_event,
17029                 .setup = alc663_g71v_setup,
17030                 .init_hook = alc663_g71v_inithook,
17031         },
17032         [ALC663_ASUS_H13] = {
17033                 .mixers = { alc663_m51va_mixer },
17034                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
17035                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17036                 .dac_nids = alc662_dac_nids,
17037                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17038                 .channel_mode = alc662_3ST_2ch_modes,
17039                 .unsol_event = alc663_m51va_unsol_event,
17040                 .init_hook = alc663_m51va_inithook,
17041         },
17042         [ALC663_ASUS_G50V] = {
17043                 .mixers = { alc663_g50v_mixer },
17044                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
17045                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17046                 .dac_nids = alc662_dac_nids,
17047                 .dig_out_nid = ALC662_DIGOUT_NID,
17048                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
17049                 .channel_mode = alc662_3ST_6ch_modes,
17050                 .input_mux = &alc663_capture_source,
17051                 .unsol_event = alc663_g50v_unsol_event,
17052                 .setup = alc663_g50v_setup,
17053                 .init_hook = alc663_g50v_inithook,
17054         },
17055         [ALC663_ASUS_MODE1] = {
17056                 .mixers = { alc663_m51va_mixer },
17057                 .cap_mixer = alc662_auto_capture_mixer,
17058                 .init_verbs = { alc662_init_verbs,
17059                                 alc663_21jd_amic_init_verbs },
17060                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17061                 .hp_nid = 0x03,
17062                 .dac_nids = alc662_dac_nids,
17063                 .dig_out_nid = ALC662_DIGOUT_NID,
17064                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17065                 .channel_mode = alc662_3ST_2ch_modes,
17066                 .unsol_event = alc663_mode1_unsol_event,
17067                 .setup = alc663_mode1_setup,
17068                 .init_hook = alc663_mode1_inithook,
17069         },
17070         [ALC662_ASUS_MODE2] = {
17071                 .mixers = { alc662_1bjd_mixer },
17072                 .cap_mixer = alc662_auto_capture_mixer,
17073                 .init_verbs = { alc662_init_verbs,
17074                                 alc662_1bjd_amic_init_verbs },
17075                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17076                 .dac_nids = alc662_dac_nids,
17077                 .dig_out_nid = ALC662_DIGOUT_NID,
17078                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17079                 .channel_mode = alc662_3ST_2ch_modes,
17080                 .unsol_event = alc662_mode2_unsol_event,
17081                 .setup = alc662_mode2_setup,
17082                 .init_hook = alc662_mode2_inithook,
17083         },
17084         [ALC663_ASUS_MODE3] = {
17085                 .mixers = { alc663_two_hp_m1_mixer },
17086                 .cap_mixer = alc662_auto_capture_mixer,
17087                 .init_verbs = { alc662_init_verbs,
17088                                 alc663_two_hp_amic_m1_init_verbs },
17089                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17090                 .hp_nid = 0x03,
17091                 .dac_nids = alc662_dac_nids,
17092                 .dig_out_nid = ALC662_DIGOUT_NID,
17093                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17094                 .channel_mode = alc662_3ST_2ch_modes,
17095                 .unsol_event = alc663_mode3_unsol_event,
17096                 .setup = alc663_mode3_setup,
17097                 .init_hook = alc663_mode3_inithook,
17098         },
17099         [ALC663_ASUS_MODE4] = {
17100                 .mixers = { alc663_asus_21jd_clfe_mixer },
17101                 .cap_mixer = alc662_auto_capture_mixer,
17102                 .init_verbs = { alc662_init_verbs,
17103                                 alc663_21jd_amic_init_verbs},
17104                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17105                 .hp_nid = 0x03,
17106                 .dac_nids = alc662_dac_nids,
17107                 .dig_out_nid = ALC662_DIGOUT_NID,
17108                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17109                 .channel_mode = alc662_3ST_2ch_modes,
17110                 .unsol_event = alc663_mode4_unsol_event,
17111                 .setup = alc663_mode4_setup,
17112                 .init_hook = alc663_mode4_inithook,
17113         },
17114         [ALC663_ASUS_MODE5] = {
17115                 .mixers = { alc663_asus_15jd_clfe_mixer },
17116                 .cap_mixer = alc662_auto_capture_mixer,
17117                 .init_verbs = { alc662_init_verbs,
17118                                 alc663_15jd_amic_init_verbs },
17119                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17120                 .hp_nid = 0x03,
17121                 .dac_nids = alc662_dac_nids,
17122                 .dig_out_nid = ALC662_DIGOUT_NID,
17123                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17124                 .channel_mode = alc662_3ST_2ch_modes,
17125                 .unsol_event = alc663_mode5_unsol_event,
17126                 .setup = alc663_mode5_setup,
17127                 .init_hook = alc663_mode5_inithook,
17128         },
17129         [ALC663_ASUS_MODE6] = {
17130                 .mixers = { alc663_two_hp_m2_mixer },
17131                 .cap_mixer = alc662_auto_capture_mixer,
17132                 .init_verbs = { alc662_init_verbs,
17133                                 alc663_two_hp_amic_m2_init_verbs },
17134                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17135                 .hp_nid = 0x03,
17136                 .dac_nids = alc662_dac_nids,
17137                 .dig_out_nid = ALC662_DIGOUT_NID,
17138                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17139                 .channel_mode = alc662_3ST_2ch_modes,
17140                 .unsol_event = alc663_mode6_unsol_event,
17141                 .setup = alc663_mode6_setup,
17142                 .init_hook = alc663_mode6_inithook,
17143         },
17144         [ALC272_DELL] = {
17145                 .mixers = { alc663_m51va_mixer },
17146                 .cap_mixer = alc272_auto_capture_mixer,
17147                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17148                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17149                 .dac_nids = alc662_dac_nids,
17150                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17151                 .adc_nids = alc272_adc_nids,
17152                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17153                 .capsrc_nids = alc272_capsrc_nids,
17154                 .channel_mode = alc662_3ST_2ch_modes,
17155                 .unsol_event = alc663_m51va_unsol_event,
17156                 .setup = alc663_m51va_setup,
17157                 .init_hook = alc663_m51va_inithook,
17158         },
17159         [ALC272_DELL_ZM1] = {
17160                 .mixers = { alc663_m51va_mixer },
17161                 .cap_mixer = alc662_auto_capture_mixer,
17162                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17163                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17164                 .dac_nids = alc662_dac_nids,
17165                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17166                 .adc_nids = alc662_adc_nids,
17167                 .num_adc_nids = 1,
17168                 .capsrc_nids = alc662_capsrc_nids,
17169                 .channel_mode = alc662_3ST_2ch_modes,
17170                 .unsol_event = alc663_m51va_unsol_event,
17171                 .setup = alc663_m51va_setup,
17172                 .init_hook = alc663_m51va_inithook,
17173         },
17174         [ALC272_SAMSUNG_NC10] = {
17175                 .mixers = { alc272_nc10_mixer },
17176                 .init_verbs = { alc662_init_verbs,
17177                                 alc663_21jd_amic_init_verbs },
17178                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17179                 .dac_nids = alc272_dac_nids,
17180                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17181                 .channel_mode = alc662_3ST_2ch_modes,
17182                 /*.input_mux = &alc272_nc10_capture_source,*/
17183                 .unsol_event = alc663_mode4_unsol_event,
17184                 .setup = alc663_mode4_setup,
17185                 .init_hook = alc663_mode4_inithook,
17186         },
17187 };
17188
17189
17190 /*
17191  * BIOS auto configuration
17192  */
17193
17194 /* convert from MIX nid to DAC */
17195 static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
17196 {
17197         if (nid == 0x0f)
17198                 return 0x02;
17199         else if (nid >= 0x0c && nid <= 0x0e)
17200                 return nid - 0x0c + 0x02;
17201         else
17202                 return 0;
17203 }
17204
17205 /* get MIX nid connected to the given pin targeted to DAC */
17206 static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
17207                                    hda_nid_t dac)
17208 {
17209         hda_nid_t mix[4];
17210         int i, num;
17211
17212         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
17213         for (i = 0; i < num; i++) {
17214                 if (alc662_mix_to_dac(mix[i]) == dac)
17215                         return mix[i];
17216         }
17217         return 0;
17218 }
17219
17220 /* look for an empty DAC slot */
17221 static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
17222 {
17223         struct alc_spec *spec = codec->spec;
17224         hda_nid_t srcs[5];
17225         int i, j, num;
17226
17227         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
17228         if (num < 0)
17229                 return 0;
17230         for (i = 0; i < num; i++) {
17231                 hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
17232                 if (!nid)
17233                         continue;
17234                 for (j = 0; j < spec->multiout.num_dacs; j++)
17235                         if (spec->multiout.dac_nids[j] == nid)
17236                                 break;
17237                 if (j >= spec->multiout.num_dacs)
17238                         return nid;
17239         }
17240         return 0;
17241 }
17242
17243 /* fill in the dac_nids table from the parsed pin configuration */
17244 static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17245                                      const struct auto_pin_cfg *cfg)
17246 {
17247         struct alc_spec *spec = codec->spec;
17248         int i;
17249         hda_nid_t dac;
17250
17251         spec->multiout.dac_nids = spec->private_dac_nids;
17252         for (i = 0; i < cfg->line_outs; i++) {
17253                 dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
17254                 if (!dac)
17255                         continue;
17256                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
17257         }
17258         return 0;
17259 }
17260
17261 static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17262                               hda_nid_t nid, unsigned int chs)
17263 {
17264         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17265                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17266 }
17267
17268 static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17269                              hda_nid_t nid, unsigned int chs)
17270 {
17271         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17272                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17273 }
17274
17275 #define alc662_add_stereo_vol(spec, pfx, nid) \
17276         alc662_add_vol_ctl(spec, pfx, nid, 3)
17277 #define alc662_add_stereo_sw(spec, pfx, nid) \
17278         alc662_add_sw_ctl(spec, pfx, nid, 3)
17279
17280 /* add playback controls from the parsed DAC table */
17281 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
17282                                              const struct auto_pin_cfg *cfg)
17283 {
17284         struct alc_spec *spec = codec->spec;
17285         static const char *chname[4] = {
17286                 "Front", "Surround", NULL /*CLFE*/, "Side"
17287         };
17288         hda_nid_t nid, mix;
17289         int i, err;
17290
17291         for (i = 0; i < cfg->line_outs; i++) {
17292                 nid = spec->multiout.dac_nids[i];
17293                 if (!nid)
17294                         continue;
17295                 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
17296                 if (!mix)
17297                         continue;
17298                 if (i == 2) {
17299                         /* Center/LFE */
17300                         err = alc662_add_vol_ctl(spec, "Center", nid, 1);
17301                         if (err < 0)
17302                                 return err;
17303                         err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
17304                         if (err < 0)
17305                                 return err;
17306                         err = alc662_add_sw_ctl(spec, "Center", mix, 1);
17307                         if (err < 0)
17308                                 return err;
17309                         err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
17310                         if (err < 0)
17311                                 return err;
17312                 } else {
17313                         const char *pfx;
17314                         if (cfg->line_outs == 1 &&
17315                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17316                                 if (cfg->hp_outs)
17317                                         pfx = "Speaker";
17318                                 else
17319                                         pfx = "PCM";
17320                         } else
17321                                 pfx = chname[i];
17322                         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17323                         if (err < 0)
17324                                 return err;
17325                         if (cfg->line_outs == 1 &&
17326                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17327                                 pfx = "Speaker";
17328                         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17329                         if (err < 0)
17330                                 return err;
17331                 }
17332         }
17333         return 0;
17334 }
17335
17336 /* add playback controls for speaker and HP outputs */
17337 /* return DAC nid if any new DAC is assigned */
17338 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17339                                         const char *pfx)
17340 {
17341         struct alc_spec *spec = codec->spec;
17342         hda_nid_t nid, mix;
17343         int err;
17344
17345         if (!pin)
17346                 return 0;
17347         nid = alc662_look_for_dac(codec, pin);
17348         if (!nid) {
17349                 /* the corresponding DAC is already occupied */
17350                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17351                         return 0; /* no way */
17352                 /* create a switch only */
17353                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17354                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17355         }
17356
17357         mix = alc662_dac_to_mix(codec, pin, nid);
17358         if (!mix)
17359                 return 0;
17360         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17361         if (err < 0)
17362                 return err;
17363         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17364         if (err < 0)
17365                 return err;
17366         return nid;
17367 }
17368
17369 /* create playback/capture controls for input pins */
17370 #define alc662_auto_create_input_ctls \
17371         alc882_auto_create_input_ctls
17372
17373 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17374                                               hda_nid_t nid, int pin_type,
17375                                               hda_nid_t dac)
17376 {
17377         int i, num;
17378         hda_nid_t srcs[4];
17379
17380         alc_set_pin_output(codec, nid, pin_type);
17381         /* need the manual connection? */
17382         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
17383         if (num <= 1)
17384                 return;
17385         for (i = 0; i < num; i++) {
17386                 if (alc662_mix_to_dac(srcs[i]) != dac)
17387                         continue;
17388                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
17389                 return;
17390         }
17391 }
17392
17393 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17394 {
17395         struct alc_spec *spec = codec->spec;
17396         int pin_type = get_pin_type(spec->autocfg.line_out_type);
17397         int i;
17398
17399         for (i = 0; i <= HDA_SIDE; i++) {
17400                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17401                 if (nid)
17402                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17403                                         spec->multiout.dac_nids[i]);
17404         }
17405 }
17406
17407 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17408 {
17409         struct alc_spec *spec = codec->spec;
17410         hda_nid_t pin;
17411
17412         pin = spec->autocfg.hp_pins[0];
17413         if (pin)
17414                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
17415                                                   spec->multiout.hp_nid);
17416         pin = spec->autocfg.speaker_pins[0];
17417         if (pin)
17418                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
17419                                         spec->multiout.extra_out_nid[0]);
17420 }
17421
17422 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17423
17424 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17425 {
17426         struct alc_spec *spec = codec->spec;
17427         int i;
17428
17429         for (i = 0; i < AUTO_PIN_LAST; i++) {
17430                 hda_nid_t nid = spec->autocfg.input_pins[i];
17431                 if (alc_is_input_pin(codec, nid)) {
17432                         alc_set_input_pin(codec, nid, i);
17433                         if (nid != ALC662_PIN_CD_NID &&
17434                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17435                                 snd_hda_codec_write(codec, nid, 0,
17436                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17437                                                     AMP_OUT_MUTE);
17438                 }
17439         }
17440 }
17441
17442 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17443
17444 static int alc662_parse_auto_config(struct hda_codec *codec)
17445 {
17446         struct alc_spec *spec = codec->spec;
17447         int err;
17448         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17449
17450         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17451                                            alc662_ignore);
17452         if (err < 0)
17453                 return err;
17454         if (!spec->autocfg.line_outs)
17455                 return 0; /* can't find valid BIOS pin config */
17456
17457         err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
17458         if (err < 0)
17459                 return err;
17460         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
17461         if (err < 0)
17462                 return err;
17463         err = alc662_auto_create_extra_out(codec,
17464                                            spec->autocfg.speaker_pins[0],
17465                                            "Speaker");
17466         if (err < 0)
17467                 return err;
17468         if (err)
17469                 spec->multiout.extra_out_nid[0] = err;
17470         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
17471                                            "Headphone");
17472         if (err < 0)
17473                 return err;
17474         if (err)
17475                 spec->multiout.hp_nid = err;
17476         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17477         if (err < 0)
17478                 return err;
17479
17480         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17481
17482         if (spec->autocfg.dig_outs)
17483                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17484
17485         if (spec->kctls.list)
17486                 add_mixer(spec, spec->kctls.list);
17487
17488         spec->num_mux_defs = 1;
17489         spec->input_mux = &spec->private_imux[0];
17490
17491         add_verb(spec, alc662_auto_init_verbs);
17492         if (codec->vendor_id == 0x10ec0663)
17493                 add_verb(spec, alc663_auto_init_verbs);
17494
17495         err = alc_auto_add_mic_boost(codec);
17496         if (err < 0)
17497                 return err;
17498
17499         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17500
17501         return 1;
17502 }
17503
17504 /* additional initialization for auto-configuration model */
17505 static void alc662_auto_init(struct hda_codec *codec)
17506 {
17507         struct alc_spec *spec = codec->spec;
17508         alc662_auto_init_multi_out(codec);
17509         alc662_auto_init_hp_out(codec);
17510         alc662_auto_init_analog_input(codec);
17511         alc662_auto_init_input_src(codec);
17512         if (spec->unsol_event)
17513                 alc_inithook(codec);
17514 }
17515
17516 static int patch_alc662(struct hda_codec *codec)
17517 {
17518         struct alc_spec *spec;
17519         int err, board_config;
17520
17521         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17522         if (!spec)
17523                 return -ENOMEM;
17524
17525         codec->spec = spec;
17526
17527         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17528
17529         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17530                                                   alc662_models,
17531                                                   alc662_cfg_tbl);
17532         if (board_config < 0) {
17533                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17534                        codec->chip_name);
17535                 board_config = ALC662_AUTO;
17536         }
17537
17538         if (board_config == ALC662_AUTO) {
17539                 /* automatic parse from the BIOS config */
17540                 err = alc662_parse_auto_config(codec);
17541                 if (err < 0) {
17542                         alc_free(codec);
17543                         return err;
17544                 } else if (!err) {
17545                         printk(KERN_INFO
17546                                "hda_codec: Cannot set up configuration "
17547                                "from BIOS.  Using base mode...\n");
17548                         board_config = ALC662_3ST_2ch_DIG;
17549                 }
17550         }
17551
17552         err = snd_hda_attach_beep_device(codec, 0x1);
17553         if (err < 0) {
17554                 alc_free(codec);
17555                 return err;
17556         }
17557
17558         if (board_config != ALC662_AUTO)
17559                 setup_preset(codec, &alc662_presets[board_config]);
17560
17561         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17562         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17563
17564         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17565         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17566
17567         if (!spec->adc_nids) {
17568                 spec->adc_nids = alc662_adc_nids;
17569                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17570         }
17571         if (!spec->capsrc_nids)
17572                 spec->capsrc_nids = alc662_capsrc_nids;
17573
17574         if (!spec->cap_mixer)
17575                 set_capture_mixer(codec);
17576         if (codec->vendor_id == 0x10ec0662)
17577                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17578         else
17579                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17580
17581         spec->vmaster_nid = 0x02;
17582
17583         codec->patch_ops = alc_patch_ops;
17584         if (board_config == ALC662_AUTO)
17585                 spec->init_hook = alc662_auto_init;
17586 #ifdef CONFIG_SND_HDA_POWER_SAVE
17587         if (!spec->loopback.amplist)
17588                 spec->loopback.amplist = alc662_loopbacks;
17589 #endif
17590         codec->proc_widget_hook = print_realtek_coef;
17591
17592         return 0;
17593 }
17594
17595 /*
17596  * patch entries
17597  */
17598 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17599         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17600         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17601         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17602         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17603         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17604         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17605         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17606           .patch = patch_alc861 },
17607         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17608         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17609         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17610         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17611           .patch = patch_alc882 },
17612         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17613           .patch = patch_alc662 },
17614         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17615         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17616         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17617         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17618         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17619           .patch = patch_alc882 },
17620         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17621           .patch = patch_alc882 },
17622         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17623         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17624         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17625           .patch = patch_alc882 },
17626         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17627         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17628         {} /* terminator */
17629 };
17630
17631 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17632
17633 MODULE_LICENSE("GPL");
17634 MODULE_DESCRIPTION("Realtek HD-audio codec");
17635
17636 static struct hda_codec_preset_list realtek_list = {
17637         .preset = snd_hda_preset_realtek,
17638         .owner = THIS_MODULE,
17639 };
17640
17641 static int __init patch_realtek_init(void)
17642 {
17643         return snd_hda_add_codec_preset(&realtek_list);
17644 }
17645
17646 static void __exit patch_realtek_exit(void)
17647 {
17648         snd_hda_delete_codec_preset(&realtek_list);
17649 }
17650
17651 module_init(patch_realtek_init)
17652 module_exit(patch_realtek_exit)