Merge branch 'fix/hda' into topic/hda
[safe/jmp/linux-2.6] / 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 /* additional beep mixers; the actual parameters are overwritten at build */
2414 static struct snd_kcontrol_new alc_beep_mixer[] = {
2415         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2416         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2417         { } /* end */
2418 };
2419
2420 static int alc_build_controls(struct hda_codec *codec)
2421 {
2422         struct alc_spec *spec = codec->spec;
2423         int err;
2424         int i;
2425
2426         for (i = 0; i < spec->num_mixers; i++) {
2427                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2428                 if (err < 0)
2429                         return err;
2430         }
2431         if (spec->cap_mixer) {
2432                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2433                 if (err < 0)
2434                         return err;
2435         }
2436         if (spec->multiout.dig_out_nid) {
2437                 err = snd_hda_create_spdif_out_ctls(codec,
2438                                                     spec->multiout.dig_out_nid);
2439                 if (err < 0)
2440                         return err;
2441                 if (!spec->no_analog) {
2442                         err = snd_hda_create_spdif_share_sw(codec,
2443                                                             &spec->multiout);
2444                         if (err < 0)
2445                                 return err;
2446                         spec->multiout.share_spdif = 1;
2447                 }
2448         }
2449         if (spec->dig_in_nid) {
2450                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2451                 if (err < 0)
2452                         return err;
2453         }
2454
2455         /* create beep controls if needed */
2456         if (spec->beep_amp) {
2457                 struct snd_kcontrol_new *knew;
2458                 for (knew = alc_beep_mixer; knew->name; knew++) {
2459                         struct snd_kcontrol *kctl;
2460                         kctl = snd_ctl_new1(knew, codec);
2461                         if (!kctl)
2462                                 return -ENOMEM;
2463                         kctl->private_value = spec->beep_amp;
2464                         err = snd_hda_ctl_add(codec, kctl);
2465                         if (err < 0)
2466                                 return err;
2467                 }
2468         }
2469
2470         /* if we have no master control, let's create it */
2471         if (!spec->no_analog &&
2472             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2473                 unsigned int vmaster_tlv[4];
2474                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2475                                         HDA_OUTPUT, vmaster_tlv);
2476                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2477                                           vmaster_tlv, alc_slave_vols);
2478                 if (err < 0)
2479                         return err;
2480         }
2481         if (!spec->no_analog &&
2482             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2483                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2484                                           NULL, alc_slave_sws);
2485                 if (err < 0)
2486                         return err;
2487         }
2488
2489         alc_free_kctls(codec); /* no longer needed */
2490         return 0;
2491 }
2492
2493
2494 /*
2495  * initialize the codec volumes, etc
2496  */
2497
2498 /*
2499  * generic initialization of ADC, input mixers and output mixers
2500  */
2501 static struct hda_verb alc880_volume_init_verbs[] = {
2502         /*
2503          * Unmute ADC0-2 and set the default input to mic-in
2504          */
2505         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2506         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2507         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2508         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2509         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2510         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2511
2512         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2513          * mixer widget
2514          * Note: PASD motherboards uses the Line In 2 as the input for front
2515          * panel mic (mic 2)
2516          */
2517         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2525
2526         /*
2527          * Set up output mixers (0x0c - 0x0f)
2528          */
2529         /* set vol=0 to output mixers */
2530         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2531         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2532         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2533         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2534         /* set up input amps for analog loopback */
2535         /* Amp Indices: DAC = 0, mixer = 1 */
2536         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2537         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2538         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2539         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2540         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2541         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2542         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2543         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2544
2545         { }
2546 };
2547
2548 /*
2549  * 3-stack pin configuration:
2550  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2551  */
2552 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2553         /*
2554          * preset connection lists of input pins
2555          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2556          */
2557         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2558         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2559         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2560
2561         /*
2562          * Set pin mode and muting
2563          */
2564         /* set front pin widgets 0x14 for output */
2565         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2566         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2567         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2568         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2569         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2570         /* Mic2 (as headphone out) for HP output */
2571         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2572         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2573         /* Line In pin widget for input */
2574         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2575         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2576         /* Line2 (as front mic) pin widget for input and vref at 80% */
2577         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2578         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2579         /* CD pin widget for input */
2580         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2581
2582         { }
2583 };
2584
2585 /*
2586  * 5-stack pin configuration:
2587  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2588  * line-in/side = 0x1a, f-mic = 0x1b
2589  */
2590 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2591         /*
2592          * preset connection lists of input pins
2593          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2594          */
2595         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2596         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2597
2598         /*
2599          * Set pin mode and muting
2600          */
2601         /* set pin widgets 0x14-0x17 for output */
2602         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2603         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2604         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2605         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2606         /* unmute pins for output (no gain on this amp) */
2607         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2608         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2609         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2610         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2611
2612         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2613         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2614         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2615         /* Mic2 (as headphone out) for HP output */
2616         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2617         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2618         /* Line In pin widget for input */
2619         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2620         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2621         /* Line2 (as front mic) pin widget for input and vref at 80% */
2622         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2623         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2624         /* CD pin widget for input */
2625         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2626
2627         { }
2628 };
2629
2630 /*
2631  * W810 pin configuration:
2632  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2633  */
2634 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2635         /* hphone/speaker input selector: front DAC */
2636         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2637
2638         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2639         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2640         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2641         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2642         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2643         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2644
2645         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2646         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2647
2648         { }
2649 };
2650
2651 /*
2652  * Z71V pin configuration:
2653  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2654  */
2655 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2656         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2657         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2658         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2659         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2660
2661         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2662         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2663         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2664         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2665
2666         { }
2667 };
2668
2669 /*
2670  * 6-stack pin configuration:
2671  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2672  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2673  */
2674 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2675         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2676
2677         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2678         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2679         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2680         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2681         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2682         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2683         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2684         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2685
2686         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2687         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2688         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2689         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2690         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2691         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2692         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2693         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2694         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2695
2696         { }
2697 };
2698
2699 /*
2700  * Uniwill pin configuration:
2701  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2702  * line = 0x1a
2703  */
2704 static struct hda_verb alc880_uniwill_init_verbs[] = {
2705         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2706
2707         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2708         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2709         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2710         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2711         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2712         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2713         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2714         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2715         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2716         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2717         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2718         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2719         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2720         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2721
2722         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2723         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2724         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2725         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2726         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2727         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2728         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2729         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2730         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2731
2732         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2733         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2734
2735         { }
2736 };
2737
2738 /*
2739 * Uniwill P53
2740 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2741  */
2742 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2743         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2744
2745         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2746         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2747         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2748         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2749         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2750         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2751         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2752         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2753         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2754         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2755         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2756         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2757
2758         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2759         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2760         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2761         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2762         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2763         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2764
2765         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2766         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2767
2768         { }
2769 };
2770
2771 static struct hda_verb alc880_beep_init_verbs[] = {
2772         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2773         { }
2774 };
2775
2776 /* auto-toggle front mic */
2777 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2778 {
2779         unsigned int present;
2780         unsigned char bits;
2781
2782         present = snd_hda_codec_read(codec, 0x18, 0,
2783                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2784         bits = present ? HDA_AMP_MUTE : 0;
2785         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2786 }
2787
2788 static void alc880_uniwill_setup(struct hda_codec *codec)
2789 {
2790         struct alc_spec *spec = codec->spec;
2791
2792         spec->autocfg.hp_pins[0] = 0x14;
2793         spec->autocfg.speaker_pins[0] = 0x15;
2794         spec->autocfg.speaker_pins[0] = 0x16;
2795 }
2796
2797 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2798 {
2799         alc_automute_amp(codec);
2800         alc880_uniwill_mic_automute(codec);
2801 }
2802
2803 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2804                                        unsigned int res)
2805 {
2806         /* Looks like the unsol event is incompatible with the standard
2807          * definition.  4bit tag is placed at 28 bit!
2808          */
2809         switch (res >> 28) {
2810         case ALC880_MIC_EVENT:
2811                 alc880_uniwill_mic_automute(codec);
2812                 break;
2813         default:
2814                 alc_automute_amp_unsol_event(codec, res);
2815                 break;
2816         }
2817 }
2818
2819 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2820 {
2821         struct alc_spec *spec = codec->spec;
2822
2823         spec->autocfg.hp_pins[0] = 0x14;
2824         spec->autocfg.speaker_pins[0] = 0x15;
2825 }
2826
2827 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2828 {
2829         unsigned int present;
2830
2831         present = snd_hda_codec_read(codec, 0x21, 0,
2832                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2833         present &= HDA_AMP_VOLMASK;
2834         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2835                                  HDA_AMP_VOLMASK, present);
2836         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2837                                  HDA_AMP_VOLMASK, present);
2838 }
2839
2840 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2841                                            unsigned int res)
2842 {
2843         /* Looks like the unsol event is incompatible with the standard
2844          * definition.  4bit tag is placed at 28 bit!
2845          */
2846         if ((res >> 28) == ALC880_DCVOL_EVENT)
2847                 alc880_uniwill_p53_dcvol_automute(codec);
2848         else
2849                 alc_automute_amp_unsol_event(codec, res);
2850 }
2851
2852 /*
2853  * F1734 pin configuration:
2854  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2855  */
2856 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2857         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2858         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2859         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2860         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2861         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2862
2863         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2864         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2865         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2866         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2867
2868         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2869         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2870         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2871         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2872         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2873         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2874         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2875         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2876         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2877
2878         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2879         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2880
2881         { }
2882 };
2883
2884 /*
2885  * ASUS pin configuration:
2886  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2887  */
2888 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2889         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2890         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2891         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2892         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2893
2894         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2895         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2896         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2897         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2898         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2899         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2900         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2901         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2902
2903         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2904         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2905         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2906         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2907         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2908         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2909         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2911         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2912
2913         { }
2914 };
2915
2916 /* Enable GPIO mask and set output */
2917 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2918 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2919 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2920
2921 /* Clevo m520g init */
2922 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2923         /* headphone output */
2924         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2925         /* line-out */
2926         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2927         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2928         /* Line-in */
2929         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2930         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2931         /* CD */
2932         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2933         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2934         /* Mic1 (rear panel) */
2935         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2936         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2937         /* Mic2 (front panel) */
2938         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2939         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2940         /* headphone */
2941         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2942         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2943         /* change to EAPD mode */
2944         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2945         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2946
2947         { }
2948 };
2949
2950 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2951         /* change to EAPD mode */
2952         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2953         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2954
2955         /* Headphone output */
2956         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2957         /* Front output*/
2958         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2959         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2960
2961         /* Line In pin widget for input */
2962         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2963         /* CD pin widget for input */
2964         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2965         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2966         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2967
2968         /* change to EAPD mode */
2969         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2970         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2971
2972         { }
2973 };
2974
2975 /*
2976  * LG m1 express dual
2977  *
2978  * Pin assignment:
2979  *   Rear Line-In/Out (blue): 0x14
2980  *   Build-in Mic-In: 0x15
2981  *   Speaker-out: 0x17
2982  *   HP-Out (green): 0x1b
2983  *   Mic-In/Out (red): 0x19
2984  *   SPDIF-Out: 0x1e
2985  */
2986
2987 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2988 static hda_nid_t alc880_lg_dac_nids[3] = {
2989         0x05, 0x02, 0x03
2990 };
2991
2992 /* seems analog CD is not working */
2993 static struct hda_input_mux alc880_lg_capture_source = {
2994         .num_items = 3,
2995         .items = {
2996                 { "Mic", 0x1 },
2997                 { "Line", 0x5 },
2998                 { "Internal Mic", 0x6 },
2999         },
3000 };
3001
3002 /* 2,4,6 channel modes */
3003 static struct hda_verb alc880_lg_ch2_init[] = {
3004         /* set line-in and mic-in to input */
3005         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3006         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3007         { }
3008 };
3009
3010 static struct hda_verb alc880_lg_ch4_init[] = {
3011         /* set line-in to out and mic-in to input */
3012         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3013         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3014         { }
3015 };
3016
3017 static struct hda_verb alc880_lg_ch6_init[] = {
3018         /* set line-in and mic-in to output */
3019         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3020         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3021         { }
3022 };
3023
3024 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3025         { 2, alc880_lg_ch2_init },
3026         { 4, alc880_lg_ch4_init },
3027         { 6, alc880_lg_ch6_init },
3028 };
3029
3030 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3031         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3032         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3033         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3034         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3035         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3036         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3037         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3038         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3039         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3040         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3041         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3042         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3043         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3044         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3045         {
3046                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3047                 .name = "Channel Mode",
3048                 .info = alc_ch_mode_info,
3049                 .get = alc_ch_mode_get,
3050                 .put = alc_ch_mode_put,
3051         },
3052         { } /* end */
3053 };
3054
3055 static struct hda_verb alc880_lg_init_verbs[] = {
3056         /* set capture source to mic-in */
3057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3058         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3059         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3060         /* mute all amp mixer inputs */
3061         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3062         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3063         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3064         /* line-in to input */
3065         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3066         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3067         /* built-in mic */
3068         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3069         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3070         /* speaker-out */
3071         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3072         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3073         /* mic-in to input */
3074         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3075         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3077         /* HP-out */
3078         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3079         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3080         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3081         /* jack sense */
3082         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3083         { }
3084 };
3085
3086 /* toggle speaker-output according to the hp-jack state */
3087 static void alc880_lg_setup(struct hda_codec *codec)
3088 {
3089         struct alc_spec *spec = codec->spec;
3090
3091         spec->autocfg.hp_pins[0] = 0x1b;
3092         spec->autocfg.speaker_pins[0] = 0x17;
3093 }
3094
3095 /*
3096  * LG LW20
3097  *
3098  * Pin assignment:
3099  *   Speaker-out: 0x14
3100  *   Mic-In: 0x18
3101  *   Built-in Mic-In: 0x19
3102  *   Line-In: 0x1b
3103  *   HP-Out: 0x1a
3104  *   SPDIF-Out: 0x1e
3105  */
3106
3107 static struct hda_input_mux alc880_lg_lw_capture_source = {
3108         .num_items = 3,
3109         .items = {
3110                 { "Mic", 0x0 },
3111                 { "Internal Mic", 0x1 },
3112                 { "Line In", 0x2 },
3113         },
3114 };
3115
3116 #define alc880_lg_lw_modes alc880_threestack_modes
3117
3118 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3119         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3120         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3121         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3122         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3123         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3124         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3125         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3126         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3127         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3128         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3129         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3130         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3131         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3132         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3133         {
3134                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3135                 .name = "Channel Mode",
3136                 .info = alc_ch_mode_info,
3137                 .get = alc_ch_mode_get,
3138                 .put = alc_ch_mode_put,
3139         },
3140         { } /* end */
3141 };
3142
3143 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3144         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3145         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3146         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3147
3148         /* set capture source to mic-in */
3149         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3150         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3151         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3153         /* speaker-out */
3154         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3155         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3156         /* HP-out */
3157         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3158         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3159         /* mic-in to input */
3160         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3161         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3162         /* built-in mic */
3163         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3164         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3165         /* jack sense */
3166         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3167         { }
3168 };
3169
3170 /* toggle speaker-output according to the hp-jack state */
3171 static void alc880_lg_lw_setup(struct hda_codec *codec)
3172 {
3173         struct alc_spec *spec = codec->spec;
3174
3175         spec->autocfg.hp_pins[0] = 0x1b;
3176         spec->autocfg.speaker_pins[0] = 0x14;
3177 }
3178
3179 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3180         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3181         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3182         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3183         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3184         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3185         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3186         { } /* end */
3187 };
3188
3189 static struct hda_input_mux alc880_medion_rim_capture_source = {
3190         .num_items = 2,
3191         .items = {
3192                 { "Mic", 0x0 },
3193                 { "Internal Mic", 0x1 },
3194         },
3195 };
3196
3197 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3198         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3199
3200         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3201         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3202
3203         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3204         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3205         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3206         /* Mic2 (as headphone out) for HP output */
3207         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3208         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3209         /* Internal Speaker */
3210         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3211         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3212
3213         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3214         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3215
3216         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3217         { }
3218 };
3219
3220 /* toggle speaker-output according to the hp-jack state */
3221 static void alc880_medion_rim_automute(struct hda_codec *codec)
3222 {
3223         struct alc_spec *spec = codec->spec;
3224         alc_automute_amp(codec);
3225         /* toggle EAPD */
3226         if (spec->jack_present)
3227                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3228         else
3229                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3230 }
3231
3232 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3233                                           unsigned int res)
3234 {
3235         /* Looks like the unsol event is incompatible with the standard
3236          * definition.  4bit tag is placed at 28 bit!
3237          */
3238         if ((res >> 28) == ALC880_HP_EVENT)
3239                 alc880_medion_rim_automute(codec);
3240 }
3241
3242 static void alc880_medion_rim_setup(struct hda_codec *codec)
3243 {
3244         struct alc_spec *spec = codec->spec;
3245
3246         spec->autocfg.hp_pins[0] = 0x14;
3247         spec->autocfg.speaker_pins[0] = 0x1b;
3248 }
3249
3250 #ifdef CONFIG_SND_HDA_POWER_SAVE
3251 static struct hda_amp_list alc880_loopbacks[] = {
3252         { 0x0b, HDA_INPUT, 0 },
3253         { 0x0b, HDA_INPUT, 1 },
3254         { 0x0b, HDA_INPUT, 2 },
3255         { 0x0b, HDA_INPUT, 3 },
3256         { 0x0b, HDA_INPUT, 4 },
3257         { } /* end */
3258 };
3259
3260 static struct hda_amp_list alc880_lg_loopbacks[] = {
3261         { 0x0b, HDA_INPUT, 1 },
3262         { 0x0b, HDA_INPUT, 6 },
3263         { 0x0b, HDA_INPUT, 7 },
3264         { } /* end */
3265 };
3266 #endif
3267
3268 /*
3269  * Common callbacks
3270  */
3271
3272 static int alc_init(struct hda_codec *codec)
3273 {
3274         struct alc_spec *spec = codec->spec;
3275         unsigned int i;
3276
3277         alc_fix_pll(codec);
3278         alc_auto_init_amp(codec, spec->init_amp);
3279
3280         for (i = 0; i < spec->num_init_verbs; i++)
3281                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3282
3283         if (spec->init_hook)
3284                 spec->init_hook(codec);
3285
3286         return 0;
3287 }
3288
3289 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3290 {
3291         struct alc_spec *spec = codec->spec;
3292
3293         if (spec->unsol_event)
3294                 spec->unsol_event(codec, res);
3295 }
3296
3297 #ifdef CONFIG_SND_HDA_POWER_SAVE
3298 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3299 {
3300         struct alc_spec *spec = codec->spec;
3301         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3302 }
3303 #endif
3304
3305 /*
3306  * Analog playback callbacks
3307  */
3308 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3309                                     struct hda_codec *codec,
3310                                     struct snd_pcm_substream *substream)
3311 {
3312         struct alc_spec *spec = codec->spec;
3313         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3314                                              hinfo);
3315 }
3316
3317 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3318                                        struct hda_codec *codec,
3319                                        unsigned int stream_tag,
3320                                        unsigned int format,
3321                                        struct snd_pcm_substream *substream)
3322 {
3323         struct alc_spec *spec = codec->spec;
3324         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3325                                                 stream_tag, format, substream);
3326 }
3327
3328 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3329                                        struct hda_codec *codec,
3330                                        struct snd_pcm_substream *substream)
3331 {
3332         struct alc_spec *spec = codec->spec;
3333         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3334 }
3335
3336 /*
3337  * Digital out
3338  */
3339 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3340                                         struct hda_codec *codec,
3341                                         struct snd_pcm_substream *substream)
3342 {
3343         struct alc_spec *spec = codec->spec;
3344         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3345 }
3346
3347 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3348                                            struct hda_codec *codec,
3349                                            unsigned int stream_tag,
3350                                            unsigned int format,
3351                                            struct snd_pcm_substream *substream)
3352 {
3353         struct alc_spec *spec = codec->spec;
3354         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3355                                              stream_tag, format, substream);
3356 }
3357
3358 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3359                                            struct hda_codec *codec,
3360                                            struct snd_pcm_substream *substream)
3361 {
3362         struct alc_spec *spec = codec->spec;
3363         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3364 }
3365
3366 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3367                                          struct hda_codec *codec,
3368                                          struct snd_pcm_substream *substream)
3369 {
3370         struct alc_spec *spec = codec->spec;
3371         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3372 }
3373
3374 /*
3375  * Analog capture
3376  */
3377 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3378                                       struct hda_codec *codec,
3379                                       unsigned int stream_tag,
3380                                       unsigned int format,
3381                                       struct snd_pcm_substream *substream)
3382 {
3383         struct alc_spec *spec = codec->spec;
3384
3385         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3386                                    stream_tag, 0, format);
3387         return 0;
3388 }
3389
3390 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3391                                       struct hda_codec *codec,
3392                                       struct snd_pcm_substream *substream)
3393 {
3394         struct alc_spec *spec = codec->spec;
3395
3396         snd_hda_codec_cleanup_stream(codec,
3397                                      spec->adc_nids[substream->number + 1]);
3398         return 0;
3399 }
3400
3401
3402 /*
3403  */
3404 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3405         .substreams = 1,
3406         .channels_min = 2,
3407         .channels_max = 8,
3408         /* NID is set in alc_build_pcms */
3409         .ops = {
3410                 .open = alc880_playback_pcm_open,
3411                 .prepare = alc880_playback_pcm_prepare,
3412                 .cleanup = alc880_playback_pcm_cleanup
3413         },
3414 };
3415
3416 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3417         .substreams = 1,
3418         .channels_min = 2,
3419         .channels_max = 2,
3420         /* NID is set in alc_build_pcms */
3421 };
3422
3423 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3424         .substreams = 1,
3425         .channels_min = 2,
3426         .channels_max = 2,
3427         /* NID is set in alc_build_pcms */
3428 };
3429
3430 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3431         .substreams = 2, /* can be overridden */
3432         .channels_min = 2,
3433         .channels_max = 2,
3434         /* NID is set in alc_build_pcms */
3435         .ops = {
3436                 .prepare = alc880_alt_capture_pcm_prepare,
3437                 .cleanup = alc880_alt_capture_pcm_cleanup
3438         },
3439 };
3440
3441 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3442         .substreams = 1,
3443         .channels_min = 2,
3444         .channels_max = 2,
3445         /* NID is set in alc_build_pcms */
3446         .ops = {
3447                 .open = alc880_dig_playback_pcm_open,
3448                 .close = alc880_dig_playback_pcm_close,
3449                 .prepare = alc880_dig_playback_pcm_prepare,
3450                 .cleanup = alc880_dig_playback_pcm_cleanup
3451         },
3452 };
3453
3454 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3455         .substreams = 1,
3456         .channels_min = 2,
3457         .channels_max = 2,
3458         /* NID is set in alc_build_pcms */
3459 };
3460
3461 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3462 static struct hda_pcm_stream alc_pcm_null_stream = {
3463         .substreams = 0,
3464         .channels_min = 0,
3465         .channels_max = 0,
3466 };
3467
3468 static int alc_build_pcms(struct hda_codec *codec)
3469 {
3470         struct alc_spec *spec = codec->spec;
3471         struct hda_pcm *info = spec->pcm_rec;
3472         int i;
3473
3474         codec->num_pcms = 1;
3475         codec->pcm_info = info;
3476
3477         if (spec->no_analog)
3478                 goto skip_analog;
3479
3480         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3481                  "%s Analog", codec->chip_name);
3482         info->name = spec->stream_name_analog;
3483         
3484         if (spec->stream_analog_playback) {
3485                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3486                         return -EINVAL;
3487                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3488                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3489         }
3490         if (spec->stream_analog_capture) {
3491                 if (snd_BUG_ON(!spec->adc_nids))
3492                         return -EINVAL;
3493                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3494                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3495         }
3496
3497         if (spec->channel_mode) {
3498                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3499                 for (i = 0; i < spec->num_channel_mode; i++) {
3500                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3501                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3502                         }
3503                 }
3504         }
3505
3506  skip_analog:
3507         /* SPDIF for stream index #1 */
3508         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3509                 snprintf(spec->stream_name_digital,
3510                          sizeof(spec->stream_name_digital),
3511                          "%s Digital", codec->chip_name);
3512                 codec->num_pcms = 2;
3513                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3514                 info = spec->pcm_rec + 1;
3515                 info->name = spec->stream_name_digital;
3516                 if (spec->dig_out_type)
3517                         info->pcm_type = spec->dig_out_type;
3518                 else
3519                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3520                 if (spec->multiout.dig_out_nid &&
3521                     spec->stream_digital_playback) {
3522                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3523                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3524                 }
3525                 if (spec->dig_in_nid &&
3526                     spec->stream_digital_capture) {
3527                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3528                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3529                 }
3530                 /* FIXME: do we need this for all Realtek codec models? */
3531                 codec->spdif_status_reset = 1;
3532         }
3533
3534         if (spec->no_analog)
3535                 return 0;
3536
3537         /* If the use of more than one ADC is requested for the current
3538          * model, configure a second analog capture-only PCM.
3539          */
3540         /* Additional Analaog capture for index #2 */
3541         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3542             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3543                 codec->num_pcms = 3;
3544                 info = spec->pcm_rec + 2;
3545                 info->name = spec->stream_name_analog;
3546                 if (spec->alt_dac_nid) {
3547                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3548                                 *spec->stream_analog_alt_playback;
3549                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3550                                 spec->alt_dac_nid;
3551                 } else {
3552                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3553                                 alc_pcm_null_stream;
3554                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3555                 }
3556                 if (spec->num_adc_nids > 1) {
3557                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3558                                 *spec->stream_analog_alt_capture;
3559                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3560                                 spec->adc_nids[1];
3561                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3562                                 spec->num_adc_nids - 1;
3563                 } else {
3564                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3565                                 alc_pcm_null_stream;
3566                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3567                 }
3568         }
3569
3570         return 0;
3571 }
3572
3573 static void alc_free_kctls(struct hda_codec *codec)
3574 {
3575         struct alc_spec *spec = codec->spec;
3576
3577         if (spec->kctls.list) {
3578                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3579                 int i;
3580                 for (i = 0; i < spec->kctls.used; i++)
3581                         kfree(kctl[i].name);
3582         }
3583         snd_array_free(&spec->kctls);
3584 }
3585
3586 static void alc_free(struct hda_codec *codec)
3587 {
3588         struct alc_spec *spec = codec->spec;
3589
3590         if (!spec)
3591                 return;
3592
3593         alc_free_kctls(codec);
3594         kfree(spec);
3595         snd_hda_detach_beep_device(codec);
3596 }
3597
3598 #ifdef SND_HDA_NEEDS_RESUME
3599 static int alc_resume(struct hda_codec *codec)
3600 {
3601         codec->patch_ops.init(codec);
3602         snd_hda_codec_resume_amp(codec);
3603         snd_hda_codec_resume_cache(codec);
3604         return 0;
3605 }
3606 #endif
3607
3608 /*
3609  */
3610 static struct hda_codec_ops alc_patch_ops = {
3611         .build_controls = alc_build_controls,
3612         .build_pcms = alc_build_pcms,
3613         .init = alc_init,
3614         .free = alc_free,
3615         .unsol_event = alc_unsol_event,
3616 #ifdef SND_HDA_NEEDS_RESUME
3617         .resume = alc_resume,
3618 #endif
3619 #ifdef CONFIG_SND_HDA_POWER_SAVE
3620         .check_power_status = alc_check_power_status,
3621 #endif
3622 };
3623
3624
3625 /*
3626  * Test configuration for debugging
3627  *
3628  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3629  * enum controls.
3630  */
3631 #ifdef CONFIG_SND_DEBUG
3632 static hda_nid_t alc880_test_dac_nids[4] = {
3633         0x02, 0x03, 0x04, 0x05
3634 };
3635
3636 static struct hda_input_mux alc880_test_capture_source = {
3637         .num_items = 7,
3638         .items = {
3639                 { "In-1", 0x0 },
3640                 { "In-2", 0x1 },
3641                 { "In-3", 0x2 },
3642                 { "In-4", 0x3 },
3643                 { "CD", 0x4 },
3644                 { "Front", 0x5 },
3645                 { "Surround", 0x6 },
3646         },
3647 };
3648
3649 static struct hda_channel_mode alc880_test_modes[4] = {
3650         { 2, NULL },
3651         { 4, NULL },
3652         { 6, NULL },
3653         { 8, NULL },
3654 };
3655
3656 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3657                                  struct snd_ctl_elem_info *uinfo)
3658 {
3659         static char *texts[] = {
3660                 "N/A", "Line Out", "HP Out",
3661                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3662         };
3663         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3664         uinfo->count = 1;
3665         uinfo->value.enumerated.items = 8;
3666         if (uinfo->value.enumerated.item >= 8)
3667                 uinfo->value.enumerated.item = 7;
3668         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3669         return 0;
3670 }
3671
3672 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3673                                 struct snd_ctl_elem_value *ucontrol)
3674 {
3675         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3676         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3677         unsigned int pin_ctl, item = 0;
3678
3679         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3680                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3681         if (pin_ctl & AC_PINCTL_OUT_EN) {
3682                 if (pin_ctl & AC_PINCTL_HP_EN)
3683                         item = 2;
3684                 else
3685                         item = 1;
3686         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3687                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3688                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3689                 case AC_PINCTL_VREF_50:  item = 4; break;
3690                 case AC_PINCTL_VREF_GRD: item = 5; break;
3691                 case AC_PINCTL_VREF_80:  item = 6; break;
3692                 case AC_PINCTL_VREF_100: item = 7; break;
3693                 }
3694         }
3695         ucontrol->value.enumerated.item[0] = item;
3696         return 0;
3697 }
3698
3699 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3700                                 struct snd_ctl_elem_value *ucontrol)
3701 {
3702         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3703         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3704         static unsigned int ctls[] = {
3705                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3706                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3707                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3708                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3709                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3710                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3711         };
3712         unsigned int old_ctl, new_ctl;
3713
3714         old_ctl = snd_hda_codec_read(codec, nid, 0,
3715                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3716         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3717         if (old_ctl != new_ctl) {
3718                 int val;
3719                 snd_hda_codec_write_cache(codec, nid, 0,
3720                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3721                                           new_ctl);
3722                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3723                         HDA_AMP_MUTE : 0;
3724                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3725                                          HDA_AMP_MUTE, val);
3726                 return 1;
3727         }
3728         return 0;
3729 }
3730
3731 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3732                                  struct snd_ctl_elem_info *uinfo)
3733 {
3734         static char *texts[] = {
3735                 "Front", "Surround", "CLFE", "Side"
3736         };
3737         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3738         uinfo->count = 1;
3739         uinfo->value.enumerated.items = 4;
3740         if (uinfo->value.enumerated.item >= 4)
3741                 uinfo->value.enumerated.item = 3;
3742         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3743         return 0;
3744 }
3745
3746 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3747                                 struct snd_ctl_elem_value *ucontrol)
3748 {
3749         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3750         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3751         unsigned int sel;
3752
3753         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3754         ucontrol->value.enumerated.item[0] = sel & 3;
3755         return 0;
3756 }
3757
3758 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3759                                 struct snd_ctl_elem_value *ucontrol)
3760 {
3761         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3762         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3763         unsigned int sel;
3764
3765         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3766         if (ucontrol->value.enumerated.item[0] != sel) {
3767                 sel = ucontrol->value.enumerated.item[0] & 3;
3768                 snd_hda_codec_write_cache(codec, nid, 0,
3769                                           AC_VERB_SET_CONNECT_SEL, sel);
3770                 return 1;
3771         }
3772         return 0;
3773 }
3774
3775 #define PIN_CTL_TEST(xname,nid) {                       \
3776                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3777                         .name = xname,                 \
3778                         .info = alc_test_pin_ctl_info, \
3779                         .get = alc_test_pin_ctl_get,   \
3780                         .put = alc_test_pin_ctl_put,   \
3781                         .private_value = nid           \
3782                         }
3783
3784 #define PIN_SRC_TEST(xname,nid) {                       \
3785                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3786                         .name = xname,                 \
3787                         .info = alc_test_pin_src_info, \
3788                         .get = alc_test_pin_src_get,   \
3789                         .put = alc_test_pin_src_put,   \
3790                         .private_value = nid           \
3791                         }
3792
3793 static struct snd_kcontrol_new alc880_test_mixer[] = {
3794         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3795         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3796         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3797         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3798         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3799         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3800         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3801         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3802         PIN_CTL_TEST("Front Pin Mode", 0x14),
3803         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3804         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3805         PIN_CTL_TEST("Side Pin Mode", 0x17),
3806         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3807         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3808         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3809         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3810         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3811         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3812         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3813         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3814         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3815         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3816         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3817         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3818         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3819         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3820         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3821         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3822         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3823         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3824         {
3825                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3826                 .name = "Channel Mode",
3827                 .info = alc_ch_mode_info,
3828                 .get = alc_ch_mode_get,
3829                 .put = alc_ch_mode_put,
3830         },
3831         { } /* end */
3832 };
3833
3834 static struct hda_verb alc880_test_init_verbs[] = {
3835         /* Unmute inputs of 0x0c - 0x0f */
3836         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3837         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3838         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3839         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3840         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3841         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3842         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3843         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3844         /* Vol output for 0x0c-0x0f */
3845         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3846         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3847         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3848         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3849         /* Set output pins 0x14-0x17 */
3850         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3851         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3852         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3853         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3854         /* Unmute output pins 0x14-0x17 */
3855         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3856         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3857         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3858         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3859         /* Set input pins 0x18-0x1c */
3860         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3861         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3862         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3863         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3864         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3865         /* Mute input pins 0x18-0x1b */
3866         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3867         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3868         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3869         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3870         /* ADC set up */
3871         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3872         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3873         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3874         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3875         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3876         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3877         /* Analog input/passthru */
3878         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3879         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3880         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3881         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3882         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3883         { }
3884 };
3885 #endif
3886
3887 /*
3888  */
3889
3890 static const char *alc880_models[ALC880_MODEL_LAST] = {
3891         [ALC880_3ST]            = "3stack",
3892         [ALC880_TCL_S700]       = "tcl",
3893         [ALC880_3ST_DIG]        = "3stack-digout",
3894         [ALC880_CLEVO]          = "clevo",
3895         [ALC880_5ST]            = "5stack",
3896         [ALC880_5ST_DIG]        = "5stack-digout",
3897         [ALC880_W810]           = "w810",
3898         [ALC880_Z71V]           = "z71v",
3899         [ALC880_6ST]            = "6stack",
3900         [ALC880_6ST_DIG]        = "6stack-digout",
3901         [ALC880_ASUS]           = "asus",
3902         [ALC880_ASUS_W1V]       = "asus-w1v",
3903         [ALC880_ASUS_DIG]       = "asus-dig",
3904         [ALC880_ASUS_DIG2]      = "asus-dig2",
3905         [ALC880_UNIWILL_DIG]    = "uniwill",
3906         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3907         [ALC880_FUJITSU]        = "fujitsu",
3908         [ALC880_F1734]          = "F1734",
3909         [ALC880_LG]             = "lg",
3910         [ALC880_LG_LW]          = "lg-lw",
3911         [ALC880_MEDION_RIM]     = "medion",
3912 #ifdef CONFIG_SND_DEBUG
3913         [ALC880_TEST]           = "test",
3914 #endif
3915         [ALC880_AUTO]           = "auto",
3916 };
3917
3918 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3919         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3920         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3921         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3922         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3923         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3924         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3925         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3926         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3927         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3928         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3929         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3930         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3931         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3932         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3933         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3934         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3935         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3936         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3937         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3938         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3939         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3940         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3941         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3942         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3943         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3944         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3945         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3946         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3947         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3948         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3949         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3950         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3951         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3952         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3953         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3954         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3955         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3956         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3957         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3958         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3959         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3960         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3961         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3962         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3963         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3964         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3965         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3966         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3967         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3968         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3969         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3970         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3971         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3972         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3973         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3974         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3975         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3976         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3977         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3978         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3979         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3980         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3981         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3982         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3983         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3984         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3985         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3986         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3987         /* default Intel */
3988         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3989         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3990         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3991         {}
3992 };
3993
3994 /*
3995  * ALC880 codec presets
3996  */
3997 static struct alc_config_preset alc880_presets[] = {
3998         [ALC880_3ST] = {
3999                 .mixers = { alc880_three_stack_mixer },
4000                 .init_verbs = { alc880_volume_init_verbs,
4001                                 alc880_pin_3stack_init_verbs },
4002                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4003                 .dac_nids = alc880_dac_nids,
4004                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4005                 .channel_mode = alc880_threestack_modes,
4006                 .need_dac_fix = 1,
4007                 .input_mux = &alc880_capture_source,
4008         },
4009         [ALC880_3ST_DIG] = {
4010                 .mixers = { alc880_three_stack_mixer },
4011                 .init_verbs = { alc880_volume_init_verbs,
4012                                 alc880_pin_3stack_init_verbs },
4013                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4014                 .dac_nids = alc880_dac_nids,
4015                 .dig_out_nid = ALC880_DIGOUT_NID,
4016                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4017                 .channel_mode = alc880_threestack_modes,
4018                 .need_dac_fix = 1,
4019                 .input_mux = &alc880_capture_source,
4020         },
4021         [ALC880_TCL_S700] = {
4022                 .mixers = { alc880_tcl_s700_mixer },
4023                 .init_verbs = { alc880_volume_init_verbs,
4024                                 alc880_pin_tcl_S700_init_verbs,
4025                                 alc880_gpio2_init_verbs },
4026                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4027                 .dac_nids = alc880_dac_nids,
4028                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4029                 .num_adc_nids = 1, /* single ADC */
4030                 .hp_nid = 0x03,
4031                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4032                 .channel_mode = alc880_2_jack_modes,
4033                 .input_mux = &alc880_capture_source,
4034         },
4035         [ALC880_5ST] = {
4036                 .mixers = { alc880_three_stack_mixer,
4037                             alc880_five_stack_mixer},
4038                 .init_verbs = { alc880_volume_init_verbs,
4039                                 alc880_pin_5stack_init_verbs },
4040                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4041                 .dac_nids = alc880_dac_nids,
4042                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4043                 .channel_mode = alc880_fivestack_modes,
4044                 .input_mux = &alc880_capture_source,
4045         },
4046         [ALC880_5ST_DIG] = {
4047                 .mixers = { alc880_three_stack_mixer,
4048                             alc880_five_stack_mixer },
4049                 .init_verbs = { alc880_volume_init_verbs,
4050                                 alc880_pin_5stack_init_verbs },
4051                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4052                 .dac_nids = alc880_dac_nids,
4053                 .dig_out_nid = ALC880_DIGOUT_NID,
4054                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4055                 .channel_mode = alc880_fivestack_modes,
4056                 .input_mux = &alc880_capture_source,
4057         },
4058         [ALC880_6ST] = {
4059                 .mixers = { alc880_six_stack_mixer },
4060                 .init_verbs = { alc880_volume_init_verbs,
4061                                 alc880_pin_6stack_init_verbs },
4062                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4063                 .dac_nids = alc880_6st_dac_nids,
4064                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4065                 .channel_mode = alc880_sixstack_modes,
4066                 .input_mux = &alc880_6stack_capture_source,
4067         },
4068         [ALC880_6ST_DIG] = {
4069                 .mixers = { alc880_six_stack_mixer },
4070                 .init_verbs = { alc880_volume_init_verbs,
4071                                 alc880_pin_6stack_init_verbs },
4072                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4073                 .dac_nids = alc880_6st_dac_nids,
4074                 .dig_out_nid = ALC880_DIGOUT_NID,
4075                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4076                 .channel_mode = alc880_sixstack_modes,
4077                 .input_mux = &alc880_6stack_capture_source,
4078         },
4079         [ALC880_W810] = {
4080                 .mixers = { alc880_w810_base_mixer },
4081                 .init_verbs = { alc880_volume_init_verbs,
4082                                 alc880_pin_w810_init_verbs,
4083                                 alc880_gpio2_init_verbs },
4084                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4085                 .dac_nids = alc880_w810_dac_nids,
4086                 .dig_out_nid = ALC880_DIGOUT_NID,
4087                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4088                 .channel_mode = alc880_w810_modes,
4089                 .input_mux = &alc880_capture_source,
4090         },
4091         [ALC880_Z71V] = {
4092                 .mixers = { alc880_z71v_mixer },
4093                 .init_verbs = { alc880_volume_init_verbs,
4094                                 alc880_pin_z71v_init_verbs },
4095                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4096                 .dac_nids = alc880_z71v_dac_nids,
4097                 .dig_out_nid = ALC880_DIGOUT_NID,
4098                 .hp_nid = 0x03,
4099                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4100                 .channel_mode = alc880_2_jack_modes,
4101                 .input_mux = &alc880_capture_source,
4102         },
4103         [ALC880_F1734] = {
4104                 .mixers = { alc880_f1734_mixer },
4105                 .init_verbs = { alc880_volume_init_verbs,
4106                                 alc880_pin_f1734_init_verbs },
4107                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4108                 .dac_nids = alc880_f1734_dac_nids,
4109                 .hp_nid = 0x02,
4110                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4111                 .channel_mode = alc880_2_jack_modes,
4112                 .input_mux = &alc880_f1734_capture_source,
4113                 .unsol_event = alc880_uniwill_p53_unsol_event,
4114                 .setup = alc880_uniwill_p53_setup,
4115                 .init_hook = alc_automute_amp,
4116         },
4117         [ALC880_ASUS] = {
4118                 .mixers = { alc880_asus_mixer },
4119                 .init_verbs = { alc880_volume_init_verbs,
4120                                 alc880_pin_asus_init_verbs,
4121                                 alc880_gpio1_init_verbs },
4122                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4123                 .dac_nids = alc880_asus_dac_nids,
4124                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4125                 .channel_mode = alc880_asus_modes,
4126                 .need_dac_fix = 1,
4127                 .input_mux = &alc880_capture_source,
4128         },
4129         [ALC880_ASUS_DIG] = {
4130                 .mixers = { alc880_asus_mixer },
4131                 .init_verbs = { alc880_volume_init_verbs,
4132                                 alc880_pin_asus_init_verbs,
4133                                 alc880_gpio1_init_verbs },
4134                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4135                 .dac_nids = alc880_asus_dac_nids,
4136                 .dig_out_nid = ALC880_DIGOUT_NID,
4137                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4138                 .channel_mode = alc880_asus_modes,
4139                 .need_dac_fix = 1,
4140                 .input_mux = &alc880_capture_source,
4141         },
4142         [ALC880_ASUS_DIG2] = {
4143                 .mixers = { alc880_asus_mixer },
4144                 .init_verbs = { alc880_volume_init_verbs,
4145                                 alc880_pin_asus_init_verbs,
4146                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4147                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4148                 .dac_nids = alc880_asus_dac_nids,
4149                 .dig_out_nid = ALC880_DIGOUT_NID,
4150                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4151                 .channel_mode = alc880_asus_modes,
4152                 .need_dac_fix = 1,
4153                 .input_mux = &alc880_capture_source,
4154         },
4155         [ALC880_ASUS_W1V] = {
4156                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4157                 .init_verbs = { alc880_volume_init_verbs,
4158                                 alc880_pin_asus_init_verbs,
4159                                 alc880_gpio1_init_verbs },
4160                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4161                 .dac_nids = alc880_asus_dac_nids,
4162                 .dig_out_nid = ALC880_DIGOUT_NID,
4163                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4164                 .channel_mode = alc880_asus_modes,
4165                 .need_dac_fix = 1,
4166                 .input_mux = &alc880_capture_source,
4167         },
4168         [ALC880_UNIWILL_DIG] = {
4169                 .mixers = { alc880_asus_mixer },
4170                 .init_verbs = { alc880_volume_init_verbs,
4171                                 alc880_pin_asus_init_verbs },
4172                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4173                 .dac_nids = alc880_asus_dac_nids,
4174                 .dig_out_nid = ALC880_DIGOUT_NID,
4175                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4176                 .channel_mode = alc880_asus_modes,
4177                 .need_dac_fix = 1,
4178                 .input_mux = &alc880_capture_source,
4179         },
4180         [ALC880_UNIWILL] = {
4181                 .mixers = { alc880_uniwill_mixer },
4182                 .init_verbs = { alc880_volume_init_verbs,
4183                                 alc880_uniwill_init_verbs },
4184                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4185                 .dac_nids = alc880_asus_dac_nids,
4186                 .dig_out_nid = ALC880_DIGOUT_NID,
4187                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4188                 .channel_mode = alc880_threestack_modes,
4189                 .need_dac_fix = 1,
4190                 .input_mux = &alc880_capture_source,
4191                 .unsol_event = alc880_uniwill_unsol_event,
4192                 .setup = alc880_uniwill_setup,
4193                 .init_hook = alc880_uniwill_init_hook,
4194         },
4195         [ALC880_UNIWILL_P53] = {
4196                 .mixers = { alc880_uniwill_p53_mixer },
4197                 .init_verbs = { alc880_volume_init_verbs,
4198                                 alc880_uniwill_p53_init_verbs },
4199                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4200                 .dac_nids = alc880_asus_dac_nids,
4201                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4202                 .channel_mode = alc880_threestack_modes,
4203                 .input_mux = &alc880_capture_source,
4204                 .unsol_event = alc880_uniwill_p53_unsol_event,
4205                 .setup = alc880_uniwill_p53_setup,
4206                 .init_hook = alc_automute_amp,
4207         },
4208         [ALC880_FUJITSU] = {
4209                 .mixers = { alc880_fujitsu_mixer },
4210                 .init_verbs = { alc880_volume_init_verbs,
4211                                 alc880_uniwill_p53_init_verbs,
4212                                 alc880_beep_init_verbs },
4213                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4214                 .dac_nids = alc880_dac_nids,
4215                 .dig_out_nid = ALC880_DIGOUT_NID,
4216                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4217                 .channel_mode = alc880_2_jack_modes,
4218                 .input_mux = &alc880_capture_source,
4219                 .unsol_event = alc880_uniwill_p53_unsol_event,
4220                 .setup = alc880_uniwill_p53_setup,
4221                 .init_hook = alc_automute_amp,
4222         },
4223         [ALC880_CLEVO] = {
4224                 .mixers = { alc880_three_stack_mixer },
4225                 .init_verbs = { alc880_volume_init_verbs,
4226                                 alc880_pin_clevo_init_verbs },
4227                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4228                 .dac_nids = alc880_dac_nids,
4229                 .hp_nid = 0x03,
4230                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4231                 .channel_mode = alc880_threestack_modes,
4232                 .need_dac_fix = 1,
4233                 .input_mux = &alc880_capture_source,
4234         },
4235         [ALC880_LG] = {
4236                 .mixers = { alc880_lg_mixer },
4237                 .init_verbs = { alc880_volume_init_verbs,
4238                                 alc880_lg_init_verbs },
4239                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4240                 .dac_nids = alc880_lg_dac_nids,
4241                 .dig_out_nid = ALC880_DIGOUT_NID,
4242                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4243                 .channel_mode = alc880_lg_ch_modes,
4244                 .need_dac_fix = 1,
4245                 .input_mux = &alc880_lg_capture_source,
4246                 .unsol_event = alc_automute_amp_unsol_event,
4247                 .setup = alc880_lg_setup,
4248                 .init_hook = alc_automute_amp,
4249 #ifdef CONFIG_SND_HDA_POWER_SAVE
4250                 .loopbacks = alc880_lg_loopbacks,
4251 #endif
4252         },
4253         [ALC880_LG_LW] = {
4254                 .mixers = { alc880_lg_lw_mixer },
4255                 .init_verbs = { alc880_volume_init_verbs,
4256                                 alc880_lg_lw_init_verbs },
4257                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4258                 .dac_nids = alc880_dac_nids,
4259                 .dig_out_nid = ALC880_DIGOUT_NID,
4260                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4261                 .channel_mode = alc880_lg_lw_modes,
4262                 .input_mux = &alc880_lg_lw_capture_source,
4263                 .unsol_event = alc_automute_amp_unsol_event,
4264                 .setup = alc880_lg_lw_setup,
4265                 .init_hook = alc_automute_amp,
4266         },
4267         [ALC880_MEDION_RIM] = {
4268                 .mixers = { alc880_medion_rim_mixer },
4269                 .init_verbs = { alc880_volume_init_verbs,
4270                                 alc880_medion_rim_init_verbs,
4271                                 alc_gpio2_init_verbs },
4272                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4273                 .dac_nids = alc880_dac_nids,
4274                 .dig_out_nid = ALC880_DIGOUT_NID,
4275                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4276                 .channel_mode = alc880_2_jack_modes,
4277                 .input_mux = &alc880_medion_rim_capture_source,
4278                 .unsol_event = alc880_medion_rim_unsol_event,
4279                 .setup = alc880_medion_rim_setup,
4280                 .init_hook = alc880_medion_rim_automute,
4281         },
4282 #ifdef CONFIG_SND_DEBUG
4283         [ALC880_TEST] = {
4284                 .mixers = { alc880_test_mixer },
4285                 .init_verbs = { alc880_test_init_verbs },
4286                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4287                 .dac_nids = alc880_test_dac_nids,
4288                 .dig_out_nid = ALC880_DIGOUT_NID,
4289                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4290                 .channel_mode = alc880_test_modes,
4291                 .input_mux = &alc880_test_capture_source,
4292         },
4293 #endif
4294 };
4295
4296 /*
4297  * Automatic parse of I/O pins from the BIOS configuration
4298  */
4299
4300 enum {
4301         ALC_CTL_WIDGET_VOL,
4302         ALC_CTL_WIDGET_MUTE,
4303         ALC_CTL_BIND_MUTE,
4304 };
4305 static struct snd_kcontrol_new alc880_control_templates[] = {
4306         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4307         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4308         HDA_BIND_MUTE(NULL, 0, 0, 0),
4309 };
4310
4311 /* add dynamic controls */
4312 static int add_control(struct alc_spec *spec, int type, const char *name,
4313                        unsigned long val)
4314 {
4315         struct snd_kcontrol_new *knew;
4316
4317         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4318         knew = snd_array_new(&spec->kctls);
4319         if (!knew)
4320                 return -ENOMEM;
4321         *knew = alc880_control_templates[type];
4322         knew->name = kstrdup(name, GFP_KERNEL);
4323         if (!knew->name)
4324                 return -ENOMEM;
4325         knew->private_value = val;
4326         return 0;
4327 }
4328
4329 static int add_control_with_pfx(struct alc_spec *spec, int type,
4330                                 const char *pfx, const char *dir,
4331                                 const char *sfx, unsigned long val)
4332 {
4333         char name[32];
4334         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4335         return add_control(spec, type, name, val);
4336 }
4337
4338 #define add_pb_vol_ctrl(spec, type, pfx, val) \
4339         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4340 #define add_pb_sw_ctrl(spec, type, pfx, val) \
4341         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4342
4343 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4344 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4345 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4346 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4347 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4348 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4349 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4350 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4351 #define ALC880_PIN_CD_NID               0x1c
4352
4353 /* fill in the dac_nids table from the parsed pin configuration */
4354 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4355                                      const struct auto_pin_cfg *cfg)
4356 {
4357         hda_nid_t nid;
4358         int assigned[4];
4359         int i, j;
4360
4361         memset(assigned, 0, sizeof(assigned));
4362         spec->multiout.dac_nids = spec->private_dac_nids;
4363
4364         /* check the pins hardwired to audio widget */
4365         for (i = 0; i < cfg->line_outs; i++) {
4366                 nid = cfg->line_out_pins[i];
4367                 if (alc880_is_fixed_pin(nid)) {
4368                         int idx = alc880_fixed_pin_idx(nid);
4369                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4370                         assigned[idx] = 1;
4371                 }
4372         }
4373         /* left pins can be connect to any audio widget */
4374         for (i = 0; i < cfg->line_outs; i++) {
4375                 nid = cfg->line_out_pins[i];
4376                 if (alc880_is_fixed_pin(nid))
4377                         continue;
4378                 /* search for an empty channel */
4379                 for (j = 0; j < cfg->line_outs; j++) {
4380                         if (!assigned[j]) {
4381                                 spec->multiout.dac_nids[i] =
4382                                         alc880_idx_to_dac(j);
4383                                 assigned[j] = 1;
4384                                 break;
4385                         }
4386                 }
4387         }
4388         spec->multiout.num_dacs = cfg->line_outs;
4389         return 0;
4390 }
4391
4392 /* add playback controls from the parsed DAC table */
4393 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4394                                              const struct auto_pin_cfg *cfg)
4395 {
4396         static const char *chname[4] = {
4397                 "Front", "Surround", NULL /*CLFE*/, "Side"
4398         };
4399         hda_nid_t nid;
4400         int i, err;
4401
4402         for (i = 0; i < cfg->line_outs; i++) {
4403                 if (!spec->multiout.dac_nids[i])
4404                         continue;
4405                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4406                 if (i == 2) {
4407                         /* Center/LFE */
4408                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4409                                               "Center",
4410                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4411                                                               HDA_OUTPUT));
4412                         if (err < 0)
4413                                 return err;
4414                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4415                                               "LFE",
4416                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4417                                                               HDA_OUTPUT));
4418                         if (err < 0)
4419                                 return err;
4420                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4421                                              "Center",
4422                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4423                                                               HDA_INPUT));
4424                         if (err < 0)
4425                                 return err;
4426                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4427                                              "LFE",
4428                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4429                                                               HDA_INPUT));
4430                         if (err < 0)
4431                                 return err;
4432                 } else {
4433                         const char *pfx;
4434                         if (cfg->line_outs == 1 &&
4435                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4436                                 pfx = "Speaker";
4437                         else
4438                                 pfx = chname[i];
4439                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4440                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4441                                                               HDA_OUTPUT));
4442                         if (err < 0)
4443                                 return err;
4444                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4445                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4446                                                               HDA_INPUT));
4447                         if (err < 0)
4448                                 return err;
4449                 }
4450         }
4451         return 0;
4452 }
4453
4454 /* add playback controls for speaker and HP outputs */
4455 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4456                                         const char *pfx)
4457 {
4458         hda_nid_t nid;
4459         int err;
4460
4461         if (!pin)
4462                 return 0;
4463
4464         if (alc880_is_fixed_pin(pin)) {
4465                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4466                 /* specify the DAC as the extra output */
4467                 if (!spec->multiout.hp_nid)
4468                         spec->multiout.hp_nid = nid;
4469                 else
4470                         spec->multiout.extra_out_nid[0] = nid;
4471                 /* control HP volume/switch on the output mixer amp */
4472                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4473                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4474                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4475                 if (err < 0)
4476                         return err;
4477                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4478                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4479                 if (err < 0)
4480                         return err;
4481         } else if (alc880_is_multi_pin(pin)) {
4482                 /* set manual connection */
4483                 /* we have only a switch on HP-out PIN */
4484                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4485                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4486                 if (err < 0)
4487                         return err;
4488         }
4489         return 0;
4490 }
4491
4492 /* create input playback/capture controls for the given pin */
4493 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4494                             const char *ctlname,
4495                             int idx, hda_nid_t mix_nid)
4496 {
4497         int err;
4498
4499         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4500                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4501         if (err < 0)
4502                 return err;
4503         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4504                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4505         if (err < 0)
4506                 return err;
4507         return 0;
4508 }
4509
4510 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4511 {
4512         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4513         return (pincap & AC_PINCAP_IN) != 0;
4514 }
4515
4516 /* create playback/capture controls for input pins */
4517 static int alc_auto_create_input_ctls(struct hda_codec *codec,
4518                                       const struct auto_pin_cfg *cfg,
4519                                       hda_nid_t mixer,
4520                                       hda_nid_t cap1, hda_nid_t cap2)
4521 {
4522         struct alc_spec *spec = codec->spec;
4523         struct hda_input_mux *imux = &spec->private_imux[0];
4524         int i, err, idx;
4525
4526         for (i = 0; i < AUTO_PIN_LAST; i++) {
4527                 hda_nid_t pin;
4528
4529                 pin = cfg->input_pins[i];
4530                 if (!alc_is_input_pin(codec, pin))
4531                         continue;
4532
4533                 if (mixer) {
4534                         idx = get_connection_index(codec, mixer, pin);
4535                         if (idx >= 0) {
4536                                 err = new_analog_input(spec, pin,
4537                                                        auto_pin_cfg_labels[i],
4538                                                        idx, mixer);
4539                                 if (err < 0)
4540                                         return err;
4541                         }
4542                 }
4543
4544                 if (!cap1)
4545                         continue;
4546                 idx = get_connection_index(codec, cap1, pin);
4547                 if (idx < 0 && cap2)
4548                         idx = get_connection_index(codec, cap2, pin);
4549                 if (idx >= 0) {
4550                         imux->items[imux->num_items].label =
4551                                 auto_pin_cfg_labels[i];
4552                         imux->items[imux->num_items].index = idx;
4553                         imux->num_items++;
4554                 }
4555         }
4556         return 0;
4557 }
4558
4559 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4560                                                 const struct auto_pin_cfg *cfg)
4561 {
4562         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4563 }
4564
4565 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4566                                unsigned int pin_type)
4567 {
4568         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4569                             pin_type);
4570         /* unmute pin */
4571         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4572                             AMP_OUT_UNMUTE);
4573 }
4574
4575 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4576                                               hda_nid_t nid, int pin_type,
4577                                               int dac_idx)
4578 {
4579         alc_set_pin_output(codec, nid, pin_type);
4580         /* need the manual connection? */
4581         if (alc880_is_multi_pin(nid)) {
4582                 struct alc_spec *spec = codec->spec;
4583                 int idx = alc880_multi_pin_idx(nid);
4584                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4585                                     AC_VERB_SET_CONNECT_SEL,
4586                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4587         }
4588 }
4589
4590 static int get_pin_type(int line_out_type)
4591 {
4592         if (line_out_type == AUTO_PIN_HP_OUT)
4593                 return PIN_HP;
4594         else
4595                 return PIN_OUT;
4596 }
4597
4598 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4599 {
4600         struct alc_spec *spec = codec->spec;
4601         int i;
4602
4603         for (i = 0; i < spec->autocfg.line_outs; i++) {
4604                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4605                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4606                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4607         }
4608 }
4609
4610 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4611 {
4612         struct alc_spec *spec = codec->spec;
4613         hda_nid_t pin;
4614
4615         pin = spec->autocfg.speaker_pins[0];
4616         if (pin) /* connect to front */
4617                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4618         pin = spec->autocfg.hp_pins[0];
4619         if (pin) /* connect to front */
4620                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4621 }
4622
4623 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4624 {
4625         struct alc_spec *spec = codec->spec;
4626         int i;
4627
4628         for (i = 0; i < AUTO_PIN_LAST; i++) {
4629                 hda_nid_t nid = spec->autocfg.input_pins[i];
4630                 if (alc_is_input_pin(codec, nid)) {
4631                         alc_set_input_pin(codec, nid, i);
4632                         if (nid != ALC880_PIN_CD_NID &&
4633                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4634                                 snd_hda_codec_write(codec, nid, 0,
4635                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4636                                                     AMP_OUT_MUTE);
4637                 }
4638         }
4639 }
4640
4641 /* parse the BIOS configuration and set up the alc_spec */
4642 /* return 1 if successful, 0 if the proper config is not found,
4643  * or a negative error code
4644  */
4645 static int alc880_parse_auto_config(struct hda_codec *codec)
4646 {
4647         struct alc_spec *spec = codec->spec;
4648         int i, err;
4649         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4650
4651         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4652                                            alc880_ignore);
4653         if (err < 0)
4654                 return err;
4655         if (!spec->autocfg.line_outs)
4656                 return 0; /* can't find valid BIOS pin config */
4657
4658         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4659         if (err < 0)
4660                 return err;
4661         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4662         if (err < 0)
4663                 return err;
4664         err = alc880_auto_create_extra_out(spec,
4665                                            spec->autocfg.speaker_pins[0],
4666                                            "Speaker");
4667         if (err < 0)
4668                 return err;
4669         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4670                                            "Headphone");
4671         if (err < 0)
4672                 return err;
4673         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4674         if (err < 0)
4675                 return err;
4676
4677         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4678
4679         /* check multiple SPDIF-out (for recent codecs) */
4680         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4681                 hda_nid_t dig_nid;
4682                 err = snd_hda_get_connections(codec,
4683                                               spec->autocfg.dig_out_pins[i],
4684                                               &dig_nid, 1);
4685                 if (err < 0)
4686                         continue;
4687                 if (!i)
4688                         spec->multiout.dig_out_nid = dig_nid;
4689                 else {
4690                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4691                         spec->slave_dig_outs[i - 1] = dig_nid;
4692                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4693                                 break;
4694                 }
4695         }
4696         if (spec->autocfg.dig_in_pin)
4697                 spec->dig_in_nid = ALC880_DIGIN_NID;
4698
4699         if (spec->kctls.list)
4700                 add_mixer(spec, spec->kctls.list);
4701
4702         add_verb(spec, alc880_volume_init_verbs);
4703
4704         spec->num_mux_defs = 1;
4705         spec->input_mux = &spec->private_imux[0];
4706
4707         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4708
4709         return 1;
4710 }
4711
4712 /* additional initialization for auto-configuration model */
4713 static void alc880_auto_init(struct hda_codec *codec)
4714 {
4715         struct alc_spec *spec = codec->spec;
4716         alc880_auto_init_multi_out(codec);
4717         alc880_auto_init_extra_out(codec);
4718         alc880_auto_init_analog_input(codec);
4719         if (spec->unsol_event)
4720                 alc_inithook(codec);
4721 }
4722
4723 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4724  * one of two digital mic pins, e.g. on ALC272
4725  */
4726 static void fixup_automic_adc(struct hda_codec *codec)
4727 {
4728         struct alc_spec *spec = codec->spec;
4729         int i;
4730
4731         for (i = 0; i < spec->num_adc_nids; i++) {
4732                 hda_nid_t cap = spec->capsrc_nids ?
4733                         spec->capsrc_nids[i] : spec->adc_nids[i];
4734                 int iidx, eidx;
4735
4736                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4737                 if (iidx < 0)
4738                         continue;
4739                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4740                 if (eidx < 0)
4741                         continue;
4742                 spec->int_mic.mux_idx = iidx;
4743                 spec->ext_mic.mux_idx = eidx;
4744                 if (spec->capsrc_nids)
4745                         spec->capsrc_nids += i;
4746                 spec->adc_nids += i;
4747                 spec->num_adc_nids = 1;
4748                 return;
4749         }
4750         snd_printd(KERN_INFO "hda_codec: %s: "
4751                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4752                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4753         spec->auto_mic = 0; /* disable auto-mic to be sure */
4754 }
4755
4756 static void set_capture_mixer(struct hda_codec *codec)
4757 {
4758         struct alc_spec *spec = codec->spec;
4759         static struct snd_kcontrol_new *caps[2][3] = {
4760                 { alc_capture_mixer_nosrc1,
4761                   alc_capture_mixer_nosrc2,
4762                   alc_capture_mixer_nosrc3 },
4763                 { alc_capture_mixer1,
4764                   alc_capture_mixer2,
4765                   alc_capture_mixer3 },
4766         };
4767         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4768                 int mux;
4769                 if (spec->auto_mic) {
4770                         mux = 0;
4771                         fixup_automic_adc(codec);
4772                 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4773                         mux = 1;
4774                 else
4775                         mux = 0;
4776                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4777         }
4778 }
4779
4780 #define set_beep_amp(spec, nid, idx, dir) \
4781         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4782
4783 /*
4784  * OK, here we have finally the patch for ALC880
4785  */
4786
4787 static int patch_alc880(struct hda_codec *codec)
4788 {
4789         struct alc_spec *spec;
4790         int board_config;
4791         int err;
4792
4793         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4794         if (spec == NULL)
4795                 return -ENOMEM;
4796
4797         codec->spec = spec;
4798
4799         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4800                                                   alc880_models,
4801                                                   alc880_cfg_tbl);
4802         if (board_config < 0) {
4803                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4804                        codec->chip_name);
4805                 board_config = ALC880_AUTO;
4806         }
4807
4808         if (board_config == ALC880_AUTO) {
4809                 /* automatic parse from the BIOS config */
4810                 err = alc880_parse_auto_config(codec);
4811                 if (err < 0) {
4812                         alc_free(codec);
4813                         return err;
4814                 } else if (!err) {
4815                         printk(KERN_INFO
4816                                "hda_codec: Cannot set up configuration "
4817                                "from BIOS.  Using 3-stack mode...\n");
4818                         board_config = ALC880_3ST;
4819                 }
4820         }
4821
4822         err = snd_hda_attach_beep_device(codec, 0x1);
4823         if (err < 0) {
4824                 alc_free(codec);
4825                 return err;
4826         }
4827
4828         if (board_config != ALC880_AUTO)
4829                 setup_preset(codec, &alc880_presets[board_config]);
4830
4831         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4832         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4833         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4834
4835         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4836         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4837
4838         if (!spec->adc_nids && spec->input_mux) {
4839                 /* check whether NID 0x07 is valid */
4840                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4841                 /* get type */
4842                 wcap = get_wcaps_type(wcap);
4843                 if (wcap != AC_WID_AUD_IN) {
4844                         spec->adc_nids = alc880_adc_nids_alt;
4845                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4846                 } else {
4847                         spec->adc_nids = alc880_adc_nids;
4848                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4849                 }
4850         }
4851         set_capture_mixer(codec);
4852         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4853
4854         spec->vmaster_nid = 0x0c;
4855
4856         codec->patch_ops = alc_patch_ops;
4857         if (board_config == ALC880_AUTO)
4858                 spec->init_hook = alc880_auto_init;
4859 #ifdef CONFIG_SND_HDA_POWER_SAVE
4860         if (!spec->loopback.amplist)
4861                 spec->loopback.amplist = alc880_loopbacks;
4862 #endif
4863         codec->proc_widget_hook = print_realtek_coef;
4864
4865         return 0;
4866 }
4867
4868
4869 /*
4870  * ALC260 support
4871  */
4872
4873 static hda_nid_t alc260_dac_nids[1] = {
4874         /* front */
4875         0x02,
4876 };
4877
4878 static hda_nid_t alc260_adc_nids[1] = {
4879         /* ADC0 */
4880         0x04,
4881 };
4882
4883 static hda_nid_t alc260_adc_nids_alt[1] = {
4884         /* ADC1 */
4885         0x05,
4886 };
4887
4888 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4889  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4890  */
4891 static hda_nid_t alc260_dual_adc_nids[2] = {
4892         /* ADC0, ADC1 */
4893         0x04, 0x05
4894 };
4895
4896 #define ALC260_DIGOUT_NID       0x03
4897 #define ALC260_DIGIN_NID        0x06
4898
4899 static struct hda_input_mux alc260_capture_source = {
4900         .num_items = 4,
4901         .items = {
4902                 { "Mic", 0x0 },
4903                 { "Front Mic", 0x1 },
4904                 { "Line", 0x2 },
4905                 { "CD", 0x4 },
4906         },
4907 };
4908
4909 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4910  * headphone jack and the internal CD lines since these are the only pins at
4911  * which audio can appear.  For flexibility, also allow the option of
4912  * recording the mixer output on the second ADC (ADC0 doesn't have a
4913  * connection to the mixer output).
4914  */
4915 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4916         {
4917                 .num_items = 3,
4918                 .items = {
4919                         { "Mic/Line", 0x0 },
4920                         { "CD", 0x4 },
4921                         { "Headphone", 0x2 },
4922                 },
4923         },
4924         {
4925                 .num_items = 4,
4926                 .items = {
4927                         { "Mic/Line", 0x0 },
4928                         { "CD", 0x4 },
4929                         { "Headphone", 0x2 },
4930                         { "Mixer", 0x5 },
4931                 },
4932         },
4933
4934 };
4935
4936 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4937  * the Fujitsu S702x, but jacks are marked differently.
4938  */
4939 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4940         {
4941                 .num_items = 4,
4942                 .items = {
4943                         { "Mic", 0x0 },
4944                         { "Line", 0x2 },
4945                         { "CD", 0x4 },
4946                         { "Headphone", 0x5 },
4947                 },
4948         },
4949         {
4950                 .num_items = 5,
4951                 .items = {
4952                         { "Mic", 0x0 },
4953                         { "Line", 0x2 },
4954                         { "CD", 0x4 },
4955                         { "Headphone", 0x6 },
4956                         { "Mixer", 0x5 },
4957                 },
4958         },
4959 };
4960
4961 /* Maxdata Favorit 100XS */
4962 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4963         {
4964                 .num_items = 2,
4965                 .items = {
4966                         { "Line/Mic", 0x0 },
4967                         { "CD", 0x4 },
4968                 },
4969         },
4970         {
4971                 .num_items = 3,
4972                 .items = {
4973                         { "Line/Mic", 0x0 },
4974                         { "CD", 0x4 },
4975                         { "Mixer", 0x5 },
4976                 },
4977         },
4978 };
4979
4980 /*
4981  * This is just place-holder, so there's something for alc_build_pcms to look
4982  * at when it calculates the maximum number of channels. ALC260 has no mixer
4983  * element which allows changing the channel mode, so the verb list is
4984  * never used.
4985  */
4986 static struct hda_channel_mode alc260_modes[1] = {
4987         { 2, NULL },
4988 };
4989
4990
4991 /* Mixer combinations
4992  *
4993  * basic: base_output + input + pc_beep + capture
4994  * HP: base_output + input + capture_alt
4995  * HP_3013: hp_3013 + input + capture
4996  * fujitsu: fujitsu + capture
4997  * acer: acer + capture
4998  */
4999
5000 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5001         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5002         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5003         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5004         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5005         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5006         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5007         { } /* end */
5008 };
5009
5010 static struct snd_kcontrol_new alc260_input_mixer[] = {
5011         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5012         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5013         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5014         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5015         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5016         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5017         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5018         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5019         { } /* end */
5020 };
5021
5022 /* update HP, line and mono out pins according to the master switch */
5023 static void alc260_hp_master_update(struct hda_codec *codec,
5024                                     hda_nid_t hp, hda_nid_t line,
5025                                     hda_nid_t mono)
5026 {
5027         struct alc_spec *spec = codec->spec;
5028         unsigned int val = spec->master_sw ? PIN_HP : 0;
5029         /* change HP and line-out pins */
5030         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5031                             val);
5032         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5033                             val);
5034         /* mono (speaker) depending on the HP jack sense */
5035         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5036         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5037                             val);
5038 }
5039
5040 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5041                                    struct snd_ctl_elem_value *ucontrol)
5042 {
5043         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5044         struct alc_spec *spec = codec->spec;
5045         *ucontrol->value.integer.value = spec->master_sw;
5046         return 0;
5047 }
5048
5049 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5050                                    struct snd_ctl_elem_value *ucontrol)
5051 {
5052         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5053         struct alc_spec *spec = codec->spec;
5054         int val = !!*ucontrol->value.integer.value;
5055         hda_nid_t hp, line, mono;
5056
5057         if (val == spec->master_sw)
5058                 return 0;
5059         spec->master_sw = val;
5060         hp = (kcontrol->private_value >> 16) & 0xff;
5061         line = (kcontrol->private_value >> 8) & 0xff;
5062         mono = kcontrol->private_value & 0xff;
5063         alc260_hp_master_update(codec, hp, line, mono);
5064         return 1;
5065 }
5066
5067 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5068         {
5069                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5070                 .name = "Master Playback Switch",
5071                 .info = snd_ctl_boolean_mono_info,
5072                 .get = alc260_hp_master_sw_get,
5073                 .put = alc260_hp_master_sw_put,
5074                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5075         },
5076         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5077         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5078         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5079         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5080         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5081                               HDA_OUTPUT),
5082         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5083         { } /* end */
5084 };
5085
5086 static struct hda_verb alc260_hp_unsol_verbs[] = {
5087         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5088         {},
5089 };
5090
5091 static void alc260_hp_automute(struct hda_codec *codec)
5092 {
5093         struct alc_spec *spec = codec->spec;
5094         unsigned int present;
5095
5096         present = snd_hda_codec_read(codec, 0x10, 0,
5097                                      AC_VERB_GET_PIN_SENSE, 0);
5098         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5099         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5100 }
5101
5102 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5103 {
5104         if ((res >> 26) == ALC880_HP_EVENT)
5105                 alc260_hp_automute(codec);
5106 }
5107
5108 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5109         {
5110                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5111                 .name = "Master Playback Switch",
5112                 .info = snd_ctl_boolean_mono_info,
5113                 .get = alc260_hp_master_sw_get,
5114                 .put = alc260_hp_master_sw_put,
5115                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5116         },
5117         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5118         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5119         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5120         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5121         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5123         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5124         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5125         { } /* end */
5126 };
5127
5128 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5129         .ops = &snd_hda_bind_vol,
5130         .values = {
5131                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5132                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5133                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5134                 0
5135         },
5136 };
5137
5138 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5139         .ops = &snd_hda_bind_sw,
5140         .values = {
5141                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5142                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5143                 0
5144         },
5145 };
5146
5147 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5148         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5149         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5150         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5151         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5152         { } /* end */
5153 };
5154
5155 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5156         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5157         {},
5158 };
5159
5160 static void alc260_hp_3013_automute(struct hda_codec *codec)
5161 {
5162         struct alc_spec *spec = codec->spec;
5163         unsigned int present;
5164
5165         present = snd_hda_codec_read(codec, 0x15, 0,
5166                                      AC_VERB_GET_PIN_SENSE, 0);
5167         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5168         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5169 }
5170
5171 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5172                                        unsigned int res)
5173 {
5174         if ((res >> 26) == ALC880_HP_EVENT)
5175                 alc260_hp_3013_automute(codec);
5176 }
5177
5178 static void alc260_hp_3012_automute(struct hda_codec *codec)
5179 {
5180         unsigned int present, bits;
5181
5182         present = snd_hda_codec_read(codec, 0x10, 0,
5183                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5184
5185         bits = present ? 0 : PIN_OUT;
5186         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5187                             bits);
5188         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5189                             bits);
5190         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5191                             bits);
5192 }
5193
5194 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5195                                        unsigned int res)
5196 {
5197         if ((res >> 26) == ALC880_HP_EVENT)
5198                 alc260_hp_3012_automute(codec);
5199 }
5200
5201 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5202  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5203  */
5204 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5205         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5206         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5207         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5208         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5209         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5210         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5211         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5212         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5213         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5214         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5215         { } /* end */
5216 };
5217
5218 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5219  * versions of the ALC260 don't act on requests to enable mic bias from NID
5220  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5221  * datasheet doesn't mention this restriction.  At this stage it's not clear
5222  * whether this behaviour is intentional or is a hardware bug in chip
5223  * revisions available in early 2006.  Therefore for now allow the
5224  * "Headphone Jack Mode" control to span all choices, but if it turns out
5225  * that the lack of mic bias for this NID is intentional we could change the
5226  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5227  *
5228  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5229  * don't appear to make the mic bias available from the "line" jack, even
5230  * though the NID used for this jack (0x14) can supply it.  The theory is
5231  * that perhaps Acer have included blocking capacitors between the ALC260
5232  * and the output jack.  If this turns out to be the case for all such
5233  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5234  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5235  *
5236  * The C20x Tablet series have a mono internal speaker which is controlled
5237  * via the chip's Mono sum widget and pin complex, so include the necessary
5238  * controls for such models.  On models without a "mono speaker" the control
5239  * won't do anything.
5240  */
5241 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5242         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5243         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5244         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5245         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5246                               HDA_OUTPUT),
5247         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5248                            HDA_INPUT),
5249         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5250         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5251         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5252         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5253         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5254         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5255         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5256         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5257         { } /* end */
5258 };
5259
5260 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5261  */
5262 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5263         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5264         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5265         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5266         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5267         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5268         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5269         { } /* end */
5270 };
5271
5272 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5273  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5274  */
5275 static struct snd_kcontrol_new alc260_will_mixer[] = {
5276         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5277         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5278         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5279         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5280         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5281         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5282         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5283         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5284         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5285         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5286         { } /* end */
5287 };
5288
5289 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5290  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5291  */
5292 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5293         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5294         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5295         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5296         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5297         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5298         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5299         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5300         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5301         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5302         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5303         { } /* end */
5304 };
5305
5306 /*
5307  * initialization verbs
5308  */
5309 static struct hda_verb alc260_init_verbs[] = {
5310         /* Line In pin widget for input */
5311         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5312         /* CD pin widget for input */
5313         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5314         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5315         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5316         /* Mic2 (front panel) pin widget for input and vref at 80% */
5317         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5318         /* LINE-2 is used for line-out in rear */
5319         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5320         /* select line-out */
5321         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5322         /* LINE-OUT pin */
5323         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5324         /* enable HP */
5325         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5326         /* enable Mono */
5327         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5328         /* mute capture amp left and right */
5329         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5330         /* set connection select to line in (default select for this ADC) */
5331         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5332         /* mute capture amp left and right */
5333         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5334         /* set connection select to line in (default select for this ADC) */
5335         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5336         /* set vol=0 Line-Out mixer amp left and right */
5337         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5338         /* unmute pin widget amp left and right (no gain on this amp) */
5339         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5340         /* set vol=0 HP mixer amp left and right */
5341         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5342         /* unmute pin widget amp left and right (no gain on this amp) */
5343         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5344         /* set vol=0 Mono mixer amp left and right */
5345         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5346         /* unmute pin widget amp left and right (no gain on this amp) */
5347         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5348         /* unmute LINE-2 out pin */
5349         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5350         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5351          * Line In 2 = 0x03
5352          */
5353         /* mute analog inputs */
5354         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5355         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5356         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5357         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5358         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5359         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5360         /* mute Front out path */
5361         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5362         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5363         /* mute Headphone out path */
5364         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5365         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5366         /* mute Mono out path */
5367         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5368         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5369         { }
5370 };
5371
5372 #if 0 /* should be identical with alc260_init_verbs? */
5373 static struct hda_verb alc260_hp_init_verbs[] = {
5374         /* Headphone and output */
5375         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5376         /* mono output */
5377         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5378         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5379         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5380         /* Mic2 (front panel) pin widget for input and vref at 80% */
5381         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5382         /* Line In pin widget for input */
5383         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5384         /* Line-2 pin widget for output */
5385         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5386         /* CD pin widget for input */
5387         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5388         /* unmute amp left and right */
5389         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5390         /* set connection select to line in (default select for this ADC) */
5391         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5392         /* unmute Line-Out mixer amp left and right (volume = 0) */
5393         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5394         /* mute pin widget amp left and right (no gain on this amp) */
5395         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5396         /* unmute HP mixer amp left and right (volume = 0) */
5397         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5398         /* mute pin widget amp left and right (no gain on this amp) */
5399         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5400         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5401          * Line In 2 = 0x03
5402          */
5403         /* mute analog inputs */
5404         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5405         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5406         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5407         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5409         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5410         /* Unmute Front out path */
5411         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5412         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5413         /* Unmute Headphone out path */
5414         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5415         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5416         /* Unmute Mono out path */
5417         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5418         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5419         { }
5420 };
5421 #endif
5422
5423 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5424         /* Line out and output */
5425         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5426         /* mono output */
5427         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5428         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5429         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5430         /* Mic2 (front panel) pin widget for input and vref at 80% */
5431         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5432         /* Line In pin widget for input */
5433         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5434         /* Headphone pin widget for output */
5435         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5436         /* CD pin widget for input */
5437         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5438         /* unmute amp left and right */
5439         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5440         /* set connection select to line in (default select for this ADC) */
5441         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5442         /* unmute Line-Out mixer amp left and right (volume = 0) */
5443         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5444         /* mute pin widget amp left and right (no gain on this amp) */
5445         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5446         /* unmute HP mixer amp left and right (volume = 0) */
5447         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5448         /* mute pin widget amp left and right (no gain on this amp) */
5449         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5450         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5451          * Line In 2 = 0x03
5452          */
5453         /* mute analog inputs */
5454         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5455         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5459         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5460         /* Unmute Front out path */
5461         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5462         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5463         /* Unmute Headphone out path */
5464         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5465         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5466         /* Unmute Mono out path */
5467         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5468         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5469         { }
5470 };
5471
5472 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5473  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5474  * audio = 0x16, internal speaker = 0x10.
5475  */
5476 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5477         /* Disable all GPIOs */
5478         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5479         /* Internal speaker is connected to headphone pin */
5480         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5481         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5482         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5483         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5484         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5485         /* Ensure all other unused pins are disabled and muted. */
5486         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5487         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5488         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5489         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5490         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5491         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5492         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5493         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5494
5495         /* Disable digital (SPDIF) pins */
5496         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5497         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5498
5499         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5500          * when acting as an output.
5501          */
5502         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5503
5504         /* Start with output sum widgets muted and their output gains at min */
5505         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5506         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5507         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5508         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5509         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5510         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5511         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5512         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5513         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5514
5515         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5516         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5517         /* Unmute Line1 pin widget output buffer since it starts as an output.
5518          * If the pin mode is changed by the user the pin mode control will
5519          * take care of enabling the pin's input/output buffers as needed.
5520          * Therefore there's no need to enable the input buffer at this
5521          * stage.
5522          */
5523         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5524         /* Unmute input buffer of pin widget used for Line-in (no equiv
5525          * mixer ctrl)
5526          */
5527         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5528
5529         /* Mute capture amp left and right */
5530         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5531         /* Set ADC connection select to match default mixer setting - line
5532          * in (on mic1 pin)
5533          */
5534         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5535
5536         /* Do the same for the second ADC: mute capture input amp and
5537          * set ADC connection to line in (on mic1 pin)
5538          */
5539         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5540         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5541
5542         /* Mute all inputs to mixer widget (even unconnected ones) */
5543         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5544         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5545         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5546         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5547         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5548         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5549         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5550         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5551
5552         { }
5553 };
5554
5555 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5556  * similar laptops (adapted from Fujitsu init verbs).
5557  */
5558 static struct hda_verb alc260_acer_init_verbs[] = {
5559         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5560          * the headphone jack.  Turn this on and rely on the standard mute
5561          * methods whenever the user wants to turn these outputs off.
5562          */
5563         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5564         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5565         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5566         /* Internal speaker/Headphone jack is connected to Line-out pin */
5567         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5568         /* Internal microphone/Mic jack is connected to Mic1 pin */
5569         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5570         /* Line In jack is connected to Line1 pin */
5571         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5572         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5573         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5574         /* Ensure all other unused pins are disabled and muted. */
5575         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5576         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5577         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5578         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5579         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5580         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5581         /* Disable digital (SPDIF) pins */
5582         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5583         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5584
5585         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5586          * bus when acting as outputs.
5587          */
5588         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5589         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5590
5591         /* Start with output sum widgets muted and their output gains at min */
5592         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5593         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5595         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5597         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5598         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5599         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5600         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5601
5602         /* Unmute Line-out pin widget amp left and right
5603          * (no equiv mixer ctrl)
5604          */
5605         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5606         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5607         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5608         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5609          * inputs. If the pin mode is changed by the user the pin mode control
5610          * will take care of enabling the pin's input/output buffers as needed.
5611          * Therefore there's no need to enable the input buffer at this
5612          * stage.
5613          */
5614         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5615         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5616
5617         /* Mute capture amp left and right */
5618         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5619         /* Set ADC connection select to match default mixer setting - mic
5620          * (on mic1 pin)
5621          */
5622         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5623
5624         /* Do similar with the second ADC: mute capture input amp and
5625          * set ADC connection to mic to match ALSA's default state.
5626          */
5627         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5628         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5629
5630         /* Mute all inputs to mixer widget (even unconnected ones) */
5631         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5633         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5634         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5635         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5636         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5637         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5638         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5639
5640         { }
5641 };
5642
5643 /* Initialisation sequence for Maxdata Favorit 100XS
5644  * (adapted from Acer init verbs).
5645  */
5646 static struct hda_verb alc260_favorit100_init_verbs[] = {
5647         /* GPIO 0 enables the output jack.
5648          * Turn this on and rely on the standard mute
5649          * methods whenever the user wants to turn these outputs off.
5650          */
5651         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5652         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5653         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5654         /* Line/Mic input jack is connected to Mic1 pin */
5655         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5656         /* Ensure all other unused pins are disabled and muted. */
5657         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5658         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5659         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5660         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5661         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5662         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5663         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5664         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5665         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5666         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5667         /* Disable digital (SPDIF) pins */
5668         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5669         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5670
5671         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5672          * bus when acting as outputs.
5673          */
5674         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5675         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5676
5677         /* Start with output sum widgets muted and their output gains at min */
5678         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5679         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5680         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5681         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5682         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5683         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5684         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5685         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5686         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5687
5688         /* Unmute Line-out pin widget amp left and right
5689          * (no equiv mixer ctrl)
5690          */
5691         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5692         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5693          * inputs. If the pin mode is changed by the user the pin mode control
5694          * will take care of enabling the pin's input/output buffers as needed.
5695          * Therefore there's no need to enable the input buffer at this
5696          * stage.
5697          */
5698         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5699
5700         /* Mute capture amp left and right */
5701         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5702         /* Set ADC connection select to match default mixer setting - mic
5703          * (on mic1 pin)
5704          */
5705         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5706
5707         /* Do similar with the second ADC: mute capture input amp and
5708          * set ADC connection to mic to match ALSA's default state.
5709          */
5710         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5711         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5712
5713         /* Mute all inputs to mixer widget (even unconnected ones) */
5714         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5715         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5716         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5717         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5718         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5719         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5720         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5721         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5722
5723         { }
5724 };
5725
5726 static struct hda_verb alc260_will_verbs[] = {
5727         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5728         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5729         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5730         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5731         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5732         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5733         {}
5734 };
5735
5736 static struct hda_verb alc260_replacer_672v_verbs[] = {
5737         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5738         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5739         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5740
5741         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5742         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5743         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5744
5745         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5746         {}
5747 };
5748
5749 /* toggle speaker-output according to the hp-jack state */
5750 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5751 {
5752         unsigned int present;
5753
5754         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5755         present = snd_hda_codec_read(codec, 0x0f, 0,
5756                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5757         if (present) {
5758                 snd_hda_codec_write_cache(codec, 0x01, 0,
5759                                           AC_VERB_SET_GPIO_DATA, 1);
5760                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5761                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5762                                           PIN_HP);
5763         } else {
5764                 snd_hda_codec_write_cache(codec, 0x01, 0,
5765                                           AC_VERB_SET_GPIO_DATA, 0);
5766                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5767                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5768                                           PIN_OUT);
5769         }
5770 }
5771
5772 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5773                                        unsigned int res)
5774 {
5775         if ((res >> 26) == ALC880_HP_EVENT)
5776                 alc260_replacer_672v_automute(codec);
5777 }
5778
5779 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5780         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5781         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5782         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5783         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5784         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5785         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5786         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5787         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5788         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5789         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5790         {}
5791 };
5792
5793 /* Test configuration for debugging, modelled after the ALC880 test
5794  * configuration.
5795  */
5796 #ifdef CONFIG_SND_DEBUG
5797 static hda_nid_t alc260_test_dac_nids[1] = {
5798         0x02,
5799 };
5800 static hda_nid_t alc260_test_adc_nids[2] = {
5801         0x04, 0x05,
5802 };
5803 /* For testing the ALC260, each input MUX needs its own definition since
5804  * the signal assignments are different.  This assumes that the first ADC
5805  * is NID 0x04.
5806  */
5807 static struct hda_input_mux alc260_test_capture_sources[2] = {
5808         {
5809                 .num_items = 7,
5810                 .items = {
5811                         { "MIC1 pin", 0x0 },
5812                         { "MIC2 pin", 0x1 },
5813                         { "LINE1 pin", 0x2 },
5814                         { "LINE2 pin", 0x3 },
5815                         { "CD pin", 0x4 },
5816                         { "LINE-OUT pin", 0x5 },
5817                         { "HP-OUT pin", 0x6 },
5818                 },
5819         },
5820         {
5821                 .num_items = 8,
5822                 .items = {
5823                         { "MIC1 pin", 0x0 },
5824                         { "MIC2 pin", 0x1 },
5825                         { "LINE1 pin", 0x2 },
5826                         { "LINE2 pin", 0x3 },
5827                         { "CD pin", 0x4 },
5828                         { "Mixer", 0x5 },
5829                         { "LINE-OUT pin", 0x6 },
5830                         { "HP-OUT pin", 0x7 },
5831                 },
5832         },
5833 };
5834 static struct snd_kcontrol_new alc260_test_mixer[] = {
5835         /* Output driver widgets */
5836         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5837         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5838         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5839         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5840         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5841         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5842
5843         /* Modes for retasking pin widgets
5844          * Note: the ALC260 doesn't seem to act on requests to enable mic
5845          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5846          * mention this restriction.  At this stage it's not clear whether
5847          * this behaviour is intentional or is a hardware bug in chip
5848          * revisions available at least up until early 2006.  Therefore for
5849          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5850          * choices, but if it turns out that the lack of mic bias for these
5851          * NIDs is intentional we could change their modes from
5852          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5853          */
5854         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5855         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5856         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5857         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5858         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5859         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5860
5861         /* Loopback mixer controls */
5862         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5863         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5864         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5865         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5866         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5867         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5868         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5869         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5870         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5871         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5872         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5873         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5874         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5875         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5876
5877         /* Controls for GPIO pins, assuming they are configured as outputs */
5878         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5879         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5880         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5881         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5882
5883         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5884          * is ambigious as to which NID is which; testing on laptops which
5885          * make this output available should provide clarification.
5886          */
5887         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5888         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5889
5890         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5891          * this output to turn on an external amplifier.
5892          */
5893         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5894         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5895
5896         { } /* end */
5897 };
5898 static struct hda_verb alc260_test_init_verbs[] = {
5899         /* Enable all GPIOs as outputs with an initial value of 0 */
5900         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5901         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5902         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5903
5904         /* Enable retasking pins as output, initially without power amp */
5905         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5906         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5907         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5908         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5909         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5910         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5911
5912         /* Disable digital (SPDIF) pins initially, but users can enable
5913          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5914          * payload also sets the generation to 0, output to be in "consumer"
5915          * PCM format, copyright asserted, no pre-emphasis and no validity
5916          * control.
5917          */
5918         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5919         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5920
5921         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5922          * OUT1 sum bus when acting as an output.
5923          */
5924         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5925         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5926         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5927         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5928
5929         /* Start with output sum widgets muted and their output gains at min */
5930         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5931         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5932         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5933         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5934         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5935         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5936         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5937         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5938         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5939
5940         /* Unmute retasking pin widget output buffers since the default
5941          * state appears to be output.  As the pin mode is changed by the
5942          * user the pin mode control will take care of enabling the pin's
5943          * input/output buffers as needed.
5944          */
5945         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5946         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5947         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5948         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5949         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5950         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5951         /* Also unmute the mono-out pin widget */
5952         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5953
5954         /* Mute capture amp left and right */
5955         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5956         /* Set ADC connection select to match default mixer setting (mic1
5957          * pin)
5958          */
5959         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5960
5961         /* Do the same for the second ADC: mute capture input amp and
5962          * set ADC connection to mic1 pin
5963          */
5964         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5965         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5966
5967         /* Mute all inputs to mixer widget (even unconnected ones) */
5968         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5969         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5970         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5971         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5972         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5973         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5974         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5975         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5976
5977         { }
5978 };
5979 #endif
5980
5981 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5982 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5983
5984 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5985 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5986
5987 /*
5988  * for BIOS auto-configuration
5989  */
5990
5991 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5992                                         const char *pfx, int *vol_bits)
5993 {
5994         hda_nid_t nid_vol;
5995         unsigned long vol_val, sw_val;
5996         int err;
5997
5998         if (nid >= 0x0f && nid < 0x11) {
5999                 nid_vol = nid - 0x7;
6000                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6001                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6002         } else if (nid == 0x11) {
6003                 nid_vol = nid - 0x7;
6004                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
6005                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
6006         } else if (nid >= 0x12 && nid <= 0x15) {
6007                 nid_vol = 0x08;
6008                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6009                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6010         } else
6011                 return 0; /* N/A */
6012
6013         if (!(*vol_bits & (1 << nid_vol))) {
6014                 /* first control for the volume widget */
6015                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6016                 if (err < 0)
6017                         return err;
6018                 *vol_bits |= (1 << nid_vol);
6019         }
6020         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6021         if (err < 0)
6022                 return err;
6023         return 1;
6024 }
6025
6026 /* add playback controls from the parsed DAC table */
6027 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
6028                                              const struct auto_pin_cfg *cfg)
6029 {
6030         hda_nid_t nid;
6031         int err;
6032         int vols = 0;
6033
6034         spec->multiout.num_dacs = 1;
6035         spec->multiout.dac_nids = spec->private_dac_nids;
6036         spec->multiout.dac_nids[0] = 0x02;
6037
6038         nid = cfg->line_out_pins[0];
6039         if (nid) {
6040                 const char *pfx;
6041                 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
6042                         pfx = "Master";
6043                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
6044                         pfx = "Speaker";
6045                 else
6046                         pfx = "Front";
6047                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
6048                 if (err < 0)
6049                         return err;
6050         }
6051
6052         nid = cfg->speaker_pins[0];
6053         if (nid) {
6054                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
6055                 if (err < 0)
6056                         return err;
6057         }
6058
6059         nid = cfg->hp_pins[0];
6060         if (nid) {
6061                 err = alc260_add_playback_controls(spec, nid, "Headphone",
6062                                                    &vols);
6063                 if (err < 0)
6064                         return err;
6065         }
6066         return 0;
6067 }
6068
6069 /* create playback/capture controls for input pins */
6070 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
6071                                                 const struct auto_pin_cfg *cfg)
6072 {
6073         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
6074 }
6075
6076 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
6077                                               hda_nid_t nid, int pin_type,
6078                                               int sel_idx)
6079 {
6080         alc_set_pin_output(codec, nid, pin_type);
6081         /* need the manual connection? */
6082         if (nid >= 0x12) {
6083                 int idx = nid - 0x12;
6084                 snd_hda_codec_write(codec, idx + 0x0b, 0,
6085                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
6086         }
6087 }
6088
6089 static void alc260_auto_init_multi_out(struct hda_codec *codec)
6090 {
6091         struct alc_spec *spec = codec->spec;
6092         hda_nid_t nid;
6093
6094         nid = spec->autocfg.line_out_pins[0];
6095         if (nid) {
6096                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6097                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
6098         }
6099
6100         nid = spec->autocfg.speaker_pins[0];
6101         if (nid)
6102                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
6103
6104         nid = spec->autocfg.hp_pins[0];
6105         if (nid)
6106                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
6107 }
6108
6109 #define ALC260_PIN_CD_NID               0x16
6110 static void alc260_auto_init_analog_input(struct hda_codec *codec)
6111 {
6112         struct alc_spec *spec = codec->spec;
6113         int i;
6114
6115         for (i = 0; i < AUTO_PIN_LAST; i++) {
6116                 hda_nid_t nid = spec->autocfg.input_pins[i];
6117                 if (nid >= 0x12) {
6118                         alc_set_input_pin(codec, nid, i);
6119                         if (nid != ALC260_PIN_CD_NID &&
6120                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
6121                                 snd_hda_codec_write(codec, nid, 0,
6122                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6123                                                     AMP_OUT_MUTE);
6124                 }
6125         }
6126 }
6127
6128 /*
6129  * generic initialization of ADC, input mixers and output mixers
6130  */
6131 static struct hda_verb alc260_volume_init_verbs[] = {
6132         /*
6133          * Unmute ADC0-1 and set the default input to mic-in
6134          */
6135         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6136         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6137         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6138         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6139
6140         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6141          * mixer widget
6142          * Note: PASD motherboards uses the Line In 2 as the input for
6143          * front panel mic (mic 2)
6144          */
6145         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6146         /* mute analog inputs */
6147         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6148         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6149         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6150         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6151         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6152
6153         /*
6154          * Set up output mixers (0x08 - 0x0a)
6155          */
6156         /* set vol=0 to output mixers */
6157         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6158         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6159         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6160         /* set up input amps for analog loopback */
6161         /* Amp Indices: DAC = 0, mixer = 1 */
6162         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6163         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6164         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6165         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6166         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6167         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6168
6169         { }
6170 };
6171
6172 static int alc260_parse_auto_config(struct hda_codec *codec)
6173 {
6174         struct alc_spec *spec = codec->spec;
6175         int err;
6176         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
6177
6178         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6179                                            alc260_ignore);
6180         if (err < 0)
6181                 return err;
6182         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
6183         if (err < 0)
6184                 return err;
6185         if (!spec->kctls.list)
6186                 return 0; /* can't find valid BIOS pin config */
6187         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
6188         if (err < 0)
6189                 return err;
6190
6191         spec->multiout.max_channels = 2;
6192
6193         if (spec->autocfg.dig_outs)
6194                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6195         if (spec->kctls.list)
6196                 add_mixer(spec, spec->kctls.list);
6197
6198         add_verb(spec, alc260_volume_init_verbs);
6199
6200         spec->num_mux_defs = 1;
6201         spec->input_mux = &spec->private_imux[0];
6202
6203         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6204
6205         return 1;
6206 }
6207
6208 /* additional initialization for auto-configuration model */
6209 static void alc260_auto_init(struct hda_codec *codec)
6210 {
6211         struct alc_spec *spec = codec->spec;
6212         alc260_auto_init_multi_out(codec);
6213         alc260_auto_init_analog_input(codec);
6214         if (spec->unsol_event)
6215                 alc_inithook(codec);
6216 }
6217
6218 #ifdef CONFIG_SND_HDA_POWER_SAVE
6219 static struct hda_amp_list alc260_loopbacks[] = {
6220         { 0x07, HDA_INPUT, 0 },
6221         { 0x07, HDA_INPUT, 1 },
6222         { 0x07, HDA_INPUT, 2 },
6223         { 0x07, HDA_INPUT, 3 },
6224         { 0x07, HDA_INPUT, 4 },
6225         { } /* end */
6226 };
6227 #endif
6228
6229 /*
6230  * ALC260 configurations
6231  */
6232 static const char *alc260_models[ALC260_MODEL_LAST] = {
6233         [ALC260_BASIC]          = "basic",
6234         [ALC260_HP]             = "hp",
6235         [ALC260_HP_3013]        = "hp-3013",
6236         [ALC260_HP_DC7600]      = "hp-dc7600",
6237         [ALC260_FUJITSU_S702X]  = "fujitsu",
6238         [ALC260_ACER]           = "acer",
6239         [ALC260_WILL]           = "will",
6240         [ALC260_REPLACER_672V]  = "replacer",
6241         [ALC260_FAVORIT100]     = "favorit100",
6242 #ifdef CONFIG_SND_DEBUG
6243         [ALC260_TEST]           = "test",
6244 #endif
6245         [ALC260_AUTO]           = "auto",
6246 };
6247
6248 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6249         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6250         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6251         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6252         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6253         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
6254         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6255         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6256         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6257         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6258         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6259         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6260         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6261         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6262         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6263         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6264         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6265         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6266         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6267         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6268         {}
6269 };
6270
6271 static struct alc_config_preset alc260_presets[] = {
6272         [ALC260_BASIC] = {
6273                 .mixers = { alc260_base_output_mixer,
6274                             alc260_input_mixer },
6275                 .init_verbs = { alc260_init_verbs },
6276                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6277                 .dac_nids = alc260_dac_nids,
6278                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6279                 .adc_nids = alc260_adc_nids,
6280                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6281                 .channel_mode = alc260_modes,
6282                 .input_mux = &alc260_capture_source,
6283         },
6284         [ALC260_HP] = {
6285                 .mixers = { alc260_hp_output_mixer,
6286                             alc260_input_mixer },
6287                 .init_verbs = { alc260_init_verbs,
6288                                 alc260_hp_unsol_verbs },
6289                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6290                 .dac_nids = alc260_dac_nids,
6291                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6292                 .adc_nids = alc260_adc_nids_alt,
6293                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6294                 .channel_mode = alc260_modes,
6295                 .input_mux = &alc260_capture_source,
6296                 .unsol_event = alc260_hp_unsol_event,
6297                 .init_hook = alc260_hp_automute,
6298         },
6299         [ALC260_HP_DC7600] = {
6300                 .mixers = { alc260_hp_dc7600_mixer,
6301                             alc260_input_mixer },
6302                 .init_verbs = { alc260_init_verbs,
6303                                 alc260_hp_dc7600_verbs },
6304                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6305                 .dac_nids = alc260_dac_nids,
6306                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6307                 .adc_nids = alc260_adc_nids_alt,
6308                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6309                 .channel_mode = alc260_modes,
6310                 .input_mux = &alc260_capture_source,
6311                 .unsol_event = alc260_hp_3012_unsol_event,
6312                 .init_hook = alc260_hp_3012_automute,
6313         },
6314         [ALC260_HP_3013] = {
6315                 .mixers = { alc260_hp_3013_mixer,
6316                             alc260_input_mixer },
6317                 .init_verbs = { alc260_hp_3013_init_verbs,
6318                                 alc260_hp_3013_unsol_verbs },
6319                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6320                 .dac_nids = alc260_dac_nids,
6321                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6322                 .adc_nids = alc260_adc_nids_alt,
6323                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6324                 .channel_mode = alc260_modes,
6325                 .input_mux = &alc260_capture_source,
6326                 .unsol_event = alc260_hp_3013_unsol_event,
6327                 .init_hook = alc260_hp_3013_automute,
6328         },
6329         [ALC260_FUJITSU_S702X] = {
6330                 .mixers = { alc260_fujitsu_mixer },
6331                 .init_verbs = { alc260_fujitsu_init_verbs },
6332                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6333                 .dac_nids = alc260_dac_nids,
6334                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6335                 .adc_nids = alc260_dual_adc_nids,
6336                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6337                 .channel_mode = alc260_modes,
6338                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6339                 .input_mux = alc260_fujitsu_capture_sources,
6340         },
6341         [ALC260_ACER] = {
6342                 .mixers = { alc260_acer_mixer },
6343                 .init_verbs = { alc260_acer_init_verbs },
6344                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6345                 .dac_nids = alc260_dac_nids,
6346                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6347                 .adc_nids = alc260_dual_adc_nids,
6348                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6349                 .channel_mode = alc260_modes,
6350                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6351                 .input_mux = alc260_acer_capture_sources,
6352         },
6353         [ALC260_FAVORIT100] = {
6354                 .mixers = { alc260_favorit100_mixer },
6355                 .init_verbs = { alc260_favorit100_init_verbs },
6356                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6357                 .dac_nids = alc260_dac_nids,
6358                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6359                 .adc_nids = alc260_dual_adc_nids,
6360                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6361                 .channel_mode = alc260_modes,
6362                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6363                 .input_mux = alc260_favorit100_capture_sources,
6364         },
6365         [ALC260_WILL] = {
6366                 .mixers = { alc260_will_mixer },
6367                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6368                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6369                 .dac_nids = alc260_dac_nids,
6370                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6371                 .adc_nids = alc260_adc_nids,
6372                 .dig_out_nid = ALC260_DIGOUT_NID,
6373                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6374                 .channel_mode = alc260_modes,
6375                 .input_mux = &alc260_capture_source,
6376         },
6377         [ALC260_REPLACER_672V] = {
6378                 .mixers = { alc260_replacer_672v_mixer },
6379                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6380                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6381                 .dac_nids = alc260_dac_nids,
6382                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6383                 .adc_nids = alc260_adc_nids,
6384                 .dig_out_nid = ALC260_DIGOUT_NID,
6385                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6386                 .channel_mode = alc260_modes,
6387                 .input_mux = &alc260_capture_source,
6388                 .unsol_event = alc260_replacer_672v_unsol_event,
6389                 .init_hook = alc260_replacer_672v_automute,
6390         },
6391 #ifdef CONFIG_SND_DEBUG
6392         [ALC260_TEST] = {
6393                 .mixers = { alc260_test_mixer },
6394                 .init_verbs = { alc260_test_init_verbs },
6395                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6396                 .dac_nids = alc260_test_dac_nids,
6397                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6398                 .adc_nids = alc260_test_adc_nids,
6399                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6400                 .channel_mode = alc260_modes,
6401                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6402                 .input_mux = alc260_test_capture_sources,
6403         },
6404 #endif
6405 };
6406
6407 static int patch_alc260(struct hda_codec *codec)
6408 {
6409         struct alc_spec *spec;
6410         int err, board_config;
6411
6412         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6413         if (spec == NULL)
6414                 return -ENOMEM;
6415
6416         codec->spec = spec;
6417
6418         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6419                                                   alc260_models,
6420                                                   alc260_cfg_tbl);
6421         if (board_config < 0) {
6422                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6423                            codec->chip_name);
6424                 board_config = ALC260_AUTO;
6425         }
6426
6427         if (board_config == ALC260_AUTO) {
6428                 /* automatic parse from the BIOS config */
6429                 err = alc260_parse_auto_config(codec);
6430                 if (err < 0) {
6431                         alc_free(codec);
6432                         return err;
6433                 } else if (!err) {
6434                         printk(KERN_INFO
6435                                "hda_codec: Cannot set up configuration "
6436                                "from BIOS.  Using base mode...\n");
6437                         board_config = ALC260_BASIC;
6438                 }
6439         }
6440
6441         err = snd_hda_attach_beep_device(codec, 0x1);
6442         if (err < 0) {
6443                 alc_free(codec);
6444                 return err;
6445         }
6446
6447         if (board_config != ALC260_AUTO)
6448                 setup_preset(codec, &alc260_presets[board_config]);
6449
6450         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6451         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6452
6453         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6454         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6455
6456         if (!spec->adc_nids && spec->input_mux) {
6457                 /* check whether NID 0x04 is valid */
6458                 unsigned int wcap = get_wcaps(codec, 0x04);
6459                 wcap = get_wcaps_type(wcap);
6460                 /* get type */
6461                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6462                         spec->adc_nids = alc260_adc_nids_alt;
6463                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6464                 } else {
6465                         spec->adc_nids = alc260_adc_nids;
6466                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6467                 }
6468         }
6469         set_capture_mixer(codec);
6470         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6471
6472         spec->vmaster_nid = 0x08;
6473
6474         codec->patch_ops = alc_patch_ops;
6475         if (board_config == ALC260_AUTO)
6476                 spec->init_hook = alc260_auto_init;
6477 #ifdef CONFIG_SND_HDA_POWER_SAVE
6478         if (!spec->loopback.amplist)
6479                 spec->loopback.amplist = alc260_loopbacks;
6480 #endif
6481         codec->proc_widget_hook = print_realtek_coef;
6482
6483         return 0;
6484 }
6485
6486
6487 /*
6488  * ALC882/883/885/888/889 support
6489  *
6490  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6491  * configuration.  Each pin widget can choose any input DACs and a mixer.
6492  * Each ADC is connected from a mixer of all inputs.  This makes possible
6493  * 6-channel independent captures.
6494  *
6495  * In addition, an independent DAC for the multi-playback (not used in this
6496  * driver yet).
6497  */
6498 #define ALC882_DIGOUT_NID       0x06
6499 #define ALC882_DIGIN_NID        0x0a
6500 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
6501 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
6502 #define ALC1200_DIGOUT_NID      0x10
6503
6504
6505 static struct hda_channel_mode alc882_ch_modes[1] = {
6506         { 8, NULL }
6507 };
6508
6509 /* DACs */
6510 static hda_nid_t alc882_dac_nids[4] = {
6511         /* front, rear, clfe, rear_surr */
6512         0x02, 0x03, 0x04, 0x05
6513 };
6514 #define alc883_dac_nids         alc882_dac_nids
6515
6516 /* ADCs */
6517 #define alc882_adc_nids         alc880_adc_nids
6518 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6519 #define alc883_adc_nids         alc882_adc_nids_alt
6520 static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
6521 static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
6522 #define alc889_adc_nids         alc880_adc_nids
6523
6524 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6525 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6526 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
6527 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
6528 #define alc889_capsrc_nids      alc882_capsrc_nids
6529
6530 /* input MUX */
6531 /* FIXME: should be a matrix-type input source selection */
6532
6533 static struct hda_input_mux alc882_capture_source = {
6534         .num_items = 4,
6535         .items = {
6536                 { "Mic", 0x0 },
6537                 { "Front Mic", 0x1 },
6538                 { "Line", 0x2 },
6539                 { "CD", 0x4 },
6540         },
6541 };
6542
6543 #define alc883_capture_source   alc882_capture_source
6544
6545 static struct hda_input_mux alc889_capture_source = {
6546         .num_items = 3,
6547         .items = {
6548                 { "Front Mic", 0x0 },
6549                 { "Mic", 0x3 },
6550                 { "Line", 0x2 },
6551         },
6552 };
6553
6554 static struct hda_input_mux mb5_capture_source = {
6555         .num_items = 3,
6556         .items = {
6557                 { "Mic", 0x1 },
6558                 { "Line", 0x2 },
6559                 { "CD", 0x4 },
6560         },
6561 };
6562
6563 static struct hda_input_mux alc883_3stack_6ch_intel = {
6564         .num_items = 4,
6565         .items = {
6566                 { "Mic", 0x1 },
6567                 { "Front Mic", 0x0 },
6568                 { "Line", 0x2 },
6569                 { "CD", 0x4 },
6570         },
6571 };
6572
6573 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6574         .num_items = 2,
6575         .items = {
6576                 { "Mic", 0x1 },
6577                 { "Line", 0x2 },
6578         },
6579 };
6580
6581 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6582         .num_items = 4,
6583         .items = {
6584                 { "Mic", 0x0 },
6585                 { "iMic", 0x1 },
6586                 { "Line", 0x2 },
6587                 { "CD", 0x4 },
6588         },
6589 };
6590
6591 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6592         .num_items = 2,
6593         .items = {
6594                 { "Mic", 0x0 },
6595                 { "Int Mic", 0x1 },
6596         },
6597 };
6598
6599 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6600         .num_items = 3,
6601         .items = {
6602                 { "Mic", 0x0 },
6603                 { "Front Mic", 0x1 },
6604                 { "Line", 0x4 },
6605         },
6606 };
6607
6608 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6609         .num_items = 2,
6610         .items = {
6611                 { "Mic", 0x0 },
6612                 { "Line", 0x2 },
6613         },
6614 };
6615
6616 static struct hda_input_mux alc889A_mb31_capture_source = {
6617         .num_items = 2,
6618         .items = {
6619                 { "Mic", 0x0 },
6620                 /* Front Mic (0x01) unused */
6621                 { "Line", 0x2 },
6622                 /* Line 2 (0x03) unused */
6623                 /* CD (0x04) unsused? */
6624         },
6625 };
6626
6627 /*
6628  * 2ch mode
6629  */
6630 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6631         { 2, NULL }
6632 };
6633
6634 /*
6635  * 2ch mode
6636  */
6637 static struct hda_verb alc882_3ST_ch2_init[] = {
6638         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6639         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6640         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6641         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6642         { } /* end */
6643 };
6644
6645 /*
6646  * 4ch mode
6647  */
6648 static struct hda_verb alc882_3ST_ch4_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_OUT },
6652         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6653         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6654         { } /* end */
6655 };
6656
6657 /*
6658  * 6ch mode
6659  */
6660 static struct hda_verb alc882_3ST_ch6_init[] = {
6661         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6662         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6663         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6664         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6665         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6666         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6667         { } /* end */
6668 };
6669
6670 static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6671         { 2, alc882_3ST_ch2_init },
6672         { 4, alc882_3ST_ch4_init },
6673         { 6, alc882_3ST_ch6_init },
6674 };
6675
6676 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
6677
6678 /*
6679  * 2ch mode
6680  */
6681 static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
6682         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
6683         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6684         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6685         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6686         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6687         { } /* end */
6688 };
6689
6690 /*
6691  * 4ch mode
6692  */
6693 static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
6694         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6695         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6696         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6697         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6698         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6699         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6700         { } /* end */
6701 };
6702
6703 /*
6704  * 6ch mode
6705  */
6706 static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
6707         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6708         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6709         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6710         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6711         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6712         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6713         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6714         { } /* end */
6715 };
6716
6717 static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
6718         { 2, alc883_3ST_ch2_clevo_init },
6719         { 4, alc883_3ST_ch4_clevo_init },
6720         { 6, alc883_3ST_ch6_clevo_init },
6721 };
6722
6723
6724 /*
6725  * 6ch mode
6726  */
6727 static struct hda_verb alc882_sixstack_ch6_init[] = {
6728         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6729         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6730         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6731         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6732         { } /* end */
6733 };
6734
6735 /*
6736  * 8ch mode
6737  */
6738 static struct hda_verb alc882_sixstack_ch8_init[] = {
6739         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
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 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6747         { 6, alc882_sixstack_ch6_init },
6748         { 8, alc882_sixstack_ch8_init },
6749 };
6750
6751 /*
6752  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6753  */
6754
6755 /*
6756  * 2ch mode
6757  */
6758 static struct hda_verb alc885_mbp_ch2_init[] = {
6759         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6760         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6761         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6762         { } /* end */
6763 };
6764
6765 /*
6766  * 4ch mode
6767  */
6768 static struct hda_verb alc885_mbp_ch4_init[] = {
6769         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6770         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6771         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6772         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6773         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6774         { } /* end */
6775 };
6776
6777 static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6778         { 2, alc885_mbp_ch2_init },
6779         { 4, alc885_mbp_ch4_init },
6780 };
6781
6782 /*
6783  * 2ch
6784  * Speakers/Woofer/HP = Front
6785  * LineIn = Input
6786  */
6787 static struct hda_verb alc885_mb5_ch2_init[] = {
6788         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6789         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6790         { } /* end */
6791 };
6792
6793 /*
6794  * 6ch mode
6795  * Speakers/HP = Front
6796  * Woofer = LFE
6797  * LineIn = Surround
6798  */
6799 static struct hda_verb alc885_mb5_ch6_init[] = {
6800         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6801         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6802         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6803         { } /* end */
6804 };
6805
6806 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6807         { 2, alc885_mb5_ch2_init },
6808         { 6, alc885_mb5_ch6_init },
6809 };
6810
6811
6812 /*
6813  * 2ch mode
6814  */
6815 static struct hda_verb alc883_4ST_ch2_init[] = {
6816         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6817         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6818         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6819         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6820         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6821         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6822         { } /* end */
6823 };
6824
6825 /*
6826  * 4ch mode
6827  */
6828 static struct hda_verb alc883_4ST_ch4_init[] = {
6829         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6830         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6831         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6832         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6833         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6834         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6835         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6836         { } /* end */
6837 };
6838
6839 /*
6840  * 6ch mode
6841  */
6842 static struct hda_verb alc883_4ST_ch6_init[] = {
6843         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6844         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6845         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6846         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6847         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6848         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6849         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6850         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6851         { } /* end */
6852 };
6853
6854 /*
6855  * 8ch mode
6856  */
6857 static struct hda_verb alc883_4ST_ch8_init[] = {
6858         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6859         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6860         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6861         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6862         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6863         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6864         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6865         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6866         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6867         { } /* end */
6868 };
6869
6870 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
6871         { 2, alc883_4ST_ch2_init },
6872         { 4, alc883_4ST_ch4_init },
6873         { 6, alc883_4ST_ch6_init },
6874         { 8, alc883_4ST_ch8_init },
6875 };
6876
6877
6878 /*
6879  * 2ch mode
6880  */
6881 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6882         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6883         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6884         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6885         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6886         { } /* end */
6887 };
6888
6889 /*
6890  * 4ch mode
6891  */
6892 static struct hda_verb alc883_3ST_ch4_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_OUT },
6896         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6897         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6898         { } /* end */
6899 };
6900
6901 /*
6902  * 6ch mode
6903  */
6904 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6905         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6906         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6907         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6908         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6909         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6910         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6911         { } /* end */
6912 };
6913
6914 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6915         { 2, alc883_3ST_ch2_intel_init },
6916         { 4, alc883_3ST_ch4_intel_init },
6917         { 6, alc883_3ST_ch6_intel_init },
6918 };
6919
6920 /*
6921  * 2ch mode
6922  */
6923 static struct hda_verb alc889_ch2_intel_init[] = {
6924         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6925         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
6926         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
6927         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
6928         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6929         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6930         { } /* end */
6931 };
6932
6933 /*
6934  * 6ch mode
6935  */
6936 static struct hda_verb alc889_ch6_intel_init[] = {
6937         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6938         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6939         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6940         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6941         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6942         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6943         { } /* end */
6944 };
6945
6946 /*
6947  * 8ch mode
6948  */
6949 static struct hda_verb alc889_ch8_intel_init[] = {
6950         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6951         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6952         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6953         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6954         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
6955         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6956         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6957         { } /* end */
6958 };
6959
6960 static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
6961         { 2, alc889_ch2_intel_init },
6962         { 6, alc889_ch6_intel_init },
6963         { 8, alc889_ch8_intel_init },
6964 };
6965
6966 /*
6967  * 6ch mode
6968  */
6969 static struct hda_verb alc883_sixstack_ch6_init[] = {
6970         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6971         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6972         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6973         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6974         { } /* end */
6975 };
6976
6977 /*
6978  * 8ch mode
6979  */
6980 static struct hda_verb alc883_sixstack_ch8_init[] = {
6981         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
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 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6989         { 6, alc883_sixstack_ch6_init },
6990         { 8, alc883_sixstack_ch8_init },
6991 };
6992
6993
6994 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6995  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6996  */
6997 static struct snd_kcontrol_new alc882_base_mixer[] = {
6998         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6999         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7000         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7001         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7002         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7003         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7004         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7005         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7006         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7007         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7008         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7009         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7010         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7011         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7012         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7013         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7014         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7015         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7016         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7017         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7018         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7019         { } /* end */
7020 };
7021
7022 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7023         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7024         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
7025         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7026         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7028         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7029         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7030         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7031         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7032         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
7033         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7034         { } /* end */
7035 };
7036
7037 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7038         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7039         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
7040         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7041         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7042         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7043         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7044         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7045         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
7046         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7047         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7048         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7049         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7050         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
7051         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
7052         { } /* end */
7053 };
7054
7055 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7056         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7057         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7058         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7059         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7060         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7061         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7063         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7064         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7065         { } /* end */
7066 };
7067
7068 static struct snd_kcontrol_new alc882_targa_mixer[] = {
7069         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7070         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7071         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7072         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7073         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7075         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7076         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7077         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7078         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7079         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7080         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7081         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7082         { } /* end */
7083 };
7084
7085 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
7086  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
7087  */
7088 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
7089         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7090         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7091         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7092         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
7093         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7094         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7095         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7096         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
7098         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
7099         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7100         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7101         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7102         { } /* end */
7103 };
7104
7105 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
7106         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7107         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7108         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7109         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7110         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7111         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7112         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7114         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7115         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7116         { } /* end */
7117 };
7118
7119 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
7120         {
7121                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7122                 .name = "Channel Mode",
7123                 .info = alc_ch_mode_info,
7124                 .get = alc_ch_mode_get,
7125                 .put = alc_ch_mode_put,
7126         },
7127         { } /* end */
7128 };
7129
7130 static struct hda_verb alc882_base_init_verbs[] = {
7131         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7132         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7133         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7134         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7135         /* Rear mixer */
7136         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7137         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7138         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7139         /* CLFE mixer */
7140         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7141         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7142         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7143         /* Side mixer */
7144         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7145         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7146         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7147
7148         /* mute analog input loopbacks */
7149         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7150         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7151         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7153         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7154
7155         /* Front Pin: output 0 (0x0c) */
7156         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7157         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7158         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7159         /* Rear Pin: output 1 (0x0d) */
7160         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7161         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7162         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7163         /* CLFE Pin: output 2 (0x0e) */
7164         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7165         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7166         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7167         /* Side Pin: output 3 (0x0f) */
7168         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7169         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7170         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7171         /* Mic (rear) pin: input vref at 80% */
7172         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7173         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7174         /* Front Mic pin: input vref at 80% */
7175         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7176         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7177         /* Line In pin: input */
7178         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7179         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7180         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7181         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7182         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7183         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7184         /* CD pin widget for input */
7185         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7186
7187         /* FIXME: use matrix-type input source selection */
7188         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7189         /* Input mixer2 */
7190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7193         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7194         /* Input mixer3 */
7195         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7196         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7197         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7199         /* ADC2: mute amp left and right */
7200         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7201         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7202         /* ADC3: mute amp left and right */
7203         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7204         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7205
7206         { }
7207 };
7208
7209 static struct hda_verb alc882_adc1_init_verbs[] = {
7210         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7211         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7212         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7213         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7214         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7215         /* ADC1: mute amp left and right */
7216         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7217         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7218         { }
7219 };
7220
7221 static struct hda_verb alc882_eapd_verbs[] = {
7222         /* change to EAPD mode */
7223         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7224         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
7225         { }
7226 };
7227
7228 static struct hda_verb alc889_eapd_verbs[] = {
7229         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
7230         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
7231         { }
7232 };
7233
7234 static struct hda_verb alc_hp15_unsol_verbs[] = {
7235         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7236         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7237         {}
7238 };
7239
7240 static struct hda_verb alc885_init_verbs[] = {
7241         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7242         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7244         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7245         /* Rear mixer */
7246         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7247         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7248         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7249         /* CLFE mixer */
7250         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7251         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7252         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7253         /* Side mixer */
7254         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7255         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7256         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7257
7258         /* mute analog input loopbacks */
7259         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7260         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7261         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7262
7263         /* Front HP Pin: output 0 (0x0c) */
7264         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7265         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7266         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7267         /* Front Pin: output 0 (0x0c) */
7268         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7269         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7270         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7271         /* Rear Pin: output 1 (0x0d) */
7272         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7273         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7274         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
7275         /* CLFE Pin: output 2 (0x0e) */
7276         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7277         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7278         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7279         /* Side Pin: output 3 (0x0f) */
7280         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7281         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7282         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7283         /* Mic (rear) pin: input vref at 80% */
7284         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7285         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7286         /* Front Mic pin: input vref at 80% */
7287         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7288         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7289         /* Line In pin: input */
7290         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7291         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7292
7293         /* Mixer elements: 0x18, , 0x1a, 0x1b */
7294         /* Input mixer1 */
7295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7296         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7297         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7298         /* Input mixer2 */
7299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7302         /* Input mixer3 */
7303         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7304         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7306         /* ADC2: mute amp left and right */
7307         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7308         /* ADC3: mute amp left and right */
7309         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7310
7311         { }
7312 };
7313
7314 static struct hda_verb alc885_init_input_verbs[] = {
7315         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7316         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7317         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7318         { }
7319 };
7320
7321
7322 /* Unmute Selector 24h and set the default input to front mic */
7323 static struct hda_verb alc889_init_input_verbs[] = {
7324         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
7325         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7326         { }
7327 };
7328
7329
7330 #define alc883_init_verbs       alc882_base_init_verbs
7331
7332 /* Mac Pro test */
7333 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7334         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7335         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7336         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
7337         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7338         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7339         /* FIXME: this looks suspicious...
7340         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
7341         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
7342         */
7343         { } /* end */
7344 };
7345
7346 static struct hda_verb alc882_macpro_init_verbs[] = {
7347         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7348         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7349         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7350         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7351         /* Front Pin: output 0 (0x0c) */
7352         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7353         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7354         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7355         /* Front Mic pin: input vref at 80% */
7356         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7357         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7358         /* Speaker:  output */
7359         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7360         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7361         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
7362         /* Headphone output (output 0 - 0x0c) */
7363         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7364         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7365         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7366
7367         /* FIXME: use matrix-type input source selection */
7368         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7369         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7370         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7371         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7372         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7373         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7374         /* Input mixer2 */
7375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7378         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7379         /* Input mixer3 */
7380         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7383         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7384         /* ADC1: mute amp left and right */
7385         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7386         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7387         /* ADC2: mute amp left and right */
7388         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7389         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7390         /* ADC3: mute amp left and right */
7391         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7392         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7393
7394         { }
7395 };
7396
7397 /* Macbook 5,1 */
7398 static struct hda_verb alc885_mb5_init_verbs[] = {
7399         /* DACs */
7400         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7401         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7402         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7403         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7404         /* Front mixer */
7405         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7406         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7407         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7408         /* Surround mixer */
7409         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7410         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7411         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7412         /* LFE mixer */
7413         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7414         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7415         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7416         /* HP mixer */
7417         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7418         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7419         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7420         /* Front Pin (0x0c) */
7421         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7422         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7423         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7424         /* LFE Pin (0x0e) */
7425         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7426         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7427         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
7428         /* HP Pin (0x0f) */
7429         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7430         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7431         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7432         /* Front Mic pin: input vref at 80% */
7433         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7434         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7435         /* Line In pin */
7436         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7437         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7438
7439         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7440         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7441         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7442         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7443         { }
7444 };
7445
7446 /* Macbook Pro rev3 */
7447 static struct hda_verb alc885_mbp3_init_verbs[] = {
7448         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7449         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7450         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7451         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7452         /* Rear mixer */
7453         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7456         /* HP mixer */
7457         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7458         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7459         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7460         /* Front Pin: output 0 (0x0c) */
7461         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7462         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7463         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7464         /* HP Pin: output 0 (0x0e) */
7465         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7466         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7467         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
7468         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7469         /* Mic (rear) pin: input vref at 80% */
7470         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7471         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7472         /* Front Mic pin: input vref at 80% */
7473         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7474         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7475         /* Line In pin: use output 1 when in LineOut mode */
7476         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7477         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7478         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7479
7480         /* FIXME: use matrix-type input source selection */
7481         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7482         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7483         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7484         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7486         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7487         /* Input mixer2 */
7488         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7489         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7490         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7491         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7492         /* Input mixer3 */
7493         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7494         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7497         /* ADC1: mute amp left and right */
7498         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7499         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7500         /* ADC2: mute amp left and right */
7501         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7502         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7503         /* ADC3: mute amp left and right */
7504         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7505         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7506
7507         { }
7508 };
7509
7510 /* iMac 24 mixer. */
7511 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7512         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7513         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
7514         { } /* end */
7515 };
7516
7517 /* iMac 24 init verbs. */
7518 static struct hda_verb alc885_imac24_init_verbs[] = {
7519         /* Internal speakers: output 0 (0x0c) */
7520         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7521         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7522         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7523         /* Internal speakers: output 0 (0x0c) */
7524         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7525         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7526         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7527         /* Headphone: output 0 (0x0c) */
7528         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7529         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7530         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7531         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7532         /* Front Mic: input vref at 80% */
7533         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7534         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7535         { }
7536 };
7537
7538 /* Toggle speaker-output according to the hp-jack state */
7539 static void alc885_imac24_setup(struct hda_codec *codec)
7540 {
7541         struct alc_spec *spec = codec->spec;
7542
7543         spec->autocfg.hp_pins[0] = 0x14;
7544         spec->autocfg.speaker_pins[0] = 0x18;
7545         spec->autocfg.speaker_pins[1] = 0x1a;
7546 }
7547
7548 static void alc885_mbp3_setup(struct hda_codec *codec)
7549 {
7550         struct alc_spec *spec = codec->spec;
7551
7552         spec->autocfg.hp_pins[0] = 0x15;
7553         spec->autocfg.speaker_pins[0] = 0x14;
7554 }
7555
7556
7557 static struct hda_verb alc882_targa_verbs[] = {
7558         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7559         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7560
7561         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7562         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7563
7564         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7565         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7566         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7567
7568         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7569         { } /* end */
7570 };
7571
7572 /* toggle speaker-output according to the hp-jack state */
7573 static void alc882_targa_automute(struct hda_codec *codec)
7574 {
7575         struct alc_spec *spec = codec->spec;
7576         alc_automute_amp(codec);
7577         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7578                                   spec->jack_present ? 1 : 3);
7579 }
7580
7581 static void alc882_targa_setup(struct hda_codec *codec)
7582 {
7583         struct alc_spec *spec = codec->spec;
7584
7585         spec->autocfg.hp_pins[0] = 0x14;
7586         spec->autocfg.speaker_pins[0] = 0x1b;
7587 }
7588
7589 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
7590 {
7591         if ((res >> 26) == ALC880_HP_EVENT)
7592                 alc882_targa_automute(codec);
7593 }
7594
7595 static struct hda_verb alc882_asus_a7j_verbs[] = {
7596         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7597         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7598
7599         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7600         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7601         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7602
7603         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7604         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7605         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7606
7607         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7608         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7609         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7610         { } /* end */
7611 };
7612
7613 static struct hda_verb alc882_asus_a7m_verbs[] = {
7614         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7615         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7616
7617         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7618         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7619         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7620
7621         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7622         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7623         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7624
7625         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7626         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7627         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7628         { } /* end */
7629 };
7630
7631 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
7632 {
7633         unsigned int gpiostate, gpiomask, gpiodir;
7634
7635         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
7636                                        AC_VERB_GET_GPIO_DATA, 0);
7637
7638         if (!muted)
7639                 gpiostate |= (1 << pin);
7640         else
7641                 gpiostate &= ~(1 << pin);
7642
7643         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7644                                       AC_VERB_GET_GPIO_MASK, 0);
7645         gpiomask |= (1 << pin);
7646
7647         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7648                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7649         gpiodir |= (1 << pin);
7650
7651
7652         snd_hda_codec_write(codec, codec->afg, 0,
7653                             AC_VERB_SET_GPIO_MASK, gpiomask);
7654         snd_hda_codec_write(codec, codec->afg, 0,
7655                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7656
7657         msleep(1);
7658
7659         snd_hda_codec_write(codec, codec->afg, 0,
7660                             AC_VERB_SET_GPIO_DATA, gpiostate);
7661 }
7662
7663 /* set up GPIO at initialization */
7664 static void alc885_macpro_init_hook(struct hda_codec *codec)
7665 {
7666         alc882_gpio_mute(codec, 0, 0);
7667         alc882_gpio_mute(codec, 1, 0);
7668 }
7669
7670 /* set up GPIO and update auto-muting at initialization */
7671 static void alc885_imac24_init_hook(struct hda_codec *codec)
7672 {
7673         alc885_macpro_init_hook(codec);
7674         alc_automute_amp(codec);
7675 }
7676
7677 /*
7678  * generic initialization of ADC, input mixers and output mixers
7679  */
7680 static struct hda_verb alc883_auto_init_verbs[] = {
7681         /*
7682          * Unmute ADC0-2 and set the default input to mic-in
7683          */
7684         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7685         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7686         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7687         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7688
7689         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7690          * mixer widget
7691          * Note: PASD motherboards uses the Line In 2 as the input for
7692          * front panel mic (mic 2)
7693          */
7694         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7695         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7697         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7698         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7700
7701         /*
7702          * Set up output mixers (0x0c - 0x0f)
7703          */
7704         /* set vol=0 to output mixers */
7705         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7706         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7707         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7708         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7709         /* set up input amps for analog loopback */
7710         /* Amp Indices: DAC = 0, mixer = 1 */
7711         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7712         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7713         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7714         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7715         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7716         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7717         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7718         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7719         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7720         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7721
7722         /* FIXME: use matrix-type input source selection */
7723         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7724         /* Input mixer2 */
7725         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7726         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7727         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7728         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7729         /* Input mixer3 */
7730         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7731         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7732         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7733         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7734
7735         { }
7736 };
7737
7738 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7739 static struct hda_verb alc889A_mb31_ch2_init[] = {
7740         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7741         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7742         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7743         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7744         { } /* end */
7745 };
7746
7747 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7748 static struct hda_verb alc889A_mb31_ch4_init[] = {
7749         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7750         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7751         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7752         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7753         { } /* end */
7754 };
7755
7756 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7757 static struct hda_verb alc889A_mb31_ch5_init[] = {
7758         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7759         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7760         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7761         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7762         { } /* end */
7763 };
7764
7765 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7766 static struct hda_verb alc889A_mb31_ch6_init[] = {
7767         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7768         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7769         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7770         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7771         { } /* end */
7772 };
7773
7774 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7775         { 2, alc889A_mb31_ch2_init },
7776         { 4, alc889A_mb31_ch4_init },
7777         { 5, alc889A_mb31_ch5_init },
7778         { 6, alc889A_mb31_ch6_init },
7779 };
7780
7781 static struct hda_verb alc883_medion_eapd_verbs[] = {
7782         /* eanable EAPD on medion laptop */
7783         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7784         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7785         { }
7786 };
7787
7788 #define alc883_base_mixer       alc882_base_mixer
7789
7790 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7791         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7792         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7793         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7794         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7795         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7796         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7797         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7798         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7799         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7800         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7801         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7802         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7803         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7804         { } /* end */
7805 };
7806
7807 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7808         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7809         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7810         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7811         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7812         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7813         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7814         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7815         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7816         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7817         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7818         { } /* end */
7819 };
7820
7821 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7822         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7823         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7824         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7825         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7827         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7828         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7829         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7830         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7831         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7832         { } /* end */
7833 };
7834
7835 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7836         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7837         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7838         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7839         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7840         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7841         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7842         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7843         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7844         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7845         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7846         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7847         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7848         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7849         { } /* end */
7850 };
7851
7852 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7853         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7854         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7855         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7856         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7857         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7858         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7859         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7860         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7861         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7862         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7863         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7864         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7865         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7866         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7867         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7868         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7869         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7870         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7871         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7872         { } /* end */
7873 };
7874
7875 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7876         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7877         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7878         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7879         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7880         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7881                               HDA_OUTPUT),
7882         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7883         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7884         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7885         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7886         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7887         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7888         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7889         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7890         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7891         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7892         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7893         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7894         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7895         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7896         { } /* end */
7897 };
7898
7899 static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
7900         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7901         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7902         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7903         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7904         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7905                               HDA_OUTPUT),
7906         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7907         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7908         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7909         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7910         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
7911         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7912         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7913         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7914         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
7915         HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
7916         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
7917         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7918         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7919         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7920         { } /* end */
7921 };
7922
7923 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7924         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7925         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7926         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7927         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7928         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7929         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7930         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7931         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7932         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7933         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7934         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7935         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7936         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7938         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7939         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7940         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7941         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7942         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7943         { } /* end */
7944 };
7945
7946 static struct snd_kcontrol_new alc883_targa_mixer[] = {
7947         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7948         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7949         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7950         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7951         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7952         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7953         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7954         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7955         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7956         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7957         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7958         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7959         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7960         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7961         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7962         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7964         { } /* end */
7965 };
7966
7967 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
7968         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7969         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7970         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7971         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7972         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7973         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7974         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7975         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7976         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7977         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7978         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7979         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7980         { } /* end */
7981 };
7982
7983 static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
7984         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7985         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7986         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7987         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7988         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7989         { } /* end */
7990 };
7991
7992 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7993         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7994         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7995         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7996         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7997         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7998         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7999         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8000         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8001         { } /* end */
8002 };
8003
8004 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8005         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8006         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8007         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8008         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8009         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8010         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8011         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8012         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8013         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8014         { } /* end */
8015 };
8016
8017 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8018         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8019         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8020         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8021         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8022         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8023         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8024         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8025         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8026         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8027         { } /* end */
8028 };
8029
8030 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8031         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8032         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8033         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8034         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8035         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8036         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8037         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8038         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8039         { } /* end */
8040 };
8041
8042 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8043         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8044         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8045         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8046         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8047         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8048         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8049         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8050         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8051         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8052         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8053         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8054         { } /* end */
8055 };
8056
8057 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8058         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8059         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8060         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8061         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8062         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8063                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8064         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8065         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8066         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8067         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8068         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8069         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8070         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8071         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8072         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8073         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8074         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8075         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8076         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8077         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8078         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8079         { } /* end */
8080 };
8081
8082 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8083         /* Output mixers */
8084         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8085         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8086         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8087         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8088         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8089                 HDA_OUTPUT),
8090         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8091         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8092         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8093         /* Output switches */
8094         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8095         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8096         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8097         /* Boost mixers */
8098         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8099         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8100         /* Input mixers */
8101         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8102         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8103         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8104         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8105         { } /* end */
8106 };
8107
8108 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8109         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8110         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8111         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8113         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8115         { } /* end */
8116 };
8117
8118 static struct hda_bind_ctls alc883_bind_cap_vol = {
8119         .ops = &snd_hda_bind_vol,
8120         .values = {
8121                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8122                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8123                 0
8124         },
8125 };
8126
8127 static struct hda_bind_ctls alc883_bind_cap_switch = {
8128         .ops = &snd_hda_bind_sw,
8129         .values = {
8130                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8131                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8132                 0
8133         },
8134 };
8135
8136 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8137         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8138         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8139         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8140         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8141         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8142         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8143         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8144         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8145         { } /* end */
8146 };
8147
8148 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8149         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8150         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8151         {
8152                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8153                 /* .name = "Capture Source", */
8154                 .name = "Input Source",
8155                 .count = 1,
8156                 .info = alc_mux_enum_info,
8157                 .get = alc_mux_enum_get,
8158                 .put = alc_mux_enum_put,
8159         },
8160         { } /* end */
8161 };
8162
8163 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8164         {
8165                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8166                 .name = "Channel Mode",
8167                 .info = alc_ch_mode_info,
8168                 .get = alc_ch_mode_get,
8169                 .put = alc_ch_mode_put,
8170         },
8171         { } /* end */
8172 };
8173
8174 /* toggle speaker-output according to the hp-jack state */
8175 static void alc883_mitac_setup(struct hda_codec *codec)
8176 {
8177         struct alc_spec *spec = codec->spec;
8178
8179         spec->autocfg.hp_pins[0] = 0x15;
8180         spec->autocfg.speaker_pins[0] = 0x14;
8181         spec->autocfg.speaker_pins[1] = 0x17;
8182 }
8183
8184 /* auto-toggle front mic */
8185 /*
8186 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8187 {
8188         unsigned int present;
8189         unsigned char bits;
8190
8191         present = snd_hda_codec_read(codec, 0x18, 0,
8192                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8193         bits = present ? HDA_AMP_MUTE : 0;
8194         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8195 }
8196 */
8197
8198 static struct hda_verb alc883_mitac_verbs[] = {
8199         /* HP */
8200         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8202         /* Subwoofer */
8203         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8204         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8205
8206         /* enable unsolicited event */
8207         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8208         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8209
8210         { } /* end */
8211 };
8212
8213 static struct hda_verb alc883_clevo_m540r_verbs[] = {
8214         /* HP */
8215         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8216         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8217         /* Int speaker */
8218         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
8219
8220         /* enable unsolicited event */
8221         /*
8222         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8223         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8224         */
8225
8226         { } /* end */
8227 };
8228
8229 static struct hda_verb alc883_clevo_m720_verbs[] = {
8230         /* HP */
8231         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8232         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8233         /* Int speaker */
8234         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8235         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8236
8237         /* enable unsolicited event */
8238         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8239         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8240
8241         { } /* end */
8242 };
8243
8244 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8245         /* HP */
8246         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8247         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8248         /* Subwoofer */
8249         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8250         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8251
8252         /* enable unsolicited event */
8253         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8254
8255         { } /* end */
8256 };
8257
8258 static struct hda_verb alc883_targa_verbs[] = {
8259         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8260         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8261
8262         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8263         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8264
8265 /* Connect Line-Out side jack (SPDIF) to Side */
8266         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8267         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8268         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8269 /* Connect Mic jack to CLFE */
8270         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8271         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8272         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8273 /* Connect Line-in jack to Surround */
8274         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8275         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8276         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8277 /* Connect HP out jack to Front */
8278         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8280         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8281
8282         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8283
8284         { } /* end */
8285 };
8286
8287 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8288         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8289         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8290         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8291         { } /* end */
8292 };
8293
8294 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8295         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8296         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8297         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8298         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8299         { } /* end */
8300 };
8301
8302 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8303         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8304         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8305         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8306         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8307         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8308         { } /* end */
8309 };
8310
8311 static struct hda_verb alc883_haier_w66_verbs[] = {
8312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8314
8315         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8316
8317         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8318         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8319         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8320         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8321         { } /* end */
8322 };
8323
8324 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8325         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8326         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8327         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8329         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8330         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8331         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8332         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8333         { } /* end */
8334 };
8335
8336 static struct hda_verb alc888_6st_dell_verbs[] = {
8337         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8338         { }
8339 };
8340
8341 static struct hda_verb alc883_vaiott_verbs[] = {
8342         /* HP */
8343         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8344         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8345
8346         /* enable unsolicited event */
8347         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8348
8349         { } /* end */
8350 };
8351
8352 static void alc888_3st_hp_setup(struct hda_codec *codec)
8353 {
8354         struct alc_spec *spec = codec->spec;
8355
8356         spec->autocfg.hp_pins[0] = 0x1b;
8357         spec->autocfg.speaker_pins[0] = 0x14;
8358         spec->autocfg.speaker_pins[1] = 0x16;
8359         spec->autocfg.speaker_pins[2] = 0x18;
8360 }
8361
8362 static struct hda_verb alc888_3st_hp_verbs[] = {
8363         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8364         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8365         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8366         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8367         { } /* end */
8368 };
8369
8370 /*
8371  * 2ch mode
8372  */
8373 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8374         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8375         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8376         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8377         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8378         { } /* end */
8379 };
8380
8381 /*
8382  * 4ch mode
8383  */
8384 static struct hda_verb alc888_3st_hp_4ch_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_OUT },
8388         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8389         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8390         { } /* end */
8391 };
8392
8393 /*
8394  * 6ch mode
8395  */
8396 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8397         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8398         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8399         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8400         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8401         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8402         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8403         { } /* end */
8404 };
8405
8406 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8407         { 2, alc888_3st_hp_2ch_init },
8408         { 4, alc888_3st_hp_4ch_init },
8409         { 6, alc888_3st_hp_6ch_init },
8410 };
8411
8412 /* toggle front-jack and RCA according to the hp-jack state */
8413 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8414 {
8415         unsigned int present;
8416
8417         present = snd_hda_codec_read(codec, 0x1b, 0,
8418                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8419         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8420                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8421         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8422                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8423 }
8424
8425 /* toggle RCA according to the front-jack state */
8426 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8427 {
8428         unsigned int present;
8429
8430         present = snd_hda_codec_read(codec, 0x14, 0,
8431                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8432         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8433                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8434 }
8435
8436 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8437                                              unsigned int res)
8438 {
8439         if ((res >> 26) == ALC880_HP_EVENT)
8440                 alc888_lenovo_ms7195_front_automute(codec);
8441         if ((res >> 26) == ALC880_FRONT_EVENT)
8442                 alc888_lenovo_ms7195_rca_automute(codec);
8443 }
8444
8445 static struct hda_verb alc883_medion_md2_verbs[] = {
8446         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8447         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8448
8449         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8450
8451         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8452         { } /* end */
8453 };
8454
8455 /* toggle speaker-output according to the hp-jack state */
8456 static void alc883_medion_md2_setup(struct hda_codec *codec)
8457 {
8458         struct alc_spec *spec = codec->spec;
8459
8460         spec->autocfg.hp_pins[0] = 0x14;
8461         spec->autocfg.speaker_pins[0] = 0x15;
8462 }
8463
8464 /* toggle speaker-output according to the hp-jack state */
8465 #define alc883_targa_init_hook          alc882_targa_init_hook
8466 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8467
8468 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8469 {
8470         unsigned int present;
8471
8472         present = snd_hda_codec_read(codec, 0x18, 0,
8473                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8474         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8475                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8476 }
8477
8478 static void alc883_clevo_m720_setup(struct hda_codec *codec)
8479 {
8480         struct alc_spec *spec = codec->spec;
8481
8482         spec->autocfg.hp_pins[0] = 0x15;
8483         spec->autocfg.speaker_pins[0] = 0x14;
8484 }
8485
8486 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8487 {
8488         alc_automute_amp(codec);
8489         alc883_clevo_m720_mic_automute(codec);
8490 }
8491
8492 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8493                                            unsigned int res)
8494 {
8495         switch (res >> 26) {
8496         case ALC880_MIC_EVENT:
8497                 alc883_clevo_m720_mic_automute(codec);
8498                 break;
8499         default:
8500                 alc_automute_amp_unsol_event(codec, res);
8501                 break;
8502         }
8503 }
8504
8505 /* toggle speaker-output according to the hp-jack state */
8506 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8507 {
8508         struct alc_spec *spec = codec->spec;
8509
8510         spec->autocfg.hp_pins[0] = 0x14;
8511         spec->autocfg.speaker_pins[0] = 0x15;
8512 }
8513
8514 static void alc883_haier_w66_setup(struct hda_codec *codec)
8515 {
8516         struct alc_spec *spec = codec->spec;
8517
8518         spec->autocfg.hp_pins[0] = 0x1b;
8519         spec->autocfg.speaker_pins[0] = 0x14;
8520 }
8521
8522 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8523 {
8524         unsigned int present;
8525         unsigned char bits;
8526
8527         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8528                 & AC_PINSENSE_PRESENCE;
8529         bits = present ? HDA_AMP_MUTE : 0;
8530         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8531                                  HDA_AMP_MUTE, bits);
8532 }
8533
8534 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8535 {
8536         unsigned int present;
8537         unsigned char bits;
8538
8539         present = snd_hda_codec_read(codec, 0x1b, 0,
8540                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8541         bits = present ? HDA_AMP_MUTE : 0;
8542         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8543                                  HDA_AMP_MUTE, bits);
8544         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8545                                  HDA_AMP_MUTE, bits);
8546 }
8547
8548 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8549                                            unsigned int res)
8550 {
8551         if ((res >> 26) == ALC880_HP_EVENT)
8552                 alc883_lenovo_101e_all_automute(codec);
8553         if ((res >> 26) == ALC880_FRONT_EVENT)
8554                 alc883_lenovo_101e_ispeaker_automute(codec);
8555 }
8556
8557 /* toggle speaker-output according to the hp-jack state */
8558 static void alc883_acer_aspire_setup(struct hda_codec *codec)
8559 {
8560         struct alc_spec *spec = codec->spec;
8561
8562         spec->autocfg.hp_pins[0] = 0x14;
8563         spec->autocfg.speaker_pins[0] = 0x15;
8564         spec->autocfg.speaker_pins[1] = 0x16;
8565 }
8566
8567 static struct hda_verb alc883_acer_eapd_verbs[] = {
8568         /* HP Pin: output 0 (0x0c) */
8569         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8570         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8571         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8572         /* Front Pin: output 0 (0x0c) */
8573         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8574         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8575         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8576         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8577         /* eanable EAPD on medion laptop */
8578         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8579         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8580         /* enable unsolicited event */
8581         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8582         { }
8583 };
8584
8585 static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
8586         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8587         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8588         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8589         { } /* end */
8590 };
8591
8592 static void alc888_6st_dell_setup(struct hda_codec *codec)
8593 {
8594         struct alc_spec *spec = codec->spec;
8595
8596         spec->autocfg.hp_pins[0] = 0x1b;
8597         spec->autocfg.speaker_pins[0] = 0x14;
8598         spec->autocfg.speaker_pins[1] = 0x15;
8599         spec->autocfg.speaker_pins[2] = 0x16;
8600         spec->autocfg.speaker_pins[3] = 0x17;
8601 }
8602
8603 static void alc888_lenovo_sky_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         spec->autocfg.speaker_pins[4] = 0x1a;
8613 }
8614
8615 static void alc883_vaiott_setup(struct hda_codec *codec)
8616 {
8617         struct alc_spec *spec = codec->spec;
8618
8619         spec->autocfg.hp_pins[0] = 0x15;
8620         spec->autocfg.speaker_pins[0] = 0x14;
8621         spec->autocfg.speaker_pins[1] = 0x17;
8622 }
8623
8624 static struct hda_verb alc888_asus_m90v_verbs[] = {
8625         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8626         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8627         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8628         /* enable unsolicited event */
8629         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8630         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8631         { } /* end */
8632 };
8633
8634 static void alc883_mode2_setup(struct hda_codec *codec)
8635 {
8636         struct alc_spec *spec = codec->spec;
8637
8638         spec->autocfg.hp_pins[0] = 0x1b;
8639         spec->autocfg.speaker_pins[0] = 0x14;
8640         spec->autocfg.speaker_pins[1] = 0x15;
8641         spec->autocfg.speaker_pins[2] = 0x16;
8642         spec->ext_mic.pin = 0x18;
8643         spec->int_mic.pin = 0x19;
8644         spec->ext_mic.mux_idx = 0;
8645         spec->int_mic.mux_idx = 1;
8646         spec->auto_mic = 1;
8647 }
8648
8649 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8650         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8651         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8652         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8653         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8654         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8655         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8656         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8657         /* enable unsolicited event */
8658         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8659         { } /* end */
8660 };
8661
8662 static void alc883_eee1601_inithook(struct hda_codec *codec)
8663 {
8664         struct alc_spec *spec = codec->spec;
8665
8666         spec->autocfg.hp_pins[0] = 0x14;
8667         spec->autocfg.speaker_pins[0] = 0x1b;
8668         alc_automute_pin(codec);
8669 }
8670
8671 static struct hda_verb alc889A_mb31_verbs[] = {
8672         /* Init rear pin (used as headphone output) */
8673         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8674         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8675         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8676         /* Init line pin (used as output in 4ch and 6ch mode) */
8677         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8678         /* Init line 2 pin (used as headphone out by default) */
8679         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8680         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
8681         { } /* end */
8682 };
8683
8684 /* Mute speakers according to the headphone jack state */
8685 static void alc889A_mb31_automute(struct hda_codec *codec)
8686 {
8687         unsigned int present;
8688
8689         /* Mute only in 2ch or 4ch mode */
8690         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8691             == 0x00) {
8692                 present = snd_hda_codec_read(codec, 0x15, 0,
8693                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8694                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
8695                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8696                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8697                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8698         }
8699 }
8700
8701 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8702 {
8703         if ((res >> 26) == ALC880_HP_EVENT)
8704                 alc889A_mb31_automute(codec);
8705 }
8706
8707
8708 #ifdef CONFIG_SND_HDA_POWER_SAVE
8709 #define alc882_loopbacks        alc880_loopbacks
8710 #endif
8711
8712 /* pcm configuration: identical with ALC880 */
8713 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
8714 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
8715 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
8716 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
8717
8718 static hda_nid_t alc883_slave_dig_outs[] = {
8719         ALC1200_DIGOUT_NID, 0,
8720 };
8721
8722 static hda_nid_t alc1200_slave_dig_outs[] = {
8723         ALC883_DIGOUT_NID, 0,
8724 };
8725
8726 /*
8727  * configuration and preset
8728  */
8729 static const char *alc882_models[ALC882_MODEL_LAST] = {
8730         [ALC882_3ST_DIG]        = "3stack-dig",
8731         [ALC882_6ST_DIG]        = "6stack-dig",
8732         [ALC882_ARIMA]          = "arima",
8733         [ALC882_W2JC]           = "w2jc",
8734         [ALC882_TARGA]          = "targa",
8735         [ALC882_ASUS_A7J]       = "asus-a7j",
8736         [ALC882_ASUS_A7M]       = "asus-a7m",
8737         [ALC885_MACPRO]         = "macpro",
8738         [ALC885_MB5]            = "mb5",
8739         [ALC885_MBP3]           = "mbp3",
8740         [ALC885_IMAC24]         = "imac24",
8741         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
8742         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8743         [ALC883_3ST_6ch]        = "3stack-6ch",
8744         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
8745         [ALC883_TARGA_DIG]      = "targa-dig",
8746         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8747         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
8748         [ALC883_ACER]           = "acer",
8749         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8750         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8751         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
8752         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
8753         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
8754         [ALC883_MEDION]         = "medion",
8755         [ALC883_MEDION_MD2]     = "medion-md2",
8756         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8757         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8758         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8759         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8760         [ALC888_LENOVO_SKY] = "lenovo-sky",
8761         [ALC883_HAIER_W66]      = "haier-w66",
8762         [ALC888_3ST_HP]         = "3stack-hp",
8763         [ALC888_6ST_DELL]       = "6stack-dell",
8764         [ALC883_MITAC]          = "mitac",
8765         [ALC883_CLEVO_M540R]    = "clevo-m540r",
8766         [ALC883_CLEVO_M720]     = "clevo-m720",
8767         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8768         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8769         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8770         [ALC889A_INTEL]         = "intel-alc889a",
8771         [ALC889_INTEL]          = "intel-x58",
8772         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8773         [ALC889A_MB31]          = "mb31",
8774         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
8775         [ALC882_AUTO]           = "auto",
8776 };
8777
8778 static struct snd_pci_quirk alc882_cfg_tbl[] = {
8779         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8780
8781         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8782         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8783         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8784         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8785         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8786         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8787         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8788                 ALC888_ACER_ASPIRE_4930G),
8789         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8790                 ALC888_ACER_ASPIRE_4930G),
8791         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
8792                 ALC888_ACER_ASPIRE_8930G),
8793         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
8794                 ALC888_ACER_ASPIRE_8930G),
8795         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
8796         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
8797         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8798                 ALC888_ACER_ASPIRE_6530G),
8799         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8800                 ALC888_ACER_ASPIRE_6530G),
8801         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8802                 ALC888_ACER_ASPIRE_7730G),
8803         /* default Acer -- disabled as it causes more problems.
8804          *    model=auto should work fine now
8805          */
8806         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8807
8808         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8809
8810         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8811         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8812         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8813         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8814         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8815         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8816
8817         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
8818         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
8819         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
8820         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8821         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
8822         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
8823         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
8824         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8825         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8826         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8827         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8828
8829         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
8830         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8831         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
8832         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8833         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8834         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8835         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8836         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8837         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8838
8839         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8840         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8841         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8842         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
8843         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8844         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8845         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8846         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8847         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8848         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8849         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8850         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8851         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8852         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8853         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
8854         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8855         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8856         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8857         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
8858         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8859         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8860         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8861         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8862         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8863         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8864         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8865         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
8866         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8867         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8868
8869         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8870         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8871         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8872         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
8873         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8874         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8875         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
8876         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8877         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8878                       ALC883_FUJITSU_PI2515),
8879         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8880                 ALC888_FUJITSU_XA3530),
8881         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8882         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8883         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8884         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8885         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8886         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8887         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8888         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8889         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8890
8891         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8892         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8893         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8894         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8895         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8896         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
8897         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8898
8899         {}
8900 };
8901
8902 /* codec SSID table for Intel Mac */
8903 static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8904         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
8905         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
8906         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
8907         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
8908         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
8909         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
8910         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
8911         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8912         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8913         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
8914         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8915         /* FIXME: HP jack sense seems not working for MBP 5,1, so apparently
8916          * no perfect solution yet
8917          */
8918         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8919         {} /* terminator */
8920 };
8921
8922 static struct alc_config_preset alc882_presets[] = {
8923         [ALC882_3ST_DIG] = {
8924                 .mixers = { alc882_base_mixer },
8925                 .init_verbs = { alc882_base_init_verbs,
8926                                 alc882_adc1_init_verbs },
8927                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8928                 .dac_nids = alc882_dac_nids,
8929                 .dig_out_nid = ALC882_DIGOUT_NID,
8930                 .dig_in_nid = ALC882_DIGIN_NID,
8931                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8932                 .channel_mode = alc882_ch_modes,
8933                 .need_dac_fix = 1,
8934                 .input_mux = &alc882_capture_source,
8935         },
8936         [ALC882_6ST_DIG] = {
8937                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8938                 .init_verbs = { alc882_base_init_verbs,
8939                                 alc882_adc1_init_verbs },
8940                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8941                 .dac_nids = alc882_dac_nids,
8942                 .dig_out_nid = ALC882_DIGOUT_NID,
8943                 .dig_in_nid = ALC882_DIGIN_NID,
8944                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8945                 .channel_mode = alc882_sixstack_modes,
8946                 .input_mux = &alc882_capture_source,
8947         },
8948         [ALC882_ARIMA] = {
8949                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8950                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8951                                 alc882_eapd_verbs },
8952                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8953                 .dac_nids = alc882_dac_nids,
8954                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8955                 .channel_mode = alc882_sixstack_modes,
8956                 .input_mux = &alc882_capture_source,
8957         },
8958         [ALC882_W2JC] = {
8959                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
8960                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8961                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
8962                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8963                 .dac_nids = alc882_dac_nids,
8964                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
8965                 .channel_mode = alc880_threestack_modes,
8966                 .need_dac_fix = 1,
8967                 .input_mux = &alc882_capture_source,
8968                 .dig_out_nid = ALC882_DIGOUT_NID,
8969         },
8970         [ALC885_MBP3] = {
8971                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8972                 .init_verbs = { alc885_mbp3_init_verbs,
8973                                 alc880_gpio1_init_verbs },
8974                 .num_dacs = 2,
8975                 .dac_nids = alc882_dac_nids,
8976                 .hp_nid = 0x04,
8977                 .channel_mode = alc885_mbp_4ch_modes,
8978                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
8979                 .input_mux = &alc882_capture_source,
8980                 .dig_out_nid = ALC882_DIGOUT_NID,
8981                 .dig_in_nid = ALC882_DIGIN_NID,
8982                 .unsol_event = alc_automute_amp_unsol_event,
8983                 .setup = alc885_mbp3_setup,
8984                 .init_hook = alc_automute_amp,
8985         },
8986         [ALC885_MB5] = {
8987                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
8988                 .init_verbs = { alc885_mb5_init_verbs,
8989                                 alc880_gpio1_init_verbs },
8990                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8991                 .dac_nids = alc882_dac_nids,
8992                 .channel_mode = alc885_mb5_6ch_modes,
8993                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
8994                 .input_mux = &mb5_capture_source,
8995                 .dig_out_nid = ALC882_DIGOUT_NID,
8996                 .dig_in_nid = ALC882_DIGIN_NID,
8997         },
8998         [ALC885_MACPRO] = {
8999                 .mixers = { alc882_macpro_mixer },
9000                 .init_verbs = { alc882_macpro_init_verbs },
9001                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9002                 .dac_nids = alc882_dac_nids,
9003                 .dig_out_nid = ALC882_DIGOUT_NID,
9004                 .dig_in_nid = ALC882_DIGIN_NID,
9005                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9006                 .channel_mode = alc882_ch_modes,
9007                 .input_mux = &alc882_capture_source,
9008                 .init_hook = alc885_macpro_init_hook,
9009         },
9010         [ALC885_IMAC24] = {
9011                 .mixers = { alc885_imac24_mixer },
9012                 .init_verbs = { alc885_imac24_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                 .unsol_event = alc_automute_amp_unsol_event,
9021                 .setup = alc885_imac24_setup,
9022                 .init_hook = alc885_imac24_init_hook,
9023         },
9024         [ALC882_TARGA] = {
9025                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9026                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9027                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
9028                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9029                 .dac_nids = alc882_dac_nids,
9030                 .dig_out_nid = ALC882_DIGOUT_NID,
9031                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9032                 .adc_nids = alc882_adc_nids,
9033                 .capsrc_nids = alc882_capsrc_nids,
9034                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9035                 .channel_mode = alc882_3ST_6ch_modes,
9036                 .need_dac_fix = 1,
9037                 .input_mux = &alc882_capture_source,
9038                 .unsol_event = alc882_targa_unsol_event,
9039                 .setup = alc882_targa_setup,
9040                 .init_hook = alc882_targa_automute,
9041         },
9042         [ALC882_ASUS_A7J] = {
9043                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9044                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9045                                 alc882_asus_a7j_verbs},
9046                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9047                 .dac_nids = alc882_dac_nids,
9048                 .dig_out_nid = ALC882_DIGOUT_NID,
9049                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9050                 .adc_nids = alc882_adc_nids,
9051                 .capsrc_nids = alc882_capsrc_nids,
9052                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9053                 .channel_mode = alc882_3ST_6ch_modes,
9054                 .need_dac_fix = 1,
9055                 .input_mux = &alc882_capture_source,
9056         },
9057         [ALC882_ASUS_A7M] = {
9058                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9059                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9060                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
9061                                 alc882_asus_a7m_verbs },
9062                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9063                 .dac_nids = alc882_dac_nids,
9064                 .dig_out_nid = ALC882_DIGOUT_NID,
9065                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
9066                 .channel_mode = alc880_threestack_modes,
9067                 .need_dac_fix = 1,
9068                 .input_mux = &alc882_capture_source,
9069         },
9070         [ALC883_3ST_2ch_DIG] = {
9071                 .mixers = { alc883_3ST_2ch_mixer },
9072                 .init_verbs = { alc883_init_verbs },
9073                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9074                 .dac_nids = alc883_dac_nids,
9075                 .dig_out_nid = ALC883_DIGOUT_NID,
9076                 .dig_in_nid = ALC883_DIGIN_NID,
9077                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9078                 .channel_mode = alc883_3ST_2ch_modes,
9079                 .input_mux = &alc883_capture_source,
9080         },
9081         [ALC883_3ST_6ch_DIG] = {
9082                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9083                 .init_verbs = { alc883_init_verbs },
9084                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9085                 .dac_nids = alc883_dac_nids,
9086                 .dig_out_nid = ALC883_DIGOUT_NID,
9087                 .dig_in_nid = ALC883_DIGIN_NID,
9088                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9089                 .channel_mode = alc883_3ST_6ch_modes,
9090                 .need_dac_fix = 1,
9091                 .input_mux = &alc883_capture_source,
9092         },
9093         [ALC883_3ST_6ch] = {
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                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9099                 .channel_mode = alc883_3ST_6ch_modes,
9100                 .need_dac_fix = 1,
9101                 .input_mux = &alc883_capture_source,
9102         },
9103         [ALC883_3ST_6ch_INTEL] = {
9104                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9105                 .init_verbs = { alc883_init_verbs },
9106                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9107                 .dac_nids = alc883_dac_nids,
9108                 .dig_out_nid = ALC883_DIGOUT_NID,
9109                 .dig_in_nid = ALC883_DIGIN_NID,
9110                 .slave_dig_outs = alc883_slave_dig_outs,
9111                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9112                 .channel_mode = alc883_3ST_6ch_intel_modes,
9113                 .need_dac_fix = 1,
9114                 .input_mux = &alc883_3stack_6ch_intel,
9115         },
9116         [ALC889A_INTEL] = {
9117                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9118                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
9119                                 alc_hp15_unsol_verbs },
9120                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9121                 .dac_nids = alc883_dac_nids,
9122                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9123                 .adc_nids = alc889_adc_nids,
9124                 .dig_out_nid = ALC883_DIGOUT_NID,
9125                 .dig_in_nid = ALC883_DIGIN_NID,
9126                 .slave_dig_outs = alc883_slave_dig_outs,
9127                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9128                 .channel_mode = alc889_8ch_intel_modes,
9129                 .capsrc_nids = alc889_capsrc_nids,
9130                 .input_mux = &alc889_capture_source,
9131                 .setup = alc889_automute_setup,
9132                 .init_hook = alc_automute_amp,
9133                 .unsol_event = alc_automute_amp_unsol_event,
9134                 .need_dac_fix = 1,
9135         },
9136         [ALC889_INTEL] = {
9137                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9138                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9139                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
9140                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9141                 .dac_nids = alc883_dac_nids,
9142                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9143                 .adc_nids = alc889_adc_nids,
9144                 .dig_out_nid = ALC883_DIGOUT_NID,
9145                 .dig_in_nid = ALC883_DIGIN_NID,
9146                 .slave_dig_outs = alc883_slave_dig_outs,
9147                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9148                 .channel_mode = alc889_8ch_intel_modes,
9149                 .capsrc_nids = alc889_capsrc_nids,
9150                 .input_mux = &alc889_capture_source,
9151                 .setup = alc889_automute_setup,
9152                 .init_hook = alc889_intel_init_hook,
9153                 .unsol_event = alc_automute_amp_unsol_event,
9154                 .need_dac_fix = 1,
9155         },
9156         [ALC883_6ST_DIG] = {
9157                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9158                 .init_verbs = { alc883_init_verbs },
9159                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9160                 .dac_nids = alc883_dac_nids,
9161                 .dig_out_nid = ALC883_DIGOUT_NID,
9162                 .dig_in_nid = ALC883_DIGIN_NID,
9163                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9164                 .channel_mode = alc883_sixstack_modes,
9165                 .input_mux = &alc883_capture_source,
9166         },
9167         [ALC883_TARGA_DIG] = {
9168                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9169                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9170                                 alc883_targa_verbs},
9171                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9172                 .dac_nids = alc883_dac_nids,
9173                 .dig_out_nid = ALC883_DIGOUT_NID,
9174                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9175                 .channel_mode = alc883_3ST_6ch_modes,
9176                 .need_dac_fix = 1,
9177                 .input_mux = &alc883_capture_source,
9178                 .unsol_event = alc883_targa_unsol_event,
9179                 .setup = alc882_targa_setup,
9180                 .init_hook = alc882_targa_automute,
9181         },
9182         [ALC883_TARGA_2ch_DIG] = {
9183                 .mixers = { alc883_targa_2ch_mixer},
9184                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9185                                 alc883_targa_verbs},
9186                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9187                 .dac_nids = alc883_dac_nids,
9188                 .adc_nids = alc883_adc_nids_alt,
9189                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9190                 .dig_out_nid = ALC883_DIGOUT_NID,
9191                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9192                 .channel_mode = alc883_3ST_2ch_modes,
9193                 .input_mux = &alc883_capture_source,
9194                 .unsol_event = alc883_targa_unsol_event,
9195                 .setup = alc882_targa_setup,
9196                 .init_hook = alc882_targa_automute,
9197         },
9198         [ALC883_TARGA_8ch_DIG] = {
9199                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9200                             alc883_chmode_mixer },
9201                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9202                                 alc883_targa_verbs },
9203                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9204                 .dac_nids = alc883_dac_nids,
9205                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9206                 .adc_nids = alc883_adc_nids_rev,
9207                 .capsrc_nids = alc883_capsrc_nids_rev,
9208                 .dig_out_nid = ALC883_DIGOUT_NID,
9209                 .dig_in_nid = ALC883_DIGIN_NID,
9210                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9211                 .channel_mode = alc883_4ST_8ch_modes,
9212                 .need_dac_fix = 1,
9213                 .input_mux = &alc883_capture_source,
9214                 .unsol_event = alc883_targa_unsol_event,
9215                 .setup = alc882_targa_setup,
9216                 .init_hook = alc882_targa_automute,
9217         },
9218         [ALC883_ACER] = {
9219                 .mixers = { alc883_base_mixer },
9220                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9221                  * and the headphone jack.  Turn this on and rely on the
9222                  * standard mute methods whenever the user wants to turn
9223                  * these outputs off.
9224                  */
9225                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9226                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9227                 .dac_nids = alc883_dac_nids,
9228                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9229                 .channel_mode = alc883_3ST_2ch_modes,
9230                 .input_mux = &alc883_capture_source,
9231         },
9232         [ALC883_ACER_ASPIRE] = {
9233                 .mixers = { alc883_acer_aspire_mixer },
9234                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9235                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9236                 .dac_nids = alc883_dac_nids,
9237                 .dig_out_nid = ALC883_DIGOUT_NID,
9238                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9239                 .channel_mode = alc883_3ST_2ch_modes,
9240                 .input_mux = &alc883_capture_source,
9241                 .unsol_event = alc_automute_amp_unsol_event,
9242                 .setup = alc883_acer_aspire_setup,
9243                 .init_hook = alc_automute_amp,
9244         },
9245         [ALC888_ACER_ASPIRE_4930G] = {
9246                 .mixers = { alc888_base_mixer,
9247                                 alc883_chmode_mixer },
9248                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9249                                 alc888_acer_aspire_4930g_verbs },
9250                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9251                 .dac_nids = alc883_dac_nids,
9252                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9253                 .adc_nids = alc883_adc_nids_rev,
9254                 .capsrc_nids = alc883_capsrc_nids_rev,
9255                 .dig_out_nid = ALC883_DIGOUT_NID,
9256                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9257                 .channel_mode = alc883_3ST_6ch_modes,
9258                 .need_dac_fix = 1,
9259                 .num_mux_defs =
9260                         ARRAY_SIZE(alc888_2_capture_sources),
9261                 .input_mux = alc888_2_capture_sources,
9262                 .unsol_event = alc_automute_amp_unsol_event,
9263                 .setup = alc888_acer_aspire_4930g_setup,
9264                 .init_hook = alc_automute_amp,
9265         },
9266         [ALC888_ACER_ASPIRE_6530G] = {
9267                 .mixers = { alc888_acer_aspire_6530_mixer },
9268                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9269                                 alc888_acer_aspire_6530g_verbs },
9270                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9271                 .dac_nids = alc883_dac_nids,
9272                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9273                 .adc_nids = alc883_adc_nids_rev,
9274                 .capsrc_nids = alc883_capsrc_nids_rev,
9275                 .dig_out_nid = ALC883_DIGOUT_NID,
9276                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9277                 .channel_mode = alc883_3ST_2ch_modes,
9278                 .num_mux_defs =
9279                         ARRAY_SIZE(alc888_2_capture_sources),
9280                 .input_mux = alc888_acer_aspire_6530_sources,
9281                 .unsol_event = alc_automute_amp_unsol_event,
9282                 .setup = alc888_acer_aspire_6530g_setup,
9283                 .init_hook = alc_automute_amp,
9284         },
9285         [ALC888_ACER_ASPIRE_8930G] = {
9286                 .mixers = { alc888_base_mixer,
9287                                 alc883_chmode_mixer },
9288                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9289                                 alc889_acer_aspire_8930g_verbs },
9290                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9291                 .dac_nids = alc883_dac_nids,
9292                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9293                 .adc_nids = alc889_adc_nids,
9294                 .capsrc_nids = alc889_capsrc_nids,
9295                 .dig_out_nid = ALC883_DIGOUT_NID,
9296                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9297                 .channel_mode = alc883_3ST_6ch_modes,
9298                 .need_dac_fix = 1,
9299                 .const_channel_count = 6,
9300                 .num_mux_defs =
9301                         ARRAY_SIZE(alc889_capture_sources),
9302                 .input_mux = alc889_capture_sources,
9303                 .unsol_event = alc_automute_amp_unsol_event,
9304                 .setup = alc889_acer_aspire_8930g_setup,
9305                 .init_hook = alc_automute_amp,
9306         },
9307         [ALC888_ACER_ASPIRE_7730G] = {
9308                 .mixers = { alc883_3ST_6ch_mixer,
9309                                 alc883_chmode_mixer },
9310                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9311                                 alc888_acer_aspire_7730G_verbs },
9312                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9313                 .dac_nids = alc883_dac_nids,
9314                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9315                 .adc_nids = alc883_adc_nids_rev,
9316                 .capsrc_nids = alc883_capsrc_nids_rev,
9317                 .dig_out_nid = ALC883_DIGOUT_NID,
9318                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9319                 .channel_mode = alc883_3ST_6ch_modes,
9320                 .need_dac_fix = 1,
9321                 .const_channel_count = 6,
9322                 .input_mux = &alc883_capture_source,
9323                 .unsol_event = alc_automute_amp_unsol_event,
9324                 .setup = alc888_acer_aspire_6530g_setup,
9325                 .init_hook = alc_automute_amp,
9326         },
9327         [ALC883_MEDION] = {
9328                 .mixers = { alc883_fivestack_mixer,
9329                             alc883_chmode_mixer },
9330                 .init_verbs = { alc883_init_verbs,
9331                                 alc883_medion_eapd_verbs },
9332                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9333                 .dac_nids = alc883_dac_nids,
9334                 .adc_nids = alc883_adc_nids_alt,
9335                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9336                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9337                 .channel_mode = alc883_sixstack_modes,
9338                 .input_mux = &alc883_capture_source,
9339         },
9340         [ALC883_MEDION_MD2] = {
9341                 .mixers = { alc883_medion_md2_mixer},
9342                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9343                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9344                 .dac_nids = alc883_dac_nids,
9345                 .dig_out_nid = ALC883_DIGOUT_NID,
9346                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9347                 .channel_mode = alc883_3ST_2ch_modes,
9348                 .input_mux = &alc883_capture_source,
9349                 .unsol_event = alc_automute_amp_unsol_event,
9350                 .setup = alc883_medion_md2_setup,
9351                 .init_hook = alc_automute_amp,
9352         },
9353         [ALC883_LAPTOP_EAPD] = {
9354                 .mixers = { alc883_base_mixer },
9355                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9356                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9357                 .dac_nids = alc883_dac_nids,
9358                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9359                 .channel_mode = alc883_3ST_2ch_modes,
9360                 .input_mux = &alc883_capture_source,
9361         },
9362         [ALC883_CLEVO_M540R] = {
9363                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9364                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
9365                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9366                 .dac_nids = alc883_dac_nids,
9367                 .dig_out_nid = ALC883_DIGOUT_NID,
9368                 .dig_in_nid = ALC883_DIGIN_NID,
9369                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
9370                 .channel_mode = alc883_3ST_6ch_clevo_modes,
9371                 .need_dac_fix = 1,
9372                 .input_mux = &alc883_capture_source,
9373                 /* This machine has the hardware HP auto-muting, thus
9374                  * we need no software mute via unsol event
9375                  */
9376         },
9377         [ALC883_CLEVO_M720] = {
9378                 .mixers = { alc883_clevo_m720_mixer },
9379                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9380                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9381                 .dac_nids = alc883_dac_nids,
9382                 .dig_out_nid = ALC883_DIGOUT_NID,
9383                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9384                 .channel_mode = alc883_3ST_2ch_modes,
9385                 .input_mux = &alc883_capture_source,
9386                 .unsol_event = alc883_clevo_m720_unsol_event,
9387                 .setup = alc883_clevo_m720_setup,
9388                 .init_hook = alc883_clevo_m720_init_hook,
9389         },
9390         [ALC883_LENOVO_101E_2ch] = {
9391                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9392                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9393                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9394                 .dac_nids = alc883_dac_nids,
9395                 .adc_nids = alc883_adc_nids_alt,
9396                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9397                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9398                 .channel_mode = alc883_3ST_2ch_modes,
9399                 .input_mux = &alc883_lenovo_101e_capture_source,
9400                 .unsol_event = alc883_lenovo_101e_unsol_event,
9401                 .init_hook = alc883_lenovo_101e_all_automute,
9402         },
9403         [ALC883_LENOVO_NB0763] = {
9404                 .mixers = { alc883_lenovo_nb0763_mixer },
9405                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9406                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9407                 .dac_nids = alc883_dac_nids,
9408                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9409                 .channel_mode = alc883_3ST_2ch_modes,
9410                 .need_dac_fix = 1,
9411                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9412                 .unsol_event = alc_automute_amp_unsol_event,
9413                 .setup = alc883_medion_md2_setup,
9414                 .init_hook = alc_automute_amp,
9415         },
9416         [ALC888_LENOVO_MS7195_DIG] = {
9417                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9418                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9419                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9420                 .dac_nids = alc883_dac_nids,
9421                 .dig_out_nid = ALC883_DIGOUT_NID,
9422                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9423                 .channel_mode = alc883_3ST_6ch_modes,
9424                 .need_dac_fix = 1,
9425                 .input_mux = &alc883_capture_source,
9426                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9427                 .init_hook = alc888_lenovo_ms7195_front_automute,
9428         },
9429         [ALC883_HAIER_W66] = {
9430                 .mixers = { alc883_targa_2ch_mixer},
9431                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9432                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9433                 .dac_nids = alc883_dac_nids,
9434                 .dig_out_nid = ALC883_DIGOUT_NID,
9435                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9436                 .channel_mode = alc883_3ST_2ch_modes,
9437                 .input_mux = &alc883_capture_source,
9438                 .unsol_event = alc_automute_amp_unsol_event,
9439                 .setup = alc883_haier_w66_setup,
9440                 .init_hook = alc_automute_amp,
9441         },
9442         [ALC888_3ST_HP] = {
9443                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9444                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9445                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9446                 .dac_nids = alc883_dac_nids,
9447                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9448                 .channel_mode = alc888_3st_hp_modes,
9449                 .need_dac_fix = 1,
9450                 .input_mux = &alc883_capture_source,
9451                 .unsol_event = alc_automute_amp_unsol_event,
9452                 .setup = alc888_3st_hp_setup,
9453                 .init_hook = alc_automute_amp,
9454         },
9455         [ALC888_6ST_DELL] = {
9456                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9457                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9458                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9459                 .dac_nids = alc883_dac_nids,
9460                 .dig_out_nid = ALC883_DIGOUT_NID,
9461                 .dig_in_nid = ALC883_DIGIN_NID,
9462                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9463                 .channel_mode = alc883_sixstack_modes,
9464                 .input_mux = &alc883_capture_source,
9465                 .unsol_event = alc_automute_amp_unsol_event,
9466                 .setup = alc888_6st_dell_setup,
9467                 .init_hook = alc_automute_amp,
9468         },
9469         [ALC883_MITAC] = {
9470                 .mixers = { alc883_mitac_mixer },
9471                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9472                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9473                 .dac_nids = alc883_dac_nids,
9474                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9475                 .channel_mode = alc883_3ST_2ch_modes,
9476                 .input_mux = &alc883_capture_source,
9477                 .unsol_event = alc_automute_amp_unsol_event,
9478                 .setup = alc883_mitac_setup,
9479                 .init_hook = alc_automute_amp,
9480         },
9481         [ALC883_FUJITSU_PI2515] = {
9482                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9483                 .init_verbs = { alc883_init_verbs,
9484                                 alc883_2ch_fujitsu_pi2515_verbs},
9485                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9486                 .dac_nids = alc883_dac_nids,
9487                 .dig_out_nid = ALC883_DIGOUT_NID,
9488                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9489                 .channel_mode = alc883_3ST_2ch_modes,
9490                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9491                 .unsol_event = alc_automute_amp_unsol_event,
9492                 .setup = alc883_2ch_fujitsu_pi2515_setup,
9493                 .init_hook = alc_automute_amp,
9494         },
9495         [ALC888_FUJITSU_XA3530] = {
9496                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9497                 .init_verbs = { alc883_init_verbs,
9498                         alc888_fujitsu_xa3530_verbs },
9499                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9500                 .dac_nids = alc883_dac_nids,
9501                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9502                 .adc_nids = alc883_adc_nids_rev,
9503                 .capsrc_nids = alc883_capsrc_nids_rev,
9504                 .dig_out_nid = ALC883_DIGOUT_NID,
9505                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9506                 .channel_mode = alc888_4ST_8ch_intel_modes,
9507                 .num_mux_defs =
9508                         ARRAY_SIZE(alc888_2_capture_sources),
9509                 .input_mux = alc888_2_capture_sources,
9510                 .unsol_event = alc_automute_amp_unsol_event,
9511                 .setup = alc888_fujitsu_xa3530_setup,
9512                 .init_hook = alc_automute_amp,
9513         },
9514         [ALC888_LENOVO_SKY] = {
9515                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9516                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9517                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9518                 .dac_nids = alc883_dac_nids,
9519                 .dig_out_nid = ALC883_DIGOUT_NID,
9520                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9521                 .channel_mode = alc883_sixstack_modes,
9522                 .need_dac_fix = 1,
9523                 .input_mux = &alc883_lenovo_sky_capture_source,
9524                 .unsol_event = alc_automute_amp_unsol_event,
9525                 .setup = alc888_lenovo_sky_setup,
9526                 .init_hook = alc_automute_amp,
9527         },
9528         [ALC888_ASUS_M90V] = {
9529                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9530                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9531                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9532                 .dac_nids = alc883_dac_nids,
9533                 .dig_out_nid = ALC883_DIGOUT_NID,
9534                 .dig_in_nid = ALC883_DIGIN_NID,
9535                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9536                 .channel_mode = alc883_3ST_6ch_modes,
9537                 .need_dac_fix = 1,
9538                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9539                 .unsol_event = alc_sku_unsol_event,
9540                 .setup = alc883_mode2_setup,
9541                 .init_hook = alc_inithook,
9542         },
9543         [ALC888_ASUS_EEE1601] = {
9544                 .mixers = { alc883_asus_eee1601_mixer },
9545                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9546                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9547                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9548                 .dac_nids = alc883_dac_nids,
9549                 .dig_out_nid = ALC883_DIGOUT_NID,
9550                 .dig_in_nid = ALC883_DIGIN_NID,
9551                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9552                 .channel_mode = alc883_3ST_2ch_modes,
9553                 .need_dac_fix = 1,
9554                 .input_mux = &alc883_asus_eee1601_capture_source,
9555                 .unsol_event = alc_sku_unsol_event,
9556                 .init_hook = alc883_eee1601_inithook,
9557         },
9558         [ALC1200_ASUS_P5Q] = {
9559                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9560                 .init_verbs = { alc883_init_verbs },
9561                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9562                 .dac_nids = alc883_dac_nids,
9563                 .dig_out_nid = ALC1200_DIGOUT_NID,
9564                 .dig_in_nid = ALC883_DIGIN_NID,
9565                 .slave_dig_outs = alc1200_slave_dig_outs,
9566                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9567                 .channel_mode = alc883_sixstack_modes,
9568                 .input_mux = &alc883_capture_source,
9569         },
9570         [ALC889A_MB31] = {
9571                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9572                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9573                         alc880_gpio1_init_verbs },
9574                 .adc_nids = alc883_adc_nids,
9575                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9576                 .dac_nids = alc883_dac_nids,
9577                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9578                 .channel_mode = alc889A_mb31_6ch_modes,
9579                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9580                 .input_mux = &alc889A_mb31_capture_source,
9581                 .dig_out_nid = ALC883_DIGOUT_NID,
9582                 .unsol_event = alc889A_mb31_unsol_event,
9583                 .init_hook = alc889A_mb31_automute,
9584         },
9585         [ALC883_SONY_VAIO_TT] = {
9586                 .mixers = { alc883_vaiott_mixer },
9587                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9588                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9589                 .dac_nids = alc883_dac_nids,
9590                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9591                 .channel_mode = alc883_3ST_2ch_modes,
9592                 .input_mux = &alc883_capture_source,
9593                 .unsol_event = alc_automute_amp_unsol_event,
9594                 .setup = alc883_vaiott_setup,
9595                 .init_hook = alc_automute_amp,
9596         },
9597 };
9598
9599
9600 /*
9601  * Pin config fixes
9602  */
9603 enum {
9604         PINFIX_ABIT_AW9D_MAX
9605 };
9606
9607 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
9608         { 0x15, 0x01080104 }, /* side */
9609         { 0x16, 0x01011012 }, /* rear */
9610         { 0x17, 0x01016011 }, /* clfe */
9611         { }
9612 };
9613
9614 static const struct alc_fixup alc882_fixups[] = {
9615         [PINFIX_ABIT_AW9D_MAX] = {
9616                 .pins = alc882_abit_aw9d_pinfix
9617         },
9618 };
9619
9620 static struct snd_pci_quirk alc882_fixup_tbl[] = {
9621         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
9622         {}
9623 };
9624
9625 /*
9626  * BIOS auto configuration
9627  */
9628 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
9629                                                 const struct auto_pin_cfg *cfg)
9630 {
9631         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
9632 }
9633
9634 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9635                                               hda_nid_t nid, int pin_type,
9636                                               int dac_idx)
9637 {
9638         /* set as output */
9639         struct alc_spec *spec = codec->spec;
9640         int idx;
9641
9642         alc_set_pin_output(codec, nid, pin_type);
9643         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9644                 idx = 4;
9645         else
9646                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9647         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9648
9649 }
9650
9651 static void alc882_auto_init_multi_out(struct hda_codec *codec)
9652 {
9653         struct alc_spec *spec = codec->spec;
9654         int i;
9655
9656         for (i = 0; i <= HDA_SIDE; i++) {
9657                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9658                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9659                 if (nid)
9660                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9661                                                           i);
9662         }
9663 }
9664
9665 static void alc882_auto_init_hp_out(struct hda_codec *codec)
9666 {
9667         struct alc_spec *spec = codec->spec;
9668         hda_nid_t pin;
9669
9670         pin = spec->autocfg.hp_pins[0];
9671         if (pin) /* connect to front */
9672                 /* use dac 0 */
9673                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9674         pin = spec->autocfg.speaker_pins[0];
9675         if (pin)
9676                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9677 }
9678
9679 static void alc882_auto_init_analog_input(struct hda_codec *codec)
9680 {
9681         struct alc_spec *spec = codec->spec;
9682         int i;
9683
9684         for (i = 0; i < AUTO_PIN_LAST; i++) {
9685                 hda_nid_t nid = spec->autocfg.input_pins[i];
9686                 if (!nid)
9687                         continue;
9688                 alc_set_input_pin(codec, nid, i);
9689                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
9690                         snd_hda_codec_write(codec, nid, 0,
9691                                             AC_VERB_SET_AMP_GAIN_MUTE,
9692                                             AMP_OUT_MUTE);
9693         }
9694 }
9695
9696 static void alc882_auto_init_input_src(struct hda_codec *codec)
9697 {
9698         struct alc_spec *spec = codec->spec;
9699         int c;
9700
9701         for (c = 0; c < spec->num_adc_nids; c++) {
9702                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
9703                 hda_nid_t nid = spec->capsrc_nids[c];
9704                 unsigned int mux_idx;
9705                 const struct hda_input_mux *imux;
9706                 int conns, mute, idx, item;
9707
9708                 conns = snd_hda_get_connections(codec, nid, conn_list,
9709                                                 ARRAY_SIZE(conn_list));
9710                 if (conns < 0)
9711                         continue;
9712                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9713                 imux = &spec->input_mux[mux_idx];
9714                 for (idx = 0; idx < conns; idx++) {
9715                         /* if the current connection is the selected one,
9716                          * unmute it as default - otherwise mute it
9717                          */
9718                         mute = AMP_IN_MUTE(idx);
9719                         for (item = 0; item < imux->num_items; item++) {
9720                                 if (imux->items[item].index == idx) {
9721                                         if (spec->cur_mux[c] == item)
9722                                                 mute = AMP_IN_UNMUTE(idx);
9723                                         break;
9724                                 }
9725                         }
9726                         /* check if we have a selector or mixer
9727                          * we could check for the widget type instead, but
9728                          * just check for Amp-In presence (in case of mixer
9729                          * without amp-in there is something wrong, this
9730                          * function shouldn't be used or capsrc nid is wrong)
9731                          */
9732                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
9733                                 snd_hda_codec_write(codec, nid, 0,
9734                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9735                                                     mute);
9736                         else if (mute != AMP_IN_MUTE(idx))
9737                                 snd_hda_codec_write(codec, nid, 0,
9738                                                     AC_VERB_SET_CONNECT_SEL,
9739                                                     idx);
9740                 }
9741         }
9742 }
9743
9744 /* add mic boosts if needed */
9745 static int alc_auto_add_mic_boost(struct hda_codec *codec)
9746 {
9747         struct alc_spec *spec = codec->spec;
9748         int err;
9749         hda_nid_t nid;
9750
9751         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
9752         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9753                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9754                                   "Mic Boost",
9755                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9756                 if (err < 0)
9757                         return err;
9758         }
9759         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
9760         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9761                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9762                                   "Front Mic Boost",
9763                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9764                 if (err < 0)
9765                         return err;
9766         }
9767         return 0;
9768 }
9769
9770 /* almost identical with ALC880 parser... */
9771 static int alc882_parse_auto_config(struct hda_codec *codec)
9772 {
9773         struct alc_spec *spec = codec->spec;
9774         static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9775         int i, err;
9776
9777         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9778                                            alc882_ignore);
9779         if (err < 0)
9780                 return err;
9781         if (!spec->autocfg.line_outs)
9782                 return 0; /* can't find valid BIOS pin config */
9783
9784         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
9785         if (err < 0)
9786                 return err;
9787         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
9788         if (err < 0)
9789                 return err;
9790         err = alc880_auto_create_extra_out(spec,
9791                                            spec->autocfg.speaker_pins[0],
9792                                            "Speaker");
9793         if (err < 0)
9794                 return err;
9795         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
9796                                            "Headphone");
9797         if (err < 0)
9798                 return err;
9799         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
9800         if (err < 0)
9801                 return err;
9802
9803         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9804
9805         /* check multiple SPDIF-out (for recent codecs) */
9806         for (i = 0; i < spec->autocfg.dig_outs; i++) {
9807                 hda_nid_t dig_nid;
9808                 err = snd_hda_get_connections(codec,
9809                                               spec->autocfg.dig_out_pins[i],
9810                                               &dig_nid, 1);
9811                 if (err < 0)
9812                         continue;
9813                 if (!i)
9814                         spec->multiout.dig_out_nid = dig_nid;
9815                 else {
9816                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9817                         spec->slave_dig_outs[i - 1] = dig_nid;
9818                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
9819                                 break;
9820                 }
9821         }
9822         if (spec->autocfg.dig_in_pin)
9823                 spec->dig_in_nid = ALC880_DIGIN_NID;
9824
9825         if (spec->kctls.list)
9826                 add_mixer(spec, spec->kctls.list);
9827
9828         add_verb(spec, alc883_auto_init_verbs);
9829         /* if ADC 0x07 is available, initialize it, too */
9830         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
9831                 add_verb(spec, alc882_adc1_init_verbs);
9832
9833         spec->num_mux_defs = 1;
9834         spec->input_mux = &spec->private_imux[0];
9835
9836         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
9837
9838         err = alc_auto_add_mic_boost(codec);
9839         if (err < 0)
9840                 return err;
9841
9842         return 1; /* config found */
9843 }
9844
9845 /* additional initialization for auto-configuration model */
9846 static void alc882_auto_init(struct hda_codec *codec)
9847 {
9848         struct alc_spec *spec = codec->spec;
9849         alc882_auto_init_multi_out(codec);
9850         alc882_auto_init_hp_out(codec);
9851         alc882_auto_init_analog_input(codec);
9852         alc882_auto_init_input_src(codec);
9853         if (spec->unsol_event)
9854                 alc_inithook(codec);
9855 }
9856
9857 static int patch_alc882(struct hda_codec *codec)
9858 {
9859         struct alc_spec *spec;
9860         int err, board_config;
9861
9862         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9863         if (spec == NULL)
9864                 return -ENOMEM;
9865
9866         codec->spec = spec;
9867
9868         switch (codec->vendor_id) {
9869         case 0x10ec0882:
9870         case 0x10ec0885:
9871                 break;
9872         default:
9873                 /* ALC883 and variants */
9874                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9875                 break;
9876         }
9877
9878         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9879                                                   alc882_models,
9880                                                   alc882_cfg_tbl);
9881
9882         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9883                 board_config = snd_hda_check_board_codec_sid_config(codec,
9884                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9885
9886         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9887                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9888                        codec->chip_name);
9889                 board_config = ALC882_AUTO;
9890         }
9891
9892         alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups);
9893
9894         if (board_config == ALC882_AUTO) {
9895                 /* automatic parse from the BIOS config */
9896                 err = alc882_parse_auto_config(codec);
9897                 if (err < 0) {
9898                         alc_free(codec);
9899                         return err;
9900                 } else if (!err) {
9901                         printk(KERN_INFO
9902                                "hda_codec: Cannot set up configuration "
9903                                "from BIOS.  Using base mode...\n");
9904                         board_config = ALC882_3ST_DIG;
9905                 }
9906         }
9907
9908         err = snd_hda_attach_beep_device(codec, 0x1);
9909         if (err < 0) {
9910                 alc_free(codec);
9911                 return err;
9912         }
9913
9914         if (board_config != ALC882_AUTO)
9915                 setup_preset(codec, &alc882_presets[board_config]);
9916
9917         spec->stream_analog_playback = &alc882_pcm_analog_playback;
9918         spec->stream_analog_capture = &alc882_pcm_analog_capture;
9919         /* FIXME: setup DAC5 */
9920         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9921         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9922
9923         spec->stream_digital_playback = &alc882_pcm_digital_playback;
9924         spec->stream_digital_capture = &alc882_pcm_digital_capture;
9925
9926         if (codec->vendor_id == 0x10ec0888)
9927                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9928
9929         if (!spec->adc_nids && spec->input_mux) {
9930                 int i;
9931                 spec->num_adc_nids = 0;
9932                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9933                         hda_nid_t cap;
9934                         hda_nid_t nid = alc882_adc_nids[i];
9935                         unsigned int wcap = get_wcaps(codec, nid);
9936                         /* get type */
9937                         wcap = get_wcaps_type(wcap);
9938                         if (wcap != AC_WID_AUD_IN)
9939                                 continue;
9940                         spec->private_adc_nids[spec->num_adc_nids] = nid;
9941                         err = snd_hda_get_connections(codec, nid, &cap, 1);
9942                         if (err < 0)
9943                                 continue;
9944                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9945                         spec->num_adc_nids++;
9946                 }
9947                 spec->adc_nids = spec->private_adc_nids;
9948                 spec->capsrc_nids = spec->private_capsrc_nids;
9949         }
9950
9951         set_capture_mixer(codec);
9952         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9953
9954         spec->vmaster_nid = 0x0c;
9955
9956         codec->patch_ops = alc_patch_ops;
9957         if (board_config == ALC882_AUTO)
9958                 spec->init_hook = alc882_auto_init;
9959 #ifdef CONFIG_SND_HDA_POWER_SAVE
9960         if (!spec->loopback.amplist)
9961                 spec->loopback.amplist = alc882_loopbacks;
9962 #endif
9963         codec->proc_widget_hook = print_realtek_coef;
9964
9965         return 0;
9966 }
9967
9968
9969 /*
9970  * ALC262 support
9971  */
9972
9973 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9974 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9975
9976 #define alc262_dac_nids         alc260_dac_nids
9977 #define alc262_adc_nids         alc882_adc_nids
9978 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9979 #define alc262_capsrc_nids      alc882_capsrc_nids
9980 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9981
9982 #define alc262_modes            alc260_modes
9983 #define alc262_capture_source   alc882_capture_source
9984
9985 static hda_nid_t alc262_dmic_adc_nids[1] = {
9986         /* ADC0 */
9987         0x09
9988 };
9989
9990 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9991
9992 static struct snd_kcontrol_new alc262_base_mixer[] = {
9993         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9994         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9995         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9996         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9997         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9998         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9999         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10000         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10001         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10002         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10003         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10004         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10005         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
10006         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10007         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
10008         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10009         { } /* end */
10010 };
10011
10012 /* update HP, line and mono-out pins according to the master switch */
10013 static void alc262_hp_master_update(struct hda_codec *codec)
10014 {
10015         struct alc_spec *spec = codec->spec;
10016         int val = spec->master_sw;
10017
10018         /* HP & line-out */
10019         snd_hda_codec_write_cache(codec, 0x1b, 0,
10020                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10021                                   val ? PIN_HP : 0);
10022         snd_hda_codec_write_cache(codec, 0x15, 0,
10023                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10024                                   val ? PIN_HP : 0);
10025         /* mono (speaker) depending on the HP jack sense */
10026         val = val && !spec->jack_present;
10027         snd_hda_codec_write_cache(codec, 0x16, 0,
10028                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10029                                   val ? PIN_OUT : 0);
10030 }
10031
10032 static void alc262_hp_bpc_automute(struct hda_codec *codec)
10033 {
10034         struct alc_spec *spec = codec->spec;
10035         unsigned int presence;
10036         presence = snd_hda_codec_read(codec, 0x1b, 0,
10037                                       AC_VERB_GET_PIN_SENSE, 0);
10038         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10039         alc262_hp_master_update(codec);
10040 }
10041
10042 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10043 {
10044         if ((res >> 26) != ALC880_HP_EVENT)
10045                 return;
10046         alc262_hp_bpc_automute(codec);
10047 }
10048
10049 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10050 {
10051         struct alc_spec *spec = codec->spec;
10052         unsigned int presence;
10053         presence = snd_hda_codec_read(codec, 0x15, 0,
10054                                       AC_VERB_GET_PIN_SENSE, 0);
10055         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10056         alc262_hp_master_update(codec);
10057 }
10058
10059 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
10060                                            unsigned int res)
10061 {
10062         if ((res >> 26) != ALC880_HP_EVENT)
10063                 return;
10064         alc262_hp_wildwest_automute(codec);
10065 }
10066
10067 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
10068
10069 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
10070                                    struct snd_ctl_elem_value *ucontrol)
10071 {
10072         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10073         struct alc_spec *spec = codec->spec;
10074         int val = !!*ucontrol->value.integer.value;
10075
10076         if (val == spec->master_sw)
10077                 return 0;
10078         spec->master_sw = val;
10079         alc262_hp_master_update(codec);
10080         return 1;
10081 }
10082
10083 #define ALC262_HP_MASTER_SWITCH                                 \
10084         {                                                       \
10085                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10086                 .name = "Master Playback Switch",               \
10087                 .info = snd_ctl_boolean_mono_info,              \
10088                 .get = alc262_hp_master_sw_get,                 \
10089                 .put = alc262_hp_master_sw_put,                 \
10090         }
10091
10092 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10093         ALC262_HP_MASTER_SWITCH,
10094         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10095         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10096         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10097         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10098                               HDA_OUTPUT),
10099         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10100                             HDA_OUTPUT),
10101         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10102         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10103         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10104         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10105         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10106         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10107         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10108         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10109         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10110         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10111         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
10112         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
10113         { } /* end */
10114 };
10115
10116 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10117         ALC262_HP_MASTER_SWITCH,
10118         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10119         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10120         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10121         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10122         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10123                               HDA_OUTPUT),
10124         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10125                             HDA_OUTPUT),
10126         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10127         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10128         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10129         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10130         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10131         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10132         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10133         { } /* end */
10134 };
10135
10136 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10137         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10138         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10139         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10140         { } /* end */
10141 };
10142
10143 /* mute/unmute internal speaker according to the hp jack and mute state */
10144 static void alc262_hp_t5735_setup(struct hda_codec *codec)
10145 {
10146         struct alc_spec *spec = codec->spec;
10147
10148         spec->autocfg.hp_pins[0] = 0x15;
10149         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10150 }
10151
10152 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10153         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10154         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10155         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10156         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10157         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10158         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10159         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10160         { } /* end */
10161 };
10162
10163 static struct hda_verb alc262_hp_t5735_verbs[] = {
10164         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10165         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10166
10167         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10168         { }
10169 };
10170
10171 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10172         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10173         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10174         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10175         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10176         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10177         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10178         { } /* end */
10179 };
10180
10181 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10182         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10183         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10184         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10185         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10186         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10187         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10188         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10189         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10192         {}
10193 };
10194
10195 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10196         .num_items = 1,
10197         .items = {
10198                 { "Line", 0x1 },
10199         },
10200 };
10201
10202 /* bind hp and internal speaker mute (with plug check) as master switch */
10203 static void alc262_hippo_master_update(struct hda_codec *codec)
10204 {
10205         struct alc_spec *spec = codec->spec;
10206         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10207         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10208         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10209         unsigned int mute;
10210
10211         /* HP */
10212         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10213         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10214                                  HDA_AMP_MUTE, mute);
10215         /* mute internal speaker per jack sense */
10216         if (spec->jack_present)
10217                 mute = HDA_AMP_MUTE;
10218         if (line_nid)
10219                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10220                                          HDA_AMP_MUTE, mute);
10221         if (speaker_nid && speaker_nid != line_nid)
10222                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10223                                          HDA_AMP_MUTE, mute);
10224 }
10225
10226 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10227
10228 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10229                                       struct snd_ctl_elem_value *ucontrol)
10230 {
10231         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10232         struct alc_spec *spec = codec->spec;
10233         int val = !!*ucontrol->value.integer.value;
10234
10235         if (val == spec->master_sw)
10236                 return 0;
10237         spec->master_sw = val;
10238         alc262_hippo_master_update(codec);
10239         return 1;
10240 }
10241
10242 #define ALC262_HIPPO_MASTER_SWITCH                              \
10243         {                                                       \
10244                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10245                 .name = "Master Playback Switch",               \
10246                 .info = snd_ctl_boolean_mono_info,              \
10247                 .get = alc262_hippo_master_sw_get,              \
10248                 .put = alc262_hippo_master_sw_put,              \
10249         }
10250
10251 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10252         ALC262_HIPPO_MASTER_SWITCH,
10253         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10254         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10255         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10256         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10257         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10258         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10259         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10260         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10261         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10262         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10263         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10264         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10265         { } /* end */
10266 };
10267
10268 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10269         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10270         ALC262_HIPPO_MASTER_SWITCH,
10271         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10272         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10273         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10274         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10275         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10276         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10277         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10278         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10279         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10280         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10281         { } /* end */
10282 };
10283
10284 /* mute/unmute internal speaker according to the hp jack and mute state */
10285 static void alc262_hippo_automute(struct hda_codec *codec)
10286 {
10287         struct alc_spec *spec = codec->spec;
10288         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10289         unsigned int present;
10290
10291         /* need to execute and sync at first */
10292         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10293         present = snd_hda_codec_read(codec, hp_nid, 0,
10294                                      AC_VERB_GET_PIN_SENSE, 0);
10295         spec->jack_present = (present & 0x80000000) != 0;
10296         alc262_hippo_master_update(codec);
10297 }
10298
10299 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10300 {
10301         if ((res >> 26) != ALC880_HP_EVENT)
10302                 return;
10303         alc262_hippo_automute(codec);
10304 }
10305
10306 static void alc262_hippo_setup(struct hda_codec *codec)
10307 {
10308         struct alc_spec *spec = codec->spec;
10309
10310         spec->autocfg.hp_pins[0] = 0x15;
10311         spec->autocfg.speaker_pins[0] = 0x14;
10312 }
10313
10314 static void alc262_hippo1_setup(struct hda_codec *codec)
10315 {
10316         struct alc_spec *spec = codec->spec;
10317
10318         spec->autocfg.hp_pins[0] = 0x1b;
10319         spec->autocfg.speaker_pins[0] = 0x14;
10320 }
10321
10322
10323 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10324         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10325         ALC262_HIPPO_MASTER_SWITCH,
10326         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10327         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10328         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10329         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10330         { } /* end */
10331 };
10332
10333 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10334         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10335         ALC262_HIPPO_MASTER_SWITCH,
10336         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10337         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10338         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10339         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10340         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10341         { } /* end */
10342 };
10343
10344 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10345         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10346         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10347         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10348         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10349         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10350         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10351         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10352         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10353         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10354         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10355         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10356         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10357         { } /* end */
10358 };
10359
10360 static struct hda_verb alc262_tyan_verbs[] = {
10361         /* Headphone automute */
10362         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10363         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10364         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10365
10366         /* P11 AUX_IN, white 4-pin connector */
10367         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10368         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10369         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10370         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10371
10372         {}
10373 };
10374
10375 /* unsolicited event for HP jack sensing */
10376 static void alc262_tyan_setup(struct hda_codec *codec)
10377 {
10378         struct alc_spec *spec = codec->spec;
10379
10380         spec->autocfg.hp_pins[0] = 0x1b;
10381         spec->autocfg.speaker_pins[0] = 0x15;
10382 }
10383
10384
10385 #define alc262_capture_mixer            alc882_capture_mixer
10386 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10387
10388 /*
10389  * generic initialization of ADC, input mixers and output mixers
10390  */
10391 static struct hda_verb alc262_init_verbs[] = {
10392         /*
10393          * Unmute ADC0-2 and set the default input to mic-in
10394          */
10395         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10396         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10397         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10398         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10399         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10400         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10401
10402         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10403          * mixer widget
10404          * Note: PASD motherboards uses the Line In 2 as the input for
10405          * front panel mic (mic 2)
10406          */
10407         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10408         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10409         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10410         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10411         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10412         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10413
10414         /*
10415          * Set up output mixers (0x0c - 0x0e)
10416          */
10417         /* set vol=0 to output mixers */
10418         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10419         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10420         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10421         /* set up input amps for analog loopback */
10422         /* Amp Indices: DAC = 0, mixer = 1 */
10423         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10424         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10425         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10426         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10427         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10428         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10429
10430         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10431         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10432         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10433         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10434         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10435         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10436
10437         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10438         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10439         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10440         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10441         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10442
10443         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10444         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10445
10446         /* FIXME: use matrix-type input source selection */
10447         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10448         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10449         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10450         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10451         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10452         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10453         /* Input mixer2 */
10454         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10455         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10456         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10457         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10458         /* Input mixer3 */
10459         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10460         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10461         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10462         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10463
10464         { }
10465 };
10466
10467 static struct hda_verb alc262_eapd_verbs[] = {
10468         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10469         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10470         { }
10471 };
10472
10473 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10474         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10475         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10476         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10477
10478         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10479         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10480         {}
10481 };
10482
10483 static struct hda_verb alc262_sony_unsol_verbs[] = {
10484         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10485         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10486         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10487
10488         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10489         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10490         {}
10491 };
10492
10493 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10494         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10495         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10496         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10497         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10498         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10499         { } /* end */
10500 };
10501
10502 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10503         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10504         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10505         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10506         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10507         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10508         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10509         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10510         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10511         {}
10512 };
10513
10514 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10515 {
10516         struct alc_spec *spec = codec->spec;
10517
10518         spec->autocfg.hp_pins[0] = 0x15;
10519         spec->autocfg.speaker_pins[0] = 0x14;
10520         spec->ext_mic.pin = 0x18;
10521         spec->ext_mic.mux_idx = 0;
10522         spec->int_mic.pin = 0x12;
10523         spec->int_mic.mux_idx = 9;
10524         spec->auto_mic = 1;
10525 }
10526
10527 /*
10528  * nec model
10529  *  0x15 = headphone
10530  *  0x16 = internal speaker
10531  *  0x18 = external mic
10532  */
10533
10534 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10535         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10536         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10537
10538         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10539         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10540         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10541
10542         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10543         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10544         { } /* end */
10545 };
10546
10547 static struct hda_verb alc262_nec_verbs[] = {
10548         /* Unmute Speaker */
10549         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10550
10551         /* Headphone */
10552         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10553         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10554
10555         /* External mic to headphone */
10556         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10557         /* External mic to speaker */
10558         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10559         {}
10560 };
10561
10562 /*
10563  * fujitsu model
10564  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10565  *  0x1b = port replicator headphone out
10566  */
10567
10568 #define ALC_HP_EVENT    0x37
10569
10570 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10571         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10572         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10573         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10574         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10575         {}
10576 };
10577
10578 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10579         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10580         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10581         {}
10582 };
10583
10584 static struct hda_input_mux alc262_fujitsu_capture_source = {
10585         .num_items = 3,
10586         .items = {
10587                 { "Mic", 0x0 },
10588                 { "Int Mic", 0x1 },
10589                 { "CD", 0x4 },
10590         },
10591 };
10592
10593 static struct hda_input_mux alc262_HP_capture_source = {
10594         .num_items = 5,
10595         .items = {
10596                 { "Mic", 0x0 },
10597                 { "Front Mic", 0x1 },
10598                 { "Line", 0x2 },
10599                 { "CD", 0x4 },
10600                 { "AUX IN", 0x6 },
10601         },
10602 };
10603
10604 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10605         .num_items = 4,
10606         .items = {
10607                 { "Mic", 0x0 },
10608                 { "Front Mic", 0x2 },
10609                 { "Line", 0x1 },
10610                 { "CD", 0x4 },
10611         },
10612 };
10613
10614 /* mute/unmute internal speaker according to the hp jacks and mute state */
10615 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10616 {
10617         struct alc_spec *spec = codec->spec;
10618         unsigned int mute;
10619
10620         if (force || !spec->sense_updated) {
10621                 unsigned int present;
10622                 /* need to execute and sync at first */
10623                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10624                 /* check laptop HP jack */
10625                 present = snd_hda_codec_read(codec, 0x14, 0,
10626                                              AC_VERB_GET_PIN_SENSE, 0);
10627                 /* need to execute and sync at first */
10628                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10629                 /* check docking HP jack */
10630                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10631                                               AC_VERB_GET_PIN_SENSE, 0);
10632                 if (present & AC_PINSENSE_PRESENCE)
10633                         spec->jack_present = 1;
10634                 else
10635                         spec->jack_present = 0;
10636                 spec->sense_updated = 1;
10637         }
10638         /* unmute internal speaker only if both HPs are unplugged and
10639          * master switch is on
10640          */
10641         if (spec->jack_present)
10642                 mute = HDA_AMP_MUTE;
10643         else
10644                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10645         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10646                                  HDA_AMP_MUTE, mute);
10647 }
10648
10649 /* unsolicited event for HP jack sensing */
10650 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10651                                        unsigned int res)
10652 {
10653         if ((res >> 26) != ALC_HP_EVENT)
10654                 return;
10655         alc262_fujitsu_automute(codec, 1);
10656 }
10657
10658 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10659 {
10660         alc262_fujitsu_automute(codec, 1);
10661 }
10662
10663 /* bind volumes of both NID 0x0c and 0x0d */
10664 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10665         .ops = &snd_hda_bind_vol,
10666         .values = {
10667                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10668                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10669                 0
10670         },
10671 };
10672
10673 /* mute/unmute internal speaker according to the hp jack and mute state */
10674 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10675 {
10676         struct alc_spec *spec = codec->spec;
10677         unsigned int mute;
10678
10679         if (force || !spec->sense_updated) {
10680                 unsigned int present_int_hp;
10681                 /* need to execute and sync at first */
10682                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10683                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10684                                         AC_VERB_GET_PIN_SENSE, 0);
10685                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10686                 spec->sense_updated = 1;
10687         }
10688         if (spec->jack_present) {
10689                 /* mute internal speaker */
10690                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10691                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10692                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10693                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10694         } else {
10695                 /* unmute internal speaker if necessary */
10696                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10697                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10698                                          HDA_AMP_MUTE, mute);
10699                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10700                                          HDA_AMP_MUTE, mute);
10701         }
10702 }
10703
10704 /* unsolicited event for HP jack sensing */
10705 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10706                                        unsigned int res)
10707 {
10708         if ((res >> 26) != ALC_HP_EVENT)
10709                 return;
10710         alc262_lenovo_3000_automute(codec, 1);
10711 }
10712
10713 static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
10714                                   int dir, int idx, long *valp)
10715 {
10716         int i, change = 0;
10717
10718         for (i = 0; i < 2; i++, valp++)
10719                 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
10720                                                    HDA_AMP_MUTE,
10721                                                    *valp ? 0 : HDA_AMP_MUTE);
10722         return change;
10723 }
10724
10725 /* bind hp and internal speaker mute (with plug check) */
10726 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10727                                          struct snd_ctl_elem_value *ucontrol)
10728 {
10729         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10730         long *valp = ucontrol->value.integer.value;
10731         int change;
10732
10733         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10734         change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10735         if (change)
10736                 alc262_fujitsu_automute(codec, 0);
10737         return change;
10738 }
10739
10740 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10741         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10742         {
10743                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10744                 .name = "Master Playback Switch",
10745                 .info = snd_hda_mixer_amp_switch_info,
10746                 .get = snd_hda_mixer_amp_switch_get,
10747                 .put = alc262_fujitsu_master_sw_put,
10748                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10749         },
10750         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10751         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10752         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10753         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10754         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10755         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10756         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10757         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10758         { } /* end */
10759 };
10760
10761 /* bind hp and internal speaker mute (with plug check) */
10762 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10763                                          struct snd_ctl_elem_value *ucontrol)
10764 {
10765         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10766         long *valp = ucontrol->value.integer.value;
10767         int change;
10768
10769         change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10770         if (change)
10771                 alc262_lenovo_3000_automute(codec, 0);
10772         return change;
10773 }
10774
10775 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10776         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10777         {
10778                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10779                 .name = "Master Playback Switch",
10780                 .info = snd_hda_mixer_amp_switch_info,
10781                 .get = snd_hda_mixer_amp_switch_get,
10782                 .put = alc262_lenovo_3000_master_sw_put,
10783                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10784         },
10785         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10786         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10787         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10788         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10789         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10790         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10791         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10792         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10793         { } /* end */
10794 };
10795
10796 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10797         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10798         ALC262_HIPPO_MASTER_SWITCH,
10799         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10800         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10801         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10802         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10803         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10804         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10805         { } /* end */
10806 };
10807
10808 /* additional init verbs for Benq laptops */
10809 static struct hda_verb alc262_EAPD_verbs[] = {
10810         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10811         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10812         {}
10813 };
10814
10815 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10816         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10817         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10818
10819         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10820         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10821         {}
10822 };
10823
10824 /* Samsung Q1 Ultra Vista model setup */
10825 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10826         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10827         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10828         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10829         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10830         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10831         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10832         { } /* end */
10833 };
10834
10835 static struct hda_verb alc262_ultra_verbs[] = {
10836         /* output mixer */
10837         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10838         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10839         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10840         /* speaker */
10841         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10842         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10843         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10844         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10845         /* HP */
10846         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10847         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10848         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10849         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10850         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10851         /* internal mic */
10852         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10853         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10854         /* ADC, choose mic */
10855         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10856         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10857         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10858         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10859         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10860         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10861         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10862         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10863         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10864         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10865         {}
10866 };
10867
10868 /* mute/unmute internal speaker according to the hp jack and mute state */
10869 static void alc262_ultra_automute(struct hda_codec *codec)
10870 {
10871         struct alc_spec *spec = codec->spec;
10872         unsigned int mute;
10873
10874         mute = 0;
10875         /* auto-mute only when HP is used as HP */
10876         if (!spec->cur_mux[0]) {
10877                 unsigned int present;
10878                 /* need to execute and sync at first */
10879                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10880                 present = snd_hda_codec_read(codec, 0x15, 0,
10881                                              AC_VERB_GET_PIN_SENSE, 0);
10882                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10883                 if (spec->jack_present)
10884                         mute = HDA_AMP_MUTE;
10885         }
10886         /* mute/unmute internal speaker */
10887         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10888                                  HDA_AMP_MUTE, mute);
10889         /* mute/unmute HP */
10890         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10891                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10892 }
10893
10894 /* unsolicited event for HP jack sensing */
10895 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10896                                        unsigned int res)
10897 {
10898         if ((res >> 26) != ALC880_HP_EVENT)
10899                 return;
10900         alc262_ultra_automute(codec);
10901 }
10902
10903 static struct hda_input_mux alc262_ultra_capture_source = {
10904         .num_items = 2,
10905         .items = {
10906                 { "Mic", 0x1 },
10907                 { "Headphone", 0x7 },
10908         },
10909 };
10910
10911 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10912                                      struct snd_ctl_elem_value *ucontrol)
10913 {
10914         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10915         struct alc_spec *spec = codec->spec;
10916         int ret;
10917
10918         ret = alc_mux_enum_put(kcontrol, ucontrol);
10919         if (!ret)
10920                 return 0;
10921         /* reprogram the HP pin as mic or HP according to the input source */
10922         snd_hda_codec_write_cache(codec, 0x15, 0,
10923                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10924                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10925         alc262_ultra_automute(codec); /* mute/unmute HP */
10926         return ret;
10927 }
10928
10929 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10930         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10931         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10932         {
10933                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10934                 .name = "Capture Source",
10935                 .info = alc_mux_enum_info,
10936                 .get = alc_mux_enum_get,
10937                 .put = alc262_ultra_mux_enum_put,
10938         },
10939         { } /* end */
10940 };
10941
10942 /* We use two mixers depending on the output pin; 0x16 is a mono output
10943  * and thus it's bound with a different mixer.
10944  * This function returns which mixer amp should be used.
10945  */
10946 static int alc262_check_volbit(hda_nid_t nid)
10947 {
10948         if (!nid)
10949                 return 0;
10950         else if (nid == 0x16)
10951                 return 2;
10952         else
10953                 return 1;
10954 }
10955
10956 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10957                                   const char *pfx, int *vbits)
10958 {
10959         unsigned long val;
10960         int vbit;
10961
10962         vbit = alc262_check_volbit(nid);
10963         if (!vbit)
10964                 return 0;
10965         if (*vbits & vbit) /* a volume control for this mixer already there */
10966                 return 0;
10967         *vbits |= vbit;
10968         if (vbit == 2)
10969                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10970         else
10971                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10972         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10973 }
10974
10975 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10976                                  const char *pfx)
10977 {
10978         unsigned long val;
10979
10980         if (!nid)
10981                 return 0;
10982         if (nid == 0x16)
10983                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10984         else
10985                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10986         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10987 }
10988
10989 /* add playback controls from the parsed DAC table */
10990 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10991                                              const struct auto_pin_cfg *cfg)
10992 {
10993         const char *pfx;
10994         int vbits;
10995         int err;
10996
10997         spec->multiout.num_dacs = 1;    /* only use one dac */
10998         spec->multiout.dac_nids = spec->private_dac_nids;
10999         spec->multiout.dac_nids[0] = 2;
11000
11001         if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
11002                 pfx = "Master";
11003         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11004                 pfx = "Speaker";
11005         else
11006                 pfx = "Front";
11007         err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
11008         if (err < 0)
11009                 return err;
11010         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
11011         if (err < 0)
11012                 return err;
11013         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
11014         if (err < 0)
11015                 return err;
11016
11017         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
11018                 alc262_check_volbit(cfg->speaker_pins[0]) |
11019                 alc262_check_volbit(cfg->hp_pins[0]);
11020         if (vbits == 1 || vbits == 2)
11021                 pfx = "Master"; /* only one mixer is used */
11022         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11023                 pfx = "Speaker";
11024         else
11025                 pfx = "Front";
11026         vbits = 0;
11027         err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
11028         if (err < 0)
11029                 return err;
11030         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
11031                                      &vbits);
11032         if (err < 0)
11033                 return err;
11034         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
11035                                      &vbits);
11036         if (err < 0)
11037                 return err;
11038         return 0;
11039 }
11040
11041 #define alc262_auto_create_input_ctls \
11042         alc880_auto_create_input_ctls
11043
11044 /*
11045  * generic initialization of ADC, input mixers and output mixers
11046  */
11047 static struct hda_verb alc262_volume_init_verbs[] = {
11048         /*
11049          * Unmute ADC0-2 and set the default input to mic-in
11050          */
11051         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11052         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11053         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11054         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11055         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11056         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11057
11058         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11059          * mixer widget
11060          * Note: PASD motherboards uses the Line In 2 as the input for
11061          * front panel mic (mic 2)
11062          */
11063         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11064         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11065         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11066         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11067         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11068         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11069
11070         /*
11071          * Set up output mixers (0x0c - 0x0f)
11072          */
11073         /* set vol=0 to output mixers */
11074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11075         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11076         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11077
11078         /* set up input amps for analog loopback */
11079         /* Amp Indices: DAC = 0, mixer = 1 */
11080         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11081         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11082         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11083         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11084         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11085         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11086
11087         /* FIXME: use matrix-type input source selection */
11088         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11089         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11090         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11093         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11094         /* Input mixer2 */
11095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11096         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11098         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11099         /* Input mixer3 */
11100         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11104
11105         { }
11106 };
11107
11108 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11109         /*
11110          * Unmute ADC0-2 and set the default input to mic-in
11111          */
11112         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11113         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11114         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11115         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11116         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11117         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11118
11119         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11120          * mixer widget
11121          * Note: PASD motherboards uses the Line In 2 as the input for
11122          * front panel mic (mic 2)
11123          */
11124         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11125         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11126         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11129         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11130         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11131         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11132
11133         /*
11134          * Set up output mixers (0x0c - 0x0e)
11135          */
11136         /* set vol=0 to output mixers */
11137         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11138         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11139         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11140
11141         /* set up input amps for analog loopback */
11142         /* Amp Indices: DAC = 0, mixer = 1 */
11143         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11144         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11145         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11146         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11147         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11148         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11149
11150         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11151         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11152         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11153
11154         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11155         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11156
11157         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11158         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11159
11160         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11161         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11162         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11163         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11164         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11165
11166         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11167         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11168         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11169         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11170         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11171         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11172
11173
11174         /* FIXME: use matrix-type input source selection */
11175         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11176         /* Input mixer1: only unmute Mic */
11177         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11178         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11179         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11180         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11181         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11182         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11183         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11184         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11185         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11186         /* Input mixer2 */
11187         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11188         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11189         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11193         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11194         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11195         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11196         /* Input mixer3 */
11197         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11199         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11200         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11201         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11205         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11206
11207         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11208
11209         { }
11210 };
11211
11212 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11213         /*
11214          * Unmute ADC0-2 and set the default input to mic-in
11215          */
11216         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11217         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11218         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11219         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11220         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11221         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11222
11223         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11224          * mixer widget
11225          * Note: PASD motherboards uses the Line In 2 as the input for front
11226          * panel mic (mic 2)
11227          */
11228         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11229         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11230         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11237         /*
11238          * Set up output mixers (0x0c - 0x0e)
11239          */
11240         /* set vol=0 to output mixers */
11241         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11242         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11243         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11244
11245         /* set up input amps for analog loopback */
11246         /* Amp Indices: DAC = 0, mixer = 1 */
11247         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11248         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11249         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11250         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11251         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11252         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11253
11254
11255         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11256         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11257         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11258         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11259         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11260         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11261         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11262
11263         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11264         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11265
11266         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11267         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11268
11269         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11270         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11271         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11272         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11273         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11274         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11275
11276         /* FIXME: use matrix-type input source selection */
11277         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11278         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11282         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11283         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11284         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11285         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11286         /* Input mixer2 */
11287         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11288         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11289         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11290         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11291         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11292         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11293         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11294         /* Input mixer3 */
11295         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11296         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11297         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11298         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11299         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11300         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11301         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11302
11303         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11304
11305         { }
11306 };
11307
11308 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11309
11310         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11311         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11312         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11313
11314         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11315         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11316         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11317         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11318
11319         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11320         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11321         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11322         {}
11323 };
11324
11325
11326 #ifdef CONFIG_SND_HDA_POWER_SAVE
11327 #define alc262_loopbacks        alc880_loopbacks
11328 #endif
11329
11330 /* pcm configuration: identical with ALC880 */
11331 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11332 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11333 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11334 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11335
11336 /*
11337  * BIOS auto configuration
11338  */
11339 static int alc262_parse_auto_config(struct hda_codec *codec)
11340 {
11341         struct alc_spec *spec = codec->spec;
11342         int err;
11343         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11344
11345         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11346                                            alc262_ignore);
11347         if (err < 0)
11348                 return err;
11349         if (!spec->autocfg.line_outs) {
11350                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11351                         spec->multiout.max_channels = 2;
11352                         spec->no_analog = 1;
11353                         goto dig_only;
11354                 }
11355                 return 0; /* can't find valid BIOS pin config */
11356         }
11357         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11358         if (err < 0)
11359                 return err;
11360         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11361         if (err < 0)
11362                 return err;
11363
11364         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11365
11366  dig_only:
11367         if (spec->autocfg.dig_outs) {
11368                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11369                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11370         }
11371         if (spec->autocfg.dig_in_pin)
11372                 spec->dig_in_nid = ALC262_DIGIN_NID;
11373
11374         if (spec->kctls.list)
11375                 add_mixer(spec, spec->kctls.list);
11376
11377         add_verb(spec, alc262_volume_init_verbs);
11378         spec->num_mux_defs = 1;
11379         spec->input_mux = &spec->private_imux[0];
11380
11381         err = alc_auto_add_mic_boost(codec);
11382         if (err < 0)
11383                 return err;
11384
11385         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11386
11387         return 1;
11388 }
11389
11390 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11391 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11392 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11393 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11394
11395
11396 /* init callback for auto-configuration model -- overriding the default init */
11397 static void alc262_auto_init(struct hda_codec *codec)
11398 {
11399         struct alc_spec *spec = codec->spec;
11400         alc262_auto_init_multi_out(codec);
11401         alc262_auto_init_hp_out(codec);
11402         alc262_auto_init_analog_input(codec);
11403         alc262_auto_init_input_src(codec);
11404         if (spec->unsol_event)
11405                 alc_inithook(codec);
11406 }
11407
11408 /*
11409  * configuration and preset
11410  */
11411 static const char *alc262_models[ALC262_MODEL_LAST] = {
11412         [ALC262_BASIC]          = "basic",
11413         [ALC262_HIPPO]          = "hippo",
11414         [ALC262_HIPPO_1]        = "hippo_1",
11415         [ALC262_FUJITSU]        = "fujitsu",
11416         [ALC262_HP_BPC]         = "hp-bpc",
11417         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11418         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11419         [ALC262_HP_RP5700]      = "hp-rp5700",
11420         [ALC262_BENQ_ED8]       = "benq",
11421         [ALC262_BENQ_T31]       = "benq-t31",
11422         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11423         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11424         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11425         [ALC262_ULTRA]          = "ultra",
11426         [ALC262_LENOVO_3000]    = "lenovo-3000",
11427         [ALC262_NEC]            = "nec",
11428         [ALC262_TYAN]           = "tyan",
11429         [ALC262_AUTO]           = "auto",
11430 };
11431
11432 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11433         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11434         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11435         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11436                            ALC262_HP_BPC),
11437         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11438                            ALC262_HP_BPC),
11439         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11440                            ALC262_HP_BPC),
11441         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11442         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11443         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11444         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11445         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11446         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11447         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11448         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11449         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11450         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11451         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11452         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11453                       ALC262_HP_TC_T5735),
11454         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11455         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11456         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11457         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11458         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11459         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11460         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11461                            ALC262_SONY_ASSAMD),
11462         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11463                       ALC262_TOSHIBA_RX1),
11464         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11465         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11466         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11467         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11468         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11469                            ALC262_ULTRA),
11470         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11471         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11472         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11473         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11474         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11475         {}
11476 };
11477
11478 static struct alc_config_preset alc262_presets[] = {
11479         [ALC262_BASIC] = {
11480                 .mixers = { alc262_base_mixer },
11481                 .init_verbs = { alc262_init_verbs },
11482                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11483                 .dac_nids = alc262_dac_nids,
11484                 .hp_nid = 0x03,
11485                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11486                 .channel_mode = alc262_modes,
11487                 .input_mux = &alc262_capture_source,
11488         },
11489         [ALC262_HIPPO] = {
11490                 .mixers = { alc262_hippo_mixer },
11491                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11492                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11493                 .dac_nids = alc262_dac_nids,
11494                 .hp_nid = 0x03,
11495                 .dig_out_nid = ALC262_DIGOUT_NID,
11496                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11497                 .channel_mode = alc262_modes,
11498                 .input_mux = &alc262_capture_source,
11499                 .unsol_event = alc262_hippo_unsol_event,
11500                 .setup = alc262_hippo_setup,
11501                 .init_hook = alc262_hippo_automute,
11502         },
11503         [ALC262_HIPPO_1] = {
11504                 .mixers = { alc262_hippo1_mixer },
11505                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11506                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11507                 .dac_nids = alc262_dac_nids,
11508                 .hp_nid = 0x02,
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_hippo1_setup,
11515                 .init_hook = alc262_hippo_automute,
11516         },
11517         [ALC262_FUJITSU] = {
11518                 .mixers = { alc262_fujitsu_mixer },
11519                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11520                                 alc262_fujitsu_unsol_verbs },
11521                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11522                 .dac_nids = alc262_dac_nids,
11523                 .hp_nid = 0x03,
11524                 .dig_out_nid = ALC262_DIGOUT_NID,
11525                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11526                 .channel_mode = alc262_modes,
11527                 .input_mux = &alc262_fujitsu_capture_source,
11528                 .unsol_event = alc262_fujitsu_unsol_event,
11529                 .init_hook = alc262_fujitsu_init_hook,
11530         },
11531         [ALC262_HP_BPC] = {
11532                 .mixers = { alc262_HP_BPC_mixer },
11533                 .init_verbs = { alc262_HP_BPC_init_verbs },
11534                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11535                 .dac_nids = alc262_dac_nids,
11536                 .hp_nid = 0x03,
11537                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11538                 .channel_mode = alc262_modes,
11539                 .input_mux = &alc262_HP_capture_source,
11540                 .unsol_event = alc262_hp_bpc_unsol_event,
11541                 .init_hook = alc262_hp_bpc_automute,
11542         },
11543         [ALC262_HP_BPC_D7000_WF] = {
11544                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11545                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11546                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11547                 .dac_nids = alc262_dac_nids,
11548                 .hp_nid = 0x03,
11549                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11550                 .channel_mode = alc262_modes,
11551                 .input_mux = &alc262_HP_D7000_capture_source,
11552                 .unsol_event = alc262_hp_wildwest_unsol_event,
11553                 .init_hook = alc262_hp_wildwest_automute,
11554         },
11555         [ALC262_HP_BPC_D7000_WL] = {
11556                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11557                             alc262_HP_BPC_WildWest_option_mixer },
11558                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11559                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11560                 .dac_nids = alc262_dac_nids,
11561                 .hp_nid = 0x03,
11562                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11563                 .channel_mode = alc262_modes,
11564                 .input_mux = &alc262_HP_D7000_capture_source,
11565                 .unsol_event = alc262_hp_wildwest_unsol_event,
11566                 .init_hook = alc262_hp_wildwest_automute,
11567         },
11568         [ALC262_HP_TC_T5735] = {
11569                 .mixers = { alc262_hp_t5735_mixer },
11570                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11571                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11572                 .dac_nids = alc262_dac_nids,
11573                 .hp_nid = 0x03,
11574                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11575                 .channel_mode = alc262_modes,
11576                 .input_mux = &alc262_capture_source,
11577                 .unsol_event = alc_automute_amp_unsol_event,
11578                 .setup = alc262_hp_t5735_setup,
11579                 .init_hook = alc_automute_amp,
11580         },
11581         [ALC262_HP_RP5700] = {
11582                 .mixers = { alc262_hp_rp5700_mixer },
11583                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11584                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11585                 .dac_nids = alc262_dac_nids,
11586                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11587                 .channel_mode = alc262_modes,
11588                 .input_mux = &alc262_hp_rp5700_capture_source,
11589         },
11590         [ALC262_BENQ_ED8] = {
11591                 .mixers = { alc262_base_mixer },
11592                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11593                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11594                 .dac_nids = alc262_dac_nids,
11595                 .hp_nid = 0x03,
11596                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11597                 .channel_mode = alc262_modes,
11598                 .input_mux = &alc262_capture_source,
11599         },
11600         [ALC262_SONY_ASSAMD] = {
11601                 .mixers = { alc262_sony_mixer },
11602                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11603                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11604                 .dac_nids = alc262_dac_nids,
11605                 .hp_nid = 0x02,
11606                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11607                 .channel_mode = alc262_modes,
11608                 .input_mux = &alc262_capture_source,
11609                 .unsol_event = alc262_hippo_unsol_event,
11610                 .setup = alc262_hippo_setup,
11611                 .init_hook = alc262_hippo_automute,
11612         },
11613         [ALC262_BENQ_T31] = {
11614                 .mixers = { alc262_benq_t31_mixer },
11615                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
11616                                 alc_hp15_unsol_verbs },
11617                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11618                 .dac_nids = alc262_dac_nids,
11619                 .hp_nid = 0x03,
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_ULTRA] = {
11628                 .mixers = { alc262_ultra_mixer },
11629                 .cap_mixer = alc262_ultra_capture_mixer,
11630                 .init_verbs = { alc262_ultra_verbs },
11631                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11632                 .dac_nids = alc262_dac_nids,
11633                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11634                 .channel_mode = alc262_modes,
11635                 .input_mux = &alc262_ultra_capture_source,
11636                 .adc_nids = alc262_adc_nids, /* ADC0 */
11637                 .capsrc_nids = alc262_capsrc_nids,
11638                 .num_adc_nids = 1, /* single ADC */
11639                 .unsol_event = alc262_ultra_unsol_event,
11640                 .init_hook = alc262_ultra_automute,
11641         },
11642         [ALC262_LENOVO_3000] = {
11643                 .mixers = { alc262_lenovo_3000_mixer },
11644                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11645                                 alc262_lenovo_3000_unsol_verbs },
11646                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11647                 .dac_nids = alc262_dac_nids,
11648                 .hp_nid = 0x03,
11649                 .dig_out_nid = ALC262_DIGOUT_NID,
11650                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11651                 .channel_mode = alc262_modes,
11652                 .input_mux = &alc262_fujitsu_capture_source,
11653                 .unsol_event = alc262_lenovo_3000_unsol_event,
11654         },
11655         [ALC262_NEC] = {
11656                 .mixers = { alc262_nec_mixer },
11657                 .init_verbs = { alc262_nec_verbs },
11658                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11659                 .dac_nids = alc262_dac_nids,
11660                 .hp_nid = 0x03,
11661                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11662                 .channel_mode = alc262_modes,
11663                 .input_mux = &alc262_capture_source,
11664         },
11665         [ALC262_TOSHIBA_S06] = {
11666                 .mixers = { alc262_toshiba_s06_mixer },
11667                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11668                                                         alc262_eapd_verbs },
11669                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11670                 .capsrc_nids = alc262_dmic_capsrc_nids,
11671                 .dac_nids = alc262_dac_nids,
11672                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11673                 .num_adc_nids = 1, /* single ADC */
11674                 .dig_out_nid = ALC262_DIGOUT_NID,
11675                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11676                 .channel_mode = alc262_modes,
11677                 .unsol_event = alc_sku_unsol_event,
11678                 .setup = alc262_toshiba_s06_setup,
11679                 .init_hook = alc_inithook,
11680         },
11681         [ALC262_TOSHIBA_RX1] = {
11682                 .mixers = { alc262_toshiba_rx1_mixer },
11683                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11684                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11685                 .dac_nids = alc262_dac_nids,
11686                 .hp_nid = 0x03,
11687                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11688                 .channel_mode = alc262_modes,
11689                 .input_mux = &alc262_capture_source,
11690                 .unsol_event = alc262_hippo_unsol_event,
11691                 .setup = alc262_hippo_setup,
11692                 .init_hook = alc262_hippo_automute,
11693         },
11694         [ALC262_TYAN] = {
11695                 .mixers = { alc262_tyan_mixer },
11696                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11697                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11698                 .dac_nids = alc262_dac_nids,
11699                 .hp_nid = 0x02,
11700                 .dig_out_nid = ALC262_DIGOUT_NID,
11701                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11702                 .channel_mode = alc262_modes,
11703                 .input_mux = &alc262_capture_source,
11704                 .unsol_event = alc_automute_amp_unsol_event,
11705                 .setup = alc262_tyan_setup,
11706                 .init_hook = alc_automute_amp,
11707         },
11708 };
11709
11710 static int patch_alc262(struct hda_codec *codec)
11711 {
11712         struct alc_spec *spec;
11713         int board_config;
11714         int err;
11715
11716         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11717         if (spec == NULL)
11718                 return -ENOMEM;
11719
11720         codec->spec = spec;
11721 #if 0
11722         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11723          * under-run
11724          */
11725         {
11726         int tmp;
11727         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11728         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11729         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11730         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11731         }
11732 #endif
11733
11734         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11735
11736         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11737                                                   alc262_models,
11738                                                   alc262_cfg_tbl);
11739
11740         if (board_config < 0) {
11741                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11742                        codec->chip_name);
11743                 board_config = ALC262_AUTO;
11744         }
11745
11746         if (board_config == ALC262_AUTO) {
11747                 /* automatic parse from the BIOS config */
11748                 err = alc262_parse_auto_config(codec);
11749                 if (err < 0) {
11750                         alc_free(codec);
11751                         return err;
11752                 } else if (!err) {
11753                         printk(KERN_INFO
11754                                "hda_codec: Cannot set up configuration "
11755                                "from BIOS.  Using base mode...\n");
11756                         board_config = ALC262_BASIC;
11757                 }
11758         }
11759
11760         if (!spec->no_analog) {
11761                 err = snd_hda_attach_beep_device(codec, 0x1);
11762                 if (err < 0) {
11763                         alc_free(codec);
11764                         return err;
11765                 }
11766         }
11767
11768         if (board_config != ALC262_AUTO)
11769                 setup_preset(codec, &alc262_presets[board_config]);
11770
11771         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11772         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11773
11774         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11775         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11776
11777         if (!spec->adc_nids && spec->input_mux) {
11778                 int i;
11779                 /* check whether the digital-mic has to be supported */
11780                 for (i = 0; i < spec->input_mux->num_items; i++) {
11781                         if (spec->input_mux->items[i].index >= 9)
11782                                 break;
11783                 }
11784                 if (i < spec->input_mux->num_items) {
11785                         /* use only ADC0 */
11786                         spec->adc_nids = alc262_dmic_adc_nids;
11787                         spec->num_adc_nids = 1;
11788                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11789                 } else {
11790                         /* all analog inputs */
11791                         /* check whether NID 0x07 is valid */
11792                         unsigned int wcap = get_wcaps(codec, 0x07);
11793
11794                         /* get type */
11795                         wcap = get_wcaps_type(wcap);
11796                         if (wcap != AC_WID_AUD_IN) {
11797                                 spec->adc_nids = alc262_adc_nids_alt;
11798                                 spec->num_adc_nids =
11799                                         ARRAY_SIZE(alc262_adc_nids_alt);
11800                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11801                         } else {
11802                                 spec->adc_nids = alc262_adc_nids;
11803                                 spec->num_adc_nids =
11804                                         ARRAY_SIZE(alc262_adc_nids);
11805                                 spec->capsrc_nids = alc262_capsrc_nids;
11806                         }
11807                 }
11808         }
11809         if (!spec->cap_mixer && !spec->no_analog)
11810                 set_capture_mixer(codec);
11811         if (!spec->no_analog)
11812                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11813
11814         spec->vmaster_nid = 0x0c;
11815
11816         codec->patch_ops = alc_patch_ops;
11817         if (board_config == ALC262_AUTO)
11818                 spec->init_hook = alc262_auto_init;
11819 #ifdef CONFIG_SND_HDA_POWER_SAVE
11820         if (!spec->loopback.amplist)
11821                 spec->loopback.amplist = alc262_loopbacks;
11822 #endif
11823         codec->proc_widget_hook = print_realtek_coef;
11824
11825         return 0;
11826 }
11827
11828 /*
11829  *  ALC268 channel source setting (2 channel)
11830  */
11831 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11832 #define alc268_modes            alc260_modes
11833
11834 static hda_nid_t alc268_dac_nids[2] = {
11835         /* front, hp */
11836         0x02, 0x03
11837 };
11838
11839 static hda_nid_t alc268_adc_nids[2] = {
11840         /* ADC0-1 */
11841         0x08, 0x07
11842 };
11843
11844 static hda_nid_t alc268_adc_nids_alt[1] = {
11845         /* ADC0 */
11846         0x08
11847 };
11848
11849 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11850
11851 static struct snd_kcontrol_new alc268_base_mixer[] = {
11852         /* output mixer control */
11853         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11854         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11855         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11856         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11857         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11858         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11859         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11860         { }
11861 };
11862
11863 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11864         /* output mixer control */
11865         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11866         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11867         ALC262_HIPPO_MASTER_SWITCH,
11868         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11869         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11870         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11871         { }
11872 };
11873
11874 /* bind Beep switches of both NID 0x0f and 0x10 */
11875 static struct hda_bind_ctls alc268_bind_beep_sw = {
11876         .ops = &snd_hda_bind_sw,
11877         .values = {
11878                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11879                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11880                 0
11881         },
11882 };
11883
11884 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11885         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11886         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11887         { }
11888 };
11889
11890 static struct hda_verb alc268_eapd_verbs[] = {
11891         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11892         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11893         { }
11894 };
11895
11896 /* Toshiba specific */
11897 static struct hda_verb alc268_toshiba_verbs[] = {
11898         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11899         { } /* end */
11900 };
11901
11902 /* Acer specific */
11903 /* bind volumes of both NID 0x02 and 0x03 */
11904 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11905         .ops = &snd_hda_bind_vol,
11906         .values = {
11907                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11908                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11909                 0
11910         },
11911 };
11912
11913 /* mute/unmute internal speaker according to the hp jack and mute state */
11914 static void alc268_acer_automute(struct hda_codec *codec, int force)
11915 {
11916         struct alc_spec *spec = codec->spec;
11917         unsigned int mute;
11918
11919         if (force || !spec->sense_updated) {
11920                 unsigned int present;
11921                 present = snd_hda_codec_read(codec, 0x14, 0,
11922                                          AC_VERB_GET_PIN_SENSE, 0);
11923                 spec->jack_present = (present & 0x80000000) != 0;
11924                 spec->sense_updated = 1;
11925         }
11926         if (spec->jack_present)
11927                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11928         else /* unmute internal speaker if necessary */
11929                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11930         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11931                                  HDA_AMP_MUTE, mute);
11932 }
11933
11934
11935 /* bind hp and internal speaker mute (with plug check) */
11936 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11937                                      struct snd_ctl_elem_value *ucontrol)
11938 {
11939         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11940         long *valp = ucontrol->value.integer.value;
11941         int change;
11942
11943         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11944         if (change)
11945                 alc268_acer_automute(codec, 0);
11946         return change;
11947 }
11948
11949 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11950         /* output mixer control */
11951         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11952         {
11953                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11954                 .name = "Master Playback Switch",
11955                 .info = snd_hda_mixer_amp_switch_info,
11956                 .get = snd_hda_mixer_amp_switch_get,
11957                 .put = alc268_acer_master_sw_put,
11958                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11959         },
11960         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11961         { }
11962 };
11963
11964 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11965         /* output mixer control */
11966         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11967         {
11968                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11969                 .name = "Master Playback Switch",
11970                 .info = snd_hda_mixer_amp_switch_info,
11971                 .get = snd_hda_mixer_amp_switch_get,
11972                 .put = alc268_acer_master_sw_put,
11973                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11974         },
11975         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11976         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11977         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11978         { }
11979 };
11980
11981 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11982         /* output mixer control */
11983         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11984         {
11985                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11986                 .name = "Master Playback Switch",
11987                 .info = snd_hda_mixer_amp_switch_info,
11988                 .get = snd_hda_mixer_amp_switch_get,
11989                 .put = alc268_acer_master_sw_put,
11990                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11991         },
11992         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11993         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11994         { }
11995 };
11996
11997 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11998         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11999         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12000         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12001         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12002         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
12003         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
12004         { }
12005 };
12006
12007 static struct hda_verb alc268_acer_verbs[] = {
12008         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
12009         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12010         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12011         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12012         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12013         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12014         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12015         { }
12016 };
12017
12018 /* unsolicited event for HP jack sensing */
12019 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
12020 #define alc268_toshiba_setup            alc262_hippo_setup
12021 #define alc268_toshiba_automute         alc262_hippo_automute
12022
12023 static void alc268_acer_unsol_event(struct hda_codec *codec,
12024                                        unsigned int res)
12025 {
12026         if ((res >> 26) != ALC880_HP_EVENT)
12027                 return;
12028         alc268_acer_automute(codec, 1);
12029 }
12030
12031 static void alc268_acer_init_hook(struct hda_codec *codec)
12032 {
12033         alc268_acer_automute(codec, 1);
12034 }
12035
12036 /* toggle speaker-output according to the hp-jack state */
12037 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12038 {
12039         unsigned int present;
12040         unsigned char bits;
12041
12042         present = snd_hda_codec_read(codec, 0x15, 0,
12043                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12044         bits = present ? AMP_IN_MUTE(0) : 0;
12045         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12046                                 AMP_IN_MUTE(0), bits);
12047         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12048                                 AMP_IN_MUTE(0), bits);
12049 }
12050
12051 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
12052                                     unsigned int res)
12053 {
12054         switch (res >> 26) {
12055         case ALC880_HP_EVENT:
12056                 alc268_aspire_one_speaker_automute(codec);
12057                 break;
12058         case ALC880_MIC_EVENT:
12059                 alc_mic_automute(codec);
12060                 break;
12061         }
12062 }
12063
12064 static void alc268_acer_lc_setup(struct hda_codec *codec)
12065 {
12066         struct alc_spec *spec = codec->spec;
12067         spec->ext_mic.pin = 0x18;
12068         spec->ext_mic.mux_idx = 0;
12069         spec->int_mic.pin = 0x12;
12070         spec->int_mic.mux_idx = 6;
12071         spec->auto_mic = 1;
12072 }
12073
12074 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
12075 {
12076         alc268_aspire_one_speaker_automute(codec);
12077         alc_mic_automute(codec);
12078 }
12079
12080 static struct snd_kcontrol_new alc268_dell_mixer[] = {
12081         /* output mixer control */
12082         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12083         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12084         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12085         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12086         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12087         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12088         { }
12089 };
12090
12091 static struct hda_verb alc268_dell_verbs[] = {
12092         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12093         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12094         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12095         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12096         { }
12097 };
12098
12099 /* mute/unmute internal speaker according to the hp jack and mute state */
12100 static void alc268_dell_setup(struct hda_codec *codec)
12101 {
12102         struct alc_spec *spec = codec->spec;
12103
12104         spec->autocfg.hp_pins[0] = 0x15;
12105         spec->autocfg.speaker_pins[0] = 0x14;
12106         spec->ext_mic.pin = 0x18;
12107         spec->ext_mic.mux_idx = 0;
12108         spec->int_mic.pin = 0x19;
12109         spec->int_mic.mux_idx = 1;
12110         spec->auto_mic = 1;
12111 }
12112
12113 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12114         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12115         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12116         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12117         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12118         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12119         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12120         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12121         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12122         { }
12123 };
12124
12125 static struct hda_verb alc267_quanta_il1_verbs[] = {
12126         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12127         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12128         { }
12129 };
12130
12131 static void alc267_quanta_il1_setup(struct hda_codec *codec)
12132 {
12133         struct alc_spec *spec = codec->spec;
12134         spec->autocfg.hp_pins[0] = 0x15;
12135         spec->autocfg.speaker_pins[0] = 0x14;
12136         spec->ext_mic.pin = 0x18;
12137         spec->ext_mic.mux_idx = 0;
12138         spec->int_mic.pin = 0x19;
12139         spec->int_mic.mux_idx = 1;
12140         spec->auto_mic = 1;
12141 }
12142
12143 /*
12144  * generic initialization of ADC, input mixers and output mixers
12145  */
12146 static struct hda_verb alc268_base_init_verbs[] = {
12147         /* Unmute DAC0-1 and set vol = 0 */
12148         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12149         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12150
12151         /*
12152          * Set up output mixers (0x0c - 0x0e)
12153          */
12154         /* set vol=0 to output mixers */
12155         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12156         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12157
12158         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12159         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12160
12161         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12162         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12163         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12164         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12165         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12166         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12167         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12168         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12169
12170         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12171         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12172         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12173         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12174         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12175
12176         /* set PCBEEP vol = 0, mute connections */
12177         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12178         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12179         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12180
12181         /* Unmute Selector 23h,24h and set the default input to mic-in */
12182
12183         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12184         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12185         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12186         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12187
12188         { }
12189 };
12190
12191 /*
12192  * generic initialization of ADC, input mixers and output mixers
12193  */
12194 static struct hda_verb alc268_volume_init_verbs[] = {
12195         /* set output DAC */
12196         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12197         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12198
12199         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12200         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12201         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12202         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12203         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12204
12205         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12206         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12207         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12208
12209         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12210         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12211
12212         /* set PCBEEP vol = 0, mute connections */
12213         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12214         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12215         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12216
12217         { }
12218 };
12219
12220 static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
12221         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12222         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12223         { } /* end */
12224 };
12225
12226 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12227         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12228         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12229         _DEFINE_CAPSRC(1),
12230         { } /* end */
12231 };
12232
12233 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12234         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12235         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12236         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12237         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12238         _DEFINE_CAPSRC(2),
12239         { } /* end */
12240 };
12241
12242 static struct hda_input_mux alc268_capture_source = {
12243         .num_items = 4,
12244         .items = {
12245                 { "Mic", 0x0 },
12246                 { "Front Mic", 0x1 },
12247                 { "Line", 0x2 },
12248                 { "CD", 0x3 },
12249         },
12250 };
12251
12252 static struct hda_input_mux alc268_acer_capture_source = {
12253         .num_items = 3,
12254         .items = {
12255                 { "Mic", 0x0 },
12256                 { "Internal Mic", 0x1 },
12257                 { "Line", 0x2 },
12258         },
12259 };
12260
12261 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12262         .num_items = 3,
12263         .items = {
12264                 { "Mic", 0x0 },
12265                 { "Internal Mic", 0x6 },
12266                 { "Line", 0x2 },
12267         },
12268 };
12269
12270 #ifdef CONFIG_SND_DEBUG
12271 static struct snd_kcontrol_new alc268_test_mixer[] = {
12272         /* Volume widgets */
12273         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12274         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12275         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12276         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12277         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12278         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12279         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12280         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12281         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12282         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12283         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12284         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12285         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12286         /* The below appears problematic on some hardwares */
12287         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12288         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12289         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12290         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12291         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12292
12293         /* Modes for retasking pin widgets */
12294         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12295         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12296         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12297         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12298
12299         /* Controls for GPIO pins, assuming they are configured as outputs */
12300         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12301         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12302         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12303         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12304
12305         /* Switches to allow the digital SPDIF output pin to be enabled.
12306          * The ALC268 does not have an SPDIF input.
12307          */
12308         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12309
12310         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12311          * this output to turn on an external amplifier.
12312          */
12313         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12314         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12315
12316         { } /* end */
12317 };
12318 #endif
12319
12320 /* create input playback/capture controls for the given pin */
12321 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12322                                     const char *ctlname, int idx)
12323 {
12324         hda_nid_t dac;
12325         int err;
12326
12327         switch (nid) {
12328         case 0x14:
12329         case 0x16:
12330                 dac = 0x02;
12331                 break;
12332         case 0x15:
12333                 dac = 0x03;
12334                 break;
12335         default:
12336                 return 0;
12337         }
12338         if (spec->multiout.dac_nids[0] != dac &&
12339             spec->multiout.dac_nids[1] != dac) {
12340                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12341                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12342                                                       HDA_OUTPUT));
12343                 if (err < 0)
12344                         return err;
12345                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12346         }
12347
12348         if (nid != 0x16)
12349                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12350                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12351         else /* mono */
12352                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12353                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12354         if (err < 0)
12355                 return err;
12356         return 0;
12357 }
12358
12359 /* add playback controls from the parsed DAC table */
12360 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12361                                              const struct auto_pin_cfg *cfg)
12362 {
12363         hda_nid_t nid;
12364         int err;
12365
12366         spec->multiout.dac_nids = spec->private_dac_nids;
12367
12368         nid = cfg->line_out_pins[0];
12369         if (nid) {
12370                 const char *name;
12371                 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12372                         name = "Speaker";
12373                 else
12374                         name = "Front";
12375                 err = alc268_new_analog_output(spec, nid, name, 0);
12376                 if (err < 0)
12377                         return err;
12378         }
12379
12380         nid = cfg->speaker_pins[0];
12381         if (nid == 0x1d) {
12382                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12383                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12384                 if (err < 0)
12385                         return err;
12386         } else {
12387                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12388                 if (err < 0)
12389                         return err;
12390         }
12391         nid = cfg->hp_pins[0];
12392         if (nid) {
12393                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
12394                 if (err < 0)
12395                         return err;
12396         }
12397
12398         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12399         if (nid == 0x16) {
12400                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12401                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12402                 if (err < 0)
12403                         return err;
12404         }
12405         return 0;
12406 }
12407
12408 /* create playback/capture controls for input pins */
12409 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12410                                                 const struct auto_pin_cfg *cfg)
12411 {
12412         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12413 }
12414
12415 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12416                                               hda_nid_t nid, int pin_type)
12417 {
12418         int idx;
12419
12420         alc_set_pin_output(codec, nid, pin_type);
12421         if (nid == 0x14 || nid == 0x16)
12422                 idx = 0;
12423         else
12424                 idx = 1;
12425         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12426 }
12427
12428 static void alc268_auto_init_multi_out(struct hda_codec *codec)
12429 {
12430         struct alc_spec *spec = codec->spec;
12431         hda_nid_t nid = spec->autocfg.line_out_pins[0];
12432         if (nid) {
12433                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12434                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12435         }
12436 }
12437
12438 static void alc268_auto_init_hp_out(struct hda_codec *codec)
12439 {
12440         struct alc_spec *spec = codec->spec;
12441         hda_nid_t pin;
12442
12443         pin = spec->autocfg.hp_pins[0];
12444         if (pin)
12445                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
12446         pin = spec->autocfg.speaker_pins[0];
12447         if (pin)
12448                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
12449 }
12450
12451 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12452 {
12453         struct alc_spec *spec = codec->spec;
12454         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12455         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12456         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12457         unsigned int    dac_vol1, dac_vol2;
12458
12459         if (line_nid == 0x1d || speaker_nid == 0x1d) {
12460                 snd_hda_codec_write(codec, speaker_nid, 0,
12461                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12462                 /* mute mixer inputs from 0x1d */
12463                 snd_hda_codec_write(codec, 0x0f, 0,
12464                                     AC_VERB_SET_AMP_GAIN_MUTE,
12465                                     AMP_IN_UNMUTE(1));
12466                 snd_hda_codec_write(codec, 0x10, 0,
12467                                     AC_VERB_SET_AMP_GAIN_MUTE,
12468                                     AMP_IN_UNMUTE(1));
12469         } else {
12470                 /* unmute mixer inputs from 0x1d */
12471                 snd_hda_codec_write(codec, 0x0f, 0,
12472                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12473                 snd_hda_codec_write(codec, 0x10, 0,
12474                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12475         }
12476
12477         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12478         if (line_nid == 0x14)
12479                 dac_vol2 = AMP_OUT_ZERO;
12480         else if (line_nid == 0x15)
12481                 dac_vol1 = AMP_OUT_ZERO;
12482         if (hp_nid == 0x14)
12483                 dac_vol2 = AMP_OUT_ZERO;
12484         else if (hp_nid == 0x15)
12485                 dac_vol1 = AMP_OUT_ZERO;
12486         if (line_nid != 0x16 || hp_nid != 0x16 ||
12487             spec->autocfg.line_out_pins[1] != 0x16 ||
12488             spec->autocfg.line_out_pins[2] != 0x16)
12489                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12490
12491         snd_hda_codec_write(codec, 0x02, 0,
12492                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12493         snd_hda_codec_write(codec, 0x03, 0,
12494                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12495 }
12496
12497 /* pcm configuration: identical with ALC880 */
12498 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12499 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12500 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12501 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12502
12503 /*
12504  * BIOS auto configuration
12505  */
12506 static int alc268_parse_auto_config(struct hda_codec *codec)
12507 {
12508         struct alc_spec *spec = codec->spec;
12509         int err;
12510         static hda_nid_t alc268_ignore[] = { 0 };
12511
12512         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12513                                            alc268_ignore);
12514         if (err < 0)
12515                 return err;
12516         if (!spec->autocfg.line_outs) {
12517                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12518                         spec->multiout.max_channels = 2;
12519                         spec->no_analog = 1;
12520                         goto dig_only;
12521                 }
12522                 return 0; /* can't find valid BIOS pin config */
12523         }
12524         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12525         if (err < 0)
12526                 return err;
12527         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12528         if (err < 0)
12529                 return err;
12530
12531         spec->multiout.max_channels = 2;
12532
12533  dig_only:
12534         /* digital only support output */
12535         if (spec->autocfg.dig_outs) {
12536                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12537                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12538         }
12539         if (spec->kctls.list)
12540                 add_mixer(spec, spec->kctls.list);
12541
12542         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12543                 add_mixer(spec, alc268_beep_mixer);
12544
12545         add_verb(spec, alc268_volume_init_verbs);
12546         spec->num_mux_defs = 2;
12547         spec->input_mux = &spec->private_imux[0];
12548
12549         err = alc_auto_add_mic_boost(codec);
12550         if (err < 0)
12551                 return err;
12552
12553         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12554
12555         return 1;
12556 }
12557
12558 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12559
12560 /* init callback for auto-configuration model -- overriding the default init */
12561 static void alc268_auto_init(struct hda_codec *codec)
12562 {
12563         struct alc_spec *spec = codec->spec;
12564         alc268_auto_init_multi_out(codec);
12565         alc268_auto_init_hp_out(codec);
12566         alc268_auto_init_mono_speaker_out(codec);
12567         alc268_auto_init_analog_input(codec);
12568         if (spec->unsol_event)
12569                 alc_inithook(codec);
12570 }
12571
12572 /*
12573  * configuration and preset
12574  */
12575 static const char *alc268_models[ALC268_MODEL_LAST] = {
12576         [ALC267_QUANTA_IL1]     = "quanta-il1",
12577         [ALC268_3ST]            = "3stack",
12578         [ALC268_TOSHIBA]        = "toshiba",
12579         [ALC268_ACER]           = "acer",
12580         [ALC268_ACER_DMIC]      = "acer-dmic",
12581         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12582         [ALC268_DELL]           = "dell",
12583         [ALC268_ZEPTO]          = "zepto",
12584 #ifdef CONFIG_SND_DEBUG
12585         [ALC268_TEST]           = "test",
12586 #endif
12587         [ALC268_AUTO]           = "auto",
12588 };
12589
12590 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12591         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12592         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12593         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12594         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12595         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12596         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12597                                                 ALC268_ACER_ASPIRE_ONE),
12598         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12599         SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
12600                         "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
12601         /* almost compatible with toshiba but with optional digital outs;
12602          * auto-probing seems working fine
12603          */
12604         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12605                            ALC268_AUTO),
12606         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12607         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12608         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12609         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12610         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12611         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12612         {}
12613 };
12614
12615 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
12616 static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
12617         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
12618         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
12619         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12620                            ALC268_TOSHIBA),
12621         {}
12622 };
12623
12624 static struct alc_config_preset alc268_presets[] = {
12625         [ALC267_QUANTA_IL1] = {
12626                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12627                             alc268_capture_nosrc_mixer },
12628                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12629                                 alc267_quanta_il1_verbs },
12630                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12631                 .dac_nids = alc268_dac_nids,
12632                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12633                 .adc_nids = alc268_adc_nids_alt,
12634                 .hp_nid = 0x03,
12635                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12636                 .channel_mode = alc268_modes,
12637                 .unsol_event = alc_sku_unsol_event,
12638                 .setup = alc267_quanta_il1_setup,
12639                 .init_hook = alc_inithook,
12640         },
12641         [ALC268_3ST] = {
12642                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12643                             alc268_beep_mixer },
12644                 .init_verbs = { alc268_base_init_verbs },
12645                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12646                 .dac_nids = alc268_dac_nids,
12647                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12648                 .adc_nids = alc268_adc_nids_alt,
12649                 .capsrc_nids = alc268_capsrc_nids,
12650                 .hp_nid = 0x03,
12651                 .dig_out_nid = ALC268_DIGOUT_NID,
12652                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12653                 .channel_mode = alc268_modes,
12654                 .input_mux = &alc268_capture_source,
12655         },
12656         [ALC268_TOSHIBA] = {
12657                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12658                             alc268_beep_mixer },
12659                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12660                                 alc268_toshiba_verbs },
12661                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12662                 .dac_nids = alc268_dac_nids,
12663                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12664                 .adc_nids = alc268_adc_nids_alt,
12665                 .capsrc_nids = alc268_capsrc_nids,
12666                 .hp_nid = 0x03,
12667                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12668                 .channel_mode = alc268_modes,
12669                 .input_mux = &alc268_capture_source,
12670                 .unsol_event = alc268_toshiba_unsol_event,
12671                 .setup = alc268_toshiba_setup,
12672                 .init_hook = alc268_toshiba_automute,
12673         },
12674         [ALC268_ACER] = {
12675                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12676                             alc268_beep_mixer },
12677                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12678                                 alc268_acer_verbs },
12679                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12680                 .dac_nids = alc268_dac_nids,
12681                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12682                 .adc_nids = alc268_adc_nids_alt,
12683                 .capsrc_nids = alc268_capsrc_nids,
12684                 .hp_nid = 0x02,
12685                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12686                 .channel_mode = alc268_modes,
12687                 .input_mux = &alc268_acer_capture_source,
12688                 .unsol_event = alc268_acer_unsol_event,
12689                 .init_hook = alc268_acer_init_hook,
12690         },
12691         [ALC268_ACER_DMIC] = {
12692                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12693                             alc268_beep_mixer },
12694                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12695                                 alc268_acer_verbs },
12696                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12697                 .dac_nids = alc268_dac_nids,
12698                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12699                 .adc_nids = alc268_adc_nids_alt,
12700                 .capsrc_nids = alc268_capsrc_nids,
12701                 .hp_nid = 0x02,
12702                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12703                 .channel_mode = alc268_modes,
12704                 .input_mux = &alc268_acer_dmic_capture_source,
12705                 .unsol_event = alc268_acer_unsol_event,
12706                 .init_hook = alc268_acer_init_hook,
12707         },
12708         [ALC268_ACER_ASPIRE_ONE] = {
12709                 .mixers = { alc268_acer_aspire_one_mixer,
12710                             alc268_beep_mixer,
12711                             alc268_capture_nosrc_mixer },
12712                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12713                                 alc268_acer_aspire_one_verbs },
12714                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12715                 .dac_nids = alc268_dac_nids,
12716                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12717                 .adc_nids = alc268_adc_nids_alt,
12718                 .capsrc_nids = alc268_capsrc_nids,
12719                 .hp_nid = 0x03,
12720                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12721                 .channel_mode = alc268_modes,
12722                 .unsol_event = alc268_acer_lc_unsol_event,
12723                 .setup = alc268_acer_lc_setup,
12724                 .init_hook = alc268_acer_lc_init_hook,
12725         },
12726         [ALC268_DELL] = {
12727                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12728                             alc268_capture_nosrc_mixer },
12729                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12730                                 alc268_dell_verbs },
12731                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12732                 .dac_nids = alc268_dac_nids,
12733                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12734                 .adc_nids = alc268_adc_nids_alt,
12735                 .capsrc_nids = alc268_capsrc_nids,
12736                 .hp_nid = 0x02,
12737                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12738                 .channel_mode = alc268_modes,
12739                 .unsol_event = alc_sku_unsol_event,
12740                 .setup = alc268_dell_setup,
12741                 .init_hook = alc_inithook,
12742         },
12743         [ALC268_ZEPTO] = {
12744                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12745                             alc268_beep_mixer },
12746                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12747                                 alc268_toshiba_verbs },
12748                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12749                 .dac_nids = alc268_dac_nids,
12750                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12751                 .adc_nids = alc268_adc_nids_alt,
12752                 .capsrc_nids = alc268_capsrc_nids,
12753                 .hp_nid = 0x03,
12754                 .dig_out_nid = ALC268_DIGOUT_NID,
12755                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12756                 .channel_mode = alc268_modes,
12757                 .input_mux = &alc268_capture_source,
12758                 .setup = alc268_toshiba_setup,
12759                 .init_hook = alc268_toshiba_automute,
12760         },
12761 #ifdef CONFIG_SND_DEBUG
12762         [ALC268_TEST] = {
12763                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12764                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12765                                 alc268_volume_init_verbs },
12766                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12767                 .dac_nids = alc268_dac_nids,
12768                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12769                 .adc_nids = alc268_adc_nids_alt,
12770                 .capsrc_nids = alc268_capsrc_nids,
12771                 .hp_nid = 0x03,
12772                 .dig_out_nid = ALC268_DIGOUT_NID,
12773                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12774                 .channel_mode = alc268_modes,
12775                 .input_mux = &alc268_capture_source,
12776         },
12777 #endif
12778 };
12779
12780 static int patch_alc268(struct hda_codec *codec)
12781 {
12782         struct alc_spec *spec;
12783         int board_config;
12784         int i, has_beep, err;
12785
12786         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12787         if (spec == NULL)
12788                 return -ENOMEM;
12789
12790         codec->spec = spec;
12791
12792         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12793                                                   alc268_models,
12794                                                   alc268_cfg_tbl);
12795
12796         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12797                 board_config = snd_hda_check_board_codec_sid_config(codec,
12798                         ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12799
12800         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12801                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12802                        codec->chip_name);
12803                 board_config = ALC268_AUTO;
12804         }
12805
12806         if (board_config == ALC268_AUTO) {
12807                 /* automatic parse from the BIOS config */
12808                 err = alc268_parse_auto_config(codec);
12809                 if (err < 0) {
12810                         alc_free(codec);
12811                         return err;
12812                 } else if (!err) {
12813                         printk(KERN_INFO
12814                                "hda_codec: Cannot set up configuration "
12815                                "from BIOS.  Using base mode...\n");
12816                         board_config = ALC268_3ST;
12817                 }
12818         }
12819
12820         if (board_config != ALC268_AUTO)
12821                 setup_preset(codec, &alc268_presets[board_config]);
12822
12823         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12824         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12825         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12826
12827         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12828
12829         has_beep = 0;
12830         for (i = 0; i < spec->num_mixers; i++) {
12831                 if (spec->mixers[i] == alc268_beep_mixer) {
12832                         has_beep = 1;
12833                         break;
12834                 }
12835         }
12836
12837         if (has_beep) {
12838                 err = snd_hda_attach_beep_device(codec, 0x1);
12839                 if (err < 0) {
12840                         alc_free(codec);
12841                         return err;
12842                 }
12843                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12844                         /* override the amp caps for beep generator */
12845                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12846                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12847                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12848                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12849                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12850         }
12851
12852         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12853                 /* check whether NID 0x07 is valid */
12854                 unsigned int wcap = get_wcaps(codec, 0x07);
12855                 int i;
12856
12857                 spec->capsrc_nids = alc268_capsrc_nids;
12858                 /* get type */
12859                 wcap = get_wcaps_type(wcap);
12860                 if (spec->auto_mic ||
12861                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12862                         spec->adc_nids = alc268_adc_nids_alt;
12863                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12864                         if (spec->auto_mic)
12865                                 fixup_automic_adc(codec);
12866                         if (spec->auto_mic || spec->input_mux->num_items == 1)
12867                                 add_mixer(spec, alc268_capture_nosrc_mixer);
12868                         else
12869                                 add_mixer(spec, alc268_capture_alt_mixer);
12870                 } else {
12871                         spec->adc_nids = alc268_adc_nids;
12872                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12873                         add_mixer(spec, alc268_capture_mixer);
12874                 }
12875                 /* set default input source */
12876                 for (i = 0; i < spec->num_adc_nids; i++)
12877                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12878                                 0, AC_VERB_SET_CONNECT_SEL,
12879                                 i < spec->num_mux_defs ?
12880                                 spec->input_mux[i].items[0].index :
12881                                 spec->input_mux->items[0].index);
12882         }
12883
12884         spec->vmaster_nid = 0x02;
12885
12886         codec->patch_ops = alc_patch_ops;
12887         if (board_config == ALC268_AUTO)
12888                 spec->init_hook = alc268_auto_init;
12889
12890         codec->proc_widget_hook = print_realtek_coef;
12891
12892         return 0;
12893 }
12894
12895 /*
12896  *  ALC269 channel source setting (2 channel)
12897  */
12898 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12899
12900 #define alc269_dac_nids         alc260_dac_nids
12901
12902 static hda_nid_t alc269_adc_nids[1] = {
12903         /* ADC1 */
12904         0x08,
12905 };
12906
12907 static hda_nid_t alc269_capsrc_nids[1] = {
12908         0x23,
12909 };
12910
12911 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12912  *       not a mux!
12913  */
12914
12915 #define alc269_modes            alc260_modes
12916 #define alc269_capture_source   alc880_lg_lw_capture_source
12917
12918 static struct snd_kcontrol_new alc269_base_mixer[] = {
12919         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12920         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12921         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12922         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12923         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12924         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12925         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12926         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12927         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12928         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12929         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12930         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12931         { } /* end */
12932 };
12933
12934 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12935         /* output mixer control */
12936         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12937         {
12938                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12939                 .name = "Master Playback Switch",
12940                 .info = snd_hda_mixer_amp_switch_info,
12941                 .get = snd_hda_mixer_amp_switch_get,
12942                 .put = alc268_acer_master_sw_put,
12943                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12944         },
12945         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12946         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12947         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12948         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12949         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12950         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12951         { }
12952 };
12953
12954 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12955         /* output mixer control */
12956         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12957         {
12958                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12959                 .name = "Master Playback Switch",
12960                 .info = snd_hda_mixer_amp_switch_info,
12961                 .get = snd_hda_mixer_amp_switch_get,
12962                 .put = alc268_acer_master_sw_put,
12963                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12964         },
12965         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12966         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12967         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12968         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12969         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12970         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12971         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12972         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12973         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12974         { }
12975 };
12976
12977 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12978         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12979         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12980         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12981         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12982         { } /* end */
12983 };
12984
12985 /* capture mixer elements */
12986 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12987         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12988         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12989         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12990         { } /* end */
12991 };
12992
12993 /* FSC amilo */
12994 #define alc269_fujitsu_mixer    alc269_eeepc_mixer
12995
12996 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12997         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12998         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12999         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13000         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13001         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13002         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13003         { }
13004 };
13005
13006 static struct hda_verb alc269_lifebook_verbs[] = {
13007         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13008         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
13009         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13010         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13011         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13012         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13013         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13014         {0x1a, 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 /* toggle speaker-output according to the hp-jack state */
13021 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13022 {
13023         unsigned int present;
13024         unsigned char bits;
13025
13026         present = snd_hda_codec_read(codec, 0x15, 0,
13027                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13028         bits = present ? AMP_IN_MUTE(0) : 0;
13029         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13030                         AMP_IN_MUTE(0), bits);
13031         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13032                         AMP_IN_MUTE(0), bits);
13033
13034         snd_hda_codec_write(codec, 0x20, 0,
13035                         AC_VERB_SET_COEF_INDEX, 0x0c);
13036         snd_hda_codec_write(codec, 0x20, 0,
13037                         AC_VERB_SET_PROC_COEF, 0x680);
13038
13039         snd_hda_codec_write(codec, 0x20, 0,
13040                         AC_VERB_SET_COEF_INDEX, 0x0c);
13041         snd_hda_codec_write(codec, 0x20, 0,
13042                         AC_VERB_SET_PROC_COEF, 0x480);
13043 }
13044
13045 /* toggle speaker-output according to the hp-jacks state */
13046 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13047 {
13048         unsigned int present;
13049         unsigned char bits;
13050
13051         /* Check laptop headphone socket */
13052         present = snd_hda_codec_read(codec, 0x15, 0,
13053                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13054
13055         /* Check port replicator headphone socket */
13056         present |= snd_hda_codec_read(codec, 0x1a, 0,
13057                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13058
13059         bits = present ? AMP_IN_MUTE(0) : 0;
13060         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13061                         AMP_IN_MUTE(0), bits);
13062         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13063                         AMP_IN_MUTE(0), bits);
13064
13065         snd_hda_codec_write(codec, 0x20, 0,
13066                         AC_VERB_SET_COEF_INDEX, 0x0c);
13067         snd_hda_codec_write(codec, 0x20, 0,
13068                         AC_VERB_SET_PROC_COEF, 0x680);
13069
13070         snd_hda_codec_write(codec, 0x20, 0,
13071                         AC_VERB_SET_COEF_INDEX, 0x0c);
13072         snd_hda_codec_write(codec, 0x20, 0,
13073                         AC_VERB_SET_PROC_COEF, 0x480);
13074 }
13075
13076 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13077 {
13078         unsigned int present_laptop;
13079         unsigned int present_dock;
13080
13081         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13082                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13083
13084         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13085                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13086
13087         /* Laptop mic port overrides dock mic port, design decision */
13088         if (present_dock)
13089                 snd_hda_codec_write(codec, 0x23, 0,
13090                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13091         if (present_laptop)
13092                 snd_hda_codec_write(codec, 0x23, 0,
13093                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13094         if (!present_dock && !present_laptop)
13095                 snd_hda_codec_write(codec, 0x23, 0,
13096                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13097 }
13098
13099 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13100                                     unsigned int res)
13101 {
13102         switch (res >> 26) {
13103         case ALC880_HP_EVENT:
13104                 alc269_quanta_fl1_speaker_automute(codec);
13105                 break;
13106         case ALC880_MIC_EVENT:
13107                 alc_mic_automute(codec);
13108                 break;
13109         }
13110 }
13111
13112 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13113                                         unsigned int res)
13114 {
13115         if ((res >> 26) == ALC880_HP_EVENT)
13116                 alc269_lifebook_speaker_automute(codec);
13117         if ((res >> 26) == ALC880_MIC_EVENT)
13118                 alc269_lifebook_mic_autoswitch(codec);
13119 }
13120
13121 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13122 {
13123         struct alc_spec *spec = codec->spec;
13124         spec->ext_mic.pin = 0x18;
13125         spec->ext_mic.mux_idx = 0;
13126         spec->int_mic.pin = 0x19;
13127         spec->int_mic.mux_idx = 1;
13128         spec->auto_mic = 1;
13129 }
13130
13131 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13132 {
13133         alc269_quanta_fl1_speaker_automute(codec);
13134         alc_mic_automute(codec);
13135 }
13136
13137 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13138 {
13139         alc269_lifebook_speaker_automute(codec);
13140         alc269_lifebook_mic_autoswitch(codec);
13141 }
13142
13143 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13144         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13145         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13146         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13147         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13148         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13149         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13150         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13151         {}
13152 };
13153
13154 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13155         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13156         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13157         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13158         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13159         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13160         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13161         {}
13162 };
13163
13164 /* toggle speaker-output according to the hp-jack state */
13165 static void alc269_speaker_automute(struct hda_codec *codec)
13166 {
13167         unsigned int present;
13168         unsigned char bits;
13169
13170         present = snd_hda_codec_read(codec, 0x15, 0,
13171                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13172         bits = present ? AMP_IN_MUTE(0) : 0;
13173         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13174                                 AMP_IN_MUTE(0), bits);
13175         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13176                                 AMP_IN_MUTE(0), bits);
13177 }
13178
13179 /* unsolicited event for HP jack sensing */
13180 static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13181                                      unsigned int res)
13182 {
13183         switch (res >> 26) {
13184         case ALC880_HP_EVENT:
13185                 alc269_speaker_automute(codec);
13186                 break;
13187         case ALC880_MIC_EVENT:
13188                 alc_mic_automute(codec);
13189                 break;
13190         }
13191 }
13192
13193 static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13194 {
13195         struct alc_spec *spec = codec->spec;
13196         spec->ext_mic.pin = 0x18;
13197         spec->ext_mic.mux_idx = 0;
13198         spec->int_mic.pin = 0x12;
13199         spec->int_mic.mux_idx = 5;
13200         spec->auto_mic = 1;
13201 }
13202
13203 static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13204 {
13205         struct alc_spec *spec = codec->spec;
13206         spec->ext_mic.pin = 0x18;
13207         spec->ext_mic.mux_idx = 0;
13208         spec->int_mic.pin = 0x19;
13209         spec->int_mic.mux_idx = 1;
13210         spec->auto_mic = 1;
13211 }
13212
13213 static void alc269_eeepc_inithook(struct hda_codec *codec)
13214 {
13215         alc269_speaker_automute(codec);
13216         alc_mic_automute(codec);
13217 }
13218
13219 /*
13220  * generic initialization of ADC, input mixers and output mixers
13221  */
13222 static struct hda_verb alc269_init_verbs[] = {
13223         /*
13224          * Unmute ADC0 and set the default input to mic-in
13225          */
13226         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13227
13228         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13229          * analog-loopback mixer widget
13230          * Note: PASD motherboards uses the Line In 2 as the input for
13231          * front panel mic (mic 2)
13232          */
13233         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13238         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13239
13240         /*
13241          * Set up output mixers (0x0c - 0x0e)
13242          */
13243         /* set vol=0 to output mixers */
13244         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13245         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13246
13247         /* set up input amps for analog loopback */
13248         /* Amp Indices: DAC = 0, mixer = 1 */
13249         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13250         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13251         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13252         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13253         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13254         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13255
13256         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13257         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13258         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13259         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13260         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13261         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13262         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13263
13264         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13265         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13266         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13267         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13268         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13269         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13270         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13271
13272         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13273         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13274
13275         /* FIXME: use matrix-type input source selection */
13276         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13277         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13282
13283         /* set EAPD */
13284         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13285         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13286         { }
13287 };
13288
13289 #define alc269_auto_create_multi_out_ctls \
13290         alc268_auto_create_multi_out_ctls
13291 #define alc269_auto_create_input_ctls \
13292         alc268_auto_create_input_ctls
13293
13294 #ifdef CONFIG_SND_HDA_POWER_SAVE
13295 #define alc269_loopbacks        alc880_loopbacks
13296 #endif
13297
13298 /* pcm configuration: identical with ALC880 */
13299 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13300 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13301 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13302 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13303
13304 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13305         .substreams = 1,
13306         .channels_min = 2,
13307         .channels_max = 8,
13308         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13309         /* NID is set in alc_build_pcms */
13310         .ops = {
13311                 .open = alc880_playback_pcm_open,
13312                 .prepare = alc880_playback_pcm_prepare,
13313                 .cleanup = alc880_playback_pcm_cleanup
13314         },
13315 };
13316
13317 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13318         .substreams = 1,
13319         .channels_min = 2,
13320         .channels_max = 2,
13321         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13322         /* NID is set in alc_build_pcms */
13323 };
13324
13325 /*
13326  * BIOS auto configuration
13327  */
13328 static int alc269_parse_auto_config(struct hda_codec *codec)
13329 {
13330         struct alc_spec *spec = codec->spec;
13331         int err;
13332         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13333
13334         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13335                                            alc269_ignore);
13336         if (err < 0)
13337                 return err;
13338
13339         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13340         if (err < 0)
13341                 return err;
13342         err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13343         if (err < 0)
13344                 return err;
13345
13346         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13347
13348         if (spec->autocfg.dig_outs)
13349                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13350
13351         if (spec->kctls.list)
13352                 add_mixer(spec, spec->kctls.list);
13353
13354         add_verb(spec, alc269_init_verbs);
13355         spec->num_mux_defs = 1;
13356         spec->input_mux = &spec->private_imux[0];
13357         /* set default input source */
13358         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13359                                   0, AC_VERB_SET_CONNECT_SEL,
13360                                   spec->input_mux->items[0].index);
13361
13362         err = alc_auto_add_mic_boost(codec);
13363         if (err < 0)
13364                 return err;
13365
13366         if (!spec->cap_mixer && !spec->no_analog)
13367                 set_capture_mixer(codec);
13368
13369         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13370
13371         return 1;
13372 }
13373
13374 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
13375 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
13376 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13377
13378
13379 /* init callback for auto-configuration model -- overriding the default init */
13380 static void alc269_auto_init(struct hda_codec *codec)
13381 {
13382         struct alc_spec *spec = codec->spec;
13383         alc269_auto_init_multi_out(codec);
13384         alc269_auto_init_hp_out(codec);
13385         alc269_auto_init_analog_input(codec);
13386         if (spec->unsol_event)
13387                 alc_inithook(codec);
13388 }
13389
13390 /*
13391  * configuration and preset
13392  */
13393 static const char *alc269_models[ALC269_MODEL_LAST] = {
13394         [ALC269_BASIC]                  = "basic",
13395         [ALC269_QUANTA_FL1]             = "quanta",
13396         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13397         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13398         [ALC269_FUJITSU]                = "fujitsu",
13399         [ALC269_LIFEBOOK]               = "lifebook",
13400         [ALC269_AUTO]                   = "auto",
13401 };
13402
13403 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13404         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13405         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13406                       ALC269_ASUS_EEEPC_P703),
13407         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13408         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13409         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13410         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13411         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13412         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13413         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13414                       ALC269_ASUS_EEEPC_P901),
13415         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13416                       ALC269_ASUS_EEEPC_P901),
13417         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13418         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13419         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13420         {}
13421 };
13422
13423 static struct alc_config_preset alc269_presets[] = {
13424         [ALC269_BASIC] = {
13425                 .mixers = { alc269_base_mixer },
13426                 .init_verbs = { alc269_init_verbs },
13427                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13428                 .dac_nids = alc269_dac_nids,
13429                 .hp_nid = 0x03,
13430                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13431                 .channel_mode = alc269_modes,
13432                 .input_mux = &alc269_capture_source,
13433         },
13434         [ALC269_QUANTA_FL1] = {
13435                 .mixers = { alc269_quanta_fl1_mixer },
13436                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13437                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13438                 .dac_nids = alc269_dac_nids,
13439                 .hp_nid = 0x03,
13440                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13441                 .channel_mode = alc269_modes,
13442                 .input_mux = &alc269_capture_source,
13443                 .unsol_event = alc269_quanta_fl1_unsol_event,
13444                 .setup = alc269_quanta_fl1_setup,
13445                 .init_hook = alc269_quanta_fl1_init_hook,
13446         },
13447         [ALC269_ASUS_EEEPC_P703] = {
13448                 .mixers = { alc269_eeepc_mixer },
13449                 .cap_mixer = alc269_epc_capture_mixer,
13450                 .init_verbs = { alc269_init_verbs,
13451                                 alc269_eeepc_amic_init_verbs },
13452                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13453                 .dac_nids = alc269_dac_nids,
13454                 .hp_nid = 0x03,
13455                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13456                 .channel_mode = alc269_modes,
13457                 .unsol_event = alc269_eeepc_unsol_event,
13458                 .setup = alc269_eeepc_amic_setup,
13459                 .init_hook = alc269_eeepc_inithook,
13460         },
13461         [ALC269_ASUS_EEEPC_P901] = {
13462                 .mixers = { alc269_eeepc_mixer },
13463                 .cap_mixer = alc269_epc_capture_mixer,
13464                 .init_verbs = { alc269_init_verbs,
13465                                 alc269_eeepc_dmic_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_dmic_setup,
13473                 .init_hook = alc269_eeepc_inithook,
13474         },
13475         [ALC269_FUJITSU] = {
13476                 .mixers = { alc269_fujitsu_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_LIFEBOOK] = {
13490                 .mixers = { alc269_lifebook_mixer },
13491                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13492                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13493                 .dac_nids = alc269_dac_nids,
13494                 .hp_nid = 0x03,
13495                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13496                 .channel_mode = alc269_modes,
13497                 .input_mux = &alc269_capture_source,
13498                 .unsol_event = alc269_lifebook_unsol_event,
13499                 .init_hook = alc269_lifebook_init_hook,
13500         },
13501 };
13502
13503 static int patch_alc269(struct hda_codec *codec)
13504 {
13505         struct alc_spec *spec;
13506         int board_config;
13507         int err;
13508
13509         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13510         if (spec == NULL)
13511                 return -ENOMEM;
13512
13513         codec->spec = spec;
13514
13515         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13516
13517         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13518                                                   alc269_models,
13519                                                   alc269_cfg_tbl);
13520
13521         if (board_config < 0) {
13522                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13523                        codec->chip_name);
13524                 board_config = ALC269_AUTO;
13525         }
13526
13527         if (board_config == ALC269_AUTO) {
13528                 /* automatic parse from the BIOS config */
13529                 err = alc269_parse_auto_config(codec);
13530                 if (err < 0) {
13531                         alc_free(codec);
13532                         return err;
13533                 } else if (!err) {
13534                         printk(KERN_INFO
13535                                "hda_codec: Cannot set up configuration "
13536                                "from BIOS.  Using base mode...\n");
13537                         board_config = ALC269_BASIC;
13538                 }
13539         }
13540
13541         err = snd_hda_attach_beep_device(codec, 0x1);
13542         if (err < 0) {
13543                 alc_free(codec);
13544                 return err;
13545         }
13546
13547         if (board_config != ALC269_AUTO)
13548                 setup_preset(codec, &alc269_presets[board_config]);
13549
13550         if (codec->subsystem_id == 0x17aa3bf8) {
13551                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13552                  * fix the sample rate of analog I/O to 44.1kHz
13553                  */
13554                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13555                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13556         } else {
13557                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13558                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13559         }
13560         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13561         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13562
13563         spec->adc_nids = alc269_adc_nids;
13564         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13565         spec->capsrc_nids = alc269_capsrc_nids;
13566         if (!spec->cap_mixer)
13567                 set_capture_mixer(codec);
13568         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13569
13570         spec->vmaster_nid = 0x02;
13571
13572         codec->patch_ops = alc_patch_ops;
13573         if (board_config == ALC269_AUTO)
13574                 spec->init_hook = alc269_auto_init;
13575 #ifdef CONFIG_SND_HDA_POWER_SAVE
13576         if (!spec->loopback.amplist)
13577                 spec->loopback.amplist = alc269_loopbacks;
13578 #endif
13579         codec->proc_widget_hook = print_realtek_coef;
13580
13581         return 0;
13582 }
13583
13584 /*
13585  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13586  */
13587
13588 /*
13589  * set the path ways for 2 channel output
13590  * need to set the codec line out and mic 1 pin widgets to inputs
13591  */
13592 static struct hda_verb alc861_threestack_ch2_init[] = {
13593         /* set pin widget 1Ah (line in) for input */
13594         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13595         /* set pin widget 18h (mic1/2) for input, for mic also enable
13596          * the vref
13597          */
13598         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13599
13600         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13601 #if 0
13602         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13603         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13604 #endif
13605         { } /* end */
13606 };
13607 /*
13608  * 6ch mode
13609  * need to set the codec line out and mic 1 pin widgets to outputs
13610  */
13611 static struct hda_verb alc861_threestack_ch6_init[] = {
13612         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13613         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13614         /* set pin widget 18h (mic1) for output (CLFE)*/
13615         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13616
13617         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13618         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13619
13620         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13621 #if 0
13622         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13623         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13624 #endif
13625         { } /* end */
13626 };
13627
13628 static struct hda_channel_mode alc861_threestack_modes[2] = {
13629         { 2, alc861_threestack_ch2_init },
13630         { 6, alc861_threestack_ch6_init },
13631 };
13632 /* Set mic1 as input and unmute the mixer */
13633 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13634         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13635         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13636         { } /* end */
13637 };
13638 /* Set mic1 as output and mute mixer */
13639 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13640         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13641         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13642         { } /* end */
13643 };
13644
13645 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13646         { 2, alc861_uniwill_m31_ch2_init },
13647         { 4, alc861_uniwill_m31_ch4_init },
13648 };
13649
13650 /* Set mic1 and line-in as input and unmute the mixer */
13651 static struct hda_verb alc861_asus_ch2_init[] = {
13652         /* set pin widget 1Ah (line in) for input */
13653         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13654         /* set pin widget 18h (mic1/2) for input, for mic also enable
13655          * the vref
13656          */
13657         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13658
13659         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13660 #if 0
13661         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13662         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13663 #endif
13664         { } /* end */
13665 };
13666 /* Set mic1 nad line-in as output and mute mixer */
13667 static struct hda_verb alc861_asus_ch6_init[] = {
13668         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13669         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13670         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13671         /* set pin widget 18h (mic1) for output (CLFE)*/
13672         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13673         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13674         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13675         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13676
13677         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13678 #if 0
13679         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13680         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13681 #endif
13682         { } /* end */
13683 };
13684
13685 static struct hda_channel_mode alc861_asus_modes[2] = {
13686         { 2, alc861_asus_ch2_init },
13687         { 6, alc861_asus_ch6_init },
13688 };
13689
13690 /* patch-ALC861 */
13691
13692 static struct snd_kcontrol_new alc861_base_mixer[] = {
13693         /* output mixer control */
13694         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13695         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13696         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13697         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13698         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13699
13700         /*Input mixer control */
13701         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13702            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13703         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13704         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13705         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13706         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13707         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13708         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13709         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13710         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13711
13712         { } /* end */
13713 };
13714
13715 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13716         /* output mixer control */
13717         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13718         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13719         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13720         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13721         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13722
13723         /* Input mixer control */
13724         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13725            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13726         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13727         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13728         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13729         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13730         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13731         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13732         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13733         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13734
13735         {
13736                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13737                 .name = "Channel Mode",
13738                 .info = alc_ch_mode_info,
13739                 .get = alc_ch_mode_get,
13740                 .put = alc_ch_mode_put,
13741                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13742         },
13743         { } /* end */
13744 };
13745
13746 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13747         /* output mixer control */
13748         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13749         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13750         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13751
13752         { } /* end */
13753 };
13754
13755 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13756         /* output mixer control */
13757         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13758         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13759         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13760         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13761         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13762
13763         /* Input mixer control */
13764         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13765            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13766         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13767         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13768         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13769         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13770         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13771         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13772         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13773         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13774
13775         {
13776                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13777                 .name = "Channel Mode",
13778                 .info = alc_ch_mode_info,
13779                 .get = alc_ch_mode_get,
13780                 .put = alc_ch_mode_put,
13781                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13782         },
13783         { } /* end */
13784 };
13785
13786 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13787         /* output mixer control */
13788         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13789         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13790         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13791         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13792         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13793
13794         /* Input mixer control */
13795         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13796         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13797         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13798         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13799         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13800         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13801         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13802         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13803         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13804         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13805
13806         {
13807                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13808                 .name = "Channel Mode",
13809                 .info = alc_ch_mode_info,
13810                 .get = alc_ch_mode_get,
13811                 .put = alc_ch_mode_put,
13812                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13813         },
13814         { }
13815 };
13816
13817 /* additional mixer */
13818 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13819         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13820         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13821         { }
13822 };
13823
13824 /*
13825  * generic initialization of ADC, input mixers and output mixers
13826  */
13827 static struct hda_verb alc861_base_init_verbs[] = {
13828         /*
13829          * Unmute ADC0 and set the default input to mic-in
13830          */
13831         /* port-A for surround (rear panel) */
13832         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13833         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13834         /* port-B for mic-in (rear panel) with vref */
13835         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13836         /* port-C for line-in (rear panel) */
13837         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13838         /* port-D for Front */
13839         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13840         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13841         /* port-E for HP out (front panel) */
13842         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13843         /* route front PCM to HP */
13844         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13845         /* port-F for mic-in (front panel) with vref */
13846         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13847         /* port-G for CLFE (rear panel) */
13848         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13849         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13850         /* port-H for side (rear panel) */
13851         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13852         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13853         /* CD-in */
13854         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13855         /* route front mic to ADC1*/
13856         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13857         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13858
13859         /* Unmute DAC0~3 & spdif out*/
13860         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13861         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13862         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13863         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13864         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13865
13866         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13867         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13868         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13869         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13870         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13871
13872         /* Unmute Stereo Mixer 15 */
13873         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13874         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13875         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13876         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13877
13878         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13879         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13880         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13881         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13882         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13883         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13884         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13885         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13886         /* hp used DAC 3 (Front) */
13887         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13888         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13889
13890         { }
13891 };
13892
13893 static struct hda_verb alc861_threestack_init_verbs[] = {
13894         /*
13895          * Unmute ADC0 and set the default input to mic-in
13896          */
13897         /* port-A for surround (rear panel) */
13898         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13899         /* port-B for mic-in (rear panel) with vref */
13900         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13901         /* port-C for line-in (rear panel) */
13902         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13903         /* port-D for Front */
13904         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13905         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13906         /* port-E for HP out (front panel) */
13907         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13908         /* route front PCM to HP */
13909         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13910         /* port-F for mic-in (front panel) with vref */
13911         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13912         /* port-G for CLFE (rear panel) */
13913         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13914         /* port-H for side (rear panel) */
13915         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13916         /* CD-in */
13917         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13918         /* route front mic to ADC1*/
13919         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13920         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13921         /* Unmute DAC0~3 & spdif out*/
13922         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13923         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13924         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13925         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13926         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13927
13928         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13929         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13930         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13931         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13932         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13933
13934         /* Unmute Stereo Mixer 15 */
13935         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13936         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13937         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13938         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13939
13940         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13941         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13942         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13943         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13944         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13945         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13946         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13947         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13948         /* hp used DAC 3 (Front) */
13949         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13950         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13951         { }
13952 };
13953
13954 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13955         /*
13956          * Unmute ADC0 and set the default input to mic-in
13957          */
13958         /* port-A for surround (rear panel) */
13959         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13960         /* port-B for mic-in (rear panel) with vref */
13961         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13962         /* port-C for line-in (rear panel) */
13963         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13964         /* port-D for Front */
13965         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13966         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13967         /* port-E for HP out (front panel) */
13968         /* this has to be set to VREF80 */
13969         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13970         /* route front PCM to HP */
13971         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13972         /* port-F for mic-in (front panel) with vref */
13973         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13974         /* port-G for CLFE (rear panel) */
13975         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13976         /* port-H for side (rear panel) */
13977         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13978         /* CD-in */
13979         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13980         /* route front mic to ADC1*/
13981         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13982         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13983         /* Unmute DAC0~3 & spdif out*/
13984         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13985         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13986         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13987         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13988         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13989
13990         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13991         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13992         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13993         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13994         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13995
13996         /* Unmute Stereo Mixer 15 */
13997         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13998         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13999         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14001
14002         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14003         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14004         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14005         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14006         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14007         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14008         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14009         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14010         /* hp used DAC 3 (Front) */
14011         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14012         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14013         { }
14014 };
14015
14016 static struct hda_verb alc861_asus_init_verbs[] = {
14017         /*
14018          * Unmute ADC0 and set the default input to mic-in
14019          */
14020         /* port-A for surround (rear panel)
14021          * according to codec#0 this is the HP jack
14022          */
14023         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14024         /* route front PCM to HP */
14025         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14026         /* port-B for mic-in (rear panel) with vref */
14027         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14028         /* port-C for line-in (rear panel) */
14029         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14030         /* port-D for Front */
14031         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14032         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14033         /* port-E for HP out (front panel) */
14034         /* this has to be set to VREF80 */
14035         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14036         /* route front PCM to HP */
14037         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14038         /* port-F for mic-in (front panel) with vref */
14039         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14040         /* port-G for CLFE (rear panel) */
14041         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14042         /* port-H for side (rear panel) */
14043         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14044         /* CD-in */
14045         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14046         /* route front mic to ADC1*/
14047         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14048         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14049         /* Unmute DAC0~3 & spdif out*/
14050         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14051         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14052         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14053         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14054         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14055         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14056         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14057         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14058         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14059         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14060
14061         /* Unmute Stereo Mixer 15 */
14062         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14063         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14064         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14066
14067         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14068         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14069         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14070         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14071         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14072         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14073         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14074         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14075         /* hp used DAC 3 (Front) */
14076         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14077         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14078         { }
14079 };
14080
14081 /* additional init verbs for ASUS laptops */
14082 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14083         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14084         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14085         { }
14086 };
14087
14088 /*
14089  * generic initialization of ADC, input mixers and output mixers
14090  */
14091 static struct hda_verb alc861_auto_init_verbs[] = {
14092         /*
14093          * Unmute ADC0 and set the default input to mic-in
14094          */
14095         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14096         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14097
14098         /* Unmute DAC0~3 & spdif out*/
14099         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14100         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14101         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14102         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14103         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14104
14105         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14106         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14107         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14108         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14109         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14110
14111         /* Unmute Stereo Mixer 15 */
14112         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14113         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14114         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14115         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14116
14117         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14118         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14119         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14120         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14121         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14122         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14123         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14124         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14125
14126         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14127         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14128         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14130         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14131         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14132         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14133         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14134
14135         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14136
14137         { }
14138 };
14139
14140 static struct hda_verb alc861_toshiba_init_verbs[] = {
14141         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14142
14143         { }
14144 };
14145
14146 /* toggle speaker-output according to the hp-jack state */
14147 static void alc861_toshiba_automute(struct hda_codec *codec)
14148 {
14149         unsigned int present;
14150
14151         present = snd_hda_codec_read(codec, 0x0f, 0,
14152                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14153         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14154                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14155         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14156                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14157 }
14158
14159 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14160                                        unsigned int res)
14161 {
14162         if ((res >> 26) == ALC880_HP_EVENT)
14163                 alc861_toshiba_automute(codec);
14164 }
14165
14166 /* pcm configuration: identical with ALC880 */
14167 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14168 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14169 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14170 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14171
14172
14173 #define ALC861_DIGOUT_NID       0x07
14174
14175 static struct hda_channel_mode alc861_8ch_modes[1] = {
14176         { 8, NULL }
14177 };
14178
14179 static hda_nid_t alc861_dac_nids[4] = {
14180         /* front, surround, clfe, side */
14181         0x03, 0x06, 0x05, 0x04
14182 };
14183
14184 static hda_nid_t alc660_dac_nids[3] = {
14185         /* front, clfe, surround */
14186         0x03, 0x05, 0x06
14187 };
14188
14189 static hda_nid_t alc861_adc_nids[1] = {
14190         /* ADC0-2 */
14191         0x08,
14192 };
14193
14194 static struct hda_input_mux alc861_capture_source = {
14195         .num_items = 5,
14196         .items = {
14197                 { "Mic", 0x0 },
14198                 { "Front Mic", 0x3 },
14199                 { "Line", 0x1 },
14200                 { "CD", 0x4 },
14201                 { "Mixer", 0x5 },
14202         },
14203 };
14204
14205 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
14206 {
14207         struct alc_spec *spec = codec->spec;
14208         hda_nid_t mix, srcs[5];
14209         int i, j, num;
14210
14211         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
14212                 return 0;
14213         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14214         if (num < 0)
14215                 return 0;
14216         for (i = 0; i < num; i++) {
14217                 unsigned int type;
14218                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14219                 if (type != AC_WID_AUD_OUT)
14220                         continue;
14221                 for (j = 0; j < spec->multiout.num_dacs; j++)
14222                         if (spec->multiout.dac_nids[j] == srcs[i])
14223                                 break;
14224                 if (j >= spec->multiout.num_dacs)
14225                         return srcs[i];
14226         }
14227         return 0;
14228 }
14229
14230 /* fill in the dac_nids table from the parsed pin configuration */
14231 static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14232                                      const struct auto_pin_cfg *cfg)
14233 {
14234         struct alc_spec *spec = codec->spec;
14235         int i;
14236         hda_nid_t nid, dac;
14237
14238         spec->multiout.dac_nids = spec->private_dac_nids;
14239         for (i = 0; i < cfg->line_outs; i++) {
14240                 nid = cfg->line_out_pins[i];
14241                 dac = alc861_look_for_dac(codec, nid);
14242                 if (!dac)
14243                         continue;
14244                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14245         }
14246         return 0;
14247 }
14248
14249 static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14250                                 hda_nid_t nid, unsigned int chs)
14251 {
14252         return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14253                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14254 }
14255
14256 /* add playback controls from the parsed DAC table */
14257 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14258                                              const struct auto_pin_cfg *cfg)
14259 {
14260         struct alc_spec *spec = codec->spec;
14261         static const char *chname[4] = {
14262                 "Front", "Surround", NULL /*CLFE*/, "Side"
14263         };
14264         hda_nid_t nid;
14265         int i, err;
14266
14267         if (cfg->line_outs == 1) {
14268                 const char *pfx = NULL;
14269                 if (!cfg->hp_outs)
14270                         pfx = "Master";
14271                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
14272                         pfx = "Speaker";
14273                 if (pfx) {
14274                         nid = spec->multiout.dac_nids[0];
14275                         return alc861_create_out_sw(codec, pfx, nid, 3);
14276                 }
14277         }
14278
14279         for (i = 0; i < cfg->line_outs; i++) {
14280                 nid = spec->multiout.dac_nids[i];
14281                 if (!nid)
14282                         continue;
14283                 if (i == 2) {
14284                         /* Center/LFE */
14285                         err = alc861_create_out_sw(codec, "Center", nid, 1);
14286                         if (err < 0)
14287                                 return err;
14288                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
14289                         if (err < 0)
14290                                 return err;
14291                 } else {
14292                         err = alc861_create_out_sw(codec, chname[i], nid, 3);
14293                         if (err < 0)
14294                                 return err;
14295                 }
14296         }
14297         return 0;
14298 }
14299
14300 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14301 {
14302         struct alc_spec *spec = codec->spec;
14303         int err;
14304         hda_nid_t nid;
14305
14306         if (!pin)
14307                 return 0;
14308
14309         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14310                 nid = alc861_look_for_dac(codec, pin);
14311                 if (nid) {
14312                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14313                         if (err < 0)
14314                                 return err;
14315                         spec->multiout.hp_nid = nid;
14316                 }
14317         }
14318         return 0;
14319 }
14320
14321 /* create playback/capture controls for input pins */
14322 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14323                                                 const struct auto_pin_cfg *cfg)
14324 {
14325         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14326 }
14327
14328 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14329                                               hda_nid_t nid,
14330                                               int pin_type, hda_nid_t dac)
14331 {
14332         hda_nid_t mix, srcs[5];
14333         int i, num;
14334
14335         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14336                             pin_type);
14337         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14338                             AMP_OUT_UNMUTE);
14339         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
14340                 return;
14341         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14342         if (num < 0)
14343                 return;
14344         for (i = 0; i < num; i++) {
14345                 unsigned int mute;
14346                 if (srcs[i] == dac || srcs[i] == 0x15)
14347                         mute = AMP_IN_UNMUTE(i);
14348                 else
14349                         mute = AMP_IN_MUTE(i);
14350                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14351                                     mute);
14352         }
14353 }
14354
14355 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14356 {
14357         struct alc_spec *spec = codec->spec;
14358         int i;
14359
14360         for (i = 0; i < spec->autocfg.line_outs; i++) {
14361                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14362                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14363                 if (nid)
14364                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14365                                                           spec->multiout.dac_nids[i]);
14366         }
14367 }
14368
14369 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14370 {
14371         struct alc_spec *spec = codec->spec;
14372
14373         if (spec->autocfg.hp_outs)
14374                 alc861_auto_set_output_and_unmute(codec,
14375                                                   spec->autocfg.hp_pins[0],
14376                                                   PIN_HP,
14377                                                   spec->multiout.hp_nid);
14378         if (spec->autocfg.speaker_outs)
14379                 alc861_auto_set_output_and_unmute(codec,
14380                                                   spec->autocfg.speaker_pins[0],
14381                                                   PIN_OUT,
14382                                                   spec->multiout.dac_nids[0]);
14383 }
14384
14385 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14386 {
14387         struct alc_spec *spec = codec->spec;
14388         int i;
14389
14390         for (i = 0; i < AUTO_PIN_LAST; i++) {
14391                 hda_nid_t nid = spec->autocfg.input_pins[i];
14392                 if (nid >= 0x0c && nid <= 0x11)
14393                         alc_set_input_pin(codec, nid, i);
14394         }
14395 }
14396
14397 /* parse the BIOS configuration and set up the alc_spec */
14398 /* return 1 if successful, 0 if the proper config is not found,
14399  * or a negative error code
14400  */
14401 static int alc861_parse_auto_config(struct hda_codec *codec)
14402 {
14403         struct alc_spec *spec = codec->spec;
14404         int err;
14405         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14406
14407         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14408                                            alc861_ignore);
14409         if (err < 0)
14410                 return err;
14411         if (!spec->autocfg.line_outs)
14412                 return 0; /* can't find valid BIOS pin config */
14413
14414         err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14415         if (err < 0)
14416                 return err;
14417         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14418         if (err < 0)
14419                 return err;
14420         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
14421         if (err < 0)
14422                 return err;
14423         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14424         if (err < 0)
14425                 return err;
14426
14427         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14428
14429         if (spec->autocfg.dig_outs)
14430                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14431
14432         if (spec->kctls.list)
14433                 add_mixer(spec, spec->kctls.list);
14434
14435         add_verb(spec, alc861_auto_init_verbs);
14436
14437         spec->num_mux_defs = 1;
14438         spec->input_mux = &spec->private_imux[0];
14439
14440         spec->adc_nids = alc861_adc_nids;
14441         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14442         set_capture_mixer(codec);
14443
14444         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14445
14446         return 1;
14447 }
14448
14449 /* additional initialization for auto-configuration model */
14450 static void alc861_auto_init(struct hda_codec *codec)
14451 {
14452         struct alc_spec *spec = codec->spec;
14453         alc861_auto_init_multi_out(codec);
14454         alc861_auto_init_hp_out(codec);
14455         alc861_auto_init_analog_input(codec);
14456         if (spec->unsol_event)
14457                 alc_inithook(codec);
14458 }
14459
14460 #ifdef CONFIG_SND_HDA_POWER_SAVE
14461 static struct hda_amp_list alc861_loopbacks[] = {
14462         { 0x15, HDA_INPUT, 0 },
14463         { 0x15, HDA_INPUT, 1 },
14464         { 0x15, HDA_INPUT, 2 },
14465         { 0x15, HDA_INPUT, 3 },
14466         { } /* end */
14467 };
14468 #endif
14469
14470
14471 /*
14472  * configuration and preset
14473  */
14474 static const char *alc861_models[ALC861_MODEL_LAST] = {
14475         [ALC861_3ST]            = "3stack",
14476         [ALC660_3ST]            = "3stack-660",
14477         [ALC861_3ST_DIG]        = "3stack-dig",
14478         [ALC861_6ST_DIG]        = "6stack-dig",
14479         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14480         [ALC861_TOSHIBA]        = "toshiba",
14481         [ALC861_ASUS]           = "asus",
14482         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14483         [ALC861_AUTO]           = "auto",
14484 };
14485
14486 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14487         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14488         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14489         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14490         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14491         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14492         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14493         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14494         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14495          *        Any other models that need this preset?
14496          */
14497         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14498         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14499         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14500         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14501         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14502         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14503         /* FIXME: the below seems conflict */
14504         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14505         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14506         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14507         {}
14508 };
14509
14510 static struct alc_config_preset alc861_presets[] = {
14511         [ALC861_3ST] = {
14512                 .mixers = { alc861_3ST_mixer },
14513                 .init_verbs = { alc861_threestack_init_verbs },
14514                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14515                 .dac_nids = alc861_dac_nids,
14516                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14517                 .channel_mode = alc861_threestack_modes,
14518                 .need_dac_fix = 1,
14519                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14520                 .adc_nids = alc861_adc_nids,
14521                 .input_mux = &alc861_capture_source,
14522         },
14523         [ALC861_3ST_DIG] = {
14524                 .mixers = { alc861_base_mixer },
14525                 .init_verbs = { alc861_threestack_init_verbs },
14526                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14527                 .dac_nids = alc861_dac_nids,
14528                 .dig_out_nid = ALC861_DIGOUT_NID,
14529                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14530                 .channel_mode = alc861_threestack_modes,
14531                 .need_dac_fix = 1,
14532                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14533                 .adc_nids = alc861_adc_nids,
14534                 .input_mux = &alc861_capture_source,
14535         },
14536         [ALC861_6ST_DIG] = {
14537                 .mixers = { alc861_base_mixer },
14538                 .init_verbs = { alc861_base_init_verbs },
14539                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14540                 .dac_nids = alc861_dac_nids,
14541                 .dig_out_nid = ALC861_DIGOUT_NID,
14542                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14543                 .channel_mode = alc861_8ch_modes,
14544                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14545                 .adc_nids = alc861_adc_nids,
14546                 .input_mux = &alc861_capture_source,
14547         },
14548         [ALC660_3ST] = {
14549                 .mixers = { alc861_3ST_mixer },
14550                 .init_verbs = { alc861_threestack_init_verbs },
14551                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14552                 .dac_nids = alc660_dac_nids,
14553                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14554                 .channel_mode = alc861_threestack_modes,
14555                 .need_dac_fix = 1,
14556                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14557                 .adc_nids = alc861_adc_nids,
14558                 .input_mux = &alc861_capture_source,
14559         },
14560         [ALC861_UNIWILL_M31] = {
14561                 .mixers = { alc861_uniwill_m31_mixer },
14562                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14563                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14564                 .dac_nids = alc861_dac_nids,
14565                 .dig_out_nid = ALC861_DIGOUT_NID,
14566                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14567                 .channel_mode = alc861_uniwill_m31_modes,
14568                 .need_dac_fix = 1,
14569                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14570                 .adc_nids = alc861_adc_nids,
14571                 .input_mux = &alc861_capture_source,
14572         },
14573         [ALC861_TOSHIBA] = {
14574                 .mixers = { alc861_toshiba_mixer },
14575                 .init_verbs = { alc861_base_init_verbs,
14576                                 alc861_toshiba_init_verbs },
14577                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14578                 .dac_nids = alc861_dac_nids,
14579                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14580                 .channel_mode = alc883_3ST_2ch_modes,
14581                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14582                 .adc_nids = alc861_adc_nids,
14583                 .input_mux = &alc861_capture_source,
14584                 .unsol_event = alc861_toshiba_unsol_event,
14585                 .init_hook = alc861_toshiba_automute,
14586         },
14587         [ALC861_ASUS] = {
14588                 .mixers = { alc861_asus_mixer },
14589                 .init_verbs = { alc861_asus_init_verbs },
14590                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14591                 .dac_nids = alc861_dac_nids,
14592                 .dig_out_nid = ALC861_DIGOUT_NID,
14593                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14594                 .channel_mode = alc861_asus_modes,
14595                 .need_dac_fix = 1,
14596                 .hp_nid = 0x06,
14597                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14598                 .adc_nids = alc861_adc_nids,
14599                 .input_mux = &alc861_capture_source,
14600         },
14601         [ALC861_ASUS_LAPTOP] = {
14602                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14603                 .init_verbs = { alc861_asus_init_verbs,
14604                                 alc861_asus_laptop_init_verbs },
14605                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14606                 .dac_nids = alc861_dac_nids,
14607                 .dig_out_nid = ALC861_DIGOUT_NID,
14608                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14609                 .channel_mode = alc883_3ST_2ch_modes,
14610                 .need_dac_fix = 1,
14611                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14612                 .adc_nids = alc861_adc_nids,
14613                 .input_mux = &alc861_capture_source,
14614         },
14615 };
14616
14617
14618 static int patch_alc861(struct hda_codec *codec)
14619 {
14620         struct alc_spec *spec;
14621         int board_config;
14622         int err;
14623
14624         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14625         if (spec == NULL)
14626                 return -ENOMEM;
14627
14628         codec->spec = spec;
14629
14630         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14631                                                   alc861_models,
14632                                                   alc861_cfg_tbl);
14633
14634         if (board_config < 0) {
14635                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14636                        codec->chip_name);
14637                 board_config = ALC861_AUTO;
14638         }
14639
14640         if (board_config == ALC861_AUTO) {
14641                 /* automatic parse from the BIOS config */
14642                 err = alc861_parse_auto_config(codec);
14643                 if (err < 0) {
14644                         alc_free(codec);
14645                         return err;
14646                 } else if (!err) {
14647                         printk(KERN_INFO
14648                                "hda_codec: Cannot set up configuration "
14649                                "from BIOS.  Using base mode...\n");
14650                    board_config = ALC861_3ST_DIG;
14651                 }
14652         }
14653
14654         err = snd_hda_attach_beep_device(codec, 0x23);
14655         if (err < 0) {
14656                 alc_free(codec);
14657                 return err;
14658         }
14659
14660         if (board_config != ALC861_AUTO)
14661                 setup_preset(codec, &alc861_presets[board_config]);
14662
14663         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14664         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14665
14666         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14667         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14668
14669         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14670
14671         spec->vmaster_nid = 0x03;
14672
14673         codec->patch_ops = alc_patch_ops;
14674         if (board_config == ALC861_AUTO)
14675                 spec->init_hook = alc861_auto_init;
14676 #ifdef CONFIG_SND_HDA_POWER_SAVE
14677         if (!spec->loopback.amplist)
14678                 spec->loopback.amplist = alc861_loopbacks;
14679 #endif
14680         codec->proc_widget_hook = print_realtek_coef;
14681
14682         return 0;
14683 }
14684
14685 /*
14686  * ALC861-VD support
14687  *
14688  * Based on ALC882
14689  *
14690  * In addition, an independent DAC
14691  */
14692 #define ALC861VD_DIGOUT_NID     0x06
14693
14694 static hda_nid_t alc861vd_dac_nids[4] = {
14695         /* front, surr, clfe, side surr */
14696         0x02, 0x03, 0x04, 0x05
14697 };
14698
14699 /* dac_nids for ALC660vd are in a different order - according to
14700  * Realtek's driver.
14701  * This should probably result in a different mixer for 6stack models
14702  * of ALC660vd codecs, but for now there is only 3stack mixer
14703  * - and it is the same as in 861vd.
14704  * adc_nids in ALC660vd are (is) the same as in 861vd
14705  */
14706 static hda_nid_t alc660vd_dac_nids[3] = {
14707         /* front, rear, clfe, rear_surr */
14708         0x02, 0x04, 0x03
14709 };
14710
14711 static hda_nid_t alc861vd_adc_nids[1] = {
14712         /* ADC0 */
14713         0x09,
14714 };
14715
14716 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14717
14718 /* input MUX */
14719 /* FIXME: should be a matrix-type input source selection */
14720 static struct hda_input_mux alc861vd_capture_source = {
14721         .num_items = 4,
14722         .items = {
14723                 { "Mic", 0x0 },
14724                 { "Front Mic", 0x1 },
14725                 { "Line", 0x2 },
14726                 { "CD", 0x4 },
14727         },
14728 };
14729
14730 static struct hda_input_mux alc861vd_dallas_capture_source = {
14731         .num_items = 2,
14732         .items = {
14733                 { "Ext Mic", 0x0 },
14734                 { "Int Mic", 0x1 },
14735         },
14736 };
14737
14738 static struct hda_input_mux alc861vd_hp_capture_source = {
14739         .num_items = 2,
14740         .items = {
14741                 { "Front Mic", 0x0 },
14742                 { "ATAPI Mic", 0x1 },
14743         },
14744 };
14745
14746 /*
14747  * 2ch mode
14748  */
14749 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14750         { 2, NULL }
14751 };
14752
14753 /*
14754  * 6ch mode
14755  */
14756 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14757         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14758         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14759         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14760         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14761         { } /* end */
14762 };
14763
14764 /*
14765  * 8ch mode
14766  */
14767 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14768         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14769         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14770         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14771         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14772         { } /* end */
14773 };
14774
14775 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14776         { 6, alc861vd_6stack_ch6_init },
14777         { 8, alc861vd_6stack_ch8_init },
14778 };
14779
14780 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14781         {
14782                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14783                 .name = "Channel Mode",
14784                 .info = alc_ch_mode_info,
14785                 .get = alc_ch_mode_get,
14786                 .put = alc_ch_mode_put,
14787         },
14788         { } /* end */
14789 };
14790
14791 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14792  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14793  */
14794 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14795         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14796         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14797
14798         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14799         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14800
14801         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14802                                 HDA_OUTPUT),
14803         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14804                                 HDA_OUTPUT),
14805         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14806         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14807
14808         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14809         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14810
14811         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14812
14813         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14814         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14815         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14816
14817         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14818         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14819         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14820
14821         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14822         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14823
14824         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14825         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14826
14827         { } /* end */
14828 };
14829
14830 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14831         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14832         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14833
14834         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14835
14836         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14837         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14838         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14839
14840         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14841         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14842         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14843
14844         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14845         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14846
14847         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14848         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14849
14850         { } /* end */
14851 };
14852
14853 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14854         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14855         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14856         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14857
14858         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14859
14860         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14861         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14862         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14863
14864         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14865         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14866         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14867
14868         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14869         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14870
14871         { } /* end */
14872 };
14873
14874 /* Pin assignment: Speaker=0x14, HP = 0x15,
14875  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14876  */
14877 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14878         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14879         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14880         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14881         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14882         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14883         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14884         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14885         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14886         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14887         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14888         { } /* end */
14889 };
14890
14891 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14892  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14893  */
14894 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14895         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14896         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14897         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14898         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14899         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14900         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14901         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14902         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14903
14904         { } /* end */
14905 };
14906
14907 /*
14908  * generic initialization of ADC, input mixers and output mixers
14909  */
14910 static struct hda_verb alc861vd_volume_init_verbs[] = {
14911         /*
14912          * Unmute ADC0 and set the default input to mic-in
14913          */
14914         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14915         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14916
14917         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14918          * the analog-loopback mixer widget
14919          */
14920         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14921         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14922         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14923         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14924         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14925         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14926
14927         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14928         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14929         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14930         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14931         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14932
14933         /*
14934          * Set up output mixers (0x02 - 0x05)
14935          */
14936         /* set vol=0 to output mixers */
14937         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14938         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14939         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14940         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14941
14942         /* set up input amps for analog loopback */
14943         /* Amp Indices: DAC = 0, mixer = 1 */
14944         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14945         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14946         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14947         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14948         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14949         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14950         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14951         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14952
14953         { }
14954 };
14955
14956 /*
14957  * 3-stack pin configuration:
14958  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14959  */
14960 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14961         /*
14962          * Set pin mode and muting
14963          */
14964         /* set front pin widgets 0x14 for output */
14965         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14966         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14967         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14968
14969         /* Mic (rear) pin: input vref at 80% */
14970         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14971         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14972         /* Front Mic pin: input vref at 80% */
14973         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14974         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14975         /* Line In pin: input */
14976         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14977         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14978         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14979         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14980         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14981         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14982         /* CD pin widget for input */
14983         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14984
14985         { }
14986 };
14987
14988 /*
14989  * 6-stack pin configuration:
14990  */
14991 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14992         /*
14993          * Set pin mode and muting
14994          */
14995         /* set front pin widgets 0x14 for output */
14996         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14997         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14998         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14999
15000         /* Rear Pin: output 1 (0x0d) */
15001         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15002         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15003         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
15004         /* CLFE Pin: output 2 (0x0e) */
15005         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15006         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15007         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
15008         /* Side Pin: output 3 (0x0f) */
15009         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15010         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15011         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
15012
15013         /* Mic (rear) pin: input vref at 80% */
15014         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15015         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15016         /* Front Mic pin: input vref at 80% */
15017         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15018         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15019         /* Line In pin: input */
15020         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15021         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15022         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15023         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15024         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15025         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15026         /* CD pin widget for input */
15027         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15028
15029         { }
15030 };
15031
15032 static struct hda_verb alc861vd_eapd_verbs[] = {
15033         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15034         { }
15035 };
15036
15037 static struct hda_verb alc660vd_eapd_verbs[] = {
15038         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15039         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15040         { }
15041 };
15042
15043 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15044         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15045         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15046         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15047         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15048         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15049         {}
15050 };
15051
15052 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15053 {
15054         unsigned int present;
15055         unsigned char bits;
15056
15057         present = snd_hda_codec_read(codec, 0x18, 0,
15058                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15059         bits = present ? HDA_AMP_MUTE : 0;
15060         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15061                                  HDA_AMP_MUTE, bits);
15062 }
15063
15064 static void alc861vd_lenovo_setup(struct hda_codec *codec)
15065 {
15066         struct alc_spec *spec = codec->spec;
15067         spec->autocfg.hp_pins[0] = 0x1b;
15068         spec->autocfg.speaker_pins[0] = 0x14;
15069 }
15070
15071 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15072 {
15073         alc_automute_amp(codec);
15074         alc861vd_lenovo_mic_automute(codec);
15075 }
15076
15077 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15078                                         unsigned int res)
15079 {
15080         switch (res >> 26) {
15081         case ALC880_MIC_EVENT:
15082                 alc861vd_lenovo_mic_automute(codec);
15083                 break;
15084         default:
15085                 alc_automute_amp_unsol_event(codec, res);
15086                 break;
15087         }
15088 }
15089
15090 static struct hda_verb alc861vd_dallas_verbs[] = {
15091         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15092         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15093         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15094         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15095
15096         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15097         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15098         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15099         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15100         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15101         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15102         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15103         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15104
15105         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15106         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15107         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15108         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15109         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15110         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15111         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15112         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15113
15114         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15115         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15116         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15117         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15118         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15119         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15120         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15121         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15122
15123         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15124         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15125         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15126         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15127
15128         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15129         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15130         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15131
15132         { } /* end */
15133 };
15134
15135 /* toggle speaker-output according to the hp-jack state */
15136 static void alc861vd_dallas_setup(struct hda_codec *codec)
15137 {
15138         struct alc_spec *spec = codec->spec;
15139
15140         spec->autocfg.hp_pins[0] = 0x15;
15141         spec->autocfg.speaker_pins[0] = 0x14;
15142 }
15143
15144 #ifdef CONFIG_SND_HDA_POWER_SAVE
15145 #define alc861vd_loopbacks      alc880_loopbacks
15146 #endif
15147
15148 /* pcm configuration: identical with ALC880 */
15149 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15150 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15151 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15152 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15153
15154 /*
15155  * configuration and preset
15156  */
15157 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15158         [ALC660VD_3ST]          = "3stack-660",
15159         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15160         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15161         [ALC861VD_3ST]          = "3stack",
15162         [ALC861VD_3ST_DIG]      = "3stack-digout",
15163         [ALC861VD_6ST_DIG]      = "6stack-digout",
15164         [ALC861VD_LENOVO]       = "lenovo",
15165         [ALC861VD_DALLAS]       = "dallas",
15166         [ALC861VD_HP]           = "hp",
15167         [ALC861VD_AUTO]         = "auto",
15168 };
15169
15170 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15171         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15172         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15173         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15174         /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
15175         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15176         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15177         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15178         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15179         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15180         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15181         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15182         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15183         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15184         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15185         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15186         {}
15187 };
15188
15189 static struct alc_config_preset alc861vd_presets[] = {
15190         [ALC660VD_3ST] = {
15191                 .mixers = { alc861vd_3st_mixer },
15192                 .init_verbs = { alc861vd_volume_init_verbs,
15193                                  alc861vd_3stack_init_verbs },
15194                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15195                 .dac_nids = alc660vd_dac_nids,
15196                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15197                 .channel_mode = alc861vd_3stack_2ch_modes,
15198                 .input_mux = &alc861vd_capture_source,
15199         },
15200         [ALC660VD_3ST_DIG] = {
15201                 .mixers = { alc861vd_3st_mixer },
15202                 .init_verbs = { alc861vd_volume_init_verbs,
15203                                  alc861vd_3stack_init_verbs },
15204                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15205                 .dac_nids = alc660vd_dac_nids,
15206                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15207                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15208                 .channel_mode = alc861vd_3stack_2ch_modes,
15209                 .input_mux = &alc861vd_capture_source,
15210         },
15211         [ALC861VD_3ST] = {
15212                 .mixers = { alc861vd_3st_mixer },
15213                 .init_verbs = { alc861vd_volume_init_verbs,
15214                                  alc861vd_3stack_init_verbs },
15215                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15216                 .dac_nids = alc861vd_dac_nids,
15217                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15218                 .channel_mode = alc861vd_3stack_2ch_modes,
15219                 .input_mux = &alc861vd_capture_source,
15220         },
15221         [ALC861VD_3ST_DIG] = {
15222                 .mixers = { alc861vd_3st_mixer },
15223                 .init_verbs = { alc861vd_volume_init_verbs,
15224                                  alc861vd_3stack_init_verbs },
15225                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15226                 .dac_nids = alc861vd_dac_nids,
15227                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15228                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15229                 .channel_mode = alc861vd_3stack_2ch_modes,
15230                 .input_mux = &alc861vd_capture_source,
15231         },
15232         [ALC861VD_6ST_DIG] = {
15233                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15234                 .init_verbs = { alc861vd_volume_init_verbs,
15235                                 alc861vd_6stack_init_verbs },
15236                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15237                 .dac_nids = alc861vd_dac_nids,
15238                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15239                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15240                 .channel_mode = alc861vd_6stack_modes,
15241                 .input_mux = &alc861vd_capture_source,
15242         },
15243         [ALC861VD_LENOVO] = {
15244                 .mixers = { alc861vd_lenovo_mixer },
15245                 .init_verbs = { alc861vd_volume_init_verbs,
15246                                 alc861vd_3stack_init_verbs,
15247                                 alc861vd_eapd_verbs,
15248                                 alc861vd_lenovo_unsol_verbs },
15249                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15250                 .dac_nids = alc660vd_dac_nids,
15251                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15252                 .channel_mode = alc861vd_3stack_2ch_modes,
15253                 .input_mux = &alc861vd_capture_source,
15254                 .unsol_event = alc861vd_lenovo_unsol_event,
15255                 .setup = alc861vd_lenovo_setup,
15256                 .init_hook = alc861vd_lenovo_init_hook,
15257         },
15258         [ALC861VD_DALLAS] = {
15259                 .mixers = { alc861vd_dallas_mixer },
15260                 .init_verbs = { alc861vd_dallas_verbs },
15261                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15262                 .dac_nids = alc861vd_dac_nids,
15263                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15264                 .channel_mode = alc861vd_3stack_2ch_modes,
15265                 .input_mux = &alc861vd_dallas_capture_source,
15266                 .unsol_event = alc_automute_amp_unsol_event,
15267                 .setup = alc861vd_dallas_setup,
15268                 .init_hook = alc_automute_amp,
15269         },
15270         [ALC861VD_HP] = {
15271                 .mixers = { alc861vd_hp_mixer },
15272                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15273                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15274                 .dac_nids = alc861vd_dac_nids,
15275                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15276                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15277                 .channel_mode = alc861vd_3stack_2ch_modes,
15278                 .input_mux = &alc861vd_hp_capture_source,
15279                 .unsol_event = alc_automute_amp_unsol_event,
15280                 .setup = alc861vd_dallas_setup,
15281                 .init_hook = alc_automute_amp,
15282         },
15283         [ALC660VD_ASUS_V1S] = {
15284                 .mixers = { alc861vd_lenovo_mixer },
15285                 .init_verbs = { alc861vd_volume_init_verbs,
15286                                 alc861vd_3stack_init_verbs,
15287                                 alc861vd_eapd_verbs,
15288                                 alc861vd_lenovo_unsol_verbs },
15289                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15290                 .dac_nids = alc660vd_dac_nids,
15291                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15292                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15293                 .channel_mode = alc861vd_3stack_2ch_modes,
15294                 .input_mux = &alc861vd_capture_source,
15295                 .unsol_event = alc861vd_lenovo_unsol_event,
15296                 .setup = alc861vd_lenovo_setup,
15297                 .init_hook = alc861vd_lenovo_init_hook,
15298         },
15299 };
15300
15301 /*
15302  * BIOS auto configuration
15303  */
15304 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
15305                                                 const struct auto_pin_cfg *cfg)
15306 {
15307         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
15308 }
15309
15310
15311 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15312                                 hda_nid_t nid, int pin_type, int dac_idx)
15313 {
15314         alc_set_pin_output(codec, nid, pin_type);
15315 }
15316
15317 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15318 {
15319         struct alc_spec *spec = codec->spec;
15320         int i;
15321
15322         for (i = 0; i <= HDA_SIDE; i++) {
15323                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15324                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15325                 if (nid)
15326                         alc861vd_auto_set_output_and_unmute(codec, nid,
15327                                                             pin_type, i);
15328         }
15329 }
15330
15331
15332 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15333 {
15334         struct alc_spec *spec = codec->spec;
15335         hda_nid_t pin;
15336
15337         pin = spec->autocfg.hp_pins[0];
15338         if (pin) /* connect to front and use dac 0 */
15339                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15340         pin = spec->autocfg.speaker_pins[0];
15341         if (pin)
15342                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15343 }
15344
15345 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15346
15347 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15348 {
15349         struct alc_spec *spec = codec->spec;
15350         int i;
15351
15352         for (i = 0; i < AUTO_PIN_LAST; i++) {
15353                 hda_nid_t nid = spec->autocfg.input_pins[i];
15354                 if (alc_is_input_pin(codec, nid)) {
15355                         alc_set_input_pin(codec, nid, i);
15356                         if (nid != ALC861VD_PIN_CD_NID &&
15357                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15358                                 snd_hda_codec_write(codec, nid, 0,
15359                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15360                                                 AMP_OUT_MUTE);
15361                 }
15362         }
15363 }
15364
15365 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15366
15367 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15368 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15369
15370 /* add playback controls from the parsed DAC table */
15371 /* Based on ALC880 version. But ALC861VD has separate,
15372  * different NIDs for mute/unmute switch and volume control */
15373 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15374                                              const struct auto_pin_cfg *cfg)
15375 {
15376         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15377         hda_nid_t nid_v, nid_s;
15378         int i, err;
15379
15380         for (i = 0; i < cfg->line_outs; i++) {
15381                 if (!spec->multiout.dac_nids[i])
15382                         continue;
15383                 nid_v = alc861vd_idx_to_mixer_vol(
15384                                 alc880_dac_to_idx(
15385                                         spec->multiout.dac_nids[i]));
15386                 nid_s = alc861vd_idx_to_mixer_switch(
15387                                 alc880_dac_to_idx(
15388                                         spec->multiout.dac_nids[i]));
15389
15390                 if (i == 2) {
15391                         /* Center/LFE */
15392                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15393                                               "Center",
15394                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15395                                                               HDA_OUTPUT));
15396                         if (err < 0)
15397                                 return err;
15398                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15399                                               "LFE",
15400                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15401                                                               HDA_OUTPUT));
15402                         if (err < 0)
15403                                 return err;
15404                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15405                                              "Center",
15406                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15407                                                               HDA_INPUT));
15408                         if (err < 0)
15409                                 return err;
15410                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15411                                              "LFE",
15412                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15413                                                               HDA_INPUT));
15414                         if (err < 0)
15415                                 return err;
15416                 } else {
15417                         const char *pfx;
15418                         if (cfg->line_outs == 1 &&
15419                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
15420                                 if (!cfg->hp_pins)
15421                                         pfx = "Speaker";
15422                                 else
15423                                         pfx = "PCM";
15424                         } else
15425                                 pfx = chname[i];
15426                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15427                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15428                                                               HDA_OUTPUT));
15429                         if (err < 0)
15430                                 return err;
15431                         if (cfg->line_outs == 1 &&
15432                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15433                                 pfx = "Speaker";
15434                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15435                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15436                                                               HDA_INPUT));
15437                         if (err < 0)
15438                                 return err;
15439                 }
15440         }
15441         return 0;
15442 }
15443
15444 /* add playback controls for speaker and HP outputs */
15445 /* Based on ALC880 version. But ALC861VD has separate,
15446  * different NIDs for mute/unmute switch and volume control */
15447 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15448                                         hda_nid_t pin, const char *pfx)
15449 {
15450         hda_nid_t nid_v, nid_s;
15451         int err;
15452
15453         if (!pin)
15454                 return 0;
15455
15456         if (alc880_is_fixed_pin(pin)) {
15457                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15458                 /* specify the DAC as the extra output */
15459                 if (!spec->multiout.hp_nid)
15460                         spec->multiout.hp_nid = nid_v;
15461                 else
15462                         spec->multiout.extra_out_nid[0] = nid_v;
15463                 /* control HP volume/switch on the output mixer amp */
15464                 nid_v = alc861vd_idx_to_mixer_vol(
15465                                 alc880_fixed_pin_idx(pin));
15466                 nid_s = alc861vd_idx_to_mixer_switch(
15467                                 alc880_fixed_pin_idx(pin));
15468
15469                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15470                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15471                 if (err < 0)
15472                         return err;
15473                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15474                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15475                 if (err < 0)
15476                         return err;
15477         } else if (alc880_is_multi_pin(pin)) {
15478                 /* set manual connection */
15479                 /* we have only a switch on HP-out PIN */
15480                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15481                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15482                 if (err < 0)
15483                         return err;
15484         }
15485         return 0;
15486 }
15487
15488 /* parse the BIOS configuration and set up the alc_spec
15489  * return 1 if successful, 0 if the proper config is not found,
15490  * or a negative error code
15491  * Based on ALC880 version - had to change it to override
15492  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15493 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15494 {
15495         struct alc_spec *spec = codec->spec;
15496         int err;
15497         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15498
15499         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15500                                            alc861vd_ignore);
15501         if (err < 0)
15502                 return err;
15503         if (!spec->autocfg.line_outs)
15504                 return 0; /* can't find valid BIOS pin config */
15505
15506         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15507         if (err < 0)
15508                 return err;
15509         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15510         if (err < 0)
15511                 return err;
15512         err = alc861vd_auto_create_extra_out(spec,
15513                                              spec->autocfg.speaker_pins[0],
15514                                              "Speaker");
15515         if (err < 0)
15516                 return err;
15517         err = alc861vd_auto_create_extra_out(spec,
15518                                              spec->autocfg.hp_pins[0],
15519                                              "Headphone");
15520         if (err < 0)
15521                 return err;
15522         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15523         if (err < 0)
15524                 return err;
15525
15526         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15527
15528         if (spec->autocfg.dig_outs)
15529                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15530
15531         if (spec->kctls.list)
15532                 add_mixer(spec, spec->kctls.list);
15533
15534         add_verb(spec, alc861vd_volume_init_verbs);
15535
15536         spec->num_mux_defs = 1;
15537         spec->input_mux = &spec->private_imux[0];
15538
15539         err = alc_auto_add_mic_boost(codec);
15540         if (err < 0)
15541                 return err;
15542
15543         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15544
15545         return 1;
15546 }
15547
15548 /* additional initialization for auto-configuration model */
15549 static void alc861vd_auto_init(struct hda_codec *codec)
15550 {
15551         struct alc_spec *spec = codec->spec;
15552         alc861vd_auto_init_multi_out(codec);
15553         alc861vd_auto_init_hp_out(codec);
15554         alc861vd_auto_init_analog_input(codec);
15555         alc861vd_auto_init_input_src(codec);
15556         if (spec->unsol_event)
15557                 alc_inithook(codec);
15558 }
15559
15560 enum {
15561         ALC660VD_FIX_ASUS_GPIO1
15562 };
15563
15564 /* reset GPIO1 */
15565 static const struct hda_verb alc660vd_fix_asus_gpio1_verbs[] = {
15566         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
15567         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
15568         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
15569         { }
15570 };
15571
15572 static const struct alc_fixup alc861vd_fixups[] = {
15573         [ALC660VD_FIX_ASUS_GPIO1] = {
15574                 .verbs = alc660vd_fix_asus_gpio1_verbs,
15575         },
15576 };
15577
15578 static struct snd_pci_quirk alc861vd_fixup_tbl[] = {
15579         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
15580         {}
15581 };
15582
15583 static int patch_alc861vd(struct hda_codec *codec)
15584 {
15585         struct alc_spec *spec;
15586         int err, board_config;
15587
15588         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15589         if (spec == NULL)
15590                 return -ENOMEM;
15591
15592         codec->spec = spec;
15593
15594         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15595                                                   alc861vd_models,
15596                                                   alc861vd_cfg_tbl);
15597
15598         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15599                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15600                        codec->chip_name);
15601                 board_config = ALC861VD_AUTO;
15602         }
15603
15604         alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups);
15605
15606         if (board_config == ALC861VD_AUTO) {
15607                 /* automatic parse from the BIOS config */
15608                 err = alc861vd_parse_auto_config(codec);
15609                 if (err < 0) {
15610                         alc_free(codec);
15611                         return err;
15612                 } else if (!err) {
15613                         printk(KERN_INFO
15614                                "hda_codec: Cannot set up configuration "
15615                                "from BIOS.  Using base mode...\n");
15616                         board_config = ALC861VD_3ST;
15617                 }
15618         }
15619
15620         err = snd_hda_attach_beep_device(codec, 0x23);
15621         if (err < 0) {
15622                 alc_free(codec);
15623                 return err;
15624         }
15625
15626         if (board_config != ALC861VD_AUTO)
15627                 setup_preset(codec, &alc861vd_presets[board_config]);
15628
15629         if (codec->vendor_id == 0x10ec0660) {
15630                 /* always turn on EAPD */
15631                 add_verb(spec, alc660vd_eapd_verbs);
15632         }
15633
15634         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15635         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15636
15637         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15638         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15639
15640         if (!spec->adc_nids) {
15641                 spec->adc_nids = alc861vd_adc_nids;
15642                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15643         }
15644         if (!spec->capsrc_nids)
15645                 spec->capsrc_nids = alc861vd_capsrc_nids;
15646
15647         set_capture_mixer(codec);
15648         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15649
15650         spec->vmaster_nid = 0x02;
15651
15652         codec->patch_ops = alc_patch_ops;
15653
15654         if (board_config == ALC861VD_AUTO)
15655                 spec->init_hook = alc861vd_auto_init;
15656 #ifdef CONFIG_SND_HDA_POWER_SAVE
15657         if (!spec->loopback.amplist)
15658                 spec->loopback.amplist = alc861vd_loopbacks;
15659 #endif
15660         codec->proc_widget_hook = print_realtek_coef;
15661
15662         return 0;
15663 }
15664
15665 /*
15666  * ALC662 support
15667  *
15668  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15669  * configuration.  Each pin widget can choose any input DACs and a mixer.
15670  * Each ADC is connected from a mixer of all inputs.  This makes possible
15671  * 6-channel independent captures.
15672  *
15673  * In addition, an independent DAC for the multi-playback (not used in this
15674  * driver yet).
15675  */
15676 #define ALC662_DIGOUT_NID       0x06
15677 #define ALC662_DIGIN_NID        0x0a
15678
15679 static hda_nid_t alc662_dac_nids[4] = {
15680         /* front, rear, clfe, rear_surr */
15681         0x02, 0x03, 0x04
15682 };
15683
15684 static hda_nid_t alc272_dac_nids[2] = {
15685         0x02, 0x03
15686 };
15687
15688 static hda_nid_t alc662_adc_nids[2] = {
15689         /* ADC1-2 */
15690         0x09, 0x08
15691 };
15692
15693 static hda_nid_t alc272_adc_nids[1] = {
15694         /* ADC1-2 */
15695         0x08,
15696 };
15697
15698 static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15699 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15700
15701
15702 /* input MUX */
15703 /* FIXME: should be a matrix-type input source selection */
15704 static struct hda_input_mux alc662_capture_source = {
15705         .num_items = 4,
15706         .items = {
15707                 { "Mic", 0x0 },
15708                 { "Front Mic", 0x1 },
15709                 { "Line", 0x2 },
15710                 { "CD", 0x4 },
15711         },
15712 };
15713
15714 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15715         .num_items = 2,
15716         .items = {
15717                 { "Mic", 0x1 },
15718                 { "Line", 0x2 },
15719         },
15720 };
15721
15722 static struct hda_input_mux alc663_capture_source = {
15723         .num_items = 3,
15724         .items = {
15725                 { "Mic", 0x0 },
15726                 { "Front Mic", 0x1 },
15727                 { "Line", 0x2 },
15728         },
15729 };
15730
15731 #if 0 /* set to 1 for testing other input sources below */
15732 static struct hda_input_mux alc272_nc10_capture_source = {
15733         .num_items = 16,
15734         .items = {
15735                 { "Autoselect Mic", 0x0 },
15736                 { "Internal Mic", 0x1 },
15737                 { "In-0x02", 0x2 },
15738                 { "In-0x03", 0x3 },
15739                 { "In-0x04", 0x4 },
15740                 { "In-0x05", 0x5 },
15741                 { "In-0x06", 0x6 },
15742                 { "In-0x07", 0x7 },
15743                 { "In-0x08", 0x8 },
15744                 { "In-0x09", 0x9 },
15745                 { "In-0x0a", 0x0a },
15746                 { "In-0x0b", 0x0b },
15747                 { "In-0x0c", 0x0c },
15748                 { "In-0x0d", 0x0d },
15749                 { "In-0x0e", 0x0e },
15750                 { "In-0x0f", 0x0f },
15751         },
15752 };
15753 #endif
15754
15755 /*
15756  * 2ch mode
15757  */
15758 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15759         { 2, NULL }
15760 };
15761
15762 /*
15763  * 2ch mode
15764  */
15765 static struct hda_verb alc662_3ST_ch2_init[] = {
15766         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15767         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15768         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15769         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15770         { } /* end */
15771 };
15772
15773 /*
15774  * 6ch mode
15775  */
15776 static struct hda_verb alc662_3ST_ch6_init[] = {
15777         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15778         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15779         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15780         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15781         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15782         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15783         { } /* end */
15784 };
15785
15786 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15787         { 2, alc662_3ST_ch2_init },
15788         { 6, alc662_3ST_ch6_init },
15789 };
15790
15791 /*
15792  * 2ch mode
15793  */
15794 static struct hda_verb alc662_sixstack_ch6_init[] = {
15795         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15796         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15797         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15798         { } /* end */
15799 };
15800
15801 /*
15802  * 6ch mode
15803  */
15804 static struct hda_verb alc662_sixstack_ch8_init[] = {
15805         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15806         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15807         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15808         { } /* end */
15809 };
15810
15811 static struct hda_channel_mode alc662_5stack_modes[2] = {
15812         { 2, alc662_sixstack_ch6_init },
15813         { 6, alc662_sixstack_ch8_init },
15814 };
15815
15816 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15817  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15818  */
15819
15820 static struct snd_kcontrol_new alc662_base_mixer[] = {
15821         /* output mixer control */
15822         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15823         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15824         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15825         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15826         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15827         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15828         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15829         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15830         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15831
15832         /*Input mixer control */
15833         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15834         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15835         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15836         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15837         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15838         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15839         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15840         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15841         { } /* end */
15842 };
15843
15844 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15845         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15846         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15847         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15848         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15849         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15850         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15851         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15852         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15853         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15854         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15855         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15856         { } /* end */
15857 };
15858
15859 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15860         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15861         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15862         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15863         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15864         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15865         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15866         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15867         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15868         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15869         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15870         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15871         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15872         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15874         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15875         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15876         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15877         { } /* end */
15878 };
15879
15880 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15881         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15882         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15883         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15884         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15885         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15886         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15887         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15888         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15889         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15890         { } /* end */
15891 };
15892
15893 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15894         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15895         ALC262_HIPPO_MASTER_SWITCH,
15896
15897         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15898         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15899         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15900
15901         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15902         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15903         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15904         { } /* end */
15905 };
15906
15907 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15908         ALC262_HIPPO_MASTER_SWITCH,
15909         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15910         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15911         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15912         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15913         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15914         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15915         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15916         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15917         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15918         { } /* end */
15919 };
15920
15921 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15922         .ops = &snd_hda_bind_vol,
15923         .values = {
15924                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15925                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15926                 0
15927         },
15928 };
15929
15930 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15931         .ops = &snd_hda_bind_sw,
15932         .values = {
15933                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15934                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15935                 0
15936         },
15937 };
15938
15939 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15940         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15941         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15942         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15943         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15944         { } /* end */
15945 };
15946
15947 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15948         .ops = &snd_hda_bind_sw,
15949         .values = {
15950                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15951                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15952                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15953                 0
15954         },
15955 };
15956
15957 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15958         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15959         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15960         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15961         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15962         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15963         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15964
15965         { } /* end */
15966 };
15967
15968 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15969         .ops = &snd_hda_bind_sw,
15970         .values = {
15971                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15972                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15973                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15974                 0
15975         },
15976 };
15977
15978 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15979         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15980         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15981         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15982         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15983         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15984         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15985         { } /* end */
15986 };
15987
15988 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15989         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15990         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15991         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15992         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15993         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15994         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15995         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15996         { } /* end */
15997 };
15998
15999 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
16000         .ops = &snd_hda_bind_vol,
16001         .values = {
16002                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
16003                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
16004                 0
16005         },
16006 };
16007
16008 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
16009         .ops = &snd_hda_bind_sw,
16010         .values = {
16011                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16012                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
16013                 0
16014         },
16015 };
16016
16017 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
16018         HDA_BIND_VOL("Master Playback Volume",
16019                                 &alc663_asus_two_bind_master_vol),
16020         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16021         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16022         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16023         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16024         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16025         { } /* end */
16026 };
16027
16028 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
16029         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
16030         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16031         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16032         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16033         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16034         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16035         { } /* end */
16036 };
16037
16038 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
16039         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16040         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16041         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16042         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16043         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16044
16045         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16046         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16047         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16048         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16049         { } /* end */
16050 };
16051
16052 static struct snd_kcontrol_new alc663_g50v_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_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16056
16057         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16058         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16059         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16060         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16061         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16062         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16063         { } /* end */
16064 };
16065
16066 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16067         {
16068                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16069                 .name = "Channel Mode",
16070                 .info = alc_ch_mode_info,
16071                 .get = alc_ch_mode_get,
16072                 .put = alc_ch_mode_put,
16073         },
16074         { } /* end */
16075 };
16076
16077 static struct hda_verb alc662_init_verbs[] = {
16078         /* ADC: mute amp left and right */
16079         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16080         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16081         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16082
16083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16088
16089         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16090         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16091         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16092         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16093         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16094         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16095
16096         /* Front Pin: output 0 (0x0c) */
16097         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16098         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16099
16100         /* Rear Pin: output 1 (0x0d) */
16101         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16102         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16103
16104         /* CLFE Pin: output 2 (0x0e) */
16105         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16106         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16107
16108         /* Mic (rear) pin: input vref at 80% */
16109         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16110         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16111         /* Front Mic pin: input vref at 80% */
16112         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16113         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16114         /* Line In pin: input */
16115         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16116         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16117         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16118         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16119         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16120         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16121         /* CD pin widget for input */
16122         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16123
16124         /* FIXME: use matrix-type input source selection */
16125         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16126         /* Input mixer */
16127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16128         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16129
16130         /* always trun on EAPD */
16131         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16132         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16133
16134         { }
16135 };
16136
16137 static struct hda_verb alc662_sue_init_verbs[] = {
16138         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16139         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16140         {}
16141 };
16142
16143 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16144         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16145         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16146         {}
16147 };
16148
16149 /* Set Unsolicited Event*/
16150 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16151         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16152         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16153         {}
16154 };
16155
16156 /*
16157  * generic initialization of ADC, input mixers and output mixers
16158  */
16159 static struct hda_verb alc662_auto_init_verbs[] = {
16160         /*
16161          * Unmute ADC and set the default input to mic-in
16162          */
16163         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16164         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16165
16166         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16167          * mixer widget
16168          * Note: PASD motherboards uses the Line In 2 as the input for front
16169          * panel mic (mic 2)
16170          */
16171         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16172         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16173         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16174         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16175         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16176         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16177
16178         /*
16179          * Set up output mixers (0x0c - 0x0f)
16180          */
16181         /* set vol=0 to output mixers */
16182         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16183         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16184         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16185
16186         /* set up input amps for analog loopback */
16187         /* Amp Indices: DAC = 0, mixer = 1 */
16188         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16189         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16190         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16191         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16192         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16193         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16194
16195
16196         /* FIXME: use matrix-type input source selection */
16197         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16198         /* Input mixer */
16199         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16201         { }
16202 };
16203
16204 /* additional verbs for ALC663 */
16205 static struct hda_verb alc663_auto_init_verbs[] = {
16206         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16207         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16208         { }
16209 };
16210
16211 static struct hda_verb alc663_m51va_init_verbs[] = {
16212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16213         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16214         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16215         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16216         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16218         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16219         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16220         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16221         {}
16222 };
16223
16224 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16225         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16226         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16227         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16228         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16229         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16230         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16231         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16232         {}
16233 };
16234
16235 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16236         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16237         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16238         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16239         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16240         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16241         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16242         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16243         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16244         {}
16245 };
16246
16247 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16248         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16249         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16250         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16251         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16252         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16253         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16254         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16255         {}
16256 };
16257
16258 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16259         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16260         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16261         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16262         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16263         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16264         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16265         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16266         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16267         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16268         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16269         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16270         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16271         {}
16272 };
16273
16274 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16275         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16276         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16277         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16278         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16279         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16280         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16281         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16282         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16283         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16284         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16285         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16286         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16287         {}
16288 };
16289
16290 static struct hda_verb alc663_g71v_init_verbs[] = {
16291         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16292         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16293         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16294
16295         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16296         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16297         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16298
16299         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16300         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16301         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16302         {}
16303 };
16304
16305 static struct hda_verb alc663_g50v_init_verbs[] = {
16306         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16307         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16308         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16309
16310         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16311         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16312         {}
16313 };
16314
16315 static struct hda_verb alc662_ecs_init_verbs[] = {
16316         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16317         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16318         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16319         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16320         {}
16321 };
16322
16323 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16324         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16325         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16326         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16327         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16328         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16329         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16330         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16331         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16332         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16333         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16334         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16335         {}
16336 };
16337
16338 static struct hda_verb alc272_dell_init_verbs[] = {
16339         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16340         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16341         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16342         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16343         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16344         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16345         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16346         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16347         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16348         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16349         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16350         {}
16351 };
16352
16353 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16354         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16355         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16356         { } /* end */
16357 };
16358
16359 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16360         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16361         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16362         { } /* end */
16363 };
16364
16365 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16366 {
16367         unsigned int present;
16368         unsigned char bits;
16369
16370         present = snd_hda_codec_read(codec, 0x14, 0,
16371                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16372         bits = present ? HDA_AMP_MUTE : 0;
16373         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16374                                  HDA_AMP_MUTE, bits);
16375 }
16376
16377 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16378 {
16379         unsigned int present;
16380         unsigned char bits;
16381
16382         present = snd_hda_codec_read(codec, 0x1b, 0,
16383                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16384         bits = present ? HDA_AMP_MUTE : 0;
16385         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16386                                  HDA_AMP_MUTE, bits);
16387         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16388                                  HDA_AMP_MUTE, bits);
16389 }
16390
16391 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16392                                            unsigned int res)
16393 {
16394         if ((res >> 26) == ALC880_HP_EVENT)
16395                 alc662_lenovo_101e_all_automute(codec);
16396         if ((res >> 26) == ALC880_FRONT_EVENT)
16397                 alc662_lenovo_101e_ispeaker_automute(codec);
16398 }
16399
16400 /* unsolicited event for HP jack sensing */
16401 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16402                                      unsigned int res)
16403 {
16404         if ((res >> 26) == ALC880_MIC_EVENT)
16405                 alc_mic_automute(codec);
16406         else
16407                 alc262_hippo_unsol_event(codec, res);
16408 }
16409
16410 static void alc662_eeepc_setup(struct hda_codec *codec)
16411 {
16412         struct alc_spec *spec = codec->spec;
16413
16414         alc262_hippo1_setup(codec);
16415         spec->ext_mic.pin = 0x18;
16416         spec->ext_mic.mux_idx = 0;
16417         spec->int_mic.pin = 0x19;
16418         spec->int_mic.mux_idx = 1;
16419         spec->auto_mic = 1;
16420 }
16421
16422 static void alc662_eeepc_inithook(struct hda_codec *codec)
16423 {
16424         alc262_hippo_automute(codec);
16425         alc_mic_automute(codec);
16426 }
16427
16428 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16429 {
16430         struct alc_spec *spec = codec->spec;
16431
16432         spec->autocfg.hp_pins[0] = 0x14;
16433         spec->autocfg.speaker_pins[0] = 0x1b;
16434 }
16435
16436 #define alc662_eeepc_ep20_inithook      alc262_hippo_master_update
16437
16438 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16439 {
16440         unsigned int present;
16441         unsigned char bits;
16442
16443         present = snd_hda_codec_read(codec, 0x21, 0,
16444                         AC_VERB_GET_PIN_SENSE, 0)
16445                         & AC_PINSENSE_PRESENCE;
16446         bits = present ? HDA_AMP_MUTE : 0;
16447         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16448                                 AMP_IN_MUTE(0), bits);
16449         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16450                                 AMP_IN_MUTE(0), bits);
16451 }
16452
16453 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16454 {
16455         unsigned int present;
16456         unsigned char bits;
16457
16458         present = snd_hda_codec_read(codec, 0x21, 0,
16459                         AC_VERB_GET_PIN_SENSE, 0)
16460                         & AC_PINSENSE_PRESENCE;
16461         bits = present ? HDA_AMP_MUTE : 0;
16462         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16463                                 AMP_IN_MUTE(0), bits);
16464         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16465                                 AMP_IN_MUTE(0), bits);
16466         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16467                                 AMP_IN_MUTE(0), bits);
16468         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16469                                 AMP_IN_MUTE(0), bits);
16470 }
16471
16472 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16473 {
16474         unsigned int present;
16475         unsigned char bits;
16476
16477         present = snd_hda_codec_read(codec, 0x15, 0,
16478                         AC_VERB_GET_PIN_SENSE, 0)
16479                         & AC_PINSENSE_PRESENCE;
16480         bits = present ? HDA_AMP_MUTE : 0;
16481         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16482                                 AMP_IN_MUTE(0), bits);
16483         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16484                                 AMP_IN_MUTE(0), bits);
16485         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16486                                 AMP_IN_MUTE(0), bits);
16487         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16488                                 AMP_IN_MUTE(0), bits);
16489 }
16490
16491 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16492 {
16493         unsigned int present;
16494         unsigned char bits;
16495
16496         present = snd_hda_codec_read(codec, 0x1b, 0,
16497                         AC_VERB_GET_PIN_SENSE, 0)
16498                         & AC_PINSENSE_PRESENCE;
16499         bits = present ? 0 : PIN_OUT;
16500         snd_hda_codec_write(codec, 0x14, 0,
16501                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16502 }
16503
16504 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16505 {
16506         unsigned int present1, present2;
16507
16508         present1 = snd_hda_codec_read(codec, 0x21, 0,
16509                         AC_VERB_GET_PIN_SENSE, 0)
16510                         & AC_PINSENSE_PRESENCE;
16511         present2 = snd_hda_codec_read(codec, 0x15, 0,
16512                         AC_VERB_GET_PIN_SENSE, 0)
16513                         & AC_PINSENSE_PRESENCE;
16514
16515         if (present1 || present2) {
16516                 snd_hda_codec_write_cache(codec, 0x14, 0,
16517                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16518         } else {
16519                 snd_hda_codec_write_cache(codec, 0x14, 0,
16520                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16521         }
16522 }
16523
16524 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16525 {
16526         unsigned int present1, present2;
16527
16528         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16529                                 AC_VERB_GET_PIN_SENSE, 0)
16530                                 & AC_PINSENSE_PRESENCE;
16531         present2 = snd_hda_codec_read(codec, 0x15, 0,
16532                                 AC_VERB_GET_PIN_SENSE, 0)
16533                                 & AC_PINSENSE_PRESENCE;
16534
16535         if (present1 || present2) {
16536                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16537                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16538                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16539                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16540         } else {
16541                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16542                                 AMP_IN_MUTE(0), 0);
16543                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16544                                 AMP_IN_MUTE(0), 0);
16545         }
16546 }
16547
16548 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16549                                            unsigned int res)
16550 {
16551         switch (res >> 26) {
16552         case ALC880_HP_EVENT:
16553                 alc663_m51va_speaker_automute(codec);
16554                 break;
16555         case ALC880_MIC_EVENT:
16556                 alc_mic_automute(codec);
16557                 break;
16558         }
16559 }
16560
16561 static void alc663_m51va_setup(struct hda_codec *codec)
16562 {
16563         struct alc_spec *spec = codec->spec;
16564         spec->ext_mic.pin = 0x18;
16565         spec->ext_mic.mux_idx = 0;
16566         spec->int_mic.pin = 0x12;
16567         spec->int_mic.mux_idx = 1;
16568         spec->auto_mic = 1;
16569 }
16570
16571 static void alc663_m51va_inithook(struct hda_codec *codec)
16572 {
16573         alc663_m51va_speaker_automute(codec);
16574         alc_mic_automute(codec);
16575 }
16576
16577 /* ***************** Mode1 ******************************/
16578 #define alc663_mode1_unsol_event        alc663_m51va_unsol_event
16579 #define alc663_mode1_setup              alc663_m51va_setup
16580 #define alc663_mode1_inithook           alc663_m51va_inithook
16581
16582 /* ***************** Mode2 ******************************/
16583 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16584                                            unsigned int res)
16585 {
16586         switch (res >> 26) {
16587         case ALC880_HP_EVENT:
16588                 alc662_f5z_speaker_automute(codec);
16589                 break;
16590         case ALC880_MIC_EVENT:
16591                 alc_mic_automute(codec);
16592                 break;
16593         }
16594 }
16595
16596 #define alc662_mode2_setup      alc663_m51va_setup
16597
16598 static void alc662_mode2_inithook(struct hda_codec *codec)
16599 {
16600         alc662_f5z_speaker_automute(codec);
16601         alc_mic_automute(codec);
16602 }
16603 /* ***************** Mode3 ******************************/
16604 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16605                                            unsigned int res)
16606 {
16607         switch (res >> 26) {
16608         case ALC880_HP_EVENT:
16609                 alc663_two_hp_m1_speaker_automute(codec);
16610                 break;
16611         case ALC880_MIC_EVENT:
16612                 alc_mic_automute(codec);
16613                 break;
16614         }
16615 }
16616
16617 #define alc663_mode3_setup      alc663_m51va_setup
16618
16619 static void alc663_mode3_inithook(struct hda_codec *codec)
16620 {
16621         alc663_two_hp_m1_speaker_automute(codec);
16622         alc_mic_automute(codec);
16623 }
16624 /* ***************** Mode4 ******************************/
16625 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16626                                            unsigned int res)
16627 {
16628         switch (res >> 26) {
16629         case ALC880_HP_EVENT:
16630                 alc663_21jd_two_speaker_automute(codec);
16631                 break;
16632         case ALC880_MIC_EVENT:
16633                 alc_mic_automute(codec);
16634                 break;
16635         }
16636 }
16637
16638 #define alc663_mode4_setup      alc663_m51va_setup
16639
16640 static void alc663_mode4_inithook(struct hda_codec *codec)
16641 {
16642         alc663_21jd_two_speaker_automute(codec);
16643         alc_mic_automute(codec);
16644 }
16645 /* ***************** Mode5 ******************************/
16646 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16647                                            unsigned int res)
16648 {
16649         switch (res >> 26) {
16650         case ALC880_HP_EVENT:
16651                 alc663_15jd_two_speaker_automute(codec);
16652                 break;
16653         case ALC880_MIC_EVENT:
16654                 alc_mic_automute(codec);
16655                 break;
16656         }
16657 }
16658
16659 #define alc663_mode5_setup      alc663_m51va_setup
16660
16661 static void alc663_mode5_inithook(struct hda_codec *codec)
16662 {
16663         alc663_15jd_two_speaker_automute(codec);
16664         alc_mic_automute(codec);
16665 }
16666 /* ***************** Mode6 ******************************/
16667 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16668                                            unsigned int res)
16669 {
16670         switch (res >> 26) {
16671         case ALC880_HP_EVENT:
16672                 alc663_two_hp_m2_speaker_automute(codec);
16673                 break;
16674         case ALC880_MIC_EVENT:
16675                 alc_mic_automute(codec);
16676                 break;
16677         }
16678 }
16679
16680 #define alc663_mode6_setup      alc663_m51va_setup
16681
16682 static void alc663_mode6_inithook(struct hda_codec *codec)
16683 {
16684         alc663_two_hp_m2_speaker_automute(codec);
16685         alc_mic_automute(codec);
16686 }
16687
16688 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16689 {
16690         unsigned int present;
16691         unsigned char bits;
16692
16693         present = snd_hda_codec_read(codec, 0x21, 0,
16694                                      AC_VERB_GET_PIN_SENSE, 0)
16695                 & AC_PINSENSE_PRESENCE;
16696         bits = present ? HDA_AMP_MUTE : 0;
16697         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16698                                  HDA_AMP_MUTE, bits);
16699         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16700                                  HDA_AMP_MUTE, bits);
16701 }
16702
16703 static void alc663_g71v_front_automute(struct hda_codec *codec)
16704 {
16705         unsigned int present;
16706         unsigned char bits;
16707
16708         present = snd_hda_codec_read(codec, 0x15, 0,
16709                                      AC_VERB_GET_PIN_SENSE, 0)
16710                 & AC_PINSENSE_PRESENCE;
16711         bits = present ? HDA_AMP_MUTE : 0;
16712         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16713                                  HDA_AMP_MUTE, bits);
16714 }
16715
16716 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16717                                            unsigned int res)
16718 {
16719         switch (res >> 26) {
16720         case ALC880_HP_EVENT:
16721                 alc663_g71v_hp_automute(codec);
16722                 break;
16723         case ALC880_FRONT_EVENT:
16724                 alc663_g71v_front_automute(codec);
16725                 break;
16726         case ALC880_MIC_EVENT:
16727                 alc_mic_automute(codec);
16728                 break;
16729         }
16730 }
16731
16732 #define alc663_g71v_setup       alc663_m51va_setup
16733
16734 static void alc663_g71v_inithook(struct hda_codec *codec)
16735 {
16736         alc663_g71v_front_automute(codec);
16737         alc663_g71v_hp_automute(codec);
16738         alc_mic_automute(codec);
16739 }
16740
16741 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16742                                            unsigned int res)
16743 {
16744         switch (res >> 26) {
16745         case ALC880_HP_EVENT:
16746                 alc663_m51va_speaker_automute(codec);
16747                 break;
16748         case ALC880_MIC_EVENT:
16749                 alc_mic_automute(codec);
16750                 break;
16751         }
16752 }
16753
16754 #define alc663_g50v_setup       alc663_m51va_setup
16755
16756 static void alc663_g50v_inithook(struct hda_codec *codec)
16757 {
16758         alc663_m51va_speaker_automute(codec);
16759         alc_mic_automute(codec);
16760 }
16761
16762 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16763         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16764         ALC262_HIPPO_MASTER_SWITCH,
16765
16766         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16767         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16768         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16769
16770         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16771         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16772         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16773         { } /* end */
16774 };
16775
16776 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16777         /* Master Playback automatically created from Speaker and Headphone */
16778         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16779         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16780         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16781         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16782
16783         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16784         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16785         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16786
16787         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16788         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16789         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16790         { } /* end */
16791 };
16792
16793 #ifdef CONFIG_SND_HDA_POWER_SAVE
16794 #define alc662_loopbacks        alc880_loopbacks
16795 #endif
16796
16797
16798 /* pcm configuration: identical with ALC880 */
16799 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16800 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16801 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16802 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16803
16804 /*
16805  * configuration and preset
16806  */
16807 static const char *alc662_models[ALC662_MODEL_LAST] = {
16808         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16809         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16810         [ALC662_3ST_6ch]        = "3stack-6ch",
16811         [ALC662_5ST_DIG]        = "6stack-dig",
16812         [ALC662_LENOVO_101E]    = "lenovo-101e",
16813         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16814         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16815         [ALC662_ECS] = "ecs",
16816         [ALC663_ASUS_M51VA] = "m51va",
16817         [ALC663_ASUS_G71V] = "g71v",
16818         [ALC663_ASUS_H13] = "h13",
16819         [ALC663_ASUS_G50V] = "g50v",
16820         [ALC663_ASUS_MODE1] = "asus-mode1",
16821         [ALC662_ASUS_MODE2] = "asus-mode2",
16822         [ALC663_ASUS_MODE3] = "asus-mode3",
16823         [ALC663_ASUS_MODE4] = "asus-mode4",
16824         [ALC663_ASUS_MODE5] = "asus-mode5",
16825         [ALC663_ASUS_MODE6] = "asus-mode6",
16826         [ALC272_DELL]           = "dell",
16827         [ALC272_DELL_ZM1]       = "dell-zm1",
16828         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16829         [ALC662_AUTO]           = "auto",
16830 };
16831
16832 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16833         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16834         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16835         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16836         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16837         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16838         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16839         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16840         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16841         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16842         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16843         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16844         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16845         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16846         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16847         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16848         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16849         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16850         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16851         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16852         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16853         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16854         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16855         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16856         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16857         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16858         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16859         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16860         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16861         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16862         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16863         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16864         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16865         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16866         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16867         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16868         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16869         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16870         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16871         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16872         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16873         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16874         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16875         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16876         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16877         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16878         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16879         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16880         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16881         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16882         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16883         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16884         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16885                       ALC662_3ST_6ch_DIG),
16886         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4),
16887         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16888         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16889                       ALC662_3ST_6ch_DIG),
16890         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16891         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16892         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16893         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16894                                         ALC662_3ST_6ch_DIG),
16895         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16896                            ALC663_ASUS_H13),
16897         {}
16898 };
16899
16900 static struct alc_config_preset alc662_presets[] = {
16901         [ALC662_3ST_2ch_DIG] = {
16902                 .mixers = { alc662_3ST_2ch_mixer },
16903                 .init_verbs = { alc662_init_verbs },
16904                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16905                 .dac_nids = alc662_dac_nids,
16906                 .dig_out_nid = ALC662_DIGOUT_NID,
16907                 .dig_in_nid = ALC662_DIGIN_NID,
16908                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16909                 .channel_mode = alc662_3ST_2ch_modes,
16910                 .input_mux = &alc662_capture_source,
16911         },
16912         [ALC662_3ST_6ch_DIG] = {
16913                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16914                 .init_verbs = { alc662_init_verbs },
16915                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16916                 .dac_nids = alc662_dac_nids,
16917                 .dig_out_nid = ALC662_DIGOUT_NID,
16918                 .dig_in_nid = ALC662_DIGIN_NID,
16919                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16920                 .channel_mode = alc662_3ST_6ch_modes,
16921                 .need_dac_fix = 1,
16922                 .input_mux = &alc662_capture_source,
16923         },
16924         [ALC662_3ST_6ch] = {
16925                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16926                 .init_verbs = { alc662_init_verbs },
16927                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16928                 .dac_nids = alc662_dac_nids,
16929                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16930                 .channel_mode = alc662_3ST_6ch_modes,
16931                 .need_dac_fix = 1,
16932                 .input_mux = &alc662_capture_source,
16933         },
16934         [ALC662_5ST_DIG] = {
16935                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16936                 .init_verbs = { alc662_init_verbs },
16937                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16938                 .dac_nids = alc662_dac_nids,
16939                 .dig_out_nid = ALC662_DIGOUT_NID,
16940                 .dig_in_nid = ALC662_DIGIN_NID,
16941                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16942                 .channel_mode = alc662_5stack_modes,
16943                 .input_mux = &alc662_capture_source,
16944         },
16945         [ALC662_LENOVO_101E] = {
16946                 .mixers = { alc662_lenovo_101e_mixer },
16947                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16948                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16949                 .dac_nids = alc662_dac_nids,
16950                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16951                 .channel_mode = alc662_3ST_2ch_modes,
16952                 .input_mux = &alc662_lenovo_101e_capture_source,
16953                 .unsol_event = alc662_lenovo_101e_unsol_event,
16954                 .init_hook = alc662_lenovo_101e_all_automute,
16955         },
16956         [ALC662_ASUS_EEEPC_P701] = {
16957                 .mixers = { alc662_eeepc_p701_mixer },
16958                 .init_verbs = { alc662_init_verbs,
16959                                 alc662_eeepc_sue_init_verbs },
16960                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16961                 .dac_nids = alc662_dac_nids,
16962                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16963                 .channel_mode = alc662_3ST_2ch_modes,
16964                 .unsol_event = alc662_eeepc_unsol_event,
16965                 .setup = alc662_eeepc_setup,
16966                 .init_hook = alc662_eeepc_inithook,
16967         },
16968         [ALC662_ASUS_EEEPC_EP20] = {
16969                 .mixers = { alc662_eeepc_ep20_mixer,
16970                             alc662_chmode_mixer },
16971                 .init_verbs = { alc662_init_verbs,
16972                                 alc662_eeepc_ep20_sue_init_verbs },
16973                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16974                 .dac_nids = alc662_dac_nids,
16975                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16976                 .channel_mode = alc662_3ST_6ch_modes,
16977                 .input_mux = &alc662_lenovo_101e_capture_source,
16978                 .unsol_event = alc662_eeepc_unsol_event,
16979                 .setup = alc662_eeepc_ep20_setup,
16980                 .init_hook = alc662_eeepc_ep20_inithook,
16981         },
16982         [ALC662_ECS] = {
16983                 .mixers = { alc662_ecs_mixer },
16984                 .init_verbs = { alc662_init_verbs,
16985                                 alc662_ecs_init_verbs },
16986                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16987                 .dac_nids = alc662_dac_nids,
16988                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16989                 .channel_mode = alc662_3ST_2ch_modes,
16990                 .unsol_event = alc662_eeepc_unsol_event,
16991                 .setup = alc662_eeepc_setup,
16992                 .init_hook = alc662_eeepc_inithook,
16993         },
16994         [ALC663_ASUS_M51VA] = {
16995                 .mixers = { alc663_m51va_mixer },
16996                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16997                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16998                 .dac_nids = alc662_dac_nids,
16999                 .dig_out_nid = ALC662_DIGOUT_NID,
17000                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17001                 .channel_mode = alc662_3ST_2ch_modes,
17002                 .unsol_event = alc663_m51va_unsol_event,
17003                 .setup = alc663_m51va_setup,
17004                 .init_hook = alc663_m51va_inithook,
17005         },
17006         [ALC663_ASUS_G71V] = {
17007                 .mixers = { alc663_g71v_mixer },
17008                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
17009                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17010                 .dac_nids = alc662_dac_nids,
17011                 .dig_out_nid = ALC662_DIGOUT_NID,
17012                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17013                 .channel_mode = alc662_3ST_2ch_modes,
17014                 .unsol_event = alc663_g71v_unsol_event,
17015                 .setup = alc663_g71v_setup,
17016                 .init_hook = alc663_g71v_inithook,
17017         },
17018         [ALC663_ASUS_H13] = {
17019                 .mixers = { alc663_m51va_mixer },
17020                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
17021                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17022                 .dac_nids = alc662_dac_nids,
17023                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17024                 .channel_mode = alc662_3ST_2ch_modes,
17025                 .unsol_event = alc663_m51va_unsol_event,
17026                 .init_hook = alc663_m51va_inithook,
17027         },
17028         [ALC663_ASUS_G50V] = {
17029                 .mixers = { alc663_g50v_mixer },
17030                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
17031                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17032                 .dac_nids = alc662_dac_nids,
17033                 .dig_out_nid = ALC662_DIGOUT_NID,
17034                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
17035                 .channel_mode = alc662_3ST_6ch_modes,
17036                 .input_mux = &alc663_capture_source,
17037                 .unsol_event = alc663_g50v_unsol_event,
17038                 .setup = alc663_g50v_setup,
17039                 .init_hook = alc663_g50v_inithook,
17040         },
17041         [ALC663_ASUS_MODE1] = {
17042                 .mixers = { alc663_m51va_mixer },
17043                 .cap_mixer = alc662_auto_capture_mixer,
17044                 .init_verbs = { alc662_init_verbs,
17045                                 alc663_21jd_amic_init_verbs },
17046                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17047                 .hp_nid = 0x03,
17048                 .dac_nids = alc662_dac_nids,
17049                 .dig_out_nid = ALC662_DIGOUT_NID,
17050                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17051                 .channel_mode = alc662_3ST_2ch_modes,
17052                 .unsol_event = alc663_mode1_unsol_event,
17053                 .setup = alc663_mode1_setup,
17054                 .init_hook = alc663_mode1_inithook,
17055         },
17056         [ALC662_ASUS_MODE2] = {
17057                 .mixers = { alc662_1bjd_mixer },
17058                 .cap_mixer = alc662_auto_capture_mixer,
17059                 .init_verbs = { alc662_init_verbs,
17060                                 alc662_1bjd_amic_init_verbs },
17061                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
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 = alc662_mode2_unsol_event,
17067                 .setup = alc662_mode2_setup,
17068                 .init_hook = alc662_mode2_inithook,
17069         },
17070         [ALC663_ASUS_MODE3] = {
17071                 .mixers = { alc663_two_hp_m1_mixer },
17072                 .cap_mixer = alc662_auto_capture_mixer,
17073                 .init_verbs = { alc662_init_verbs,
17074                                 alc663_two_hp_amic_m1_init_verbs },
17075                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17076                 .hp_nid = 0x03,
17077                 .dac_nids = alc662_dac_nids,
17078                 .dig_out_nid = ALC662_DIGOUT_NID,
17079                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17080                 .channel_mode = alc662_3ST_2ch_modes,
17081                 .unsol_event = alc663_mode3_unsol_event,
17082                 .setup = alc663_mode3_setup,
17083                 .init_hook = alc663_mode3_inithook,
17084         },
17085         [ALC663_ASUS_MODE4] = {
17086                 .mixers = { alc663_asus_21jd_clfe_mixer },
17087                 .cap_mixer = alc662_auto_capture_mixer,
17088                 .init_verbs = { alc662_init_verbs,
17089                                 alc663_21jd_amic_init_verbs},
17090                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17091                 .hp_nid = 0x03,
17092                 .dac_nids = alc662_dac_nids,
17093                 .dig_out_nid = ALC662_DIGOUT_NID,
17094                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17095                 .channel_mode = alc662_3ST_2ch_modes,
17096                 .unsol_event = alc663_mode4_unsol_event,
17097                 .setup = alc663_mode4_setup,
17098                 .init_hook = alc663_mode4_inithook,
17099         },
17100         [ALC663_ASUS_MODE5] = {
17101                 .mixers = { alc663_asus_15jd_clfe_mixer },
17102                 .cap_mixer = alc662_auto_capture_mixer,
17103                 .init_verbs = { alc662_init_verbs,
17104                                 alc663_15jd_amic_init_verbs },
17105                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17106                 .hp_nid = 0x03,
17107                 .dac_nids = alc662_dac_nids,
17108                 .dig_out_nid = ALC662_DIGOUT_NID,
17109                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17110                 .channel_mode = alc662_3ST_2ch_modes,
17111                 .unsol_event = alc663_mode5_unsol_event,
17112                 .setup = alc663_mode5_setup,
17113                 .init_hook = alc663_mode5_inithook,
17114         },
17115         [ALC663_ASUS_MODE6] = {
17116                 .mixers = { alc663_two_hp_m2_mixer },
17117                 .cap_mixer = alc662_auto_capture_mixer,
17118                 .init_verbs = { alc662_init_verbs,
17119                                 alc663_two_hp_amic_m2_init_verbs },
17120                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17121                 .hp_nid = 0x03,
17122                 .dac_nids = alc662_dac_nids,
17123                 .dig_out_nid = ALC662_DIGOUT_NID,
17124                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17125                 .channel_mode = alc662_3ST_2ch_modes,
17126                 .unsol_event = alc663_mode6_unsol_event,
17127                 .setup = alc663_mode6_setup,
17128                 .init_hook = alc663_mode6_inithook,
17129         },
17130         [ALC272_DELL] = {
17131                 .mixers = { alc663_m51va_mixer },
17132                 .cap_mixer = alc272_auto_capture_mixer,
17133                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17134                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17135                 .dac_nids = alc662_dac_nids,
17136                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17137                 .adc_nids = alc272_adc_nids,
17138                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17139                 .capsrc_nids = alc272_capsrc_nids,
17140                 .channel_mode = alc662_3ST_2ch_modes,
17141                 .unsol_event = alc663_m51va_unsol_event,
17142                 .setup = alc663_m51va_setup,
17143                 .init_hook = alc663_m51va_inithook,
17144         },
17145         [ALC272_DELL_ZM1] = {
17146                 .mixers = { alc663_m51va_mixer },
17147                 .cap_mixer = alc662_auto_capture_mixer,
17148                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17149                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17150                 .dac_nids = alc662_dac_nids,
17151                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17152                 .adc_nids = alc662_adc_nids,
17153                 .num_adc_nids = 1,
17154                 .capsrc_nids = alc662_capsrc_nids,
17155                 .channel_mode = alc662_3ST_2ch_modes,
17156                 .unsol_event = alc663_m51va_unsol_event,
17157                 .setup = alc663_m51va_setup,
17158                 .init_hook = alc663_m51va_inithook,
17159         },
17160         [ALC272_SAMSUNG_NC10] = {
17161                 .mixers = { alc272_nc10_mixer },
17162                 .init_verbs = { alc662_init_verbs,
17163                                 alc663_21jd_amic_init_verbs },
17164                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17165                 .dac_nids = alc272_dac_nids,
17166                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17167                 .channel_mode = alc662_3ST_2ch_modes,
17168                 /*.input_mux = &alc272_nc10_capture_source,*/
17169                 .unsol_event = alc663_mode4_unsol_event,
17170                 .setup = alc663_mode4_setup,
17171                 .init_hook = alc663_mode4_inithook,
17172         },
17173 };
17174
17175
17176 /*
17177  * BIOS auto configuration
17178  */
17179
17180 /* convert from MIX nid to DAC */
17181 static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
17182 {
17183         if (nid == 0x0f)
17184                 return 0x02;
17185         else if (nid >= 0x0c && nid <= 0x0e)
17186                 return nid - 0x0c + 0x02;
17187         else
17188                 return 0;
17189 }
17190
17191 /* get MIX nid connected to the given pin targeted to DAC */
17192 static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
17193                                    hda_nid_t dac)
17194 {
17195         hda_nid_t mix[4];
17196         int i, num;
17197
17198         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
17199         for (i = 0; i < num; i++) {
17200                 if (alc662_mix_to_dac(mix[i]) == dac)
17201                         return mix[i];
17202         }
17203         return 0;
17204 }
17205
17206 /* look for an empty DAC slot */
17207 static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
17208 {
17209         struct alc_spec *spec = codec->spec;
17210         hda_nid_t srcs[5];
17211         int i, j, num;
17212
17213         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
17214         if (num < 0)
17215                 return 0;
17216         for (i = 0; i < num; i++) {
17217                 hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
17218                 if (!nid)
17219                         continue;
17220                 for (j = 0; j < spec->multiout.num_dacs; j++)
17221                         if (spec->multiout.dac_nids[j] == nid)
17222                                 break;
17223                 if (j >= spec->multiout.num_dacs)
17224                         return nid;
17225         }
17226         return 0;
17227 }
17228
17229 /* fill in the dac_nids table from the parsed pin configuration */
17230 static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17231                                      const struct auto_pin_cfg *cfg)
17232 {
17233         struct alc_spec *spec = codec->spec;
17234         int i;
17235         hda_nid_t dac;
17236
17237         spec->multiout.dac_nids = spec->private_dac_nids;
17238         for (i = 0; i < cfg->line_outs; i++) {
17239                 dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
17240                 if (!dac)
17241                         continue;
17242                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
17243         }
17244         return 0;
17245 }
17246
17247 static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17248                               hda_nid_t nid, unsigned int chs)
17249 {
17250         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17251                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17252 }
17253
17254 static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17255                              hda_nid_t nid, unsigned int chs)
17256 {
17257         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17258                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17259 }
17260
17261 #define alc662_add_stereo_vol(spec, pfx, nid) \
17262         alc662_add_vol_ctl(spec, pfx, nid, 3)
17263 #define alc662_add_stereo_sw(spec, pfx, nid) \
17264         alc662_add_sw_ctl(spec, pfx, nid, 3)
17265
17266 /* add playback controls from the parsed DAC table */
17267 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
17268                                              const struct auto_pin_cfg *cfg)
17269 {
17270         struct alc_spec *spec = codec->spec;
17271         static const char *chname[4] = {
17272                 "Front", "Surround", NULL /*CLFE*/, "Side"
17273         };
17274         hda_nid_t nid, mix;
17275         int i, err;
17276
17277         for (i = 0; i < cfg->line_outs; i++) {
17278                 nid = spec->multiout.dac_nids[i];
17279                 if (!nid)
17280                         continue;
17281                 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
17282                 if (!mix)
17283                         continue;
17284                 if (i == 2) {
17285                         /* Center/LFE */
17286                         err = alc662_add_vol_ctl(spec, "Center", nid, 1);
17287                         if (err < 0)
17288                                 return err;
17289                         err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
17290                         if (err < 0)
17291                                 return err;
17292                         err = alc662_add_sw_ctl(spec, "Center", mix, 1);
17293                         if (err < 0)
17294                                 return err;
17295                         err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
17296                         if (err < 0)
17297                                 return err;
17298                 } else {
17299                         const char *pfx;
17300                         if (cfg->line_outs == 1 &&
17301                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17302                                 if (cfg->hp_outs)
17303                                         pfx = "Speaker";
17304                                 else
17305                                         pfx = "PCM";
17306                         } else
17307                                 pfx = chname[i];
17308                         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17309                         if (err < 0)
17310                                 return err;
17311                         if (cfg->line_outs == 1 &&
17312                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17313                                 pfx = "Speaker";
17314                         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17315                         if (err < 0)
17316                                 return err;
17317                 }
17318         }
17319         return 0;
17320 }
17321
17322 /* add playback controls for speaker and HP outputs */
17323 /* return DAC nid if any new DAC is assigned */
17324 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17325                                         const char *pfx)
17326 {
17327         struct alc_spec *spec = codec->spec;
17328         hda_nid_t nid, mix;
17329         int err;
17330
17331         if (!pin)
17332                 return 0;
17333         nid = alc662_look_for_dac(codec, pin);
17334         if (!nid) {
17335                 /* the corresponding DAC is already occupied */
17336                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17337                         return 0; /* no way */
17338                 /* create a switch only */
17339                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17340                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17341         }
17342
17343         mix = alc662_dac_to_mix(codec, pin, nid);
17344         if (!mix)
17345                 return 0;
17346         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17347         if (err < 0)
17348                 return err;
17349         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17350         if (err < 0)
17351                 return err;
17352         return nid;
17353 }
17354
17355 /* create playback/capture controls for input pins */
17356 #define alc662_auto_create_input_ctls \
17357         alc882_auto_create_input_ctls
17358
17359 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17360                                               hda_nid_t nid, int pin_type,
17361                                               hda_nid_t dac)
17362 {
17363         int i, num;
17364         hda_nid_t srcs[4];
17365
17366         alc_set_pin_output(codec, nid, pin_type);
17367         /* need the manual connection? */
17368         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
17369         if (num <= 1)
17370                 return;
17371         for (i = 0; i < num; i++) {
17372                 if (alc662_mix_to_dac(srcs[i]) != dac)
17373                         continue;
17374                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
17375                 return;
17376         }
17377 }
17378
17379 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17380 {
17381         struct alc_spec *spec = codec->spec;
17382         int pin_type = get_pin_type(spec->autocfg.line_out_type);
17383         int i;
17384
17385         for (i = 0; i <= HDA_SIDE; i++) {
17386                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17387                 if (nid)
17388                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17389                                         spec->multiout.dac_nids[i]);
17390         }
17391 }
17392
17393 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17394 {
17395         struct alc_spec *spec = codec->spec;
17396         hda_nid_t pin;
17397
17398         pin = spec->autocfg.hp_pins[0];
17399         if (pin)
17400                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
17401                                                   spec->multiout.hp_nid);
17402         pin = spec->autocfg.speaker_pins[0];
17403         if (pin)
17404                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
17405                                         spec->multiout.extra_out_nid[0]);
17406 }
17407
17408 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17409
17410 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17411 {
17412         struct alc_spec *spec = codec->spec;
17413         int i;
17414
17415         for (i = 0; i < AUTO_PIN_LAST; i++) {
17416                 hda_nid_t nid = spec->autocfg.input_pins[i];
17417                 if (alc_is_input_pin(codec, nid)) {
17418                         alc_set_input_pin(codec, nid, i);
17419                         if (nid != ALC662_PIN_CD_NID &&
17420                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17421                                 snd_hda_codec_write(codec, nid, 0,
17422                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17423                                                     AMP_OUT_MUTE);
17424                 }
17425         }
17426 }
17427
17428 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17429
17430 static int alc662_parse_auto_config(struct hda_codec *codec)
17431 {
17432         struct alc_spec *spec = codec->spec;
17433         int err;
17434         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17435
17436         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17437                                            alc662_ignore);
17438         if (err < 0)
17439                 return err;
17440         if (!spec->autocfg.line_outs)
17441                 return 0; /* can't find valid BIOS pin config */
17442
17443         err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
17444         if (err < 0)
17445                 return err;
17446         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
17447         if (err < 0)
17448                 return err;
17449         err = alc662_auto_create_extra_out(codec,
17450                                            spec->autocfg.speaker_pins[0],
17451                                            "Speaker");
17452         if (err < 0)
17453                 return err;
17454         if (err)
17455                 spec->multiout.extra_out_nid[0] = err;
17456         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
17457                                            "Headphone");
17458         if (err < 0)
17459                 return err;
17460         if (err)
17461                 spec->multiout.hp_nid = err;
17462         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17463         if (err < 0)
17464                 return err;
17465
17466         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17467
17468         if (spec->autocfg.dig_outs)
17469                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17470
17471         if (spec->kctls.list)
17472                 add_mixer(spec, spec->kctls.list);
17473
17474         spec->num_mux_defs = 1;
17475         spec->input_mux = &spec->private_imux[0];
17476
17477         add_verb(spec, alc662_auto_init_verbs);
17478         if (codec->vendor_id == 0x10ec0663)
17479                 add_verb(spec, alc663_auto_init_verbs);
17480
17481         err = alc_auto_add_mic_boost(codec);
17482         if (err < 0)
17483                 return err;
17484
17485         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17486
17487         return 1;
17488 }
17489
17490 /* additional initialization for auto-configuration model */
17491 static void alc662_auto_init(struct hda_codec *codec)
17492 {
17493         struct alc_spec *spec = codec->spec;
17494         alc662_auto_init_multi_out(codec);
17495         alc662_auto_init_hp_out(codec);
17496         alc662_auto_init_analog_input(codec);
17497         alc662_auto_init_input_src(codec);
17498         if (spec->unsol_event)
17499                 alc_inithook(codec);
17500 }
17501
17502 static int patch_alc662(struct hda_codec *codec)
17503 {
17504         struct alc_spec *spec;
17505         int err, board_config;
17506
17507         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17508         if (!spec)
17509                 return -ENOMEM;
17510
17511         codec->spec = spec;
17512
17513         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17514
17515         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17516                                                   alc662_models,
17517                                                   alc662_cfg_tbl);
17518         if (board_config < 0) {
17519                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17520                        codec->chip_name);
17521                 board_config = ALC662_AUTO;
17522         }
17523
17524         if (board_config == ALC662_AUTO) {
17525                 /* automatic parse from the BIOS config */
17526                 err = alc662_parse_auto_config(codec);
17527                 if (err < 0) {
17528                         alc_free(codec);
17529                         return err;
17530                 } else if (!err) {
17531                         printk(KERN_INFO
17532                                "hda_codec: Cannot set up configuration "
17533                                "from BIOS.  Using base mode...\n");
17534                         board_config = ALC662_3ST_2ch_DIG;
17535                 }
17536         }
17537
17538         err = snd_hda_attach_beep_device(codec, 0x1);
17539         if (err < 0) {
17540                 alc_free(codec);
17541                 return err;
17542         }
17543
17544         if (board_config != ALC662_AUTO)
17545                 setup_preset(codec, &alc662_presets[board_config]);
17546
17547         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17548         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17549
17550         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17551         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17552
17553         if (!spec->adc_nids) {
17554                 spec->adc_nids = alc662_adc_nids;
17555                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17556         }
17557         if (!spec->capsrc_nids)
17558                 spec->capsrc_nids = alc662_capsrc_nids;
17559
17560         if (!spec->cap_mixer)
17561                 set_capture_mixer(codec);
17562         if (codec->vendor_id == 0x10ec0662)
17563                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17564         else
17565                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17566
17567         spec->vmaster_nid = 0x02;
17568
17569         codec->patch_ops = alc_patch_ops;
17570         if (board_config == ALC662_AUTO)
17571                 spec->init_hook = alc662_auto_init;
17572 #ifdef CONFIG_SND_HDA_POWER_SAVE
17573         if (!spec->loopback.amplist)
17574                 spec->loopback.amplist = alc662_loopbacks;
17575 #endif
17576         codec->proc_widget_hook = print_realtek_coef;
17577
17578         return 0;
17579 }
17580
17581 /*
17582  * patch entries
17583  */
17584 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17585         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17586         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17587         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17588         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17589         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17590         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17591         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17592           .patch = patch_alc861 },
17593         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17594         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17595         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17596         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17597           .patch = patch_alc882 },
17598         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17599           .patch = patch_alc662 },
17600         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17601         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17602         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17603         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17604         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17605           .patch = patch_alc882 },
17606         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17607           .patch = patch_alc882 },
17608         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17609         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17610         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17611           .patch = patch_alc882 },
17612         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17613         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17614         {} /* terminator */
17615 };
17616
17617 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17618
17619 MODULE_LICENSE("GPL");
17620 MODULE_DESCRIPTION("Realtek HD-audio codec");
17621
17622 static struct hda_codec_preset_list realtek_list = {
17623         .preset = snd_hda_preset_realtek,
17624         .owner = THIS_MODULE,
17625 };
17626
17627 static int __init patch_realtek_init(void)
17628 {
17629         return snd_hda_add_codec_preset(&realtek_list);
17630 }
17631
17632 static void __exit patch_realtek_exit(void)
17633 {
17634         snd_hda_delete_codec_preset(&realtek_list);
17635 }
17636
17637 module_init(patch_realtek_init)
17638 module_exit(patch_realtek_exit)