Merge branch 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/vegard...
[pandora-kernel.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC882_AUTO,
212         ALC882_MODEL_LAST,
213 };
214
215 /* ALC883 models */
216 enum {
217         ALC883_3ST_2ch_DIG,
218         ALC883_3ST_6ch_DIG,
219         ALC883_3ST_6ch,
220         ALC883_6ST_DIG,
221         ALC883_TARGA_DIG,
222         ALC883_TARGA_2ch_DIG,
223         ALC883_TARGA_8ch_DIG,
224         ALC883_ACER,
225         ALC883_ACER_ASPIRE,
226         ALC888_ACER_ASPIRE_4930G,
227         ALC888_ACER_ASPIRE_8930G,
228         ALC883_MEDION,
229         ALC883_MEDION_MD2,
230         ALC883_LAPTOP_EAPD,
231         ALC883_LENOVO_101E_2ch,
232         ALC883_LENOVO_NB0763,
233         ALC888_LENOVO_MS7195_DIG,
234         ALC888_LENOVO_SKY,
235         ALC883_HAIER_W66,
236         ALC888_3ST_HP,
237         ALC888_6ST_DELL,
238         ALC883_MITAC,
239         ALC883_CLEVO_M720,
240         ALC883_FUJITSU_PI2515,
241         ALC888_FUJITSU_XA3530,
242         ALC883_3ST_6ch_INTEL,
243         ALC888_ASUS_M90V,
244         ALC888_ASUS_EEE1601,
245         ALC889A_MB31,
246         ALC1200_ASUS_P5Q,
247         ALC883_SONY_VAIO_TT,
248         ALC883_AUTO,
249         ALC883_MODEL_LAST,
250 };
251
252 /* styles of capture selection */
253 enum {
254         CAPT_MUX = 0,   /* only mux based */
255         CAPT_MIX,       /* only mixer based */
256         CAPT_1MUX_MIX,  /* first mux and other mixers */
257 };
258
259 /* for GPIO Poll */
260 #define GPIO_MASK       0x03
261
262 /* extra amp-initialization sequence types */
263 enum {
264         ALC_INIT_NONE,
265         ALC_INIT_DEFAULT,
266         ALC_INIT_GPIO1,
267         ALC_INIT_GPIO2,
268         ALC_INIT_GPIO3,
269 };
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[5];   /* initialization verbs
279                                                  * don't forget NULL
280                                                  * termination!
281                                                  */
282         unsigned int num_init_verbs;
283
284         char stream_name_analog[16];    /* 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[16];   /* 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         int capture_style;              /* capture style (CAPT_*) */
309
310         /* capture source */
311         unsigned int num_mux_defs;
312         const struct hda_input_mux *input_mux;
313         unsigned int cur_mux[3];
314
315         /* channel model */
316         const struct hda_channel_mode *channel_mode;
317         int num_channel_mode;
318         int need_dac_fix;
319         int const_channel_count;
320         int ext_channel_count;
321
322         /* PCM information */
323         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
324
325         /* dynamic controls, init_verbs and input_mux */
326         struct auto_pin_cfg autocfg;
327         struct snd_array kctls;
328         struct hda_input_mux private_imux[3];
329         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
330
331         /* hooks */
332         void (*init_hook)(struct hda_codec *codec);
333         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
334
335         /* for pin sensing */
336         unsigned int sense_updated: 1;
337         unsigned int jack_present: 1;
338         unsigned int master_sw: 1;
339
340         /* other flags */
341         unsigned int no_analog :1; /* digital I/O only */
342         int init_amp;
343
344         /* for virtual master */
345         hda_nid_t vmaster_nid;
346 #ifdef CONFIG_SND_HDA_POWER_SAVE
347         struct hda_loopback_check loopback;
348 #endif
349
350         /* for PLL fix */
351         hda_nid_t pll_nid;
352         unsigned int pll_coef_idx, pll_coef_bit;
353 };
354
355 /*
356  * configuration template - to be copied to the spec instance
357  */
358 struct alc_config_preset {
359         struct snd_kcontrol_new *mixers[5]; /* should be identical size
360                                              * with spec
361                                              */
362         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
363         const struct hda_verb *init_verbs[5];
364         unsigned int num_dacs;
365         hda_nid_t *dac_nids;
366         hda_nid_t dig_out_nid;          /* optional */
367         hda_nid_t hp_nid;               /* optional */
368         hda_nid_t *slave_dig_outs;
369         unsigned int num_adc_nids;
370         hda_nid_t *adc_nids;
371         hda_nid_t *capsrc_nids;
372         hda_nid_t dig_in_nid;
373         unsigned int num_channel_mode;
374         const struct hda_channel_mode *channel_mode;
375         int need_dac_fix;
376         int const_channel_count;
377         unsigned int num_mux_defs;
378         const struct hda_input_mux *input_mux;
379         void (*unsol_event)(struct hda_codec *, unsigned int);
380         void (*init_hook)(struct hda_codec *);
381 #ifdef CONFIG_SND_HDA_POWER_SAVE
382         struct hda_amp_list *loopbacks;
383 #endif
384 };
385
386
387 /*
388  * input MUX handling
389  */
390 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
391                              struct snd_ctl_elem_info *uinfo)
392 {
393         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
394         struct alc_spec *spec = codec->spec;
395         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
396         if (mux_idx >= spec->num_mux_defs)
397                 mux_idx = 0;
398         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
399 }
400
401 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
402                             struct snd_ctl_elem_value *ucontrol)
403 {
404         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
405         struct alc_spec *spec = codec->spec;
406         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
407
408         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
409         return 0;
410 }
411
412 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
413                             struct snd_ctl_elem_value *ucontrol)
414 {
415         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
416         struct alc_spec *spec = codec->spec;
417         const struct hda_input_mux *imux;
418         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
419         unsigned int mux_idx;
420         hda_nid_t nid = spec->capsrc_nids ?
421                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
422
423         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
424         imux = &spec->input_mux[mux_idx];
425
426         if (spec->capture_style &&
427             !(spec->capture_style == CAPT_1MUX_MIX && !adc_idx)) {
428                 /* Matrix-mixer style (e.g. ALC882) */
429                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
430                 unsigned int i, idx;
431
432                 idx = ucontrol->value.enumerated.item[0];
433                 if (idx >= imux->num_items)
434                         idx = imux->num_items - 1;
435                 if (*cur_val == idx)
436                         return 0;
437                 for (i = 0; i < imux->num_items; i++) {
438                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
439                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
440                                                  imux->items[i].index,
441                                                  HDA_AMP_MUTE, v);
442                 }
443                 *cur_val = idx;
444                 return 1;
445         } else {
446                 /* MUX style (e.g. ALC880) */
447                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
448                                              &spec->cur_mux[adc_idx]);
449         }
450 }
451
452 /*
453  * channel mode setting
454  */
455 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
456                             struct snd_ctl_elem_info *uinfo)
457 {
458         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
459         struct alc_spec *spec = codec->spec;
460         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
461                                     spec->num_channel_mode);
462 }
463
464 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
465                            struct snd_ctl_elem_value *ucontrol)
466 {
467         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
468         struct alc_spec *spec = codec->spec;
469         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
470                                    spec->num_channel_mode,
471                                    spec->ext_channel_count);
472 }
473
474 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
475                            struct snd_ctl_elem_value *ucontrol)
476 {
477         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
478         struct alc_spec *spec = codec->spec;
479         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
480                                       spec->num_channel_mode,
481                                       &spec->ext_channel_count);
482         if (err >= 0 && !spec->const_channel_count) {
483                 spec->multiout.max_channels = spec->ext_channel_count;
484                 if (spec->need_dac_fix)
485                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
486         }
487         return err;
488 }
489
490 /*
491  * Control the mode of pin widget settings via the mixer.  "pc" is used
492  * instead of "%" to avoid consequences of accidently treating the % as
493  * being part of a format specifier.  Maximum allowed length of a value is
494  * 63 characters plus NULL terminator.
495  *
496  * Note: some retasking pin complexes seem to ignore requests for input
497  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
498  * are requested.  Therefore order this list so that this behaviour will not
499  * cause problems when mixer clients move through the enum sequentially.
500  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
501  * March 2006.
502  */
503 static char *alc_pin_mode_names[] = {
504         "Mic 50pc bias", "Mic 80pc bias",
505         "Line in", "Line out", "Headphone out",
506 };
507 static unsigned char alc_pin_mode_values[] = {
508         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
509 };
510 /* The control can present all 5 options, or it can limit the options based
511  * in the pin being assumed to be exclusively an input or an output pin.  In
512  * addition, "input" pins may or may not process the mic bias option
513  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
514  * accept requests for bias as of chip versions up to March 2006) and/or
515  * wiring in the computer.
516  */
517 #define ALC_PIN_DIR_IN              0x00
518 #define ALC_PIN_DIR_OUT             0x01
519 #define ALC_PIN_DIR_INOUT           0x02
520 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
521 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
522
523 /* Info about the pin modes supported by the different pin direction modes.
524  * For each direction the minimum and maximum values are given.
525  */
526 static signed char alc_pin_mode_dir_info[5][2] = {
527         { 0, 2 },    /* ALC_PIN_DIR_IN */
528         { 3, 4 },    /* ALC_PIN_DIR_OUT */
529         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
530         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
531         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
532 };
533 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
534 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
535 #define alc_pin_mode_n_items(_dir) \
536         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
537
538 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
539                              struct snd_ctl_elem_info *uinfo)
540 {
541         unsigned int item_num = uinfo->value.enumerated.item;
542         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
543
544         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
545         uinfo->count = 1;
546         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
547
548         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
549                 item_num = alc_pin_mode_min(dir);
550         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
551         return 0;
552 }
553
554 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
555                             struct snd_ctl_elem_value *ucontrol)
556 {
557         unsigned int i;
558         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
559         hda_nid_t nid = kcontrol->private_value & 0xffff;
560         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
561         long *valp = ucontrol->value.integer.value;
562         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
563                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
564                                                  0x00);
565
566         /* Find enumerated value for current pinctl setting */
567         i = alc_pin_mode_min(dir);
568         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
569                 i++;
570         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
571         return 0;
572 }
573
574 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
575                             struct snd_ctl_elem_value *ucontrol)
576 {
577         signed int change;
578         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579         hda_nid_t nid = kcontrol->private_value & 0xffff;
580         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
581         long val = *ucontrol->value.integer.value;
582         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
583                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
584                                                  0x00);
585
586         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
587                 val = alc_pin_mode_min(dir);
588
589         change = pinctl != alc_pin_mode_values[val];
590         if (change) {
591                 /* Set pin mode to that requested */
592                 snd_hda_codec_write_cache(codec, nid, 0,
593                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
594                                           alc_pin_mode_values[val]);
595
596                 /* Also enable the retasking pin's input/output as required
597                  * for the requested pin mode.  Enum values of 2 or less are
598                  * input modes.
599                  *
600                  * Dynamically switching the input/output buffers probably
601                  * reduces noise slightly (particularly on input) so we'll
602                  * do it.  However, having both input and output buffers
603                  * enabled simultaneously doesn't seem to be problematic if
604                  * this turns out to be necessary in the future.
605                  */
606                 if (val <= 2) {
607                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
608                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
609                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
610                                                  HDA_AMP_MUTE, 0);
611                 } else {
612                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
613                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
614                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
615                                                  HDA_AMP_MUTE, 0);
616                 }
617         }
618         return change;
619 }
620
621 #define ALC_PIN_MODE(xname, nid, dir) \
622         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
623           .info = alc_pin_mode_info, \
624           .get = alc_pin_mode_get, \
625           .put = alc_pin_mode_put, \
626           .private_value = nid | (dir<<16) }
627
628 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
629  * together using a mask with more than one bit set.  This control is
630  * currently used only by the ALC260 test model.  At this stage they are not
631  * needed for any "production" models.
632  */
633 #ifdef CONFIG_SND_DEBUG
634 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
635
636 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
637                              struct snd_ctl_elem_value *ucontrol)
638 {
639         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640         hda_nid_t nid = kcontrol->private_value & 0xffff;
641         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
642         long *valp = ucontrol->value.integer.value;
643         unsigned int val = snd_hda_codec_read(codec, nid, 0,
644                                               AC_VERB_GET_GPIO_DATA, 0x00);
645
646         *valp = (val & mask) != 0;
647         return 0;
648 }
649 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
650                              struct snd_ctl_elem_value *ucontrol)
651 {
652         signed int change;
653         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654         hda_nid_t nid = kcontrol->private_value & 0xffff;
655         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
656         long val = *ucontrol->value.integer.value;
657         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
658                                                     AC_VERB_GET_GPIO_DATA,
659                                                     0x00);
660
661         /* Set/unset the masked GPIO bit(s) as needed */
662         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
663         if (val == 0)
664                 gpio_data &= ~mask;
665         else
666                 gpio_data |= mask;
667         snd_hda_codec_write_cache(codec, nid, 0,
668                                   AC_VERB_SET_GPIO_DATA, gpio_data);
669
670         return change;
671 }
672 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
673         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
674           .info = alc_gpio_data_info, \
675           .get = alc_gpio_data_get, \
676           .put = alc_gpio_data_put, \
677           .private_value = nid | (mask<<16) }
678 #endif   /* CONFIG_SND_DEBUG */
679
680 /* A switch control to allow the enabling of the digital IO pins on the
681  * ALC260.  This is incredibly simplistic; the intention of this control is
682  * to provide something in the test model allowing digital outputs to be
683  * identified if present.  If models are found which can utilise these
684  * outputs a more complete mixer control can be devised for those models if
685  * necessary.
686  */
687 #ifdef CONFIG_SND_DEBUG
688 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
689
690 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
691                               struct snd_ctl_elem_value *ucontrol)
692 {
693         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
694         hda_nid_t nid = kcontrol->private_value & 0xffff;
695         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
696         long *valp = ucontrol->value.integer.value;
697         unsigned int val = snd_hda_codec_read(codec, nid, 0,
698                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
699
700         *valp = (val & mask) != 0;
701         return 0;
702 }
703 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
704                               struct snd_ctl_elem_value *ucontrol)
705 {
706         signed int change;
707         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
708         hda_nid_t nid = kcontrol->private_value & 0xffff;
709         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
710         long val = *ucontrol->value.integer.value;
711         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
712                                                     AC_VERB_GET_DIGI_CONVERT_1,
713                                                     0x00);
714
715         /* Set/unset the masked control bit(s) as needed */
716         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
717         if (val==0)
718                 ctrl_data &= ~mask;
719         else
720                 ctrl_data |= mask;
721         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
722                                   ctrl_data);
723
724         return change;
725 }
726 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
727         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
728           .info = alc_spdif_ctrl_info, \
729           .get = alc_spdif_ctrl_get, \
730           .put = alc_spdif_ctrl_put, \
731           .private_value = nid | (mask<<16) }
732 #endif   /* CONFIG_SND_DEBUG */
733
734 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
735  * Again, this is only used in the ALC26x test models to help identify when
736  * the EAPD line must be asserted for features to work.
737  */
738 #ifdef CONFIG_SND_DEBUG
739 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
740
741 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
742                               struct snd_ctl_elem_value *ucontrol)
743 {
744         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745         hda_nid_t nid = kcontrol->private_value & 0xffff;
746         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
747         long *valp = ucontrol->value.integer.value;
748         unsigned int val = snd_hda_codec_read(codec, nid, 0,
749                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
750
751         *valp = (val & mask) != 0;
752         return 0;
753 }
754
755 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
756                               struct snd_ctl_elem_value *ucontrol)
757 {
758         int change;
759         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
760         hda_nid_t nid = kcontrol->private_value & 0xffff;
761         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
762         long val = *ucontrol->value.integer.value;
763         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
764                                                     AC_VERB_GET_EAPD_BTLENABLE,
765                                                     0x00);
766
767         /* Set/unset the masked control bit(s) as needed */
768         change = (!val ? 0 : mask) != (ctrl_data & mask);
769         if (!val)
770                 ctrl_data &= ~mask;
771         else
772                 ctrl_data |= mask;
773         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
774                                   ctrl_data);
775
776         return change;
777 }
778
779 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
780         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
781           .info = alc_eapd_ctrl_info, \
782           .get = alc_eapd_ctrl_get, \
783           .put = alc_eapd_ctrl_put, \
784           .private_value = nid | (mask<<16) }
785 #endif   /* CONFIG_SND_DEBUG */
786
787 /*
788  * set up the input pin config (depending on the given auto-pin type)
789  */
790 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
791                               int auto_pin_type)
792 {
793         unsigned int val = PIN_IN;
794
795         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
796                 unsigned int pincap;
797                 pincap = snd_hda_query_pin_caps(codec, nid);
798                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
799                 if (pincap & AC_PINCAP_VREF_80)
800                         val = PIN_VREF80;
801                 else if (pincap & AC_PINCAP_VREF_50)
802                         val = PIN_VREF50;
803                 else if (pincap & AC_PINCAP_VREF_100)
804                         val = PIN_VREF100;
805                 else if (pincap & AC_PINCAP_VREF_GRD)
806                         val = PIN_VREFGRD;
807         }
808         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
809 }
810
811 /*
812  */
813 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
814 {
815         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
816                 return;
817         spec->mixers[spec->num_mixers++] = mix;
818 }
819
820 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
821 {
822         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
823                 return;
824         spec->init_verbs[spec->num_init_verbs++] = verb;
825 }
826
827 #ifdef CONFIG_PROC_FS
828 /*
829  * hook for proc
830  */
831 static void print_realtek_coef(struct snd_info_buffer *buffer,
832                                struct hda_codec *codec, hda_nid_t nid)
833 {
834         int coeff;
835
836         if (nid != 0x20)
837                 return;
838         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
839         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
840         coeff = snd_hda_codec_read(codec, nid, 0,
841                                    AC_VERB_GET_COEF_INDEX, 0);
842         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
843 }
844 #else
845 #define print_realtek_coef      NULL
846 #endif
847
848 /*
849  * set up from the preset table
850  */
851 static void setup_preset(struct alc_spec *spec,
852                          const struct alc_config_preset *preset)
853 {
854         int i;
855
856         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
857                 add_mixer(spec, preset->mixers[i]);
858         spec->cap_mixer = preset->cap_mixer;
859         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
860              i++)
861                 add_verb(spec, preset->init_verbs[i]);
862
863         spec->channel_mode = preset->channel_mode;
864         spec->num_channel_mode = preset->num_channel_mode;
865         spec->need_dac_fix = preset->need_dac_fix;
866         spec->const_channel_count = preset->const_channel_count;
867
868         if (preset->const_channel_count)
869                 spec->multiout.max_channels = preset->const_channel_count;
870         else
871                 spec->multiout.max_channels = spec->channel_mode[0].channels;
872         spec->ext_channel_count = spec->channel_mode[0].channels;
873
874         spec->multiout.num_dacs = preset->num_dacs;
875         spec->multiout.dac_nids = preset->dac_nids;
876         spec->multiout.dig_out_nid = preset->dig_out_nid;
877         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
878         spec->multiout.hp_nid = preset->hp_nid;
879
880         spec->num_mux_defs = preset->num_mux_defs;
881         if (!spec->num_mux_defs)
882                 spec->num_mux_defs = 1;
883         spec->input_mux = preset->input_mux;
884
885         spec->num_adc_nids = preset->num_adc_nids;
886         spec->adc_nids = preset->adc_nids;
887         spec->capsrc_nids = preset->capsrc_nids;
888         spec->dig_in_nid = preset->dig_in_nid;
889
890         spec->unsol_event = preset->unsol_event;
891         spec->init_hook = preset->init_hook;
892 #ifdef CONFIG_SND_HDA_POWER_SAVE
893         spec->loopback.amplist = preset->loopbacks;
894 #endif
895 }
896
897 /* Enable GPIO mask and set output */
898 static struct hda_verb alc_gpio1_init_verbs[] = {
899         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
900         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
901         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
902         { }
903 };
904
905 static struct hda_verb alc_gpio2_init_verbs[] = {
906         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
907         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
908         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
909         { }
910 };
911
912 static struct hda_verb alc_gpio3_init_verbs[] = {
913         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
914         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
915         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
916         { }
917 };
918
919 /*
920  * Fix hardware PLL issue
921  * On some codecs, the analog PLL gating control must be off while
922  * the default value is 1.
923  */
924 static void alc_fix_pll(struct hda_codec *codec)
925 {
926         struct alc_spec *spec = codec->spec;
927         unsigned int val;
928
929         if (!spec->pll_nid)
930                 return;
931         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
932                             spec->pll_coef_idx);
933         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
934                                  AC_VERB_GET_PROC_COEF, 0);
935         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
936                             spec->pll_coef_idx);
937         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
938                             val & ~(1 << spec->pll_coef_bit));
939 }
940
941 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
942                              unsigned int coef_idx, unsigned int coef_bit)
943 {
944         struct alc_spec *spec = codec->spec;
945         spec->pll_nid = nid;
946         spec->pll_coef_idx = coef_idx;
947         spec->pll_coef_bit = coef_bit;
948         alc_fix_pll(codec);
949 }
950
951 static void alc_automute_pin(struct hda_codec *codec)
952 {
953         struct alc_spec *spec = codec->spec;
954         unsigned int present;
955         unsigned int nid = spec->autocfg.hp_pins[0];
956         int i;
957
958         /* need to execute and sync at first */
959         snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
960         present = snd_hda_codec_read(codec, nid, 0,
961                                      AC_VERB_GET_PIN_SENSE, 0);
962         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
963         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
964                 nid = spec->autocfg.speaker_pins[i];
965                 if (!nid)
966                         break;
967                 snd_hda_codec_write(codec, nid, 0,
968                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
969                                     spec->jack_present ? 0 : PIN_OUT);
970         }
971 }
972
973 #if 0 /* it's broken in some acses -- temporarily disabled */
974 static void alc_mic_automute(struct hda_codec *codec)
975 {
976         struct alc_spec *spec = codec->spec;
977         unsigned int present;
978         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
979         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
980         unsigned int mix_nid = spec->capsrc_nids[0];
981         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
982
983         capsrc_idx_mic = mic_nid - 0x18;
984         capsrc_idx_fmic = fmic_nid - 0x18;
985         present = snd_hda_codec_read(codec, mic_nid, 0,
986                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
987         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
988                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
989         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
990                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
991         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
992                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
993 }
994 #else
995 #define alc_mic_automute(codec) do {} while(0) /* NOP */
996 #endif /* disabled */
997
998 /* unsolicited event for HP jack sensing */
999 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1000 {
1001         if (codec->vendor_id == 0x10ec0880)
1002                 res >>= 28;
1003         else
1004                 res >>= 26;
1005         switch (res) {
1006         case ALC880_HP_EVENT:
1007                 alc_automute_pin(codec);
1008                 break;
1009         case ALC880_MIC_EVENT:
1010                 alc_mic_automute(codec);
1011                 break;
1012         }
1013 }
1014
1015 static void alc_inithook(struct hda_codec *codec)
1016 {
1017         alc_automute_pin(codec);
1018         alc_mic_automute(codec);
1019 }
1020
1021 /* additional initialization for ALC888 variants */
1022 static void alc888_coef_init(struct hda_codec *codec)
1023 {
1024         unsigned int tmp;
1025
1026         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1027         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1028         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1029         if ((tmp & 0xf0) == 0x20)
1030                 /* alc888S-VC */
1031                 snd_hda_codec_read(codec, 0x20, 0,
1032                                    AC_VERB_SET_PROC_COEF, 0x830);
1033          else
1034                  /* alc888-VB */
1035                  snd_hda_codec_read(codec, 0x20, 0,
1036                                     AC_VERB_SET_PROC_COEF, 0x3030);
1037 }
1038
1039 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1040 {
1041         unsigned int tmp;
1042
1043         switch (type) {
1044         case ALC_INIT_GPIO1:
1045                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1046                 break;
1047         case ALC_INIT_GPIO2:
1048                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1049                 break;
1050         case ALC_INIT_GPIO3:
1051                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1052                 break;
1053         case ALC_INIT_DEFAULT:
1054                 switch (codec->vendor_id) {
1055                 case 0x10ec0260:
1056                         snd_hda_codec_write(codec, 0x0f, 0,
1057                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1058                         snd_hda_codec_write(codec, 0x10, 0,
1059                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1060                         break;
1061                 case 0x10ec0262:
1062                 case 0x10ec0267:
1063                 case 0x10ec0268:
1064                 case 0x10ec0269:
1065                 case 0x10ec0272:
1066                 case 0x10ec0660:
1067                 case 0x10ec0662:
1068                 case 0x10ec0663:
1069                 case 0x10ec0862:
1070                 case 0x10ec0889:
1071                         snd_hda_codec_write(codec, 0x14, 0,
1072                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1073                         snd_hda_codec_write(codec, 0x15, 0,
1074                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1075                         break;
1076                 }
1077                 switch (codec->vendor_id) {
1078                 case 0x10ec0260:
1079                         snd_hda_codec_write(codec, 0x1a, 0,
1080                                             AC_VERB_SET_COEF_INDEX, 7);
1081                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1082                                                  AC_VERB_GET_PROC_COEF, 0);
1083                         snd_hda_codec_write(codec, 0x1a, 0,
1084                                             AC_VERB_SET_COEF_INDEX, 7);
1085                         snd_hda_codec_write(codec, 0x1a, 0,
1086                                             AC_VERB_SET_PROC_COEF,
1087                                             tmp | 0x2010);
1088                         break;
1089                 case 0x10ec0262:
1090                 case 0x10ec0880:
1091                 case 0x10ec0882:
1092                 case 0x10ec0883:
1093                 case 0x10ec0885:
1094                 case 0x10ec0887:
1095                 case 0x10ec0889:
1096                         snd_hda_codec_write(codec, 0x20, 0,
1097                                             AC_VERB_SET_COEF_INDEX, 7);
1098                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1099                                                  AC_VERB_GET_PROC_COEF, 0);
1100                         snd_hda_codec_write(codec, 0x20, 0,
1101                                             AC_VERB_SET_COEF_INDEX, 7);
1102                         snd_hda_codec_write(codec, 0x20, 0,
1103                                             AC_VERB_SET_PROC_COEF,
1104                                             tmp | 0x2010);
1105                         break;
1106                 case 0x10ec0888:
1107                         alc888_coef_init(codec);
1108                         break;
1109                 case 0x10ec0267:
1110                 case 0x10ec0268:
1111                         snd_hda_codec_write(codec, 0x20, 0,
1112                                             AC_VERB_SET_COEF_INDEX, 7);
1113                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1114                                                  AC_VERB_GET_PROC_COEF, 0);
1115                         snd_hda_codec_write(codec, 0x20, 0,
1116                                             AC_VERB_SET_COEF_INDEX, 7);
1117                         snd_hda_codec_write(codec, 0x20, 0,
1118                                             AC_VERB_SET_PROC_COEF,
1119                                             tmp | 0x3000);
1120                         break;
1121                 }
1122                 break;
1123         }
1124 }
1125
1126 static void alc_init_auto_hp(struct hda_codec *codec)
1127 {
1128         struct alc_spec *spec = codec->spec;
1129
1130         if (!spec->autocfg.hp_pins[0])
1131                 return;
1132
1133         if (!spec->autocfg.speaker_pins[0]) {
1134                 if (spec->autocfg.line_out_pins[0] &&
1135                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1136                         spec->autocfg.speaker_pins[0] =
1137                                 spec->autocfg.line_out_pins[0];
1138                 else
1139                         return;
1140         }
1141
1142         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1143                     spec->autocfg.hp_pins[0]);
1144         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1145                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1146                                   AC_USRSP_EN | ALC880_HP_EVENT);
1147         spec->unsol_event = alc_sku_unsol_event;
1148 }
1149
1150 /* check subsystem ID and set up device-specific initialization;
1151  * return 1 if initialized, 0 if invalid SSID
1152  */
1153 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1154  *      31 ~ 16 :       Manufacture ID
1155  *      15 ~ 8  :       SKU ID
1156  *      7  ~ 0  :       Assembly ID
1157  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1158  */
1159 static int alc_subsystem_id(struct hda_codec *codec,
1160                             hda_nid_t porta, hda_nid_t porte,
1161                             hda_nid_t portd)
1162 {
1163         unsigned int ass, tmp, i;
1164         unsigned nid;
1165         struct alc_spec *spec = codec->spec;
1166
1167         ass = codec->subsystem_id & 0xffff;
1168         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1169                 goto do_sku;
1170
1171         /* invalid SSID, check the special NID pin defcfg instead */
1172         /*
1173          * 31~30        : port conetcivity
1174          * 29~21        : reserve
1175          * 20           : PCBEEP input
1176          * 19~16        : Check sum (15:1)
1177          * 15~1         : Custom
1178          * 0            : override
1179         */
1180         nid = 0x1d;
1181         if (codec->vendor_id == 0x10ec0260)
1182                 nid = 0x17;
1183         ass = snd_hda_codec_get_pincfg(codec, nid);
1184         snd_printd("realtek: No valid SSID, "
1185                    "checking pincfg 0x%08x for NID 0x%x\n",
1186                    ass, nid);
1187         if (!(ass & 1) && !(ass & 0x100000))
1188                 return 0;
1189         if ((ass >> 30) != 1)   /* no physical connection */
1190                 return 0;
1191
1192         /* check sum */
1193         tmp = 0;
1194         for (i = 1; i < 16; i++) {
1195                 if ((ass >> i) & 1)
1196                         tmp++;
1197         }
1198         if (((ass >> 16) & 0xf) != tmp)
1199                 return 0;
1200 do_sku:
1201         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1202                    ass & 0xffff, codec->vendor_id);
1203         /*
1204          * 0 : override
1205          * 1 :  Swap Jack
1206          * 2 : 0 --> Desktop, 1 --> Laptop
1207          * 3~5 : External Amplifier control
1208          * 7~6 : Reserved
1209         */
1210         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1211         switch (tmp) {
1212         case 1:
1213                 spec->init_amp = ALC_INIT_GPIO1;
1214                 break;
1215         case 3:
1216                 spec->init_amp = ALC_INIT_GPIO2;
1217                 break;
1218         case 7:
1219                 spec->init_amp = ALC_INIT_GPIO3;
1220                 break;
1221         case 5:
1222                 spec->init_amp = ALC_INIT_DEFAULT;
1223                 break;
1224         }
1225
1226         /* is laptop or Desktop and enable the function "Mute internal speaker
1227          * when the external headphone out jack is plugged"
1228          */
1229         if (!(ass & 0x8000))
1230                 return 1;
1231         /*
1232          * 10~8 : Jack location
1233          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1234          * 14~13: Resvered
1235          * 15   : 1 --> enable the function "Mute internal speaker
1236          *              when the external headphone out jack is plugged"
1237          */
1238         if (!spec->autocfg.hp_pins[0]) {
1239                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1240                 if (tmp == 0)
1241                         spec->autocfg.hp_pins[0] = porta;
1242                 else if (tmp == 1)
1243                         spec->autocfg.hp_pins[0] = porte;
1244                 else if (tmp == 2)
1245                         spec->autocfg.hp_pins[0] = portd;
1246                 else
1247                         return 1;
1248         }
1249
1250         alc_init_auto_hp(codec);
1251         return 1;
1252 }
1253
1254 static void alc_ssid_check(struct hda_codec *codec,
1255                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1256 {
1257         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1258                 struct alc_spec *spec = codec->spec;
1259                 snd_printd("realtek: "
1260                            "Enable default setup for auto mode as fallback\n");
1261                 spec->init_amp = ALC_INIT_DEFAULT;
1262                 alc_init_auto_hp(codec);
1263         }
1264 }
1265
1266 /*
1267  * Fix-up pin default configurations
1268  */
1269
1270 struct alc_pincfg {
1271         hda_nid_t nid;
1272         u32 val;
1273 };
1274
1275 static void alc_fix_pincfg(struct hda_codec *codec,
1276                            const struct snd_pci_quirk *quirk,
1277                            const struct alc_pincfg **pinfix)
1278 {
1279         const struct alc_pincfg *cfg;
1280
1281         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1282         if (!quirk)
1283                 return;
1284
1285         cfg = pinfix[quirk->value];
1286         for (; cfg->nid; cfg++)
1287                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1288 }
1289
1290 /*
1291  * ALC888
1292  */
1293
1294 /*
1295  * 2ch mode
1296  */
1297 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1298 /* Mic-in jack as mic in */
1299         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1300         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1301 /* Line-in jack as Line in */
1302         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1303         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1304 /* Line-Out as Front */
1305         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1306         { } /* end */
1307 };
1308
1309 /*
1310  * 4ch mode
1311  */
1312 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1313 /* Mic-in jack as mic in */
1314         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1315         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1316 /* Line-in jack as Surround */
1317         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1318         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1319 /* Line-Out as Front */
1320         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1321         { } /* end */
1322 };
1323
1324 /*
1325  * 6ch mode
1326  */
1327 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1328 /* Mic-in jack as CLFE */
1329         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1330         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1331 /* Line-in jack as Surround */
1332         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1333         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1334 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1335         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1336         { } /* end */
1337 };
1338
1339 /*
1340  * 8ch mode
1341  */
1342 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1343 /* Mic-in jack as CLFE */
1344         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1345         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1346 /* Line-in jack as Surround */
1347         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1348         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1349 /* Line-Out as Side */
1350         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1351         { } /* end */
1352 };
1353
1354 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1355         { 2, alc888_4ST_ch2_intel_init },
1356         { 4, alc888_4ST_ch4_intel_init },
1357         { 6, alc888_4ST_ch6_intel_init },
1358         { 8, alc888_4ST_ch8_intel_init },
1359 };
1360
1361 /*
1362  * ALC888 Fujitsu Siemens Amillo xa3530
1363  */
1364
1365 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1366 /* Front Mic: set to PIN_IN (empty by default) */
1367         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1368 /* Connect Internal HP to Front */
1369         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1370         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1371         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1372 /* Connect Bass HP to Front */
1373         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1374         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1375         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1376 /* Connect Line-Out side jack (SPDIF) to Side */
1377         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1378         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1379         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1380 /* Connect Mic jack to CLFE */
1381         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1382         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1383         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1384 /* Connect Line-in jack to Surround */
1385         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1386         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1387         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1388 /* Connect HP out jack to Front */
1389         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1390         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1391         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1392 /* Enable unsolicited event for HP jack and Line-out jack */
1393         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1394         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1395         {}
1396 };
1397
1398 static void alc_automute_amp(struct hda_codec *codec)
1399 {
1400         struct alc_spec *spec = codec->spec;
1401         unsigned int val, mute;
1402         hda_nid_t nid;
1403         int i;
1404
1405         spec->jack_present = 0;
1406         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1407                 nid = spec->autocfg.hp_pins[i];
1408                 if (!nid)
1409                         break;
1410                 val = snd_hda_codec_read(codec, nid, 0,
1411                                          AC_VERB_GET_PIN_SENSE, 0);
1412                 if (val & AC_PINSENSE_PRESENCE) {
1413                         spec->jack_present = 1;
1414                         break;
1415                 }
1416         }
1417
1418         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1419         /* Toggle internal speakers muting */
1420         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1421                 nid = spec->autocfg.speaker_pins[i];
1422                 if (!nid)
1423                         break;
1424                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1425                                          HDA_AMP_MUTE, mute);
1426         }
1427 }
1428
1429 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1430                                          unsigned int res)
1431 {
1432         if (codec->vendor_id == 0x10ec0880)
1433                 res >>= 28;
1434         else
1435                 res >>= 26;
1436         if (res == ALC880_HP_EVENT)
1437                 alc_automute_amp(codec);
1438 }
1439
1440 static void alc888_fujitsu_xa3530_init_hook(struct hda_codec *codec)
1441 {
1442         struct alc_spec *spec = codec->spec;
1443
1444         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1445         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1446         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1447         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1448         alc_automute_amp(codec);
1449 }
1450
1451 /*
1452  * ALC888 Acer Aspire 4930G model
1453  */
1454
1455 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1456 /* Front Mic: set to PIN_IN (empty by default) */
1457         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1458 /* Unselect Front Mic by default in input mixer 3 */
1459         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1460 /* Enable unsolicited event for HP jack */
1461         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1462 /* Connect Internal HP to front */
1463         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1464         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1465         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1466 /* Connect HP out to front */
1467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1469         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1470         { }
1471 };
1472
1473 /*
1474  * ALC889 Acer Aspire 8930G model
1475  */
1476
1477 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1478 /* Front Mic: set to PIN_IN (empty by default) */
1479         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1480 /* Unselect Front Mic by default in input mixer 3 */
1481         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1482 /* Enable unsolicited event for HP jack */
1483         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1484 /* Connect Internal Front to Front */
1485         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1486         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1487         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1488 /* Connect Internal Rear to Rear */
1489         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1490         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1491         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1492 /* Connect Internal CLFE to CLFE */
1493         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1494         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1495         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1496 /* Connect HP out to Front */
1497         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1498         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1499         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1500 /* Enable all DACs */
1501 /*  DAC DISABLE/MUTE 1? */
1502 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1503         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1504         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1505 /*  DAC DISABLE/MUTE 2? */
1506 /*  some bit here disables the other DACs. Init=0x4900 */
1507         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1508         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1509 /* Enable amplifiers */
1510         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1511         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1512 /* DMIC fix
1513  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1514  * which makes the stereo useless. However, either the mic or the ALC889
1515  * makes the signal become a difference/sum signal instead of standard
1516  * stereo, which is annoying. So instead we flip this bit which makes the
1517  * codec replicate the sum signal to both channels, turning it into a
1518  * normal mono mic.
1519  */
1520 /*  DMIC_CONTROL? Init value = 0x0001 */
1521         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1522         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1523         { }
1524 };
1525
1526 static struct hda_input_mux alc888_2_capture_sources[2] = {
1527         /* Front mic only available on one ADC */
1528         {
1529                 .num_items = 4,
1530                 .items = {
1531                         { "Mic", 0x0 },
1532                         { "Line", 0x2 },
1533                         { "CD", 0x4 },
1534                         { "Front Mic", 0xb },
1535                 },
1536         },
1537         {
1538                 .num_items = 3,
1539                 .items = {
1540                         { "Mic", 0x0 },
1541                         { "Line", 0x2 },
1542                         { "CD", 0x4 },
1543                 },
1544         }
1545 };
1546
1547 static struct hda_input_mux alc889_capture_sources[3] = {
1548         /* Digital mic only available on first "ADC" */
1549         {
1550                 .num_items = 5,
1551                 .items = {
1552                         { "Mic", 0x0 },
1553                         { "Line", 0x2 },
1554                         { "CD", 0x4 },
1555                         { "Front Mic", 0xb },
1556                         { "Input Mix", 0xa },
1557                 },
1558         },
1559         {
1560                 .num_items = 4,
1561                 .items = {
1562                         { "Mic", 0x0 },
1563                         { "Line", 0x2 },
1564                         { "CD", 0x4 },
1565                         { "Input Mix", 0xa },
1566                 },
1567         },
1568         {
1569                 .num_items = 4,
1570                 .items = {
1571                         { "Mic", 0x0 },
1572                         { "Line", 0x2 },
1573                         { "CD", 0x4 },
1574                         { "Input Mix", 0xa },
1575                 },
1576         }
1577 };
1578
1579 static struct snd_kcontrol_new alc888_base_mixer[] = {
1580         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1581         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1582         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1583         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1584         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1585                 HDA_OUTPUT),
1586         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1587         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1588         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1589         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1590         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1591         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1592         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1593         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1594         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1595         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1596         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1597         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1598         { } /* end */
1599 };
1600
1601 static void alc888_acer_aspire_4930g_init_hook(struct hda_codec *codec)
1602 {
1603         struct alc_spec *spec = codec->spec;
1604
1605         spec->autocfg.hp_pins[0] = 0x15;
1606         spec->autocfg.speaker_pins[0] = 0x14;
1607         alc_automute_amp(codec);
1608 }
1609
1610 static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec)
1611 {
1612         struct alc_spec *spec = codec->spec;
1613
1614         spec->autocfg.hp_pins[0] = 0x15;
1615         spec->autocfg.speaker_pins[0] = 0x14;
1616         spec->autocfg.speaker_pins[1] = 0x16;
1617         spec->autocfg.speaker_pins[2] = 0x1b;
1618         alc_automute_amp(codec);
1619 }
1620
1621 /*
1622  * ALC880 3-stack model
1623  *
1624  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1625  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1626  *                 F-Mic = 0x1b, HP = 0x19
1627  */
1628
1629 static hda_nid_t alc880_dac_nids[4] = {
1630         /* front, rear, clfe, rear_surr */
1631         0x02, 0x05, 0x04, 0x03
1632 };
1633
1634 static hda_nid_t alc880_adc_nids[3] = {
1635         /* ADC0-2 */
1636         0x07, 0x08, 0x09,
1637 };
1638
1639 /* The datasheet says the node 0x07 is connected from inputs,
1640  * but it shows zero connection in the real implementation on some devices.
1641  * Note: this is a 915GAV bug, fixed on 915GLV
1642  */
1643 static hda_nid_t alc880_adc_nids_alt[2] = {
1644         /* ADC1-2 */
1645         0x08, 0x09,
1646 };
1647
1648 #define ALC880_DIGOUT_NID       0x06
1649 #define ALC880_DIGIN_NID        0x0a
1650
1651 static struct hda_input_mux alc880_capture_source = {
1652         .num_items = 4,
1653         .items = {
1654                 { "Mic", 0x0 },
1655                 { "Front Mic", 0x3 },
1656                 { "Line", 0x2 },
1657                 { "CD", 0x4 },
1658         },
1659 };
1660
1661 /* channel source setting (2/6 channel selection for 3-stack) */
1662 /* 2ch mode */
1663 static struct hda_verb alc880_threestack_ch2_init[] = {
1664         /* set line-in to input, mute it */
1665         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1666         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1667         /* set mic-in to input vref 80%, mute it */
1668         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1669         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1670         { } /* end */
1671 };
1672
1673 /* 6ch mode */
1674 static struct hda_verb alc880_threestack_ch6_init[] = {
1675         /* set line-in to output, unmute it */
1676         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1677         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1678         /* set mic-in to output, unmute it */
1679         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1680         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1681         { } /* end */
1682 };
1683
1684 static struct hda_channel_mode alc880_threestack_modes[2] = {
1685         { 2, alc880_threestack_ch2_init },
1686         { 6, alc880_threestack_ch6_init },
1687 };
1688
1689 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1690         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1691         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1692         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1693         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1694         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1695         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1696         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1697         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1698         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1699         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1700         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1701         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1702         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1703         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1704         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1705         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1706         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1707         {
1708                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1709                 .name = "Channel Mode",
1710                 .info = alc_ch_mode_info,
1711                 .get = alc_ch_mode_get,
1712                 .put = alc_ch_mode_put,
1713         },
1714         { } /* end */
1715 };
1716
1717 /* capture mixer elements */
1718 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1719                             struct snd_ctl_elem_info *uinfo)
1720 {
1721         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1722         struct alc_spec *spec = codec->spec;
1723         int err;
1724
1725         mutex_lock(&codec->control_mutex);
1726         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1727                                                       HDA_INPUT);
1728         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1729         mutex_unlock(&codec->control_mutex);
1730         return err;
1731 }
1732
1733 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1734                            unsigned int size, unsigned int __user *tlv)
1735 {
1736         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1737         struct alc_spec *spec = codec->spec;
1738         int err;
1739
1740         mutex_lock(&codec->control_mutex);
1741         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1742                                                       HDA_INPUT);
1743         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1744         mutex_unlock(&codec->control_mutex);
1745         return err;
1746 }
1747
1748 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1749                              struct snd_ctl_elem_value *ucontrol);
1750
1751 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1752                                  struct snd_ctl_elem_value *ucontrol,
1753                                  getput_call_t func)
1754 {
1755         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1756         struct alc_spec *spec = codec->spec;
1757         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1758         int err;
1759
1760         mutex_lock(&codec->control_mutex);
1761         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1762                                                       3, 0, HDA_INPUT);
1763         err = func(kcontrol, ucontrol);
1764         mutex_unlock(&codec->control_mutex);
1765         return err;
1766 }
1767
1768 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1769                            struct snd_ctl_elem_value *ucontrol)
1770 {
1771         return alc_cap_getput_caller(kcontrol, ucontrol,
1772                                      snd_hda_mixer_amp_volume_get);
1773 }
1774
1775 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1776                            struct snd_ctl_elem_value *ucontrol)
1777 {
1778         return alc_cap_getput_caller(kcontrol, ucontrol,
1779                                      snd_hda_mixer_amp_volume_put);
1780 }
1781
1782 /* capture mixer elements */
1783 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1784
1785 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1786                           struct snd_ctl_elem_value *ucontrol)
1787 {
1788         return alc_cap_getput_caller(kcontrol, ucontrol,
1789                                      snd_hda_mixer_amp_switch_get);
1790 }
1791
1792 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1793                           struct snd_ctl_elem_value *ucontrol)
1794 {
1795         return alc_cap_getput_caller(kcontrol, ucontrol,
1796                                      snd_hda_mixer_amp_switch_put);
1797 }
1798
1799 #define _DEFINE_CAPMIX(num) \
1800         { \
1801                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1802                 .name = "Capture Switch", \
1803                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1804                 .count = num, \
1805                 .info = alc_cap_sw_info, \
1806                 .get = alc_cap_sw_get, \
1807                 .put = alc_cap_sw_put, \
1808         }, \
1809         { \
1810                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1811                 .name = "Capture Volume", \
1812                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1813                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1814                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1815                 .count = num, \
1816                 .info = alc_cap_vol_info, \
1817                 .get = alc_cap_vol_get, \
1818                 .put = alc_cap_vol_put, \
1819                 .tlv = { .c = alc_cap_vol_tlv }, \
1820         }
1821
1822 #define _DEFINE_CAPSRC(num) \
1823         { \
1824                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1825                 /* .name = "Capture Source", */ \
1826                 .name = "Input Source", \
1827                 .count = num, \
1828                 .info = alc_mux_enum_info, \
1829                 .get = alc_mux_enum_get, \
1830                 .put = alc_mux_enum_put, \
1831         }
1832
1833 #define DEFINE_CAPMIX(num) \
1834 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1835         _DEFINE_CAPMIX(num),                                  \
1836         _DEFINE_CAPSRC(num),                                  \
1837         { } /* end */                                         \
1838 }
1839
1840 #define DEFINE_CAPMIX_NOSRC(num) \
1841 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1842         _DEFINE_CAPMIX(num),                                        \
1843         { } /* end */                                               \
1844 }
1845
1846 /* up to three ADCs */
1847 DEFINE_CAPMIX(1);
1848 DEFINE_CAPMIX(2);
1849 DEFINE_CAPMIX(3);
1850 DEFINE_CAPMIX_NOSRC(1);
1851 DEFINE_CAPMIX_NOSRC(2);
1852 DEFINE_CAPMIX_NOSRC(3);
1853
1854 /*
1855  * ALC880 5-stack model
1856  *
1857  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1858  *      Side = 0x02 (0xd)
1859  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1860  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1861  */
1862
1863 /* additional mixers to alc880_three_stack_mixer */
1864 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1865         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1866         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1867         { } /* end */
1868 };
1869
1870 /* channel source setting (6/8 channel selection for 5-stack) */
1871 /* 6ch mode */
1872 static struct hda_verb alc880_fivestack_ch6_init[] = {
1873         /* set line-in to input, mute it */
1874         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1875         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1876         { } /* end */
1877 };
1878
1879 /* 8ch mode */
1880 static struct hda_verb alc880_fivestack_ch8_init[] = {
1881         /* set line-in to output, unmute it */
1882         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1883         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1884         { } /* end */
1885 };
1886
1887 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1888         { 6, alc880_fivestack_ch6_init },
1889         { 8, alc880_fivestack_ch8_init },
1890 };
1891
1892
1893 /*
1894  * ALC880 6-stack model
1895  *
1896  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1897  *      Side = 0x05 (0x0f)
1898  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1899  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1900  */
1901
1902 static hda_nid_t alc880_6st_dac_nids[4] = {
1903         /* front, rear, clfe, rear_surr */
1904         0x02, 0x03, 0x04, 0x05
1905 };
1906
1907 static struct hda_input_mux alc880_6stack_capture_source = {
1908         .num_items = 4,
1909         .items = {
1910                 { "Mic", 0x0 },
1911                 { "Front Mic", 0x1 },
1912                 { "Line", 0x2 },
1913                 { "CD", 0x4 },
1914         },
1915 };
1916
1917 /* fixed 8-channels */
1918 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1919         { 8, NULL },
1920 };
1921
1922 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1923         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1924         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1925         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1926         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1927         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1928         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1929         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1930         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1931         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1932         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1933         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1934         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1935         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1936         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1939         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1940         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1941         {
1942                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1943                 .name = "Channel Mode",
1944                 .info = alc_ch_mode_info,
1945                 .get = alc_ch_mode_get,
1946                 .put = alc_ch_mode_put,
1947         },
1948         { } /* end */
1949 };
1950
1951
1952 /*
1953  * ALC880 W810 model
1954  *
1955  * W810 has rear IO for:
1956  * Front (DAC 02)
1957  * Surround (DAC 03)
1958  * Center/LFE (DAC 04)
1959  * Digital out (06)
1960  *
1961  * The system also has a pair of internal speakers, and a headphone jack.
1962  * These are both connected to Line2 on the codec, hence to DAC 02.
1963  *
1964  * There is a variable resistor to control the speaker or headphone
1965  * volume. This is a hardware-only device without a software API.
1966  *
1967  * Plugging headphones in will disable the internal speakers. This is
1968  * implemented in hardware, not via the driver using jack sense. In
1969  * a similar fashion, plugging into the rear socket marked "front" will
1970  * disable both the speakers and headphones.
1971  *
1972  * For input, there's a microphone jack, and an "audio in" jack.
1973  * These may not do anything useful with this driver yet, because I
1974  * haven't setup any initialization verbs for these yet...
1975  */
1976
1977 static hda_nid_t alc880_w810_dac_nids[3] = {
1978         /* front, rear/surround, clfe */
1979         0x02, 0x03, 0x04
1980 };
1981
1982 /* fixed 6 channels */
1983 static struct hda_channel_mode alc880_w810_modes[1] = {
1984         { 6, NULL }
1985 };
1986
1987 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1988 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1989         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1990         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1991         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1992         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1993         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1994         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1995         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1996         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1997         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1998         { } /* end */
1999 };
2000
2001
2002 /*
2003  * Z710V model
2004  *
2005  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2006  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2007  *                 Line = 0x1a
2008  */
2009
2010 static hda_nid_t alc880_z71v_dac_nids[1] = {
2011         0x02
2012 };
2013 #define ALC880_Z71V_HP_DAC      0x03
2014
2015 /* fixed 2 channels */
2016 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2017         { 2, NULL }
2018 };
2019
2020 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2021         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2022         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2023         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2024         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2025         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2026         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2027         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2028         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2029         { } /* end */
2030 };
2031
2032
2033 /*
2034  * ALC880 F1734 model
2035  *
2036  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2037  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2038  */
2039
2040 static hda_nid_t alc880_f1734_dac_nids[1] = {
2041         0x03
2042 };
2043 #define ALC880_F1734_HP_DAC     0x02
2044
2045 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2046         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2047         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2048         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2049         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2050         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2051         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2052         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2053         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2054         { } /* end */
2055 };
2056
2057 static struct hda_input_mux alc880_f1734_capture_source = {
2058         .num_items = 2,
2059         .items = {
2060                 { "Mic", 0x1 },
2061                 { "CD", 0x4 },
2062         },
2063 };
2064
2065
2066 /*
2067  * ALC880 ASUS model
2068  *
2069  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2070  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2071  *  Mic = 0x18, Line = 0x1a
2072  */
2073
2074 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2075 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2076
2077 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2078         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2079         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2080         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2081         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2082         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2083         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2084         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2085         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2086         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2087         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2088         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2089         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2090         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2091         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2092         {
2093                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2094                 .name = "Channel Mode",
2095                 .info = alc_ch_mode_info,
2096                 .get = alc_ch_mode_get,
2097                 .put = alc_ch_mode_put,
2098         },
2099         { } /* end */
2100 };
2101
2102 /*
2103  * ALC880 ASUS W1V model
2104  *
2105  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2106  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2107  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2108  */
2109
2110 /* additional mixers to alc880_asus_mixer */
2111 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2112         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2113         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2114         { } /* end */
2115 };
2116
2117 /* TCL S700 */
2118 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2119         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2120         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2121         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2122         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2123         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2124         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2125         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2126         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2127         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2128         { } /* end */
2129 };
2130
2131 /* Uniwill */
2132 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2133         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2134         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2135         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2136         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2137         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2138         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2139         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2140         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2141         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2142         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2143         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2144         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2145         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2146         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2147         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2148         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2149         {
2150                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2151                 .name = "Channel Mode",
2152                 .info = alc_ch_mode_info,
2153                 .get = alc_ch_mode_get,
2154                 .put = alc_ch_mode_put,
2155         },
2156         { } /* end */
2157 };
2158
2159 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2160         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2161         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2162         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2163         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2164         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2165         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2166         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2167         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2168         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2169         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2170         { } /* end */
2171 };
2172
2173 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2174         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2175         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2176         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2177         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2178         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2179         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2180         { } /* end */
2181 };
2182
2183 /*
2184  * virtual master controls
2185  */
2186
2187 /*
2188  * slave controls for virtual master
2189  */
2190 static const char *alc_slave_vols[] = {
2191         "Front Playback Volume",
2192         "Surround Playback Volume",
2193         "Center Playback Volume",
2194         "LFE Playback Volume",
2195         "Side Playback Volume",
2196         "Headphone Playback Volume",
2197         "Speaker Playback Volume",
2198         "Mono Playback Volume",
2199         "Line-Out Playback Volume",
2200         "PCM Playback Volume",
2201         NULL,
2202 };
2203
2204 static const char *alc_slave_sws[] = {
2205         "Front Playback Switch",
2206         "Surround Playback Switch",
2207         "Center Playback Switch",
2208         "LFE Playback Switch",
2209         "Side Playback Switch",
2210         "Headphone Playback Switch",
2211         "Speaker Playback Switch",
2212         "Mono Playback Switch",
2213         "IEC958 Playback Switch",
2214         NULL,
2215 };
2216
2217 /*
2218  * build control elements
2219  */
2220
2221 static void alc_free_kctls(struct hda_codec *codec);
2222
2223 /* additional beep mixers; the actual parameters are overwritten at build */
2224 static struct snd_kcontrol_new alc_beep_mixer[] = {
2225         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2226         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2227         { } /* end */
2228 };
2229
2230 static int alc_build_controls(struct hda_codec *codec)
2231 {
2232         struct alc_spec *spec = codec->spec;
2233         int err;
2234         int i;
2235
2236         for (i = 0; i < spec->num_mixers; i++) {
2237                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2238                 if (err < 0)
2239                         return err;
2240         }
2241         if (spec->cap_mixer) {
2242                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2243                 if (err < 0)
2244                         return err;
2245         }
2246         if (spec->multiout.dig_out_nid) {
2247                 err = snd_hda_create_spdif_out_ctls(codec,
2248                                                     spec->multiout.dig_out_nid);
2249                 if (err < 0)
2250                         return err;
2251                 if (!spec->no_analog) {
2252                         err = snd_hda_create_spdif_share_sw(codec,
2253                                                             &spec->multiout);
2254                         if (err < 0)
2255                                 return err;
2256                         spec->multiout.share_spdif = 1;
2257                 }
2258         }
2259         if (spec->dig_in_nid) {
2260                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2261                 if (err < 0)
2262                         return err;
2263         }
2264
2265         /* create beep controls if needed */
2266         if (spec->beep_amp) {
2267                 struct snd_kcontrol_new *knew;
2268                 for (knew = alc_beep_mixer; knew->name; knew++) {
2269                         struct snd_kcontrol *kctl;
2270                         kctl = snd_ctl_new1(knew, codec);
2271                         if (!kctl)
2272                                 return -ENOMEM;
2273                         kctl->private_value = spec->beep_amp;
2274                         err = snd_hda_ctl_add(codec, kctl);
2275                         if (err < 0)
2276                                 return err;
2277                 }
2278         }
2279
2280         /* if we have no master control, let's create it */
2281         if (!spec->no_analog &&
2282             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2283                 unsigned int vmaster_tlv[4];
2284                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2285                                         HDA_OUTPUT, vmaster_tlv);
2286                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2287                                           vmaster_tlv, alc_slave_vols);
2288                 if (err < 0)
2289                         return err;
2290         }
2291         if (!spec->no_analog &&
2292             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2293                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2294                                           NULL, alc_slave_sws);
2295                 if (err < 0)
2296                         return err;
2297         }
2298
2299         alc_free_kctls(codec); /* no longer needed */
2300         return 0;
2301 }
2302
2303
2304 /*
2305  * initialize the codec volumes, etc
2306  */
2307
2308 /*
2309  * generic initialization of ADC, input mixers and output mixers
2310  */
2311 static struct hda_verb alc880_volume_init_verbs[] = {
2312         /*
2313          * Unmute ADC0-2 and set the default input to mic-in
2314          */
2315         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2316         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2317         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2318         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2319         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2320         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2321
2322         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2323          * mixer widget
2324          * Note: PASD motherboards uses the Line In 2 as the input for front
2325          * panel mic (mic 2)
2326          */
2327         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2328         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2329         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2330         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2331         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2332         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2333         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2334         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2335
2336         /*
2337          * Set up output mixers (0x0c - 0x0f)
2338          */
2339         /* set vol=0 to output mixers */
2340         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2341         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2342         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2343         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2344         /* set up input amps for analog loopback */
2345         /* Amp Indices: DAC = 0, mixer = 1 */
2346         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2347         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2348         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2349         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2350         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2351         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2352         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2353         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2354
2355         { }
2356 };
2357
2358 /*
2359  * 3-stack pin configuration:
2360  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2361  */
2362 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2363         /*
2364          * preset connection lists of input pins
2365          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2366          */
2367         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2368         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2369         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2370
2371         /*
2372          * Set pin mode and muting
2373          */
2374         /* set front pin widgets 0x14 for output */
2375         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2376         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2377         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2378         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2379         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2380         /* Mic2 (as headphone out) for HP output */
2381         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2382         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2383         /* Line In pin widget for input */
2384         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2385         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2386         /* Line2 (as front mic) pin widget for input and vref at 80% */
2387         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2388         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2389         /* CD pin widget for input */
2390         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2391
2392         { }
2393 };
2394
2395 /*
2396  * 5-stack pin configuration:
2397  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2398  * line-in/side = 0x1a, f-mic = 0x1b
2399  */
2400 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2401         /*
2402          * preset connection lists of input pins
2403          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2404          */
2405         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2406         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2407
2408         /*
2409          * Set pin mode and muting
2410          */
2411         /* set pin widgets 0x14-0x17 for output */
2412         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2413         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2414         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2415         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2416         /* unmute pins for output (no gain on this amp) */
2417         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2418         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2419         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2420         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2421
2422         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2423         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2424         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2425         /* Mic2 (as headphone out) for HP output */
2426         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2427         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2428         /* Line In pin widget for input */
2429         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2430         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2431         /* Line2 (as front mic) pin widget for input and vref at 80% */
2432         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2433         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2434         /* CD pin widget for input */
2435         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2436
2437         { }
2438 };
2439
2440 /*
2441  * W810 pin configuration:
2442  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2443  */
2444 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2445         /* hphone/speaker input selector: front DAC */
2446         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2447
2448         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2449         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2450         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2451         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2452         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2453         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2454
2455         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2456         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2457
2458         { }
2459 };
2460
2461 /*
2462  * Z71V pin configuration:
2463  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2464  */
2465 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2466         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2467         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2468         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2469         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2470
2471         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2472         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2473         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2474         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2475
2476         { }
2477 };
2478
2479 /*
2480  * 6-stack pin configuration:
2481  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2482  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2483  */
2484 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2485         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2486
2487         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2488         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2489         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2490         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2491         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2492         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2493         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2494         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2495
2496         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2497         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2498         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2499         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2500         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2501         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2502         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2503         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2504         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2505
2506         { }
2507 };
2508
2509 /*
2510  * Uniwill pin configuration:
2511  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2512  * line = 0x1a
2513  */
2514 static struct hda_verb alc880_uniwill_init_verbs[] = {
2515         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2516
2517         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2518         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2519         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2520         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2521         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2522         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2523         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2524         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2525         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2526         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2527         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2528         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2529         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2530         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2531
2532         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2533         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2534         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2535         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2536         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2537         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2538         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2539         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2540         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2541
2542         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2543         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2544
2545         { }
2546 };
2547
2548 /*
2549 * Uniwill P53
2550 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2551  */
2552 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2553         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2554
2555         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2556         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2557         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2558         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2559         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2560         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2561         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2562         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2563         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2564         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2565         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2566         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2567
2568         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2569         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2570         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2571         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2572         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2573         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2574
2575         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2576         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2577
2578         { }
2579 };
2580
2581 static struct hda_verb alc880_beep_init_verbs[] = {
2582         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2583         { }
2584 };
2585
2586 /* auto-toggle front mic */
2587 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2588 {
2589         unsigned int present;
2590         unsigned char bits;
2591
2592         present = snd_hda_codec_read(codec, 0x18, 0,
2593                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2594         bits = present ? HDA_AMP_MUTE : 0;
2595         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2596 }
2597
2598 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2599 {
2600         struct alc_spec *spec = codec->spec;
2601
2602         spec->autocfg.hp_pins[0] = 0x14;
2603         spec->autocfg.speaker_pins[0] = 0x15;
2604         spec->autocfg.speaker_pins[0] = 0x16;
2605         alc_automute_amp(codec);
2606         alc880_uniwill_mic_automute(codec);
2607 }
2608
2609 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2610                                        unsigned int res)
2611 {
2612         /* Looks like the unsol event is incompatible with the standard
2613          * definition.  4bit tag is placed at 28 bit!
2614          */
2615         switch (res >> 28) {
2616         case ALC880_MIC_EVENT:
2617                 alc880_uniwill_mic_automute(codec);
2618                 break;
2619         default:
2620                 alc_automute_amp_unsol_event(codec, res);
2621                 break;
2622         }
2623 }
2624
2625 static void alc880_uniwill_p53_init_hook(struct hda_codec *codec)
2626 {
2627         struct alc_spec *spec = codec->spec;
2628
2629         spec->autocfg.hp_pins[0] = 0x14;
2630         spec->autocfg.speaker_pins[0] = 0x15;
2631         alc_automute_amp(codec);
2632 }
2633
2634 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2635 {
2636         unsigned int present;
2637
2638         present = snd_hda_codec_read(codec, 0x21, 0,
2639                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2640         present &= HDA_AMP_VOLMASK;
2641         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2642                                  HDA_AMP_VOLMASK, present);
2643         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2644                                  HDA_AMP_VOLMASK, present);
2645 }
2646
2647 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2648                                            unsigned int res)
2649 {
2650         /* Looks like the unsol event is incompatible with the standard
2651          * definition.  4bit tag is placed at 28 bit!
2652          */
2653         if ((res >> 28) == ALC880_DCVOL_EVENT)
2654                 alc880_uniwill_p53_dcvol_automute(codec);
2655         else
2656                 alc_automute_amp_unsol_event(codec, res);
2657 }
2658
2659 /*
2660  * F1734 pin configuration:
2661  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2662  */
2663 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2664         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2665         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2666         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2667         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2668         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2669
2670         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2671         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2672         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2673         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2674
2675         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2676         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2677         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2678         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2679         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2680         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2681         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2682         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2683         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2684
2685         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2686         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2687
2688         { }
2689 };
2690
2691 /*
2692  * ASUS pin configuration:
2693  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2694  */
2695 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2696         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2697         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2698         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2699         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2700
2701         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2702         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2703         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2704         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2705         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2706         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2707         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2708         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2709
2710         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2711         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2712         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2713         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2714         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2715         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2716         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2717         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2718         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2719
2720         { }
2721 };
2722
2723 /* Enable GPIO mask and set output */
2724 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2725 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2726 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2727
2728 /* Clevo m520g init */
2729 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2730         /* headphone output */
2731         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2732         /* line-out */
2733         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2734         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2735         /* Line-in */
2736         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2737         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2738         /* CD */
2739         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2740         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2741         /* Mic1 (rear panel) */
2742         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2743         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2744         /* Mic2 (front panel) */
2745         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2746         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2747         /* headphone */
2748         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2749         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2750         /* change to EAPD mode */
2751         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2752         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2753
2754         { }
2755 };
2756
2757 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2758         /* change to EAPD mode */
2759         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2760         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2761
2762         /* Headphone output */
2763         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2764         /* Front output*/
2765         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2766         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2767
2768         /* Line In pin widget for input */
2769         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2770         /* CD pin widget for input */
2771         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2772         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2773         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2774
2775         /* change to EAPD mode */
2776         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2777         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2778
2779         { }
2780 };
2781
2782 /*
2783  * LG m1 express dual
2784  *
2785  * Pin assignment:
2786  *   Rear Line-In/Out (blue): 0x14
2787  *   Build-in Mic-In: 0x15
2788  *   Speaker-out: 0x17
2789  *   HP-Out (green): 0x1b
2790  *   Mic-In/Out (red): 0x19
2791  *   SPDIF-Out: 0x1e
2792  */
2793
2794 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2795 static hda_nid_t alc880_lg_dac_nids[3] = {
2796         0x05, 0x02, 0x03
2797 };
2798
2799 /* seems analog CD is not working */
2800 static struct hda_input_mux alc880_lg_capture_source = {
2801         .num_items = 3,
2802         .items = {
2803                 { "Mic", 0x1 },
2804                 { "Line", 0x5 },
2805                 { "Internal Mic", 0x6 },
2806         },
2807 };
2808
2809 /* 2,4,6 channel modes */
2810 static struct hda_verb alc880_lg_ch2_init[] = {
2811         /* set line-in and mic-in to input */
2812         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2813         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2814         { }
2815 };
2816
2817 static struct hda_verb alc880_lg_ch4_init[] = {
2818         /* set line-in to out and mic-in to input */
2819         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2820         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2821         { }
2822 };
2823
2824 static struct hda_verb alc880_lg_ch6_init[] = {
2825         /* set line-in and mic-in to output */
2826         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2827         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2828         { }
2829 };
2830
2831 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2832         { 2, alc880_lg_ch2_init },
2833         { 4, alc880_lg_ch4_init },
2834         { 6, alc880_lg_ch6_init },
2835 };
2836
2837 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2838         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2839         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2840         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2841         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2842         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2843         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2844         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2845         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2846         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2847         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2848         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2849         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2850         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2851         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2852         {
2853                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2854                 .name = "Channel Mode",
2855                 .info = alc_ch_mode_info,
2856                 .get = alc_ch_mode_get,
2857                 .put = alc_ch_mode_put,
2858         },
2859         { } /* end */
2860 };
2861
2862 static struct hda_verb alc880_lg_init_verbs[] = {
2863         /* set capture source to mic-in */
2864         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2865         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2866         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2867         /* mute all amp mixer inputs */
2868         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2869         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2870         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2871         /* line-in to input */
2872         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2873         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2874         /* built-in mic */
2875         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2876         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2877         /* speaker-out */
2878         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2879         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2880         /* mic-in to input */
2881         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2882         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2883         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2884         /* HP-out */
2885         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2886         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2887         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2888         /* jack sense */
2889         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2890         { }
2891 };
2892
2893 /* toggle speaker-output according to the hp-jack state */
2894 static void alc880_lg_init_hook(struct hda_codec *codec)
2895 {
2896         struct alc_spec *spec = codec->spec;
2897
2898         spec->autocfg.hp_pins[0] = 0x1b;
2899         spec->autocfg.speaker_pins[0] = 0x17;
2900         alc_automute_amp(codec);
2901 }
2902
2903 /*
2904  * LG LW20
2905  *
2906  * Pin assignment:
2907  *   Speaker-out: 0x14
2908  *   Mic-In: 0x18
2909  *   Built-in Mic-In: 0x19
2910  *   Line-In: 0x1b
2911  *   HP-Out: 0x1a
2912  *   SPDIF-Out: 0x1e
2913  */
2914
2915 static struct hda_input_mux alc880_lg_lw_capture_source = {
2916         .num_items = 3,
2917         .items = {
2918                 { "Mic", 0x0 },
2919                 { "Internal Mic", 0x1 },
2920                 { "Line In", 0x2 },
2921         },
2922 };
2923
2924 #define alc880_lg_lw_modes alc880_threestack_modes
2925
2926 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2927         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2928         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2929         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2930         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2931         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2932         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2933         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2934         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2935         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2936         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2939         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2940         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2941         {
2942                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2943                 .name = "Channel Mode",
2944                 .info = alc_ch_mode_info,
2945                 .get = alc_ch_mode_get,
2946                 .put = alc_ch_mode_put,
2947         },
2948         { } /* end */
2949 };
2950
2951 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2952         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2953         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2954         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2955
2956         /* set capture source to mic-in */
2957         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2958         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2959         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2960         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2961         /* speaker-out */
2962         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2963         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2964         /* HP-out */
2965         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2966         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2967         /* mic-in to input */
2968         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2969         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2970         /* built-in mic */
2971         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2972         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2973         /* jack sense */
2974         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2975         { }
2976 };
2977
2978 /* toggle speaker-output according to the hp-jack state */
2979 static void alc880_lg_lw_init_hook(struct hda_codec *codec)
2980 {
2981         struct alc_spec *spec = codec->spec;
2982
2983         spec->autocfg.hp_pins[0] = 0x1b;
2984         spec->autocfg.speaker_pins[0] = 0x14;
2985         alc_automute_amp(codec);
2986 }
2987
2988 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2989         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2990         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2991         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2992         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2993         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2994         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2995         { } /* end */
2996 };
2997
2998 static struct hda_input_mux alc880_medion_rim_capture_source = {
2999         .num_items = 2,
3000         .items = {
3001                 { "Mic", 0x0 },
3002                 { "Internal Mic", 0x1 },
3003         },
3004 };
3005
3006 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3007         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3008
3009         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3010         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3011
3012         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3013         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3014         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3015         /* Mic2 (as headphone out) for HP output */
3016         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3017         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3018         /* Internal Speaker */
3019         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3020         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3021
3022         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3023         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3024
3025         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3026         { }
3027 };
3028
3029 /* toggle speaker-output according to the hp-jack state */
3030 static void alc880_medion_rim_automute(struct hda_codec *codec)
3031 {
3032         struct alc_spec *spec = codec->spec;
3033         alc_automute_amp(codec);
3034         /* toggle EAPD */
3035         if (spec->jack_present)
3036                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3037         else
3038                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3039 }
3040
3041 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3042                                           unsigned int res)
3043 {
3044         /* Looks like the unsol event is incompatible with the standard
3045          * definition.  4bit tag is placed at 28 bit!
3046          */
3047         if ((res >> 28) == ALC880_HP_EVENT)
3048                 alc880_medion_rim_automute(codec);
3049 }
3050
3051 static void alc880_medion_rim_init_hook(struct hda_codec *codec)
3052 {
3053         struct alc_spec *spec = codec->spec;
3054
3055         spec->autocfg.hp_pins[0] = 0x14;
3056         spec->autocfg.speaker_pins[0] = 0x1b;
3057         alc880_medion_rim_automute(codec);
3058 }
3059
3060 #ifdef CONFIG_SND_HDA_POWER_SAVE
3061 static struct hda_amp_list alc880_loopbacks[] = {
3062         { 0x0b, HDA_INPUT, 0 },
3063         { 0x0b, HDA_INPUT, 1 },
3064         { 0x0b, HDA_INPUT, 2 },
3065         { 0x0b, HDA_INPUT, 3 },
3066         { 0x0b, HDA_INPUT, 4 },
3067         { } /* end */
3068 };
3069
3070 static struct hda_amp_list alc880_lg_loopbacks[] = {
3071         { 0x0b, HDA_INPUT, 1 },
3072         { 0x0b, HDA_INPUT, 6 },
3073         { 0x0b, HDA_INPUT, 7 },
3074         { } /* end */
3075 };
3076 #endif
3077
3078 /*
3079  * Common callbacks
3080  */
3081
3082 static int alc_init(struct hda_codec *codec)
3083 {
3084         struct alc_spec *spec = codec->spec;
3085         unsigned int i;
3086
3087         alc_fix_pll(codec);
3088         alc_auto_init_amp(codec, spec->init_amp);
3089
3090         for (i = 0; i < spec->num_init_verbs; i++)
3091                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3092
3093         if (spec->init_hook)
3094                 spec->init_hook(codec);
3095
3096         return 0;
3097 }
3098
3099 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3100 {
3101         struct alc_spec *spec = codec->spec;
3102
3103         if (spec->unsol_event)
3104                 spec->unsol_event(codec, res);
3105 }
3106
3107 #ifdef CONFIG_SND_HDA_POWER_SAVE
3108 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3109 {
3110         struct alc_spec *spec = codec->spec;
3111         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3112 }
3113 #endif
3114
3115 /*
3116  * Analog playback callbacks
3117  */
3118 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3119                                     struct hda_codec *codec,
3120                                     struct snd_pcm_substream *substream)
3121 {
3122         struct alc_spec *spec = codec->spec;
3123         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3124                                              hinfo);
3125 }
3126
3127 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3128                                        struct hda_codec *codec,
3129                                        unsigned int stream_tag,
3130                                        unsigned int format,
3131                                        struct snd_pcm_substream *substream)
3132 {
3133         struct alc_spec *spec = codec->spec;
3134         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3135                                                 stream_tag, format, substream);
3136 }
3137
3138 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3139                                        struct hda_codec *codec,
3140                                        struct snd_pcm_substream *substream)
3141 {
3142         struct alc_spec *spec = codec->spec;
3143         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3144 }
3145
3146 /*
3147  * Digital out
3148  */
3149 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3150                                         struct hda_codec *codec,
3151                                         struct snd_pcm_substream *substream)
3152 {
3153         struct alc_spec *spec = codec->spec;
3154         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3155 }
3156
3157 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3158                                            struct hda_codec *codec,
3159                                            unsigned int stream_tag,
3160                                            unsigned int format,
3161                                            struct snd_pcm_substream *substream)
3162 {
3163         struct alc_spec *spec = codec->spec;
3164         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3165                                              stream_tag, format, substream);
3166 }
3167
3168 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3169                                            struct hda_codec *codec,
3170                                            struct snd_pcm_substream *substream)
3171 {
3172         struct alc_spec *spec = codec->spec;
3173         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3174 }
3175
3176 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3177                                          struct hda_codec *codec,
3178                                          struct snd_pcm_substream *substream)
3179 {
3180         struct alc_spec *spec = codec->spec;
3181         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3182 }
3183
3184 /*
3185  * Analog capture
3186  */
3187 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3188                                       struct hda_codec *codec,
3189                                       unsigned int stream_tag,
3190                                       unsigned int format,
3191                                       struct snd_pcm_substream *substream)
3192 {
3193         struct alc_spec *spec = codec->spec;
3194
3195         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3196                                    stream_tag, 0, format);
3197         return 0;
3198 }
3199
3200 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3201                                       struct hda_codec *codec,
3202                                       struct snd_pcm_substream *substream)
3203 {
3204         struct alc_spec *spec = codec->spec;
3205
3206         snd_hda_codec_cleanup_stream(codec,
3207                                      spec->adc_nids[substream->number + 1]);
3208         return 0;
3209 }
3210
3211
3212 /*
3213  */
3214 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3215         .substreams = 1,
3216         .channels_min = 2,
3217         .channels_max = 8,
3218         /* NID is set in alc_build_pcms */
3219         .ops = {
3220                 .open = alc880_playback_pcm_open,
3221                 .prepare = alc880_playback_pcm_prepare,
3222                 .cleanup = alc880_playback_pcm_cleanup
3223         },
3224 };
3225
3226 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3227         .substreams = 1,
3228         .channels_min = 2,
3229         .channels_max = 2,
3230         /* NID is set in alc_build_pcms */
3231 };
3232
3233 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3234         .substreams = 1,
3235         .channels_min = 2,
3236         .channels_max = 2,
3237         /* NID is set in alc_build_pcms */
3238 };
3239
3240 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3241         .substreams = 2, /* can be overridden */
3242         .channels_min = 2,
3243         .channels_max = 2,
3244         /* NID is set in alc_build_pcms */
3245         .ops = {
3246                 .prepare = alc880_alt_capture_pcm_prepare,
3247                 .cleanup = alc880_alt_capture_pcm_cleanup
3248         },
3249 };
3250
3251 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3252         .substreams = 1,
3253         .channels_min = 2,
3254         .channels_max = 2,
3255         /* NID is set in alc_build_pcms */
3256         .ops = {
3257                 .open = alc880_dig_playback_pcm_open,
3258                 .close = alc880_dig_playback_pcm_close,
3259                 .prepare = alc880_dig_playback_pcm_prepare,
3260                 .cleanup = alc880_dig_playback_pcm_cleanup
3261         },
3262 };
3263
3264 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3265         .substreams = 1,
3266         .channels_min = 2,
3267         .channels_max = 2,
3268         /* NID is set in alc_build_pcms */
3269 };
3270
3271 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3272 static struct hda_pcm_stream alc_pcm_null_stream = {
3273         .substreams = 0,
3274         .channels_min = 0,
3275         .channels_max = 0,
3276 };
3277
3278 static int alc_build_pcms(struct hda_codec *codec)
3279 {
3280         struct alc_spec *spec = codec->spec;
3281         struct hda_pcm *info = spec->pcm_rec;
3282         int i;
3283
3284         codec->num_pcms = 1;
3285         codec->pcm_info = info;
3286
3287         if (spec->no_analog)
3288                 goto skip_analog;
3289
3290         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3291                  "%s Analog", codec->chip_name);
3292         info->name = spec->stream_name_analog;
3293         
3294         if (spec->stream_analog_playback) {
3295                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3296                         return -EINVAL;
3297                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3298                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3299         }
3300         if (spec->stream_analog_capture) {
3301                 if (snd_BUG_ON(!spec->adc_nids))
3302                         return -EINVAL;
3303                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3304                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3305         }
3306
3307         if (spec->channel_mode) {
3308                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3309                 for (i = 0; i < spec->num_channel_mode; i++) {
3310                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3311                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3312                         }
3313                 }
3314         }
3315
3316  skip_analog:
3317         /* SPDIF for stream index #1 */
3318         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3319                 snprintf(spec->stream_name_digital,
3320                          sizeof(spec->stream_name_digital),
3321                          "%s Digital", codec->chip_name);
3322                 codec->num_pcms = 2;
3323                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3324                 info = spec->pcm_rec + 1;
3325                 info->name = spec->stream_name_digital;
3326                 if (spec->dig_out_type)
3327                         info->pcm_type = spec->dig_out_type;
3328                 else
3329                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3330                 if (spec->multiout.dig_out_nid &&
3331                     spec->stream_digital_playback) {
3332                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3333                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3334                 }
3335                 if (spec->dig_in_nid &&
3336                     spec->stream_digital_capture) {
3337                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3338                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3339                 }
3340                 /* FIXME: do we need this for all Realtek codec models? */
3341                 codec->spdif_status_reset = 1;
3342         }
3343
3344         if (spec->no_analog)
3345                 return 0;
3346
3347         /* If the use of more than one ADC is requested for the current
3348          * model, configure a second analog capture-only PCM.
3349          */
3350         /* Additional Analaog capture for index #2 */
3351         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3352             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3353                 codec->num_pcms = 3;
3354                 info = spec->pcm_rec + 2;
3355                 info->name = spec->stream_name_analog;
3356                 if (spec->alt_dac_nid) {
3357                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3358                                 *spec->stream_analog_alt_playback;
3359                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3360                                 spec->alt_dac_nid;
3361                 } else {
3362                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3363                                 alc_pcm_null_stream;
3364                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3365                 }
3366                 if (spec->num_adc_nids > 1) {
3367                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3368                                 *spec->stream_analog_alt_capture;
3369                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3370                                 spec->adc_nids[1];
3371                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3372                                 spec->num_adc_nids - 1;
3373                 } else {
3374                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3375                                 alc_pcm_null_stream;
3376                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3377                 }
3378         }
3379
3380         return 0;
3381 }
3382
3383 static void alc_free_kctls(struct hda_codec *codec)
3384 {
3385         struct alc_spec *spec = codec->spec;
3386
3387         if (spec->kctls.list) {
3388                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3389                 int i;
3390                 for (i = 0; i < spec->kctls.used; i++)
3391                         kfree(kctl[i].name);
3392         }
3393         snd_array_free(&spec->kctls);
3394 }
3395
3396 static void alc_free(struct hda_codec *codec)
3397 {
3398         struct alc_spec *spec = codec->spec;
3399
3400         if (!spec)
3401                 return;
3402
3403         alc_free_kctls(codec);
3404         kfree(spec);
3405         snd_hda_detach_beep_device(codec);
3406 }
3407
3408 #ifdef SND_HDA_NEEDS_RESUME
3409 static int alc_resume(struct hda_codec *codec)
3410 {
3411         codec->patch_ops.init(codec);
3412         snd_hda_codec_resume_amp(codec);
3413         snd_hda_codec_resume_cache(codec);
3414         return 0;
3415 }
3416 #endif
3417
3418 /*
3419  */
3420 static struct hda_codec_ops alc_patch_ops = {
3421         .build_controls = alc_build_controls,
3422         .build_pcms = alc_build_pcms,
3423         .init = alc_init,
3424         .free = alc_free,
3425         .unsol_event = alc_unsol_event,
3426 #ifdef SND_HDA_NEEDS_RESUME
3427         .resume = alc_resume,
3428 #endif
3429 #ifdef CONFIG_SND_HDA_POWER_SAVE
3430         .check_power_status = alc_check_power_status,
3431 #endif
3432 };
3433
3434
3435 /*
3436  * Test configuration for debugging
3437  *
3438  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3439  * enum controls.
3440  */
3441 #ifdef CONFIG_SND_DEBUG
3442 static hda_nid_t alc880_test_dac_nids[4] = {
3443         0x02, 0x03, 0x04, 0x05
3444 };
3445
3446 static struct hda_input_mux alc880_test_capture_source = {
3447         .num_items = 7,
3448         .items = {
3449                 { "In-1", 0x0 },
3450                 { "In-2", 0x1 },
3451                 { "In-3", 0x2 },
3452                 { "In-4", 0x3 },
3453                 { "CD", 0x4 },
3454                 { "Front", 0x5 },
3455                 { "Surround", 0x6 },
3456         },
3457 };
3458
3459 static struct hda_channel_mode alc880_test_modes[4] = {
3460         { 2, NULL },
3461         { 4, NULL },
3462         { 6, NULL },
3463         { 8, NULL },
3464 };
3465
3466 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3467                                  struct snd_ctl_elem_info *uinfo)
3468 {
3469         static char *texts[] = {
3470                 "N/A", "Line Out", "HP Out",
3471                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3472         };
3473         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3474         uinfo->count = 1;
3475         uinfo->value.enumerated.items = 8;
3476         if (uinfo->value.enumerated.item >= 8)
3477                 uinfo->value.enumerated.item = 7;
3478         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3479         return 0;
3480 }
3481
3482 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3483                                 struct snd_ctl_elem_value *ucontrol)
3484 {
3485         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3486         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3487         unsigned int pin_ctl, item = 0;
3488
3489         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3490                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3491         if (pin_ctl & AC_PINCTL_OUT_EN) {
3492                 if (pin_ctl & AC_PINCTL_HP_EN)
3493                         item = 2;
3494                 else
3495                         item = 1;
3496         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3497                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3498                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3499                 case AC_PINCTL_VREF_50:  item = 4; break;
3500                 case AC_PINCTL_VREF_GRD: item = 5; break;
3501                 case AC_PINCTL_VREF_80:  item = 6; break;
3502                 case AC_PINCTL_VREF_100: item = 7; break;
3503                 }
3504         }
3505         ucontrol->value.enumerated.item[0] = item;
3506         return 0;
3507 }
3508
3509 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3510                                 struct snd_ctl_elem_value *ucontrol)
3511 {
3512         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3513         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3514         static unsigned int ctls[] = {
3515                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3516                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3517                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3518                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3519                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3520                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3521         };
3522         unsigned int old_ctl, new_ctl;
3523
3524         old_ctl = snd_hda_codec_read(codec, nid, 0,
3525                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3526         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3527         if (old_ctl != new_ctl) {
3528                 int val;
3529                 snd_hda_codec_write_cache(codec, nid, 0,
3530                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3531                                           new_ctl);
3532                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3533                         HDA_AMP_MUTE : 0;
3534                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3535                                          HDA_AMP_MUTE, val);
3536                 return 1;
3537         }
3538         return 0;
3539 }
3540
3541 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3542                                  struct snd_ctl_elem_info *uinfo)
3543 {
3544         static char *texts[] = {
3545                 "Front", "Surround", "CLFE", "Side"
3546         };
3547         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3548         uinfo->count = 1;
3549         uinfo->value.enumerated.items = 4;
3550         if (uinfo->value.enumerated.item >= 4)
3551                 uinfo->value.enumerated.item = 3;
3552         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3553         return 0;
3554 }
3555
3556 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3557                                 struct snd_ctl_elem_value *ucontrol)
3558 {
3559         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3560         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3561         unsigned int sel;
3562
3563         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3564         ucontrol->value.enumerated.item[0] = sel & 3;
3565         return 0;
3566 }
3567
3568 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3569                                 struct snd_ctl_elem_value *ucontrol)
3570 {
3571         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3572         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3573         unsigned int sel;
3574
3575         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3576         if (ucontrol->value.enumerated.item[0] != sel) {
3577                 sel = ucontrol->value.enumerated.item[0] & 3;
3578                 snd_hda_codec_write_cache(codec, nid, 0,
3579                                           AC_VERB_SET_CONNECT_SEL, sel);
3580                 return 1;
3581         }
3582         return 0;
3583 }
3584
3585 #define PIN_CTL_TEST(xname,nid) {                       \
3586                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3587                         .name = xname,                 \
3588                         .info = alc_test_pin_ctl_info, \
3589                         .get = alc_test_pin_ctl_get,   \
3590                         .put = alc_test_pin_ctl_put,   \
3591                         .private_value = nid           \
3592                         }
3593
3594 #define PIN_SRC_TEST(xname,nid) {                       \
3595                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3596                         .name = xname,                 \
3597                         .info = alc_test_pin_src_info, \
3598                         .get = alc_test_pin_src_get,   \
3599                         .put = alc_test_pin_src_put,   \
3600                         .private_value = nid           \
3601                         }
3602
3603 static struct snd_kcontrol_new alc880_test_mixer[] = {
3604         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3605         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3606         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3607         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3608         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3609         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3610         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3611         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3612         PIN_CTL_TEST("Front Pin Mode", 0x14),
3613         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3614         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3615         PIN_CTL_TEST("Side Pin Mode", 0x17),
3616         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3617         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3618         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3619         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3620         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3621         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3622         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3623         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3624         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3625         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3626         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3627         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3628         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3629         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3630         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3631         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3632         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3633         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3634         {
3635                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3636                 .name = "Channel Mode",
3637                 .info = alc_ch_mode_info,
3638                 .get = alc_ch_mode_get,
3639                 .put = alc_ch_mode_put,
3640         },
3641         { } /* end */
3642 };
3643
3644 static struct hda_verb alc880_test_init_verbs[] = {
3645         /* Unmute inputs of 0x0c - 0x0f */
3646         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3647         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3648         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3649         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3650         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3651         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3652         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3653         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3654         /* Vol output for 0x0c-0x0f */
3655         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3656         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3657         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3658         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3659         /* Set output pins 0x14-0x17 */
3660         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3661         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3662         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3663         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3664         /* Unmute output pins 0x14-0x17 */
3665         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3666         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3667         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3668         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3669         /* Set input pins 0x18-0x1c */
3670         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3671         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3672         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3673         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3674         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3675         /* Mute input pins 0x18-0x1b */
3676         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3677         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3678         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3679         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3680         /* ADC set up */
3681         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3682         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3683         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3684         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3685         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3686         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3687         /* Analog input/passthru */
3688         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3689         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3690         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3691         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3692         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3693         { }
3694 };
3695 #endif
3696
3697 /*
3698  */
3699
3700 static const char *alc880_models[ALC880_MODEL_LAST] = {
3701         [ALC880_3ST]            = "3stack",
3702         [ALC880_TCL_S700]       = "tcl",
3703         [ALC880_3ST_DIG]        = "3stack-digout",
3704         [ALC880_CLEVO]          = "clevo",
3705         [ALC880_5ST]            = "5stack",
3706         [ALC880_5ST_DIG]        = "5stack-digout",
3707         [ALC880_W810]           = "w810",
3708         [ALC880_Z71V]           = "z71v",
3709         [ALC880_6ST]            = "6stack",
3710         [ALC880_6ST_DIG]        = "6stack-digout",
3711         [ALC880_ASUS]           = "asus",
3712         [ALC880_ASUS_W1V]       = "asus-w1v",
3713         [ALC880_ASUS_DIG]       = "asus-dig",
3714         [ALC880_ASUS_DIG2]      = "asus-dig2",
3715         [ALC880_UNIWILL_DIG]    = "uniwill",
3716         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3717         [ALC880_FUJITSU]        = "fujitsu",
3718         [ALC880_F1734]          = "F1734",
3719         [ALC880_LG]             = "lg",
3720         [ALC880_LG_LW]          = "lg-lw",
3721         [ALC880_MEDION_RIM]     = "medion",
3722 #ifdef CONFIG_SND_DEBUG
3723         [ALC880_TEST]           = "test",
3724 #endif
3725         [ALC880_AUTO]           = "auto",
3726 };
3727
3728 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3729         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3730         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3731         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3732         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3733         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3734         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3735         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3736         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3737         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3738         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3739         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3740         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3741         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3742         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3743         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3744         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3745         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3746         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3747         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3748         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3749         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3750         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3751         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3752         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3753         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3754         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3755         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3756         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3757         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3758         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3759         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3760         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3761         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3762         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3763         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3764         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3765         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3766         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3767         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3768         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3769         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3770         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3771         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3772         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3773         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3774         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3775         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3776         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3777         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3778         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3779         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3780         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3781         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3782         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3783         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3784         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3785         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3786         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3787         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3788         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3789         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3790         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3791         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3792         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3793         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3794         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3795         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3796         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3797         /* default Intel */
3798         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3799         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3800         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3801         {}
3802 };
3803
3804 /*
3805  * ALC880 codec presets
3806  */
3807 static struct alc_config_preset alc880_presets[] = {
3808         [ALC880_3ST] = {
3809                 .mixers = { alc880_three_stack_mixer },
3810                 .init_verbs = { alc880_volume_init_verbs,
3811                                 alc880_pin_3stack_init_verbs },
3812                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3813                 .dac_nids = alc880_dac_nids,
3814                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3815                 .channel_mode = alc880_threestack_modes,
3816                 .need_dac_fix = 1,
3817                 .input_mux = &alc880_capture_source,
3818         },
3819         [ALC880_3ST_DIG] = {
3820                 .mixers = { alc880_three_stack_mixer },
3821                 .init_verbs = { alc880_volume_init_verbs,
3822                                 alc880_pin_3stack_init_verbs },
3823                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3824                 .dac_nids = alc880_dac_nids,
3825                 .dig_out_nid = ALC880_DIGOUT_NID,
3826                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3827                 .channel_mode = alc880_threestack_modes,
3828                 .need_dac_fix = 1,
3829                 .input_mux = &alc880_capture_source,
3830         },
3831         [ALC880_TCL_S700] = {
3832                 .mixers = { alc880_tcl_s700_mixer },
3833                 .init_verbs = { alc880_volume_init_verbs,
3834                                 alc880_pin_tcl_S700_init_verbs,
3835                                 alc880_gpio2_init_verbs },
3836                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3837                 .dac_nids = alc880_dac_nids,
3838                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3839                 .num_adc_nids = 1, /* single ADC */
3840                 .hp_nid = 0x03,
3841                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3842                 .channel_mode = alc880_2_jack_modes,
3843                 .input_mux = &alc880_capture_source,
3844         },
3845         [ALC880_5ST] = {
3846                 .mixers = { alc880_three_stack_mixer,
3847                             alc880_five_stack_mixer},
3848                 .init_verbs = { alc880_volume_init_verbs,
3849                                 alc880_pin_5stack_init_verbs },
3850                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3851                 .dac_nids = alc880_dac_nids,
3852                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3853                 .channel_mode = alc880_fivestack_modes,
3854                 .input_mux = &alc880_capture_source,
3855         },
3856         [ALC880_5ST_DIG] = {
3857                 .mixers = { alc880_three_stack_mixer,
3858                             alc880_five_stack_mixer },
3859                 .init_verbs = { alc880_volume_init_verbs,
3860                                 alc880_pin_5stack_init_verbs },
3861                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3862                 .dac_nids = alc880_dac_nids,
3863                 .dig_out_nid = ALC880_DIGOUT_NID,
3864                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3865                 .channel_mode = alc880_fivestack_modes,
3866                 .input_mux = &alc880_capture_source,
3867         },
3868         [ALC880_6ST] = {
3869                 .mixers = { alc880_six_stack_mixer },
3870                 .init_verbs = { alc880_volume_init_verbs,
3871                                 alc880_pin_6stack_init_verbs },
3872                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3873                 .dac_nids = alc880_6st_dac_nids,
3874                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3875                 .channel_mode = alc880_sixstack_modes,
3876                 .input_mux = &alc880_6stack_capture_source,
3877         },
3878         [ALC880_6ST_DIG] = {
3879                 .mixers = { alc880_six_stack_mixer },
3880                 .init_verbs = { alc880_volume_init_verbs,
3881                                 alc880_pin_6stack_init_verbs },
3882                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3883                 .dac_nids = alc880_6st_dac_nids,
3884                 .dig_out_nid = ALC880_DIGOUT_NID,
3885                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3886                 .channel_mode = alc880_sixstack_modes,
3887                 .input_mux = &alc880_6stack_capture_source,
3888         },
3889         [ALC880_W810] = {
3890                 .mixers = { alc880_w810_base_mixer },
3891                 .init_verbs = { alc880_volume_init_verbs,
3892                                 alc880_pin_w810_init_verbs,
3893                                 alc880_gpio2_init_verbs },
3894                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3895                 .dac_nids = alc880_w810_dac_nids,
3896                 .dig_out_nid = ALC880_DIGOUT_NID,
3897                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3898                 .channel_mode = alc880_w810_modes,
3899                 .input_mux = &alc880_capture_source,
3900         },
3901         [ALC880_Z71V] = {
3902                 .mixers = { alc880_z71v_mixer },
3903                 .init_verbs = { alc880_volume_init_verbs,
3904                                 alc880_pin_z71v_init_verbs },
3905                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3906                 .dac_nids = alc880_z71v_dac_nids,
3907                 .dig_out_nid = ALC880_DIGOUT_NID,
3908                 .hp_nid = 0x03,
3909                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3910                 .channel_mode = alc880_2_jack_modes,
3911                 .input_mux = &alc880_capture_source,
3912         },
3913         [ALC880_F1734] = {
3914                 .mixers = { alc880_f1734_mixer },
3915                 .init_verbs = { alc880_volume_init_verbs,
3916                                 alc880_pin_f1734_init_verbs },
3917                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3918                 .dac_nids = alc880_f1734_dac_nids,
3919                 .hp_nid = 0x02,
3920                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3921                 .channel_mode = alc880_2_jack_modes,
3922                 .input_mux = &alc880_f1734_capture_source,
3923                 .unsol_event = alc880_uniwill_p53_unsol_event,
3924                 .init_hook = alc880_uniwill_p53_init_hook,
3925         },
3926         [ALC880_ASUS] = {
3927                 .mixers = { alc880_asus_mixer },
3928                 .init_verbs = { alc880_volume_init_verbs,
3929                                 alc880_pin_asus_init_verbs,
3930                                 alc880_gpio1_init_verbs },
3931                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3932                 .dac_nids = alc880_asus_dac_nids,
3933                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3934                 .channel_mode = alc880_asus_modes,
3935                 .need_dac_fix = 1,
3936                 .input_mux = &alc880_capture_source,
3937         },
3938         [ALC880_ASUS_DIG] = {
3939                 .mixers = { alc880_asus_mixer },
3940                 .init_verbs = { alc880_volume_init_verbs,
3941                                 alc880_pin_asus_init_verbs,
3942                                 alc880_gpio1_init_verbs },
3943                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3944                 .dac_nids = alc880_asus_dac_nids,
3945                 .dig_out_nid = ALC880_DIGOUT_NID,
3946                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3947                 .channel_mode = alc880_asus_modes,
3948                 .need_dac_fix = 1,
3949                 .input_mux = &alc880_capture_source,
3950         },
3951         [ALC880_ASUS_DIG2] = {
3952                 .mixers = { alc880_asus_mixer },
3953                 .init_verbs = { alc880_volume_init_verbs,
3954                                 alc880_pin_asus_init_verbs,
3955                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3956                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3957                 .dac_nids = alc880_asus_dac_nids,
3958                 .dig_out_nid = ALC880_DIGOUT_NID,
3959                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3960                 .channel_mode = alc880_asus_modes,
3961                 .need_dac_fix = 1,
3962                 .input_mux = &alc880_capture_source,
3963         },
3964         [ALC880_ASUS_W1V] = {
3965                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3966                 .init_verbs = { alc880_volume_init_verbs,
3967                                 alc880_pin_asus_init_verbs,
3968                                 alc880_gpio1_init_verbs },
3969                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3970                 .dac_nids = alc880_asus_dac_nids,
3971                 .dig_out_nid = ALC880_DIGOUT_NID,
3972                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3973                 .channel_mode = alc880_asus_modes,
3974                 .need_dac_fix = 1,
3975                 .input_mux = &alc880_capture_source,
3976         },
3977         [ALC880_UNIWILL_DIG] = {
3978                 .mixers = { alc880_asus_mixer },
3979                 .init_verbs = { alc880_volume_init_verbs,
3980                                 alc880_pin_asus_init_verbs },
3981                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3982                 .dac_nids = alc880_asus_dac_nids,
3983                 .dig_out_nid = ALC880_DIGOUT_NID,
3984                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3985                 .channel_mode = alc880_asus_modes,
3986                 .need_dac_fix = 1,
3987                 .input_mux = &alc880_capture_source,
3988         },
3989         [ALC880_UNIWILL] = {
3990                 .mixers = { alc880_uniwill_mixer },
3991                 .init_verbs = { alc880_volume_init_verbs,
3992                                 alc880_uniwill_init_verbs },
3993                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3994                 .dac_nids = alc880_asus_dac_nids,
3995                 .dig_out_nid = ALC880_DIGOUT_NID,
3996                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3997                 .channel_mode = alc880_threestack_modes,
3998                 .need_dac_fix = 1,
3999                 .input_mux = &alc880_capture_source,
4000                 .unsol_event = alc880_uniwill_unsol_event,
4001                 .init_hook = alc880_uniwill_init_hook,
4002         },
4003         [ALC880_UNIWILL_P53] = {
4004                 .mixers = { alc880_uniwill_p53_mixer },
4005                 .init_verbs = { alc880_volume_init_verbs,
4006                                 alc880_uniwill_p53_init_verbs },
4007                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4008                 .dac_nids = alc880_asus_dac_nids,
4009                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4010                 .channel_mode = alc880_threestack_modes,
4011                 .input_mux = &alc880_capture_source,
4012                 .unsol_event = alc880_uniwill_p53_unsol_event,
4013                 .init_hook = alc880_uniwill_p53_init_hook,
4014         },
4015         [ALC880_FUJITSU] = {
4016                 .mixers = { alc880_fujitsu_mixer },
4017                 .init_verbs = { alc880_volume_init_verbs,
4018                                 alc880_uniwill_p53_init_verbs,
4019                                 alc880_beep_init_verbs },
4020                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4021                 .dac_nids = alc880_dac_nids,
4022                 .dig_out_nid = ALC880_DIGOUT_NID,
4023                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4024                 .channel_mode = alc880_2_jack_modes,
4025                 .input_mux = &alc880_capture_source,
4026                 .unsol_event = alc880_uniwill_p53_unsol_event,
4027                 .init_hook = alc880_uniwill_p53_init_hook,
4028         },
4029         [ALC880_CLEVO] = {
4030                 .mixers = { alc880_three_stack_mixer },
4031                 .init_verbs = { alc880_volume_init_verbs,
4032                                 alc880_pin_clevo_init_verbs },
4033                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4034                 .dac_nids = alc880_dac_nids,
4035                 .hp_nid = 0x03,
4036                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4037                 .channel_mode = alc880_threestack_modes,
4038                 .need_dac_fix = 1,
4039                 .input_mux = &alc880_capture_source,
4040         },
4041         [ALC880_LG] = {
4042                 .mixers = { alc880_lg_mixer },
4043                 .init_verbs = { alc880_volume_init_verbs,
4044                                 alc880_lg_init_verbs },
4045                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4046                 .dac_nids = alc880_lg_dac_nids,
4047                 .dig_out_nid = ALC880_DIGOUT_NID,
4048                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4049                 .channel_mode = alc880_lg_ch_modes,
4050                 .need_dac_fix = 1,
4051                 .input_mux = &alc880_lg_capture_source,
4052                 .unsol_event = alc_automute_amp_unsol_event,
4053                 .init_hook = alc880_lg_init_hook,
4054 #ifdef CONFIG_SND_HDA_POWER_SAVE
4055                 .loopbacks = alc880_lg_loopbacks,
4056 #endif
4057         },
4058         [ALC880_LG_LW] = {
4059                 .mixers = { alc880_lg_lw_mixer },
4060                 .init_verbs = { alc880_volume_init_verbs,
4061                                 alc880_lg_lw_init_verbs },
4062                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4063                 .dac_nids = alc880_dac_nids,
4064                 .dig_out_nid = ALC880_DIGOUT_NID,
4065                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4066                 .channel_mode = alc880_lg_lw_modes,
4067                 .input_mux = &alc880_lg_lw_capture_source,
4068                 .unsol_event = alc_automute_amp_unsol_event,
4069                 .init_hook = alc880_lg_lw_init_hook,
4070         },
4071         [ALC880_MEDION_RIM] = {
4072                 .mixers = { alc880_medion_rim_mixer },
4073                 .init_verbs = { alc880_volume_init_verbs,
4074                                 alc880_medion_rim_init_verbs,
4075                                 alc_gpio2_init_verbs },
4076                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4077                 .dac_nids = alc880_dac_nids,
4078                 .dig_out_nid = ALC880_DIGOUT_NID,
4079                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4080                 .channel_mode = alc880_2_jack_modes,
4081                 .input_mux = &alc880_medion_rim_capture_source,
4082                 .unsol_event = alc880_medion_rim_unsol_event,
4083                 .init_hook = alc880_medion_rim_init_hook,
4084         },
4085 #ifdef CONFIG_SND_DEBUG
4086         [ALC880_TEST] = {
4087                 .mixers = { alc880_test_mixer },
4088                 .init_verbs = { alc880_test_init_verbs },
4089                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4090                 .dac_nids = alc880_test_dac_nids,
4091                 .dig_out_nid = ALC880_DIGOUT_NID,
4092                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4093                 .channel_mode = alc880_test_modes,
4094                 .input_mux = &alc880_test_capture_source,
4095         },
4096 #endif
4097 };
4098
4099 /*
4100  * Automatic parse of I/O pins from the BIOS configuration
4101  */
4102
4103 enum {
4104         ALC_CTL_WIDGET_VOL,
4105         ALC_CTL_WIDGET_MUTE,
4106         ALC_CTL_BIND_MUTE,
4107 };
4108 static struct snd_kcontrol_new alc880_control_templates[] = {
4109         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4110         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4111         HDA_BIND_MUTE(NULL, 0, 0, 0),
4112 };
4113
4114 /* add dynamic controls */
4115 static int add_control(struct alc_spec *spec, int type, const char *name,
4116                        unsigned long val)
4117 {
4118         struct snd_kcontrol_new *knew;
4119
4120         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4121         knew = snd_array_new(&spec->kctls);
4122         if (!knew)
4123                 return -ENOMEM;
4124         *knew = alc880_control_templates[type];
4125         knew->name = kstrdup(name, GFP_KERNEL);
4126         if (!knew->name)
4127                 return -ENOMEM;
4128         knew->private_value = val;
4129         return 0;
4130 }
4131
4132 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4133 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4134 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4135 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4136 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
4137 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
4138 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4139 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4140 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4141 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4142 #define ALC880_PIN_CD_NID               0x1c
4143
4144 /* fill in the dac_nids table from the parsed pin configuration */
4145 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4146                                      const struct auto_pin_cfg *cfg)
4147 {
4148         hda_nid_t nid;
4149         int assigned[4];
4150         int i, j;
4151
4152         memset(assigned, 0, sizeof(assigned));
4153         spec->multiout.dac_nids = spec->private_dac_nids;
4154
4155         /* check the pins hardwired to audio widget */
4156         for (i = 0; i < cfg->line_outs; i++) {
4157                 nid = cfg->line_out_pins[i];
4158                 if (alc880_is_fixed_pin(nid)) {
4159                         int idx = alc880_fixed_pin_idx(nid);
4160                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4161                         assigned[idx] = 1;
4162                 }
4163         }
4164         /* left pins can be connect to any audio widget */
4165         for (i = 0; i < cfg->line_outs; i++) {
4166                 nid = cfg->line_out_pins[i];
4167                 if (alc880_is_fixed_pin(nid))
4168                         continue;
4169                 /* search for an empty channel */
4170                 for (j = 0; j < cfg->line_outs; j++) {
4171                         if (!assigned[j]) {
4172                                 spec->multiout.dac_nids[i] =
4173                                         alc880_idx_to_dac(j);
4174                                 assigned[j] = 1;
4175                                 break;
4176                         }
4177                 }
4178         }
4179         spec->multiout.num_dacs = cfg->line_outs;
4180         return 0;
4181 }
4182
4183 /* add playback controls from the parsed DAC table */
4184 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4185                                              const struct auto_pin_cfg *cfg)
4186 {
4187         char name[32];
4188         static const char *chname[4] = {
4189                 "Front", "Surround", NULL /*CLFE*/, "Side"
4190         };
4191         hda_nid_t nid;
4192         int i, err;
4193
4194         for (i = 0; i < cfg->line_outs; i++) {
4195                 if (!spec->multiout.dac_nids[i])
4196                         continue;
4197                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4198                 if (i == 2) {
4199                         /* Center/LFE */
4200                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4201                                           "Center Playback Volume",
4202                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4203                                                               HDA_OUTPUT));
4204                         if (err < 0)
4205                                 return err;
4206                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4207                                           "LFE Playback Volume",
4208                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4209                                                               HDA_OUTPUT));
4210                         if (err < 0)
4211                                 return err;
4212                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4213                                           "Center Playback Switch",
4214                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4215                                                               HDA_INPUT));
4216                         if (err < 0)
4217                                 return err;
4218                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4219                                           "LFE Playback Switch",
4220                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4221                                                               HDA_INPUT));
4222                         if (err < 0)
4223                                 return err;
4224                 } else {
4225                         sprintf(name, "%s Playback Volume", chname[i]);
4226                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4227                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4228                                                               HDA_OUTPUT));
4229                         if (err < 0)
4230                                 return err;
4231                         sprintf(name, "%s Playback Switch", chname[i]);
4232                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4233                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4234                                                               HDA_INPUT));
4235                         if (err < 0)
4236                                 return err;
4237                 }
4238         }
4239         return 0;
4240 }
4241
4242 /* add playback controls for speaker and HP outputs */
4243 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4244                                         const char *pfx)
4245 {
4246         hda_nid_t nid;
4247         int err;
4248         char name[32];
4249
4250         if (!pin)
4251                 return 0;
4252
4253         if (alc880_is_fixed_pin(pin)) {
4254                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4255                 /* specify the DAC as the extra output */
4256                 if (!spec->multiout.hp_nid)
4257                         spec->multiout.hp_nid = nid;
4258                 else
4259                         spec->multiout.extra_out_nid[0] = nid;
4260                 /* control HP volume/switch on the output mixer amp */
4261                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4262                 sprintf(name, "%s Playback Volume", pfx);
4263                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4264                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4265                 if (err < 0)
4266                         return err;
4267                 sprintf(name, "%s Playback Switch", pfx);
4268                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4269                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4270                 if (err < 0)
4271                         return err;
4272         } else if (alc880_is_multi_pin(pin)) {
4273                 /* set manual connection */
4274                 /* we have only a switch on HP-out PIN */
4275                 sprintf(name, "%s Playback Switch", pfx);
4276                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4277                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4278                 if (err < 0)
4279                         return err;
4280         }
4281         return 0;
4282 }
4283
4284 /* create input playback/capture controls for the given pin */
4285 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4286                             const char *ctlname,
4287                             int idx, hda_nid_t mix_nid)
4288 {
4289         char name[32];
4290         int err;
4291
4292         sprintf(name, "%s Playback Volume", ctlname);
4293         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4294                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4295         if (err < 0)
4296                 return err;
4297         sprintf(name, "%s Playback Switch", ctlname);
4298         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4299                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4300         if (err < 0)
4301                 return err;
4302         return 0;
4303 }
4304
4305 /* create playback/capture controls for input pins */
4306 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4307                                                 const struct auto_pin_cfg *cfg)
4308 {
4309         struct hda_input_mux *imux = &spec->private_imux[0];
4310         int i, err, idx;
4311
4312         for (i = 0; i < AUTO_PIN_LAST; i++) {
4313                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4314                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4315                         err = new_analog_input(spec, cfg->input_pins[i],
4316                                                auto_pin_cfg_labels[i],
4317                                                idx, 0x0b);
4318                         if (err < 0)
4319                                 return err;
4320                         imux->items[imux->num_items].label =
4321                                 auto_pin_cfg_labels[i];
4322                         imux->items[imux->num_items].index =
4323                                 alc880_input_pin_idx(cfg->input_pins[i]);
4324                         imux->num_items++;
4325                 }
4326         }
4327         return 0;
4328 }
4329
4330 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4331                                unsigned int pin_type)
4332 {
4333         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4334                             pin_type);
4335         /* unmute pin */
4336         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4337                             AMP_OUT_UNMUTE);
4338 }
4339
4340 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4341                                               hda_nid_t nid, int pin_type,
4342                                               int dac_idx)
4343 {
4344         alc_set_pin_output(codec, nid, pin_type);
4345         /* need the manual connection? */
4346         if (alc880_is_multi_pin(nid)) {
4347                 struct alc_spec *spec = codec->spec;
4348                 int idx = alc880_multi_pin_idx(nid);
4349                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4350                                     AC_VERB_SET_CONNECT_SEL,
4351                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4352         }
4353 }
4354
4355 static int get_pin_type(int line_out_type)
4356 {
4357         if (line_out_type == AUTO_PIN_HP_OUT)
4358                 return PIN_HP;
4359         else
4360                 return PIN_OUT;
4361 }
4362
4363 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4364 {
4365         struct alc_spec *spec = codec->spec;
4366         int i;
4367
4368         for (i = 0; i < spec->autocfg.line_outs; i++) {
4369                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4370                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4371                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4372         }
4373 }
4374
4375 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4376 {
4377         struct alc_spec *spec = codec->spec;
4378         hda_nid_t pin;
4379
4380         pin = spec->autocfg.speaker_pins[0];
4381         if (pin) /* connect to front */
4382                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4383         pin = spec->autocfg.hp_pins[0];
4384         if (pin) /* connect to front */
4385                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4386 }
4387
4388 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4389 {
4390         struct alc_spec *spec = codec->spec;
4391         int i;
4392
4393         for (i = 0; i < AUTO_PIN_LAST; i++) {
4394                 hda_nid_t nid = spec->autocfg.input_pins[i];
4395                 if (alc880_is_input_pin(nid)) {
4396                         alc_set_input_pin(codec, nid, i);
4397                         if (nid != ALC880_PIN_CD_NID &&
4398                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4399                                 snd_hda_codec_write(codec, nid, 0,
4400                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4401                                                     AMP_OUT_MUTE);
4402                 }
4403         }
4404 }
4405
4406 /* parse the BIOS configuration and set up the alc_spec */
4407 /* return 1 if successful, 0 if the proper config is not found,
4408  * or a negative error code
4409  */
4410 static int alc880_parse_auto_config(struct hda_codec *codec)
4411 {
4412         struct alc_spec *spec = codec->spec;
4413         int i, err;
4414         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4415
4416         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4417                                            alc880_ignore);
4418         if (err < 0)
4419                 return err;
4420         if (!spec->autocfg.line_outs)
4421                 return 0; /* can't find valid BIOS pin config */
4422
4423         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4424         if (err < 0)
4425                 return err;
4426         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4427         if (err < 0)
4428                 return err;
4429         err = alc880_auto_create_extra_out(spec,
4430                                            spec->autocfg.speaker_pins[0],
4431                                            "Speaker");
4432         if (err < 0)
4433                 return err;
4434         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4435                                            "Headphone");
4436         if (err < 0)
4437                 return err;
4438         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4439         if (err < 0)
4440                 return err;
4441
4442         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4443
4444         /* check multiple SPDIF-out (for recent codecs) */
4445         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4446                 hda_nid_t dig_nid;
4447                 err = snd_hda_get_connections(codec,
4448                                               spec->autocfg.dig_out_pins[i],
4449                                               &dig_nid, 1);
4450                 if (err < 0)
4451                         continue;
4452                 if (!i)
4453                         spec->multiout.dig_out_nid = dig_nid;
4454                 else {
4455                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4456                         spec->slave_dig_outs[i - 1] = dig_nid;
4457                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4458                                 break;
4459                 }
4460         }
4461         if (spec->autocfg.dig_in_pin)
4462                 spec->dig_in_nid = ALC880_DIGIN_NID;
4463
4464         if (spec->kctls.list)
4465                 add_mixer(spec, spec->kctls.list);
4466
4467         add_verb(spec, alc880_volume_init_verbs);
4468
4469         spec->num_mux_defs = 1;
4470         spec->input_mux = &spec->private_imux[0];
4471
4472         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4473
4474         return 1;
4475 }
4476
4477 /* additional initialization for auto-configuration model */
4478 static void alc880_auto_init(struct hda_codec *codec)
4479 {
4480         struct alc_spec *spec = codec->spec;
4481         alc880_auto_init_multi_out(codec);
4482         alc880_auto_init_extra_out(codec);
4483         alc880_auto_init_analog_input(codec);
4484         if (spec->unsol_event)
4485                 alc_inithook(codec);
4486 }
4487
4488 static void set_capture_mixer(struct alc_spec *spec)
4489 {
4490         static struct snd_kcontrol_new *caps[2][3] = {
4491                 { alc_capture_mixer_nosrc1,
4492                   alc_capture_mixer_nosrc2,
4493                   alc_capture_mixer_nosrc3 },
4494                 { alc_capture_mixer1,
4495                   alc_capture_mixer2,
4496                   alc_capture_mixer3 },
4497         };
4498         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4499                 int mux;
4500                 if (spec->input_mux && spec->input_mux->num_items > 1)
4501                         mux = 1;
4502                 else
4503                         mux = 0;
4504                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4505         }
4506 }
4507
4508 #define set_beep_amp(spec, nid, idx, dir) \
4509         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4510
4511 /*
4512  * OK, here we have finally the patch for ALC880
4513  */
4514
4515 static int patch_alc880(struct hda_codec *codec)
4516 {
4517         struct alc_spec *spec;
4518         int board_config;
4519         int err;
4520
4521         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4522         if (spec == NULL)
4523                 return -ENOMEM;
4524
4525         codec->spec = spec;
4526
4527         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4528                                                   alc880_models,
4529                                                   alc880_cfg_tbl);
4530         if (board_config < 0) {
4531                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
4532                        "trying auto-probe from BIOS...\n", codec->chip_name);
4533                 board_config = ALC880_AUTO;
4534         }
4535
4536         if (board_config == ALC880_AUTO) {
4537                 /* automatic parse from the BIOS config */
4538                 err = alc880_parse_auto_config(codec);
4539                 if (err < 0) {
4540                         alc_free(codec);
4541                         return err;
4542                 } else if (!err) {
4543                         printk(KERN_INFO
4544                                "hda_codec: Cannot set up configuration "
4545                                "from BIOS.  Using 3-stack mode...\n");
4546                         board_config = ALC880_3ST;
4547                 }
4548         }
4549
4550         err = snd_hda_attach_beep_device(codec, 0x1);
4551         if (err < 0) {
4552                 alc_free(codec);
4553                 return err;
4554         }
4555
4556         if (board_config != ALC880_AUTO)
4557                 setup_preset(spec, &alc880_presets[board_config]);
4558
4559         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4560         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4561         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4562
4563         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4564         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4565
4566         if (!spec->adc_nids && spec->input_mux) {
4567                 /* check whether NID 0x07 is valid */
4568                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4569                 /* get type */
4570                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4571                 if (wcap != AC_WID_AUD_IN) {
4572                         spec->adc_nids = alc880_adc_nids_alt;
4573                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4574                 } else {
4575                         spec->adc_nids = alc880_adc_nids;
4576                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4577                 }
4578         }
4579         set_capture_mixer(spec);
4580         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4581
4582         spec->vmaster_nid = 0x0c;
4583
4584         codec->patch_ops = alc_patch_ops;
4585         if (board_config == ALC880_AUTO)
4586                 spec->init_hook = alc880_auto_init;
4587 #ifdef CONFIG_SND_HDA_POWER_SAVE
4588         if (!spec->loopback.amplist)
4589                 spec->loopback.amplist = alc880_loopbacks;
4590 #endif
4591         codec->proc_widget_hook = print_realtek_coef;
4592
4593         return 0;
4594 }
4595
4596
4597 /*
4598  * ALC260 support
4599  */
4600
4601 static hda_nid_t alc260_dac_nids[1] = {
4602         /* front */
4603         0x02,
4604 };
4605
4606 static hda_nid_t alc260_adc_nids[1] = {
4607         /* ADC0 */
4608         0x04,
4609 };
4610
4611 static hda_nid_t alc260_adc_nids_alt[1] = {
4612         /* ADC1 */
4613         0x05,
4614 };
4615
4616 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4617  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4618  */
4619 static hda_nid_t alc260_dual_adc_nids[2] = {
4620         /* ADC0, ADC1 */
4621         0x04, 0x05
4622 };
4623
4624 #define ALC260_DIGOUT_NID       0x03
4625 #define ALC260_DIGIN_NID        0x06
4626
4627 static struct hda_input_mux alc260_capture_source = {
4628         .num_items = 4,
4629         .items = {
4630                 { "Mic", 0x0 },
4631                 { "Front Mic", 0x1 },
4632                 { "Line", 0x2 },
4633                 { "CD", 0x4 },
4634         },
4635 };
4636
4637 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4638  * headphone jack and the internal CD lines since these are the only pins at
4639  * which audio can appear.  For flexibility, also allow the option of
4640  * recording the mixer output on the second ADC (ADC0 doesn't have a
4641  * connection to the mixer output).
4642  */
4643 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4644         {
4645                 .num_items = 3,
4646                 .items = {
4647                         { "Mic/Line", 0x0 },
4648                         { "CD", 0x4 },
4649                         { "Headphone", 0x2 },
4650                 },
4651         },
4652         {
4653                 .num_items = 4,
4654                 .items = {
4655                         { "Mic/Line", 0x0 },
4656                         { "CD", 0x4 },
4657                         { "Headphone", 0x2 },
4658                         { "Mixer", 0x5 },
4659                 },
4660         },
4661
4662 };
4663
4664 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4665  * the Fujitsu S702x, but jacks are marked differently.
4666  */
4667 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4668         {
4669                 .num_items = 4,
4670                 .items = {
4671                         { "Mic", 0x0 },
4672                         { "Line", 0x2 },
4673                         { "CD", 0x4 },
4674                         { "Headphone", 0x5 },
4675                 },
4676         },
4677         {
4678                 .num_items = 5,
4679                 .items = {
4680                         { "Mic", 0x0 },
4681                         { "Line", 0x2 },
4682                         { "CD", 0x4 },
4683                         { "Headphone", 0x6 },
4684                         { "Mixer", 0x5 },
4685                 },
4686         },
4687 };
4688
4689 /* Maxdata Favorit 100XS */
4690 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4691         {
4692                 .num_items = 2,
4693                 .items = {
4694                         { "Line/Mic", 0x0 },
4695                         { "CD", 0x4 },
4696                 },
4697         },
4698         {
4699                 .num_items = 3,
4700                 .items = {
4701                         { "Line/Mic", 0x0 },
4702                         { "CD", 0x4 },
4703                         { "Mixer", 0x5 },
4704                 },
4705         },
4706 };
4707
4708 /*
4709  * This is just place-holder, so there's something for alc_build_pcms to look
4710  * at when it calculates the maximum number of channels. ALC260 has no mixer
4711  * element which allows changing the channel mode, so the verb list is
4712  * never used.
4713  */
4714 static struct hda_channel_mode alc260_modes[1] = {
4715         { 2, NULL },
4716 };
4717
4718
4719 /* Mixer combinations
4720  *
4721  * basic: base_output + input + pc_beep + capture
4722  * HP: base_output + input + capture_alt
4723  * HP_3013: hp_3013 + input + capture
4724  * fujitsu: fujitsu + capture
4725  * acer: acer + capture
4726  */
4727
4728 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4729         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4730         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4731         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4732         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4733         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4734         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4735         { } /* end */
4736 };
4737
4738 static struct snd_kcontrol_new alc260_input_mixer[] = {
4739         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4740         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4741         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4742         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4743         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4744         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4745         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4746         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4747         { } /* end */
4748 };
4749
4750 /* update HP, line and mono out pins according to the master switch */
4751 static void alc260_hp_master_update(struct hda_codec *codec,
4752                                     hda_nid_t hp, hda_nid_t line,
4753                                     hda_nid_t mono)
4754 {
4755         struct alc_spec *spec = codec->spec;
4756         unsigned int val = spec->master_sw ? PIN_HP : 0;
4757         /* change HP and line-out pins */
4758         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4759                             val);
4760         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4761                             val);
4762         /* mono (speaker) depending on the HP jack sense */
4763         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4764         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4765                             val);
4766 }
4767
4768 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4769                                    struct snd_ctl_elem_value *ucontrol)
4770 {
4771         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4772         struct alc_spec *spec = codec->spec;
4773         *ucontrol->value.integer.value = spec->master_sw;
4774         return 0;
4775 }
4776
4777 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4778                                    struct snd_ctl_elem_value *ucontrol)
4779 {
4780         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4781         struct alc_spec *spec = codec->spec;
4782         int val = !!*ucontrol->value.integer.value;
4783         hda_nid_t hp, line, mono;
4784
4785         if (val == spec->master_sw)
4786                 return 0;
4787         spec->master_sw = val;
4788         hp = (kcontrol->private_value >> 16) & 0xff;
4789         line = (kcontrol->private_value >> 8) & 0xff;
4790         mono = kcontrol->private_value & 0xff;
4791         alc260_hp_master_update(codec, hp, line, mono);
4792         return 1;
4793 }
4794
4795 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4796         {
4797                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4798                 .name = "Master Playback Switch",
4799                 .info = snd_ctl_boolean_mono_info,
4800                 .get = alc260_hp_master_sw_get,
4801                 .put = alc260_hp_master_sw_put,
4802                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4803         },
4804         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4805         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4806         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4807         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4808         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4809                               HDA_OUTPUT),
4810         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4811         { } /* end */
4812 };
4813
4814 static struct hda_verb alc260_hp_unsol_verbs[] = {
4815         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4816         {},
4817 };
4818
4819 static void alc260_hp_automute(struct hda_codec *codec)
4820 {
4821         struct alc_spec *spec = codec->spec;
4822         unsigned int present;
4823
4824         present = snd_hda_codec_read(codec, 0x10, 0,
4825                                      AC_VERB_GET_PIN_SENSE, 0);
4826         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4827         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4828 }
4829
4830 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4831 {
4832         if ((res >> 26) == ALC880_HP_EVENT)
4833                 alc260_hp_automute(codec);
4834 }
4835
4836 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4837         {
4838                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4839                 .name = "Master Playback Switch",
4840                 .info = snd_ctl_boolean_mono_info,
4841                 .get = alc260_hp_master_sw_get,
4842                 .put = alc260_hp_master_sw_put,
4843                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4844         },
4845         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4846         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4847         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4848         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4849         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4850         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4851         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4852         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4853         { } /* end */
4854 };
4855
4856 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4857         .ops = &snd_hda_bind_vol,
4858         .values = {
4859                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4860                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4861                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4862                 0
4863         },
4864 };
4865
4866 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4867         .ops = &snd_hda_bind_sw,
4868         .values = {
4869                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4870                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4871                 0
4872         },
4873 };
4874
4875 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4876         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4877         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4878         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4879         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4880         { } /* end */
4881 };
4882
4883 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4884         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4885         {},
4886 };
4887
4888 static void alc260_hp_3013_automute(struct hda_codec *codec)
4889 {
4890         struct alc_spec *spec = codec->spec;
4891         unsigned int present;
4892
4893         present = snd_hda_codec_read(codec, 0x15, 0,
4894                                      AC_VERB_GET_PIN_SENSE, 0);
4895         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4896         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4897 }
4898
4899 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4900                                        unsigned int res)
4901 {
4902         if ((res >> 26) == ALC880_HP_EVENT)
4903                 alc260_hp_3013_automute(codec);
4904 }
4905
4906 static void alc260_hp_3012_automute(struct hda_codec *codec)
4907 {
4908         unsigned int present, bits;
4909
4910         present = snd_hda_codec_read(codec, 0x10, 0,
4911                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4912
4913         bits = present ? 0 : PIN_OUT;
4914         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4915                             bits);
4916         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4917                             bits);
4918         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4919                             bits);
4920 }
4921
4922 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4923                                        unsigned int res)
4924 {
4925         if ((res >> 26) == ALC880_HP_EVENT)
4926                 alc260_hp_3012_automute(codec);
4927 }
4928
4929 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4930  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4931  */
4932 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4933         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4934         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4935         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4936         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4937         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4938         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4939         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4940         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4941         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4942         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4943         { } /* end */
4944 };
4945
4946 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4947  * versions of the ALC260 don't act on requests to enable mic bias from NID
4948  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4949  * datasheet doesn't mention this restriction.  At this stage it's not clear
4950  * whether this behaviour is intentional or is a hardware bug in chip
4951  * revisions available in early 2006.  Therefore for now allow the
4952  * "Headphone Jack Mode" control to span all choices, but if it turns out
4953  * that the lack of mic bias for this NID is intentional we could change the
4954  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4955  *
4956  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4957  * don't appear to make the mic bias available from the "line" jack, even
4958  * though the NID used for this jack (0x14) can supply it.  The theory is
4959  * that perhaps Acer have included blocking capacitors between the ALC260
4960  * and the output jack.  If this turns out to be the case for all such
4961  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4962  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4963  *
4964  * The C20x Tablet series have a mono internal speaker which is controlled
4965  * via the chip's Mono sum widget and pin complex, so include the necessary
4966  * controls for such models.  On models without a "mono speaker" the control
4967  * won't do anything.
4968  */
4969 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4970         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4971         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4972         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4973         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4974                               HDA_OUTPUT),
4975         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4976                            HDA_INPUT),
4977         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4978         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4979         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4980         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4981         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4982         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4983         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4984         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4985         { } /* end */
4986 };
4987
4988 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
4989  */
4990 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
4991         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4992         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4993         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4994         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4995         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4996         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4997         { } /* end */
4998 };
4999
5000 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5001  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5002  */
5003 static struct snd_kcontrol_new alc260_will_mixer[] = {
5004         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5005         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5006         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5007         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5008         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5009         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5010         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5011         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5012         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5013         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5014         { } /* end */
5015 };
5016
5017 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5018  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5019  */
5020 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5021         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5022         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5023         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5024         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5025         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5026         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5027         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5028         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5029         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5030         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5031         { } /* end */
5032 };
5033
5034 /*
5035  * initialization verbs
5036  */
5037 static struct hda_verb alc260_init_verbs[] = {
5038         /* Line In pin widget for input */
5039         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5040         /* CD pin widget for input */
5041         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5042         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5043         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5044         /* Mic2 (front panel) pin widget for input and vref at 80% */
5045         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5046         /* LINE-2 is used for line-out in rear */
5047         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5048         /* select line-out */
5049         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5050         /* LINE-OUT pin */
5051         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5052         /* enable HP */
5053         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5054         /* enable Mono */
5055         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5056         /* mute capture amp left and right */
5057         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5058         /* set connection select to line in (default select for this ADC) */
5059         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5060         /* mute capture amp left and right */
5061         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5062         /* set connection select to line in (default select for this ADC) */
5063         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5064         /* set vol=0 Line-Out mixer amp left and right */
5065         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5066         /* unmute pin widget amp left and right (no gain on this amp) */
5067         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5068         /* set vol=0 HP mixer amp left and right */
5069         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5070         /* unmute pin widget amp left and right (no gain on this amp) */
5071         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5072         /* set vol=0 Mono mixer amp left and right */
5073         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5074         /* unmute pin widget amp left and right (no gain on this amp) */
5075         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5076         /* unmute LINE-2 out pin */
5077         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5078         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5079          * Line In 2 = 0x03
5080          */
5081         /* mute analog inputs */
5082         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5083         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5084         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5085         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5086         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5087         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5088         /* mute Front out path */
5089         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5090         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5091         /* mute Headphone out path */
5092         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5093         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5094         /* mute Mono out path */
5095         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5096         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5097         { }
5098 };
5099
5100 #if 0 /* should be identical with alc260_init_verbs? */
5101 static struct hda_verb alc260_hp_init_verbs[] = {
5102         /* Headphone and output */
5103         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5104         /* mono output */
5105         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5106         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5107         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5108         /* Mic2 (front panel) pin widget for input and vref at 80% */
5109         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5110         /* Line In pin widget for input */
5111         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5112         /* Line-2 pin widget for output */
5113         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5114         /* CD pin widget for input */
5115         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5116         /* unmute amp left and right */
5117         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5118         /* set connection select to line in (default select for this ADC) */
5119         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5120         /* unmute Line-Out mixer amp left and right (volume = 0) */
5121         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5122         /* mute pin widget amp left and right (no gain on this amp) */
5123         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5124         /* unmute HP mixer amp left and right (volume = 0) */
5125         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5126         /* mute pin widget amp left and right (no gain on this amp) */
5127         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5128         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5129          * Line In 2 = 0x03
5130          */
5131         /* mute analog inputs */
5132         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5133         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5134         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5135         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5136         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5137         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5138         /* Unmute Front out path */
5139         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5140         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5141         /* Unmute Headphone out path */
5142         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5143         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5144         /* Unmute Mono out path */
5145         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5146         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5147         { }
5148 };
5149 #endif
5150
5151 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5152         /* Line out and output */
5153         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5154         /* mono output */
5155         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5156         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5157         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5158         /* Mic2 (front panel) pin widget for input and vref at 80% */
5159         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5160         /* Line In pin widget for input */
5161         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5162         /* Headphone pin widget for output */
5163         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5164         /* CD pin widget for input */
5165         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5166         /* unmute amp left and right */
5167         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5168         /* set connection select to line in (default select for this ADC) */
5169         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5170         /* unmute Line-Out mixer amp left and right (volume = 0) */
5171         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5172         /* mute pin widget amp left and right (no gain on this amp) */
5173         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5174         /* unmute HP mixer amp left and right (volume = 0) */
5175         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5176         /* mute pin widget amp left and right (no gain on this amp) */
5177         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5178         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5179          * Line In 2 = 0x03
5180          */
5181         /* mute analog inputs */
5182         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5183         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5184         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5185         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5186         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5187         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5188         /* Unmute Front out path */
5189         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5190         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5191         /* Unmute Headphone out path */
5192         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5193         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5194         /* Unmute Mono out path */
5195         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5196         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5197         { }
5198 };
5199
5200 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5201  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5202  * audio = 0x16, internal speaker = 0x10.
5203  */
5204 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5205         /* Disable all GPIOs */
5206         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5207         /* Internal speaker is connected to headphone pin */
5208         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5209         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5210         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5211         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5212         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5213         /* Ensure all other unused pins are disabled and muted. */
5214         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5215         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5216         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5217         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5218         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5219         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5220         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5221         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5222
5223         /* Disable digital (SPDIF) pins */
5224         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5225         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5226
5227         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5228          * when acting as an output.
5229          */
5230         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5231
5232         /* Start with output sum widgets muted and their output gains at min */
5233         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5234         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5235         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5236         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5237         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5238         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5239         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5240         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5241         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5242
5243         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5244         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5245         /* Unmute Line1 pin widget output buffer since it starts as an output.
5246          * If the pin mode is changed by the user the pin mode control will
5247          * take care of enabling the pin's input/output buffers as needed.
5248          * Therefore there's no need to enable the input buffer at this
5249          * stage.
5250          */
5251         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5252         /* Unmute input buffer of pin widget used for Line-in (no equiv
5253          * mixer ctrl)
5254          */
5255         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5256
5257         /* Mute capture amp left and right */
5258         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5259         /* Set ADC connection select to match default mixer setting - line
5260          * in (on mic1 pin)
5261          */
5262         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5263
5264         /* Do the same for the second ADC: mute capture input amp and
5265          * set ADC connection to line in (on mic1 pin)
5266          */
5267         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5268         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5269
5270         /* Mute all inputs to mixer widget (even unconnected ones) */
5271         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5272         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5273         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5274         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5275         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5276         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5277         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5278         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5279
5280         { }
5281 };
5282
5283 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5284  * similar laptops (adapted from Fujitsu init verbs).
5285  */
5286 static struct hda_verb alc260_acer_init_verbs[] = {
5287         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5288          * the headphone jack.  Turn this on and rely on the standard mute
5289          * methods whenever the user wants to turn these outputs off.
5290          */
5291         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5292         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5293         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5294         /* Internal speaker/Headphone jack is connected to Line-out pin */
5295         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5296         /* Internal microphone/Mic jack is connected to Mic1 pin */
5297         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5298         /* Line In jack is connected to Line1 pin */
5299         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5300         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5301         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5302         /* Ensure all other unused pins are disabled and muted. */
5303         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5304         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5305         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5306         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5307         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5308         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5309         /* Disable digital (SPDIF) pins */
5310         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5311         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5312
5313         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5314          * bus when acting as outputs.
5315          */
5316         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5317         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5318
5319         /* Start with output sum widgets muted and their output gains at min */
5320         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5321         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5322         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5323         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5324         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5325         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5326         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5327         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5328         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5329
5330         /* Unmute Line-out pin widget amp left and right
5331          * (no equiv mixer ctrl)
5332          */
5333         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5334         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5335         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5336         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5337          * inputs. If the pin mode is changed by the user the pin mode control
5338          * will take care of enabling the pin's input/output buffers as needed.
5339          * Therefore there's no need to enable the input buffer at this
5340          * stage.
5341          */
5342         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5343         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5344
5345         /* Mute capture amp left and right */
5346         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5347         /* Set ADC connection select to match default mixer setting - mic
5348          * (on mic1 pin)
5349          */
5350         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5351
5352         /* Do similar with the second ADC: mute capture input amp and
5353          * set ADC connection to mic to match ALSA's default state.
5354          */
5355         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5356         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5357
5358         /* Mute all inputs to mixer widget (even unconnected ones) */
5359         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5360         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5361         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5362         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5363         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5364         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5365         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5366         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5367
5368         { }
5369 };
5370
5371 /* Initialisation sequence for Maxdata Favorit 100XS
5372  * (adapted from Acer init verbs).
5373  */
5374 static struct hda_verb alc260_favorit100_init_verbs[] = {
5375         /* GPIO 0 enables the output jack.
5376          * Turn this on and rely on the standard mute
5377          * methods whenever the user wants to turn these outputs off.
5378          */
5379         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5380         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5381         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5382         /* Line/Mic input jack is connected to Mic1 pin */
5383         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5384         /* Ensure all other unused pins are disabled and muted. */
5385         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5386         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5387         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5388         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5389         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5390         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5391         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5392         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5393         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5394         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5395         /* Disable digital (SPDIF) pins */
5396         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5397         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5398
5399         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5400          * bus when acting as outputs.
5401          */
5402         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5403         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5404
5405         /* Start with output sum widgets muted and their output gains at min */
5406         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5407         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5408         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5409         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5410         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5411         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5412         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5413         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5414         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5415
5416         /* Unmute Line-out pin widget amp left and right
5417          * (no equiv mixer ctrl)
5418          */
5419         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5420         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5421          * inputs. If the pin mode is changed by the user the pin mode control
5422          * will take care of enabling the pin's input/output buffers as needed.
5423          * Therefore there's no need to enable the input buffer at this
5424          * stage.
5425          */
5426         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5427
5428         /* Mute capture amp left and right */
5429         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5430         /* Set ADC connection select to match default mixer setting - mic
5431          * (on mic1 pin)
5432          */
5433         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5434
5435         /* Do similar with the second ADC: mute capture input amp and
5436          * set ADC connection to mic to match ALSA's default state.
5437          */
5438         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5439         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5440
5441         /* Mute all inputs to mixer widget (even unconnected ones) */
5442         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5443         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5444         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5445         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5446         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5447         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5448         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5449         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5450
5451         { }
5452 };
5453
5454 static struct hda_verb alc260_will_verbs[] = {
5455         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5456         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5457         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5458         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5459         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5460         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5461         {}
5462 };
5463
5464 static struct hda_verb alc260_replacer_672v_verbs[] = {
5465         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5466         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5467         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5468
5469         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5470         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5471         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5472
5473         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5474         {}
5475 };
5476
5477 /* toggle speaker-output according to the hp-jack state */
5478 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5479 {
5480         unsigned int present;
5481
5482         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5483         present = snd_hda_codec_read(codec, 0x0f, 0,
5484                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5485         if (present) {
5486                 snd_hda_codec_write_cache(codec, 0x01, 0,
5487                                           AC_VERB_SET_GPIO_DATA, 1);
5488                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5489                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5490                                           PIN_HP);
5491         } else {
5492                 snd_hda_codec_write_cache(codec, 0x01, 0,
5493                                           AC_VERB_SET_GPIO_DATA, 0);
5494                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5495                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5496                                           PIN_OUT);
5497         }
5498 }
5499
5500 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5501                                        unsigned int res)
5502 {
5503         if ((res >> 26) == ALC880_HP_EVENT)
5504                 alc260_replacer_672v_automute(codec);
5505 }
5506
5507 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5508         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5509         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5510         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5511         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5512         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5513         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5514         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5515         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5516         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5517         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5518         {}
5519 };
5520
5521 /* Test configuration for debugging, modelled after the ALC880 test
5522  * configuration.
5523  */
5524 #ifdef CONFIG_SND_DEBUG
5525 static hda_nid_t alc260_test_dac_nids[1] = {
5526         0x02,
5527 };
5528 static hda_nid_t alc260_test_adc_nids[2] = {
5529         0x04, 0x05,
5530 };
5531 /* For testing the ALC260, each input MUX needs its own definition since
5532  * the signal assignments are different.  This assumes that the first ADC
5533  * is NID 0x04.
5534  */
5535 static struct hda_input_mux alc260_test_capture_sources[2] = {
5536         {
5537                 .num_items = 7,
5538                 .items = {
5539                         { "MIC1 pin", 0x0 },
5540                         { "MIC2 pin", 0x1 },
5541                         { "LINE1 pin", 0x2 },
5542                         { "LINE2 pin", 0x3 },
5543                         { "CD pin", 0x4 },
5544                         { "LINE-OUT pin", 0x5 },
5545                         { "HP-OUT pin", 0x6 },
5546                 },
5547         },
5548         {
5549                 .num_items = 8,
5550                 .items = {
5551                         { "MIC1 pin", 0x0 },
5552                         { "MIC2 pin", 0x1 },
5553                         { "LINE1 pin", 0x2 },
5554                         { "LINE2 pin", 0x3 },
5555                         { "CD pin", 0x4 },
5556                         { "Mixer", 0x5 },
5557                         { "LINE-OUT pin", 0x6 },
5558                         { "HP-OUT pin", 0x7 },
5559                 },
5560         },
5561 };
5562 static struct snd_kcontrol_new alc260_test_mixer[] = {
5563         /* Output driver widgets */
5564         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5565         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5566         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5567         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5568         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5569         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5570
5571         /* Modes for retasking pin widgets
5572          * Note: the ALC260 doesn't seem to act on requests to enable mic
5573          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5574          * mention this restriction.  At this stage it's not clear whether
5575          * this behaviour is intentional or is a hardware bug in chip
5576          * revisions available at least up until early 2006.  Therefore for
5577          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5578          * choices, but if it turns out that the lack of mic bias for these
5579          * NIDs is intentional we could change their modes from
5580          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5581          */
5582         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5583         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5584         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5585         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5586         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5587         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5588
5589         /* Loopback mixer controls */
5590         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5591         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5592         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5593         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5594         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5595         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5596         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5597         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5598         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5599         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5600         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5601         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5602         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5603         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5604
5605         /* Controls for GPIO pins, assuming they are configured as outputs */
5606         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5607         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5608         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5609         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5610
5611         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5612          * is ambigious as to which NID is which; testing on laptops which
5613          * make this output available should provide clarification.
5614          */
5615         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5616         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5617
5618         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5619          * this output to turn on an external amplifier.
5620          */
5621         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5622         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5623
5624         { } /* end */
5625 };
5626 static struct hda_verb alc260_test_init_verbs[] = {
5627         /* Enable all GPIOs as outputs with an initial value of 0 */
5628         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5629         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5630         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5631
5632         /* Enable retasking pins as output, initially without power amp */
5633         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5634         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5635         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5636         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5637         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5638         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5639
5640         /* Disable digital (SPDIF) pins initially, but users can enable
5641          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5642          * payload also sets the generation to 0, output to be in "consumer"
5643          * PCM format, copyright asserted, no pre-emphasis and no validity
5644          * control.
5645          */
5646         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5647         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5648
5649         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5650          * OUT1 sum bus when acting as an output.
5651          */
5652         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5653         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5654         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5655         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5656
5657         /* Start with output sum widgets muted and their output gains at min */
5658         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5659         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5660         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5661         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5662         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5663         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5664         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5665         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5666         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5667
5668         /* Unmute retasking pin widget output buffers since the default
5669          * state appears to be output.  As the pin mode is changed by the
5670          * user the pin mode control will take care of enabling the pin's
5671          * input/output buffers as needed.
5672          */
5673         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5674         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5675         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5676         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5677         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5678         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5679         /* Also unmute the mono-out pin widget */
5680         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5681
5682         /* Mute capture amp left and right */
5683         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5684         /* Set ADC connection select to match default mixer setting (mic1
5685          * pin)
5686          */
5687         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5688
5689         /* Do the same for the second ADC: mute capture input amp and
5690          * set ADC connection to mic1 pin
5691          */
5692         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5693         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5694
5695         /* Mute all inputs to mixer widget (even unconnected ones) */
5696         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5697         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5698         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5699         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5700         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5701         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5702         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5703         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5704
5705         { }
5706 };
5707 #endif
5708
5709 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5710 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5711
5712 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5713 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5714
5715 /*
5716  * for BIOS auto-configuration
5717  */
5718
5719 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5720                                         const char *pfx, int *vol_bits)
5721 {
5722         hda_nid_t nid_vol;
5723         unsigned long vol_val, sw_val;
5724         char name[32];
5725         int err;
5726
5727         if (nid >= 0x0f && nid < 0x11) {
5728                 nid_vol = nid - 0x7;
5729                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5730                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5731         } else if (nid == 0x11) {
5732                 nid_vol = nid - 0x7;
5733                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5734                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5735         } else if (nid >= 0x12 && nid <= 0x15) {
5736                 nid_vol = 0x08;
5737                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5738                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5739         } else
5740                 return 0; /* N/A */
5741
5742         if (!(*vol_bits & (1 << nid_vol))) {
5743                 /* first control for the volume widget */
5744                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5745                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5746                 if (err < 0)
5747                         return err;
5748                 *vol_bits |= (1 << nid_vol);
5749         }
5750         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5751         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5752         if (err < 0)
5753                 return err;
5754         return 1;
5755 }
5756
5757 /* add playback controls from the parsed DAC table */
5758 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5759                                              const struct auto_pin_cfg *cfg)
5760 {
5761         hda_nid_t nid;
5762         int err;
5763         int vols = 0;
5764
5765         spec->multiout.num_dacs = 1;
5766         spec->multiout.dac_nids = spec->private_dac_nids;
5767         spec->multiout.dac_nids[0] = 0x02;
5768
5769         nid = cfg->line_out_pins[0];
5770         if (nid) {
5771                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5772                 if (err < 0)
5773                         return err;
5774         }
5775
5776         nid = cfg->speaker_pins[0];
5777         if (nid) {
5778                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5779                 if (err < 0)
5780                         return err;
5781         }
5782
5783         nid = cfg->hp_pins[0];
5784         if (nid) {
5785                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5786                                                    &vols);
5787                 if (err < 0)
5788                         return err;
5789         }
5790         return 0;
5791 }
5792
5793 /* create playback/capture controls for input pins */
5794 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5795                                                 const struct auto_pin_cfg *cfg)
5796 {
5797         struct hda_input_mux *imux = &spec->private_imux[0];
5798         int i, err, idx;
5799
5800         for (i = 0; i < AUTO_PIN_LAST; i++) {
5801                 if (cfg->input_pins[i] >= 0x12) {
5802                         idx = cfg->input_pins[i] - 0x12;
5803                         err = new_analog_input(spec, cfg->input_pins[i],
5804                                                auto_pin_cfg_labels[i], idx,
5805                                                0x07);
5806                         if (err < 0)
5807                                 return err;
5808                         imux->items[imux->num_items].label =
5809                                 auto_pin_cfg_labels[i];
5810                         imux->items[imux->num_items].index = idx;
5811                         imux->num_items++;
5812                 }
5813                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5814                         idx = cfg->input_pins[i] - 0x09;
5815                         err = new_analog_input(spec, cfg->input_pins[i],
5816                                                auto_pin_cfg_labels[i], idx,
5817                                                0x07);
5818                         if (err < 0)
5819                                 return err;
5820                         imux->items[imux->num_items].label =
5821                                 auto_pin_cfg_labels[i];
5822                         imux->items[imux->num_items].index = idx;
5823                         imux->num_items++;
5824                 }
5825         }
5826         return 0;
5827 }
5828
5829 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5830                                               hda_nid_t nid, int pin_type,
5831                                               int sel_idx)
5832 {
5833         alc_set_pin_output(codec, nid, pin_type);
5834         /* need the manual connection? */
5835         if (nid >= 0x12) {
5836                 int idx = nid - 0x12;
5837                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5838                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5839         }
5840 }
5841
5842 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5843 {
5844         struct alc_spec *spec = codec->spec;
5845         hda_nid_t nid;
5846
5847         nid = spec->autocfg.line_out_pins[0];
5848         if (nid) {
5849                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5850                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5851         }
5852
5853         nid = spec->autocfg.speaker_pins[0];
5854         if (nid)
5855                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5856
5857         nid = spec->autocfg.hp_pins[0];
5858         if (nid)
5859                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5860 }
5861
5862 #define ALC260_PIN_CD_NID               0x16
5863 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5864 {
5865         struct alc_spec *spec = codec->spec;
5866         int i;
5867
5868         for (i = 0; i < AUTO_PIN_LAST; i++) {
5869                 hda_nid_t nid = spec->autocfg.input_pins[i];
5870                 if (nid >= 0x12) {
5871                         alc_set_input_pin(codec, nid, i);
5872                         if (nid != ALC260_PIN_CD_NID &&
5873                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5874                                 snd_hda_codec_write(codec, nid, 0,
5875                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5876                                                     AMP_OUT_MUTE);
5877                 }
5878         }
5879 }
5880
5881 /*
5882  * generic initialization of ADC, input mixers and output mixers
5883  */
5884 static struct hda_verb alc260_volume_init_verbs[] = {
5885         /*
5886          * Unmute ADC0-1 and set the default input to mic-in
5887          */
5888         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5889         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5890         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5891         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5892
5893         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5894          * mixer widget
5895          * Note: PASD motherboards uses the Line In 2 as the input for
5896          * front panel mic (mic 2)
5897          */
5898         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5899         /* mute analog inputs */
5900         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5901         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5902         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5903         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5904         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5905
5906         /*
5907          * Set up output mixers (0x08 - 0x0a)
5908          */
5909         /* set vol=0 to output mixers */
5910         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5911         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5912         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5913         /* set up input amps for analog loopback */
5914         /* Amp Indices: DAC = 0, mixer = 1 */
5915         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5916         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5917         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5918         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5919         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5920         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5921
5922         { }
5923 };
5924
5925 static int alc260_parse_auto_config(struct hda_codec *codec)
5926 {
5927         struct alc_spec *spec = codec->spec;
5928         int err;
5929         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5930
5931         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5932                                            alc260_ignore);
5933         if (err < 0)
5934                 return err;
5935         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5936         if (err < 0)
5937                 return err;
5938         if (!spec->kctls.list)
5939                 return 0; /* can't find valid BIOS pin config */
5940         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5941         if (err < 0)
5942                 return err;
5943
5944         spec->multiout.max_channels = 2;
5945
5946         if (spec->autocfg.dig_outs)
5947                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5948         if (spec->kctls.list)
5949                 add_mixer(spec, spec->kctls.list);
5950
5951         add_verb(spec, alc260_volume_init_verbs);
5952
5953         spec->num_mux_defs = 1;
5954         spec->input_mux = &spec->private_imux[0];
5955
5956         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
5957
5958         return 1;
5959 }
5960
5961 /* additional initialization for auto-configuration model */
5962 static void alc260_auto_init(struct hda_codec *codec)
5963 {
5964         struct alc_spec *spec = codec->spec;
5965         alc260_auto_init_multi_out(codec);
5966         alc260_auto_init_analog_input(codec);
5967         if (spec->unsol_event)
5968                 alc_inithook(codec);
5969 }
5970
5971 #ifdef CONFIG_SND_HDA_POWER_SAVE
5972 static struct hda_amp_list alc260_loopbacks[] = {
5973         { 0x07, HDA_INPUT, 0 },
5974         { 0x07, HDA_INPUT, 1 },
5975         { 0x07, HDA_INPUT, 2 },
5976         { 0x07, HDA_INPUT, 3 },
5977         { 0x07, HDA_INPUT, 4 },
5978         { } /* end */
5979 };
5980 #endif
5981
5982 /*
5983  * ALC260 configurations
5984  */
5985 static const char *alc260_models[ALC260_MODEL_LAST] = {
5986         [ALC260_BASIC]          = "basic",
5987         [ALC260_HP]             = "hp",
5988         [ALC260_HP_3013]        = "hp-3013",
5989         [ALC260_HP_DC7600]      = "hp-dc7600",
5990         [ALC260_FUJITSU_S702X]  = "fujitsu",
5991         [ALC260_ACER]           = "acer",
5992         [ALC260_WILL]           = "will",
5993         [ALC260_REPLACER_672V]  = "replacer",
5994         [ALC260_FAVORIT100]     = "favorit100",
5995 #ifdef CONFIG_SND_DEBUG
5996         [ALC260_TEST]           = "test",
5997 #endif
5998         [ALC260_AUTO]           = "auto",
5999 };
6000
6001 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6002         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6003         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6004         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6005         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6006         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
6007         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6008         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6009         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6010         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6011         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6012         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6013         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6014         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6015         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6016         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6017         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6018         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6019         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6020         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6021         {}
6022 };
6023
6024 static struct alc_config_preset alc260_presets[] = {
6025         [ALC260_BASIC] = {
6026                 .mixers = { alc260_base_output_mixer,
6027                             alc260_input_mixer },
6028                 .init_verbs = { alc260_init_verbs },
6029                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6030                 .dac_nids = alc260_dac_nids,
6031                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6032                 .adc_nids = alc260_adc_nids,
6033                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6034                 .channel_mode = alc260_modes,
6035                 .input_mux = &alc260_capture_source,
6036         },
6037         [ALC260_HP] = {
6038                 .mixers = { alc260_hp_output_mixer,
6039                             alc260_input_mixer },
6040                 .init_verbs = { alc260_init_verbs,
6041                                 alc260_hp_unsol_verbs },
6042                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6043                 .dac_nids = alc260_dac_nids,
6044                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6045                 .adc_nids = alc260_adc_nids_alt,
6046                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6047                 .channel_mode = alc260_modes,
6048                 .input_mux = &alc260_capture_source,
6049                 .unsol_event = alc260_hp_unsol_event,
6050                 .init_hook = alc260_hp_automute,
6051         },
6052         [ALC260_HP_DC7600] = {
6053                 .mixers = { alc260_hp_dc7600_mixer,
6054                             alc260_input_mixer },
6055                 .init_verbs = { alc260_init_verbs,
6056                                 alc260_hp_dc7600_verbs },
6057                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6058                 .dac_nids = alc260_dac_nids,
6059                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6060                 .adc_nids = alc260_adc_nids_alt,
6061                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6062                 .channel_mode = alc260_modes,
6063                 .input_mux = &alc260_capture_source,
6064                 .unsol_event = alc260_hp_3012_unsol_event,
6065                 .init_hook = alc260_hp_3012_automute,
6066         },
6067         [ALC260_HP_3013] = {
6068                 .mixers = { alc260_hp_3013_mixer,
6069                             alc260_input_mixer },
6070                 .init_verbs = { alc260_hp_3013_init_verbs,
6071                                 alc260_hp_3013_unsol_verbs },
6072                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6073                 .dac_nids = alc260_dac_nids,
6074                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6075                 .adc_nids = alc260_adc_nids_alt,
6076                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6077                 .channel_mode = alc260_modes,
6078                 .input_mux = &alc260_capture_source,
6079                 .unsol_event = alc260_hp_3013_unsol_event,
6080                 .init_hook = alc260_hp_3013_automute,
6081         },
6082         [ALC260_FUJITSU_S702X] = {
6083                 .mixers = { alc260_fujitsu_mixer },
6084                 .init_verbs = { alc260_fujitsu_init_verbs },
6085                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6086                 .dac_nids = alc260_dac_nids,
6087                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6088                 .adc_nids = alc260_dual_adc_nids,
6089                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6090                 .channel_mode = alc260_modes,
6091                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6092                 .input_mux = alc260_fujitsu_capture_sources,
6093         },
6094         [ALC260_ACER] = {
6095                 .mixers = { alc260_acer_mixer },
6096                 .init_verbs = { alc260_acer_init_verbs },
6097                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6098                 .dac_nids = alc260_dac_nids,
6099                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6100                 .adc_nids = alc260_dual_adc_nids,
6101                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6102                 .channel_mode = alc260_modes,
6103                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6104                 .input_mux = alc260_acer_capture_sources,
6105         },
6106         [ALC260_FAVORIT100] = {
6107                 .mixers = { alc260_favorit100_mixer },
6108                 .init_verbs = { alc260_favorit100_init_verbs },
6109                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6110                 .dac_nids = alc260_dac_nids,
6111                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6112                 .adc_nids = alc260_dual_adc_nids,
6113                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6114                 .channel_mode = alc260_modes,
6115                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6116                 .input_mux = alc260_favorit100_capture_sources,
6117         },
6118         [ALC260_WILL] = {
6119                 .mixers = { alc260_will_mixer },
6120                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6121                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6122                 .dac_nids = alc260_dac_nids,
6123                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6124                 .adc_nids = alc260_adc_nids,
6125                 .dig_out_nid = ALC260_DIGOUT_NID,
6126                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6127                 .channel_mode = alc260_modes,
6128                 .input_mux = &alc260_capture_source,
6129         },
6130         [ALC260_REPLACER_672V] = {
6131                 .mixers = { alc260_replacer_672v_mixer },
6132                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6133                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6134                 .dac_nids = alc260_dac_nids,
6135                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6136                 .adc_nids = alc260_adc_nids,
6137                 .dig_out_nid = ALC260_DIGOUT_NID,
6138                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6139                 .channel_mode = alc260_modes,
6140                 .input_mux = &alc260_capture_source,
6141                 .unsol_event = alc260_replacer_672v_unsol_event,
6142                 .init_hook = alc260_replacer_672v_automute,
6143         },
6144 #ifdef CONFIG_SND_DEBUG
6145         [ALC260_TEST] = {
6146                 .mixers = { alc260_test_mixer },
6147                 .init_verbs = { alc260_test_init_verbs },
6148                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6149                 .dac_nids = alc260_test_dac_nids,
6150                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6151                 .adc_nids = alc260_test_adc_nids,
6152                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6153                 .channel_mode = alc260_modes,
6154                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6155                 .input_mux = alc260_test_capture_sources,
6156         },
6157 #endif
6158 };
6159
6160 static int patch_alc260(struct hda_codec *codec)
6161 {
6162         struct alc_spec *spec;
6163         int err, board_config;
6164
6165         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6166         if (spec == NULL)
6167                 return -ENOMEM;
6168
6169         codec->spec = spec;
6170
6171         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6172                                                   alc260_models,
6173                                                   alc260_cfg_tbl);
6174         if (board_config < 0) {
6175                 snd_printd(KERN_INFO "hda_codec: Unknown model for %s, "
6176                            "trying auto-probe from BIOS...\n",
6177                            codec->chip_name);
6178                 board_config = ALC260_AUTO;
6179         }
6180
6181         if (board_config == ALC260_AUTO) {
6182                 /* automatic parse from the BIOS config */
6183                 err = alc260_parse_auto_config(codec);
6184                 if (err < 0) {
6185                         alc_free(codec);
6186                         return err;
6187                 } else if (!err) {
6188                         printk(KERN_INFO
6189                                "hda_codec: Cannot set up configuration "
6190                                "from BIOS.  Using base mode...\n");
6191                         board_config = ALC260_BASIC;
6192                 }
6193         }
6194
6195         err = snd_hda_attach_beep_device(codec, 0x1);
6196         if (err < 0) {
6197                 alc_free(codec);
6198                 return err;
6199         }
6200
6201         if (board_config != ALC260_AUTO)
6202                 setup_preset(spec, &alc260_presets[board_config]);
6203
6204         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6205         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6206
6207         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6208         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6209
6210         if (!spec->adc_nids && spec->input_mux) {
6211                 /* check whether NID 0x04 is valid */
6212                 unsigned int wcap = get_wcaps(codec, 0x04);
6213                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6214                 /* get type */
6215                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6216                         spec->adc_nids = alc260_adc_nids_alt;
6217                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6218                 } else {
6219                         spec->adc_nids = alc260_adc_nids;
6220                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6221                 }
6222         }
6223         set_capture_mixer(spec);
6224         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6225
6226         spec->vmaster_nid = 0x08;
6227
6228         codec->patch_ops = alc_patch_ops;
6229         if (board_config == ALC260_AUTO)
6230                 spec->init_hook = alc260_auto_init;
6231 #ifdef CONFIG_SND_HDA_POWER_SAVE
6232         if (!spec->loopback.amplist)
6233                 spec->loopback.amplist = alc260_loopbacks;
6234 #endif
6235         codec->proc_widget_hook = print_realtek_coef;
6236
6237         return 0;
6238 }
6239
6240
6241 /*
6242  * ALC882 support
6243  *
6244  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6245  * configuration.  Each pin widget can choose any input DACs and a mixer.
6246  * Each ADC is connected from a mixer of all inputs.  This makes possible
6247  * 6-channel independent captures.
6248  *
6249  * In addition, an independent DAC for the multi-playback (not used in this
6250  * driver yet).
6251  */
6252 #define ALC882_DIGOUT_NID       0x06
6253 #define ALC882_DIGIN_NID        0x0a
6254
6255 static struct hda_channel_mode alc882_ch_modes[1] = {
6256         { 8, NULL }
6257 };
6258
6259 static hda_nid_t alc882_dac_nids[4] = {
6260         /* front, rear, clfe, rear_surr */
6261         0x02, 0x03, 0x04, 0x05
6262 };
6263
6264 /* identical with ALC880 */
6265 #define alc882_adc_nids         alc880_adc_nids
6266 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6267
6268 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6269 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6270
6271 /* input MUX */
6272 /* FIXME: should be a matrix-type input source selection */
6273
6274 static struct hda_input_mux alc882_capture_source = {
6275         .num_items = 4,
6276         .items = {
6277                 { "Mic", 0x0 },
6278                 { "Front Mic", 0x1 },
6279                 { "Line", 0x2 },
6280                 { "CD", 0x4 },
6281         },
6282 };
6283
6284 static struct hda_input_mux mb5_capture_source = {
6285         .num_items = 3,
6286         .items = {
6287                 { "Mic", 0x1 },
6288                 { "Line", 0x2 },
6289                 { "CD", 0x4 },
6290         },
6291 };
6292
6293 /*
6294  * 2ch mode
6295  */
6296 static struct hda_verb alc882_3ST_ch2_init[] = {
6297         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6298         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6299         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6300         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6301         { } /* end */
6302 };
6303
6304 /*
6305  * 6ch mode
6306  */
6307 static struct hda_verb alc882_3ST_ch6_init[] = {
6308         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6309         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6310         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6311         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6312         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6313         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6314         { } /* end */
6315 };
6316
6317 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
6318         { 2, alc882_3ST_ch2_init },
6319         { 6, alc882_3ST_ch6_init },
6320 };
6321
6322 /*
6323  * 6ch mode
6324  */
6325 static struct hda_verb alc882_sixstack_ch6_init[] = {
6326         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6327         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6328         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6329         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6330         { } /* end */
6331 };
6332
6333 /*
6334  * 8ch mode
6335  */
6336 static struct hda_verb alc882_sixstack_ch8_init[] = {
6337         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6338         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6339         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6340         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6341         { } /* end */
6342 };
6343
6344 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6345         { 6, alc882_sixstack_ch6_init },
6346         { 8, alc882_sixstack_ch8_init },
6347 };
6348
6349 /*
6350  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6351  */
6352
6353 /*
6354  * 2ch mode
6355  */
6356 static struct hda_verb alc885_mbp_ch2_init[] = {
6357         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6358         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6359         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6360         { } /* end */
6361 };
6362
6363 /*
6364  * 6ch mode
6365  */
6366 static struct hda_verb alc885_mbp_ch6_init[] = {
6367         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6368         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6369         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6370         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6371         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6372         { } /* end */
6373 };
6374
6375 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6376         { 2, alc885_mbp_ch2_init },
6377         { 6, alc885_mbp_ch6_init },
6378 };
6379
6380 /*
6381  * 2ch
6382  * Speakers/Woofer/HP = Front
6383  * LineIn = Input
6384  */
6385 static struct hda_verb alc885_mb5_ch2_init[] = {
6386         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6387         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6388         { } /* end */
6389 };
6390
6391 /*
6392  * 6ch mode
6393  * Speakers/HP = Front
6394  * Woofer = LFE
6395  * LineIn = Surround
6396  */
6397 static struct hda_verb alc885_mb5_ch6_init[] = {
6398         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6399         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6400         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6401         { } /* end */
6402 };
6403
6404 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6405         { 2, alc885_mb5_ch2_init },
6406         { 6, alc885_mb5_ch6_init },
6407 };
6408
6409 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6410  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6411  */
6412 static struct snd_kcontrol_new alc882_base_mixer[] = {
6413         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6414         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6415         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6416         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6417         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6418         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6419         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6420         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6421         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6422         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6423         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6424         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6425         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6426         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6427         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6428         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6429         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6430         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6431         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6432         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6433         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6434         { } /* end */
6435 };
6436
6437 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6438         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6439         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6440         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6441         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6442         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6443         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6444         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6445         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6446         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6447         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6448         { } /* end */
6449 };
6450
6451 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
6452         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6453         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6454         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6455         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
6456         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
6457         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
6458         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
6459         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
6460         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6461         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6462         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6463         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6464         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
6465         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
6466         { } /* end */
6467 };
6468
6469 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6470         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6471         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6472         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6473         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6474         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6475         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6476         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6477         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6478         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6479         { } /* end */
6480 };
6481
6482 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6483         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6484         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6485         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6486         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6487         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6488         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6489         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6490         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6491         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6492         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6493         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6494         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6495         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6496         { } /* end */
6497 };
6498
6499 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6500  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6501  */
6502 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6503         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6504         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6505         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6506         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6507         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6508         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6509         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6510         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6511         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6512         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6513         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6514         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6515         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6516         { } /* end */
6517 };
6518
6519 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6520         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6521         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6522         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6523         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6524         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6525         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6526         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6527         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6528         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6529         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6530         { } /* end */
6531 };
6532
6533 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6534         {
6535                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6536                 .name = "Channel Mode",
6537                 .info = alc_ch_mode_info,
6538                 .get = alc_ch_mode_get,
6539                 .put = alc_ch_mode_put,
6540         },
6541         { } /* end */
6542 };
6543
6544 static struct hda_verb alc882_init_verbs[] = {
6545         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6546         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6547         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6548         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6549         /* Rear mixer */
6550         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6551         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6552         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6553         /* CLFE mixer */
6554         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6555         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6556         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6557         /* Side mixer */
6558         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6559         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6560         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6561
6562         /* Front Pin: output 0 (0x0c) */
6563         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6564         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6565         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6566         /* Rear Pin: output 1 (0x0d) */
6567         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6568         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6569         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6570         /* CLFE Pin: output 2 (0x0e) */
6571         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6572         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6573         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6574         /* Side Pin: output 3 (0x0f) */
6575         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6576         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6577         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6578         /* Mic (rear) pin: input vref at 80% */
6579         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6580         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6581         /* Front Mic pin: input vref at 80% */
6582         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6583         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6584         /* Line In pin: input */
6585         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6586         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6587         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6588         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6589         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6590         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6591         /* CD pin widget for input */
6592         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6593
6594         /* FIXME: use matrix-type input source selection */
6595         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6596         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6597         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6598         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6599         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6600         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6601         /* Input mixer2 */
6602         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6603         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6604         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6605         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6606         /* Input mixer3 */
6607         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6608         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6609         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6610         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6611         /* ADC1: mute amp left and right */
6612         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6613         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6614         /* ADC2: mute amp left and right */
6615         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6616         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6617         /* ADC3: mute amp left and right */
6618         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6619         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6620
6621         { }
6622 };
6623
6624 static struct hda_verb alc882_eapd_verbs[] = {
6625         /* change to EAPD mode */
6626         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6627         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6628         { }
6629 };
6630
6631 /* Mac Pro test */
6632 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6633         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6634         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6635         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6636         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6637         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6638         /* FIXME: this looks suspicious...
6639         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6640         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6641         */
6642         { } /* end */
6643 };
6644
6645 static struct hda_verb alc882_macpro_init_verbs[] = {
6646         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6647         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6648         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6649         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6650         /* Front Pin: output 0 (0x0c) */
6651         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6652         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6653         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6654         /* Front Mic pin: input vref at 80% */
6655         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6656         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6657         /* Speaker:  output */
6658         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6659         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6660         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6661         /* Headphone output (output 0 - 0x0c) */
6662         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6663         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6664         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6665
6666         /* FIXME: use matrix-type input source selection */
6667         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6668         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6669         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6670         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6671         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6672         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6673         /* Input mixer2 */
6674         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6675         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6676         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6677         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6678         /* Input mixer3 */
6679         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6680         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6681         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6682         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6683         /* ADC1: mute amp left and right */
6684         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6685         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6686         /* ADC2: mute amp left and right */
6687         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6688         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6689         /* ADC3: mute amp left and right */
6690         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6691         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6692
6693         { }
6694 };
6695
6696 /* Macbook 5,1 */
6697 static struct hda_verb alc885_mb5_init_verbs[] = {
6698         /* DACs */
6699         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6700         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6701         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6702         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6703         /* Front mixer */
6704         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6705         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6706         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6707         /* Surround mixer */
6708         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6709         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6710         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6711         /* LFE mixer */
6712         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6713         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6714         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6715         /* HP mixer */
6716         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6717         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6718         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6719         /* Front Pin (0x0c) */
6720         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
6721         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6722         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6723         /* LFE Pin (0x0e) */
6724         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
6725         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6726         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
6727         /* HP Pin (0x0f) */
6728         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6729         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6730         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
6731         /* Front Mic pin: input vref at 80% */
6732         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6733         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6734         /* Line In pin */
6735         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6736         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6737
6738         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6739         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6740         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6741         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6742         { }
6743 };
6744
6745 /* Macbook Pro rev3 */
6746 static struct hda_verb alc885_mbp3_init_verbs[] = {
6747         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6748         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6749         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6750         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6751         /* Rear mixer */
6752         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6753         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6754         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6755         /* Front Pin: output 0 (0x0c) */
6756         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6757         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6758         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6759         /* HP Pin: output 0 (0x0d) */
6760         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6761         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6762         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6763         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6764         /* Mic (rear) pin: input vref at 80% */
6765         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6766         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6767         /* Front Mic pin: input vref at 80% */
6768         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6769         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6770         /* Line In pin: use output 1 when in LineOut mode */
6771         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6772         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6773         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6774
6775         /* FIXME: use matrix-type input source selection */
6776         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6777         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6778         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6779         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6780         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6781         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6782         /* Input mixer2 */
6783         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6784         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6785         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6786         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6787         /* Input mixer3 */
6788         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6789         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6790         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6791         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6792         /* ADC1: mute amp left and right */
6793         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6794         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6795         /* ADC2: mute amp left and right */
6796         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6797         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6798         /* ADC3: mute amp left and right */
6799         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6800         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6801
6802         { }
6803 };
6804
6805 /* iMac 24 mixer. */
6806 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6807         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6808         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6809         { } /* end */
6810 };
6811
6812 /* iMac 24 init verbs. */
6813 static struct hda_verb alc885_imac24_init_verbs[] = {
6814         /* Internal speakers: output 0 (0x0c) */
6815         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6816         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6817         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6818         /* Internal speakers: output 0 (0x0c) */
6819         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6820         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6821         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6822         /* Headphone: output 0 (0x0c) */
6823         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6824         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6825         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6826         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6827         /* Front Mic: input vref at 80% */
6828         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6829         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6830         { }
6831 };
6832
6833 /* Toggle speaker-output according to the hp-jack state */
6834 static void alc885_imac24_automute_init_hook(struct hda_codec *codec)
6835 {
6836         struct alc_spec *spec = codec->spec;
6837
6838         spec->autocfg.hp_pins[0] = 0x14;
6839         spec->autocfg.speaker_pins[0] = 0x18;
6840         spec->autocfg.speaker_pins[1] = 0x1a;
6841         alc_automute_amp(codec);
6842 }
6843
6844 static void alc885_mbp3_init_hook(struct hda_codec *codec)
6845 {
6846         struct alc_spec *spec = codec->spec;
6847
6848         spec->autocfg.hp_pins[0] = 0x15;
6849         spec->autocfg.speaker_pins[0] = 0x14;
6850         alc_automute_amp(codec);
6851 }
6852
6853
6854 static struct hda_verb alc882_targa_verbs[] = {
6855         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6856         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6857
6858         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6859         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6860
6861         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6862         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6863         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6864
6865         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6866         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6867         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6868         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6869         { } /* end */
6870 };
6871
6872 /* toggle speaker-output according to the hp-jack state */
6873 static void alc882_targa_automute(struct hda_codec *codec)
6874 {
6875         struct alc_spec *spec = codec->spec;
6876         alc_automute_amp(codec);
6877         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6878                                   spec->jack_present ? 1 : 3);
6879 }
6880
6881 static void alc882_targa_init_hook(struct hda_codec *codec)
6882 {
6883         struct alc_spec *spec = codec->spec;
6884
6885         spec->autocfg.hp_pins[0] = 0x14;
6886         spec->autocfg.speaker_pins[0] = 0x1b;
6887         alc882_targa_automute(codec);
6888 }
6889
6890 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6891 {
6892         if ((res >> 26) == ALC880_HP_EVENT)
6893                 alc882_targa_automute(codec);
6894 }
6895
6896 static struct hda_verb alc882_asus_a7j_verbs[] = {
6897         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6898         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6899
6900         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6901         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6902         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6903
6904         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6905         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6906         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6907
6908         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6909         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6910         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6911         { } /* end */
6912 };
6913
6914 static struct hda_verb alc882_asus_a7m_verbs[] = {
6915         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6916         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6917
6918         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6919         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6920         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6921
6922         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6923         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6924         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6925
6926         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6927         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6928         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6929         { } /* end */
6930 };
6931
6932 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6933 {
6934         unsigned int gpiostate, gpiomask, gpiodir;
6935
6936         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6937                                        AC_VERB_GET_GPIO_DATA, 0);
6938
6939         if (!muted)
6940                 gpiostate |= (1 << pin);
6941         else
6942                 gpiostate &= ~(1 << pin);
6943
6944         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6945                                       AC_VERB_GET_GPIO_MASK, 0);
6946         gpiomask |= (1 << pin);
6947
6948         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6949                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6950         gpiodir |= (1 << pin);
6951
6952
6953         snd_hda_codec_write(codec, codec->afg, 0,
6954                             AC_VERB_SET_GPIO_MASK, gpiomask);
6955         snd_hda_codec_write(codec, codec->afg, 0,
6956                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6957
6958         msleep(1);
6959
6960         snd_hda_codec_write(codec, codec->afg, 0,
6961                             AC_VERB_SET_GPIO_DATA, gpiostate);
6962 }
6963
6964 /* set up GPIO at initialization */
6965 static void alc885_macpro_init_hook(struct hda_codec *codec)
6966 {
6967         alc882_gpio_mute(codec, 0, 0);
6968         alc882_gpio_mute(codec, 1, 0);
6969 }
6970
6971 /* set up GPIO and update auto-muting at initialization */
6972 static void alc885_imac24_init_hook(struct hda_codec *codec)
6973 {
6974         alc885_macpro_init_hook(codec);
6975         alc885_imac24_automute_init_hook(codec);
6976 }
6977
6978 /*
6979  * generic initialization of ADC, input mixers and output mixers
6980  */
6981 static struct hda_verb alc882_auto_init_verbs[] = {
6982         /*
6983          * Unmute ADC0-2 and set the default input to mic-in
6984          */
6985         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6986         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6987         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6988         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6989         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6990         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6991
6992         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6993          * mixer widget
6994          * Note: PASD motherboards uses the Line In 2 as the input for
6995          * front panel mic (mic 2)
6996          */
6997         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6998         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6999         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7000         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7001         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7002         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7003
7004         /*
7005          * Set up output mixers (0x0c - 0x0f)
7006          */
7007         /* set vol=0 to output mixers */
7008         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7009         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7010         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7011         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7012         /* set up input amps for analog loopback */
7013         /* Amp Indices: DAC = 0, mixer = 1 */
7014         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7015         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7016         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7017         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7018         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7019         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7020         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7021         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7022         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7023         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7024
7025         /* FIXME: use matrix-type input source selection */
7026         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7027         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7028         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7029         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7030         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7031         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7032         /* Input mixer2 */
7033         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7034         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7035         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7036         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7037         /* Input mixer3 */
7038         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7039         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7040         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7041         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7042
7043         { }
7044 };
7045
7046 #ifdef CONFIG_SND_HDA_POWER_SAVE
7047 #define alc882_loopbacks        alc880_loopbacks
7048 #endif
7049
7050 /* pcm configuration: identiacal with ALC880 */
7051 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
7052 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
7053 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
7054 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
7055
7056 /*
7057  * configuration and preset
7058  */
7059 static const char *alc882_models[ALC882_MODEL_LAST] = {
7060         [ALC882_3ST_DIG]        = "3stack-dig",
7061         [ALC882_6ST_DIG]        = "6stack-dig",
7062         [ALC882_ARIMA]          = "arima",
7063         [ALC882_W2JC]           = "w2jc",
7064         [ALC882_TARGA]          = "targa",
7065         [ALC882_ASUS_A7J]       = "asus-a7j",
7066         [ALC882_ASUS_A7M]       = "asus-a7m",
7067         [ALC885_MACPRO]         = "macpro",
7068         [ALC885_MB5]            = "mb5",
7069         [ALC885_MBP3]           = "mbp3",
7070         [ALC885_IMAC24]         = "imac24",
7071         [ALC882_AUTO]           = "auto",
7072 };
7073
7074 static struct snd_pci_quirk alc882_cfg_tbl[] = {
7075         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
7076         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
7077         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
7078         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
7079         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
7080         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
7081         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
7082         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
7083         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
7084         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
7085         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
7086         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
7087         {}
7088 };
7089
7090 static struct alc_config_preset alc882_presets[] = {
7091         [ALC882_3ST_DIG] = {
7092                 .mixers = { alc882_base_mixer },
7093                 .init_verbs = { alc882_init_verbs },
7094                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7095                 .dac_nids = alc882_dac_nids,
7096                 .dig_out_nid = ALC882_DIGOUT_NID,
7097                 .dig_in_nid = ALC882_DIGIN_NID,
7098                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7099                 .channel_mode = alc882_ch_modes,
7100                 .need_dac_fix = 1,
7101                 .input_mux = &alc882_capture_source,
7102         },
7103         [ALC882_6ST_DIG] = {
7104                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7105                 .init_verbs = { alc882_init_verbs },
7106                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7107                 .dac_nids = alc882_dac_nids,
7108                 .dig_out_nid = ALC882_DIGOUT_NID,
7109                 .dig_in_nid = ALC882_DIGIN_NID,
7110                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7111                 .channel_mode = alc882_sixstack_modes,
7112                 .input_mux = &alc882_capture_source,
7113         },
7114         [ALC882_ARIMA] = {
7115                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7116                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
7117                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7118                 .dac_nids = alc882_dac_nids,
7119                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7120                 .channel_mode = alc882_sixstack_modes,
7121                 .input_mux = &alc882_capture_source,
7122         },
7123         [ALC882_W2JC] = {
7124                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
7125                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7126                                 alc880_gpio1_init_verbs },
7127                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7128                 .dac_nids = alc882_dac_nids,
7129                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7130                 .channel_mode = alc880_threestack_modes,
7131                 .need_dac_fix = 1,
7132                 .input_mux = &alc882_capture_source,
7133                 .dig_out_nid = ALC882_DIGOUT_NID,
7134         },
7135         [ALC885_MBP3] = {
7136                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
7137                 .init_verbs = { alc885_mbp3_init_verbs,
7138                                 alc880_gpio1_init_verbs },
7139                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7140                 .dac_nids = alc882_dac_nids,
7141                 .channel_mode = alc885_mbp_6ch_modes,
7142                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
7143                 .input_mux = &alc882_capture_source,
7144                 .dig_out_nid = ALC882_DIGOUT_NID,
7145                 .dig_in_nid = ALC882_DIGIN_NID,
7146                 .unsol_event = alc_automute_amp_unsol_event,
7147                 .init_hook = alc885_mbp3_init_hook,
7148         },
7149         [ALC885_MB5] = {
7150                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
7151                 .init_verbs = { alc885_mb5_init_verbs,
7152                                 alc880_gpio1_init_verbs },
7153                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7154                 .dac_nids = alc882_dac_nids,
7155                 .channel_mode = alc885_mb5_6ch_modes,
7156                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
7157                 .input_mux = &mb5_capture_source,
7158                 .dig_out_nid = ALC882_DIGOUT_NID,
7159                 .dig_in_nid = ALC882_DIGIN_NID,
7160         },
7161         [ALC885_MACPRO] = {
7162                 .mixers = { alc882_macpro_mixer },
7163                 .init_verbs = { alc882_macpro_init_verbs },
7164                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7165                 .dac_nids = alc882_dac_nids,
7166                 .dig_out_nid = ALC882_DIGOUT_NID,
7167                 .dig_in_nid = ALC882_DIGIN_NID,
7168                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7169                 .channel_mode = alc882_ch_modes,
7170                 .input_mux = &alc882_capture_source,
7171                 .init_hook = alc885_macpro_init_hook,
7172         },
7173         [ALC885_IMAC24] = {
7174                 .mixers = { alc885_imac24_mixer },
7175                 .init_verbs = { alc885_imac24_init_verbs },
7176                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7177                 .dac_nids = alc882_dac_nids,
7178                 .dig_out_nid = ALC882_DIGOUT_NID,
7179                 .dig_in_nid = ALC882_DIGIN_NID,
7180                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7181                 .channel_mode = alc882_ch_modes,
7182                 .input_mux = &alc882_capture_source,
7183                 .unsol_event = alc_automute_amp_unsol_event,
7184                 .init_hook = alc885_imac24_init_hook,
7185         },
7186         [ALC882_TARGA] = {
7187                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
7188                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
7189                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7190                 .dac_nids = alc882_dac_nids,
7191                 .dig_out_nid = ALC882_DIGOUT_NID,
7192                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7193                 .adc_nids = alc882_adc_nids,
7194                 .capsrc_nids = alc882_capsrc_nids,
7195                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7196                 .channel_mode = alc882_3ST_6ch_modes,
7197                 .need_dac_fix = 1,
7198                 .input_mux = &alc882_capture_source,
7199                 .unsol_event = alc882_targa_unsol_event,
7200                 .init_hook = alc882_targa_init_hook,
7201         },
7202         [ALC882_ASUS_A7J] = {
7203                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
7204                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
7205                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7206                 .dac_nids = alc882_dac_nids,
7207                 .dig_out_nid = ALC882_DIGOUT_NID,
7208                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7209                 .adc_nids = alc882_adc_nids,
7210                 .capsrc_nids = alc882_capsrc_nids,
7211                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7212                 .channel_mode = alc882_3ST_6ch_modes,
7213                 .need_dac_fix = 1,
7214                 .input_mux = &alc882_capture_source,
7215         },
7216         [ALC882_ASUS_A7M] = {
7217                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
7218                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7219                                 alc880_gpio1_init_verbs,
7220                                 alc882_asus_a7m_verbs },
7221                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7222                 .dac_nids = alc882_dac_nids,
7223                 .dig_out_nid = ALC882_DIGOUT_NID,
7224                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7225                 .channel_mode = alc880_threestack_modes,
7226                 .need_dac_fix = 1,
7227                 .input_mux = &alc882_capture_source,
7228         },
7229 };
7230
7231
7232 /*
7233  * Pin config fixes
7234  */
7235 enum {
7236         PINFIX_ABIT_AW9D_MAX
7237 };
7238
7239 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
7240         { 0x15, 0x01080104 }, /* side */
7241         { 0x16, 0x01011012 }, /* rear */
7242         { 0x17, 0x01016011 }, /* clfe */
7243         { }
7244 };
7245
7246 static const struct alc_pincfg *alc882_pin_fixes[] = {
7247         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
7248 };
7249
7250 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
7251         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
7252         {}
7253 };
7254
7255 /*
7256  * BIOS auto configuration
7257  */
7258 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
7259                                               hda_nid_t nid, int pin_type,
7260                                               int dac_idx)
7261 {
7262         /* set as output */
7263         struct alc_spec *spec = codec->spec;
7264         int idx;
7265
7266         alc_set_pin_output(codec, nid, pin_type);
7267         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7268                 idx = 4;
7269         else
7270                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7271         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7272
7273 }
7274
7275 static void alc882_auto_init_multi_out(struct hda_codec *codec)
7276 {
7277         struct alc_spec *spec = codec->spec;
7278         int i;
7279
7280         for (i = 0; i <= HDA_SIDE; i++) {
7281                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7282                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7283                 if (nid)
7284                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
7285                                                           i);
7286         }
7287 }
7288
7289 static void alc882_auto_init_hp_out(struct hda_codec *codec)
7290 {
7291         struct alc_spec *spec = codec->spec;
7292         hda_nid_t pin;
7293
7294         pin = spec->autocfg.hp_pins[0];
7295         if (pin) /* connect to front */
7296                 /* use dac 0 */
7297                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7298         pin = spec->autocfg.speaker_pins[0];
7299         if (pin)
7300                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7301 }
7302
7303 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
7304 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
7305
7306 static void alc882_auto_init_analog_input(struct hda_codec *codec)
7307 {
7308         struct alc_spec *spec = codec->spec;
7309         int i;
7310
7311         for (i = 0; i < AUTO_PIN_LAST; i++) {
7312                 hda_nid_t nid = spec->autocfg.input_pins[i];
7313                 if (!nid)
7314                         continue;
7315                 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
7316                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
7317                         snd_hda_codec_write(codec, nid, 0,
7318                                             AC_VERB_SET_AMP_GAIN_MUTE,
7319                                             AMP_OUT_MUTE);
7320         }
7321 }
7322
7323 static void alc882_auto_init_input_src(struct hda_codec *codec)
7324 {
7325         struct alc_spec *spec = codec->spec;
7326         int c;
7327
7328         for (c = 0; c < spec->num_adc_nids; c++) {
7329                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
7330                 hda_nid_t nid = spec->capsrc_nids[c];
7331                 unsigned int mux_idx;
7332                 const struct hda_input_mux *imux;
7333                 int conns, mute, idx, item;
7334
7335                 conns = snd_hda_get_connections(codec, nid, conn_list,
7336                                                 ARRAY_SIZE(conn_list));
7337                 if (conns < 0)
7338                         continue;
7339                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7340                 imux = &spec->input_mux[mux_idx];
7341                 for (idx = 0; idx < conns; idx++) {
7342                         /* if the current connection is the selected one,
7343                          * unmute it as default - otherwise mute it
7344                          */
7345                         mute = AMP_IN_MUTE(idx);
7346                         for (item = 0; item < imux->num_items; item++) {
7347                                 if (imux->items[item].index == idx) {
7348                                         if (spec->cur_mux[c] == item)
7349                                                 mute = AMP_IN_UNMUTE(idx);
7350                                         break;
7351                                 }
7352                         }
7353                         /* check if we have a selector or mixer
7354                          * we could check for the widget type instead, but
7355                          * just check for Amp-In presence (in case of mixer
7356                          * without amp-in there is something wrong, this
7357                          * function shouldn't be used or capsrc nid is wrong)
7358                          */
7359                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7360                                 snd_hda_codec_write(codec, nid, 0,
7361                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7362                                                     mute);
7363                         else if (mute != AMP_IN_MUTE(idx))
7364                                 snd_hda_codec_write(codec, nid, 0,
7365                                                     AC_VERB_SET_CONNECT_SEL,
7366                                                     idx);
7367                 }
7368         }
7369 }
7370
7371 /* add mic boosts if needed */
7372 static int alc_auto_add_mic_boost(struct hda_codec *codec)
7373 {
7374         struct alc_spec *spec = codec->spec;
7375         int err;
7376         hda_nid_t nid;
7377
7378         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
7379         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7380                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7381                                   "Mic Boost",
7382                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7383                 if (err < 0)
7384                         return err;
7385         }
7386         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
7387         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7388                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7389                                   "Front Mic Boost",
7390                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7391                 if (err < 0)
7392                         return err;
7393         }
7394         return 0;
7395 }
7396
7397 /* almost identical with ALC880 parser... */
7398 static int alc882_parse_auto_config(struct hda_codec *codec)
7399 {
7400         struct alc_spec *spec = codec->spec;
7401         int err = alc880_parse_auto_config(codec);
7402
7403         if (err < 0)
7404                 return err;
7405         else if (!err)
7406                 return 0; /* no config found */
7407
7408         err = alc_auto_add_mic_boost(codec);
7409         if (err < 0)
7410                 return err;
7411
7412         /* hack - override the init verbs */
7413         spec->init_verbs[0] = alc882_auto_init_verbs;
7414
7415         return 1; /* config found */
7416 }
7417
7418 /* additional initialization for auto-configuration model */
7419 static void alc882_auto_init(struct hda_codec *codec)
7420 {
7421         struct alc_spec *spec = codec->spec;
7422         alc882_auto_init_multi_out(codec);
7423         alc882_auto_init_hp_out(codec);
7424         alc882_auto_init_analog_input(codec);
7425         alc882_auto_init_input_src(codec);
7426         if (spec->unsol_event)
7427                 alc_inithook(codec);
7428 }
7429
7430 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7431
7432 static int patch_alc882(struct hda_codec *codec)
7433 {
7434         struct alc_spec *spec;
7435         int err, board_config;
7436
7437         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7438         if (spec == NULL)
7439                 return -ENOMEM;
7440
7441         codec->spec = spec;
7442
7443         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7444                                                   alc882_models,
7445                                                   alc882_cfg_tbl);
7446
7447         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7448                 /* Pick up systems that don't supply PCI SSID */
7449                 switch (codec->subsystem_id) {
7450                 case 0x106b0c00: /* Mac Pro */
7451                         board_config = ALC885_MACPRO;
7452                         break;
7453                 case 0x106b1000: /* iMac 24 */
7454                 case 0x106b2800: /* AppleTV */
7455                 case 0x106b3e00: /* iMac 24 Aluminium */
7456                         board_config = ALC885_IMAC24;
7457                         break;
7458                 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7459                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7460                 case 0x106b00a4: /* MacbookPro4,1 */
7461                 case 0x106b2c00: /* Macbook Pro rev3 */
7462                 /* Macbook 3.1 (0x106b3600) is handled by patch_alc883() */
7463                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7464                         board_config = ALC885_MBP3;
7465                         break;
7466                 case 0x106b3f00: /* Macbook 5,1 */
7467                 case 0x106b4000: /* Macbook Pro 5,1 - FIXME: HP jack sense
7468                                   *   seems not working, so apparently
7469                                   *   no perfect solution yet
7470                                   */
7471                         board_config = ALC885_MB5;
7472                         break;
7473                 default:
7474                         /* ALC889A is handled better as ALC888-compatible */
7475                         if (codec->revision_id == 0x100101 ||
7476                             codec->revision_id == 0x100103) {
7477                                 alc_free(codec);
7478                                 return patch_alc883(codec);
7479                         }
7480                         printk(KERN_INFO "hda_codec: Unknown model for %s, "
7481                                "trying auto-probe from BIOS...\n",
7482                                codec->chip_name);
7483                         board_config = ALC882_AUTO;
7484                 }
7485         }
7486
7487         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7488
7489         if (board_config == ALC882_AUTO) {
7490                 /* automatic parse from the BIOS config */
7491                 err = alc882_parse_auto_config(codec);
7492                 if (err < 0) {
7493                         alc_free(codec);
7494                         return err;
7495                 } else if (!err) {
7496                         printk(KERN_INFO
7497                                "hda_codec: Cannot set up configuration "
7498                                "from BIOS.  Using base mode...\n");
7499                         board_config = ALC882_3ST_DIG;
7500                 }
7501         }
7502
7503         err = snd_hda_attach_beep_device(codec, 0x1);
7504         if (err < 0) {
7505                 alc_free(codec);
7506                 return err;
7507         }
7508
7509         if (board_config != ALC882_AUTO)
7510                 setup_preset(spec, &alc882_presets[board_config]);
7511
7512         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7513         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7514         /* FIXME: setup DAC5 */
7515         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7516         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7517
7518         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7519         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7520
7521         spec->capture_style = CAPT_MIX; /* matrix-style capture */
7522         if (!spec->adc_nids && spec->input_mux) {
7523                 /* check whether NID 0x07 is valid */
7524                 unsigned int wcap = get_wcaps(codec, 0x07);
7525                 /* get type */
7526                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7527                 if (wcap != AC_WID_AUD_IN) {
7528                         spec->adc_nids = alc882_adc_nids_alt;
7529                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7530                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7531                 } else {
7532                         spec->adc_nids = alc882_adc_nids;
7533                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7534                         spec->capsrc_nids = alc882_capsrc_nids;
7535                 }
7536         }
7537         set_capture_mixer(spec);
7538         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7539
7540         spec->vmaster_nid = 0x0c;
7541
7542         codec->patch_ops = alc_patch_ops;
7543         if (board_config == ALC882_AUTO)
7544                 spec->init_hook = alc882_auto_init;
7545 #ifdef CONFIG_SND_HDA_POWER_SAVE
7546         if (!spec->loopback.amplist)
7547                 spec->loopback.amplist = alc882_loopbacks;
7548 #endif
7549         codec->proc_widget_hook = print_realtek_coef;
7550
7551         return 0;
7552 }
7553
7554 /*
7555  * ALC883 support
7556  *
7557  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7558  * configuration.  Each pin widget can choose any input DACs and a mixer.
7559  * Each ADC is connected from a mixer of all inputs.  This makes possible
7560  * 6-channel independent captures.
7561  *
7562  * In addition, an independent DAC for the multi-playback (not used in this
7563  * driver yet).
7564  */
7565 #define ALC883_DIGOUT_NID       0x06
7566 #define ALC883_DIGIN_NID        0x0a
7567
7568 #define ALC1200_DIGOUT_NID      0x10
7569
7570 static hda_nid_t alc883_dac_nids[4] = {
7571         /* front, rear, clfe, rear_surr */
7572         0x02, 0x03, 0x04, 0x05
7573 };
7574
7575 static hda_nid_t alc883_adc_nids[2] = {
7576         /* ADC1-2 */
7577         0x08, 0x09,
7578 };
7579
7580 static hda_nid_t alc883_adc_nids_alt[1] = {
7581         /* ADC1 */
7582         0x08,
7583 };
7584
7585 static hda_nid_t alc883_adc_nids_rev[2] = {
7586         /* ADC2-1 */
7587         0x09, 0x08
7588 };
7589
7590 #define alc889_adc_nids         alc880_adc_nids
7591
7592 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7593
7594 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7595
7596 #define alc889_capsrc_nids      alc882_capsrc_nids
7597
7598 /* input MUX */
7599 /* FIXME: should be a matrix-type input source selection */
7600
7601 static struct hda_input_mux alc883_capture_source = {
7602         .num_items = 4,
7603         .items = {
7604                 { "Mic", 0x0 },
7605                 { "Front Mic", 0x1 },
7606                 { "Line", 0x2 },
7607                 { "CD", 0x4 },
7608         },
7609 };
7610
7611 static struct hda_input_mux alc883_3stack_6ch_intel = {
7612         .num_items = 4,
7613         .items = {
7614                 { "Mic", 0x1 },
7615                 { "Front Mic", 0x0 },
7616                 { "Line", 0x2 },
7617                 { "CD", 0x4 },
7618         },
7619 };
7620
7621 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7622         .num_items = 2,
7623         .items = {
7624                 { "Mic", 0x1 },
7625                 { "Line", 0x2 },
7626         },
7627 };
7628
7629 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7630         .num_items = 4,
7631         .items = {
7632                 { "Mic", 0x0 },
7633                 { "iMic", 0x1 },
7634                 { "Line", 0x2 },
7635                 { "CD", 0x4 },
7636         },
7637 };
7638
7639 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7640         .num_items = 2,
7641         .items = {
7642                 { "Mic", 0x0 },
7643                 { "Int Mic", 0x1 },
7644         },
7645 };
7646
7647 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7648         .num_items = 3,
7649         .items = {
7650                 { "Mic", 0x0 },
7651                 { "Front Mic", 0x1 },
7652                 { "Line", 0x4 },
7653         },
7654 };
7655
7656 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7657         .num_items = 2,
7658         .items = {
7659                 { "Mic", 0x0 },
7660                 { "Line", 0x2 },
7661         },
7662 };
7663
7664 static struct hda_input_mux alc889A_mb31_capture_source = {
7665         .num_items = 2,
7666         .items = {
7667                 { "Mic", 0x0 },
7668                 /* Front Mic (0x01) unused */
7669                 { "Line", 0x2 },
7670                 /* Line 2 (0x03) unused */
7671                 /* CD (0x04) unsused? */
7672         },
7673 };
7674
7675 /*
7676  * 2ch mode
7677  */
7678 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7679         { 2, NULL }
7680 };
7681
7682 /*
7683  * 2ch mode
7684  */
7685 static struct hda_verb alc883_3ST_ch2_init[] = {
7686         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7687         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7688         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7689         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7690         { } /* end */
7691 };
7692
7693 /*
7694  * 4ch mode
7695  */
7696 static struct hda_verb alc883_3ST_ch4_init[] = {
7697         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7698         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7699         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7700         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7701         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7702         { } /* end */
7703 };
7704
7705 /*
7706  * 6ch mode
7707  */
7708 static struct hda_verb alc883_3ST_ch6_init[] = {
7709         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7710         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7711         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7712         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7713         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7714         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7715         { } /* end */
7716 };
7717
7718 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7719         { 2, alc883_3ST_ch2_init },
7720         { 4, alc883_3ST_ch4_init },
7721         { 6, alc883_3ST_ch6_init },
7722 };
7723
7724
7725 /*
7726  * 2ch mode
7727  */
7728 static struct hda_verb alc883_4ST_ch2_init[] = {
7729         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7730         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7731         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7732         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7733         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7734         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7735         { } /* end */
7736 };
7737
7738 /*
7739  * 4ch mode
7740  */
7741 static struct hda_verb alc883_4ST_ch4_init[] = {
7742         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7743         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7744         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7745         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7746         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7747         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7748         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7749         { } /* end */
7750 };
7751
7752 /*
7753  * 6ch mode
7754  */
7755 static struct hda_verb alc883_4ST_ch6_init[] = {
7756         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7757         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7758         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7759         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7760         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7761         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7762         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7763         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7764         { } /* end */
7765 };
7766
7767 /*
7768  * 8ch mode
7769  */
7770 static struct hda_verb alc883_4ST_ch8_init[] = {
7771         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7772         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7773         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
7774         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7775         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7776         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7777         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7778         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7779         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7780         { } /* end */
7781 };
7782
7783 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
7784         { 2, alc883_4ST_ch2_init },
7785         { 4, alc883_4ST_ch4_init },
7786         { 6, alc883_4ST_ch6_init },
7787         { 8, alc883_4ST_ch8_init },
7788 };
7789
7790
7791 /*
7792  * 2ch mode
7793  */
7794 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7795         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7796         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7797         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7798         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7799         { } /* end */
7800 };
7801
7802 /*
7803  * 4ch mode
7804  */
7805 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7806         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7807         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7808         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7809         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7810         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7811         { } /* end */
7812 };
7813
7814 /*
7815  * 6ch mode
7816  */
7817 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7818         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7819         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7820         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7821         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7822         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7823         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7824         { } /* end */
7825 };
7826
7827 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7828         { 2, alc883_3ST_ch2_intel_init },
7829         { 4, alc883_3ST_ch4_intel_init },
7830         { 6, alc883_3ST_ch6_intel_init },
7831 };
7832
7833 /*
7834  * 6ch mode
7835  */
7836 static struct hda_verb alc883_sixstack_ch6_init[] = {
7837         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7838         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7839         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7840         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7841         { } /* end */
7842 };
7843
7844 /*
7845  * 8ch mode
7846  */
7847 static struct hda_verb alc883_sixstack_ch8_init[] = {
7848         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7849         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7850         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7851         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7852         { } /* end */
7853 };
7854
7855 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7856         { 6, alc883_sixstack_ch6_init },
7857         { 8, alc883_sixstack_ch8_init },
7858 };
7859
7860 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7861 static struct hda_verb alc889A_mb31_ch2_init[] = {
7862         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7863         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7864         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7865         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7866         { } /* end */
7867 };
7868
7869 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7870 static struct hda_verb alc889A_mb31_ch4_init[] = {
7871         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7872         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7873         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7874         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7875         { } /* end */
7876 };
7877
7878 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7879 static struct hda_verb alc889A_mb31_ch5_init[] = {
7880         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7881         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7882         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7883         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7884         { } /* end */
7885 };
7886
7887 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7888 static struct hda_verb alc889A_mb31_ch6_init[] = {
7889         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7890         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7891         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7892         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7893         { } /* end */
7894 };
7895
7896 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7897         { 2, alc889A_mb31_ch2_init },
7898         { 4, alc889A_mb31_ch4_init },
7899         { 5, alc889A_mb31_ch5_init },
7900         { 6, alc889A_mb31_ch6_init },
7901 };
7902
7903 static struct hda_verb alc883_medion_eapd_verbs[] = {
7904         /* eanable EAPD on medion laptop */
7905         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7906         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7907         { }
7908 };
7909
7910 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7911  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7912  */
7913
7914 static struct snd_kcontrol_new alc883_base_mixer[] = {
7915         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7916         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7917         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7918         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7919         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7920         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7921         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7922         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7923         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7924         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7925         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7926         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7927         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7928         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7929         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7930         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7931         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7932         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7933         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7934         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7935         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7936         { } /* end */
7937 };
7938
7939 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7940         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7941         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7942         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7943         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7944         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7945         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7946         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7947         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7948         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7949         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7950         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7951         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7952         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7953         { } /* end */
7954 };
7955
7956 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7957         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7958         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7959         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7960         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, 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         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7965         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7966         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7967         { } /* end */
7968 };
7969
7970 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7971         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7972         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7973         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7974         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7975         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7976         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7977         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7978         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7979         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7980         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7981         { } /* end */
7982 };
7983
7984 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7985         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7986         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7987         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7988         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7989         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7990         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7991         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7992         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7993         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7995         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7996         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7997         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7998         { } /* end */
7999 };
8000
8001 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
8002         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8003         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8004         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8005         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8006         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8007         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8008         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8009         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8010         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8011         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8012         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8013         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8014         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8015         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8016         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8017         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8018         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8019         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8020         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8021         { } /* end */
8022 };
8023
8024 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
8025         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8026         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8027         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8028         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8029         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
8030                               HDA_OUTPUT),
8031         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8032         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8033         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8034         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8035         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8036         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8037         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8038         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8039         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8040         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8041         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8042         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8043         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
8044         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8045         { } /* end */
8046 };
8047
8048 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8049         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8050         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8051         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8052         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8053         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8054         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8055         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8056         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8057         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8058         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8059         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8060         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8061         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8063         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8064         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8065         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8066         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8067         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8068         { } /* end */
8069 };
8070
8071 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
8072         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8073         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8074         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8075         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8076         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8077         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8078         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8079         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8080         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8081         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8082         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8083         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8084         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8085         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8086         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8087         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8088         { } /* end */
8089 };
8090
8091 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
8092         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8093         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8094         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8095         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8096         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8097         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8098         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8099         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8100         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8101         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8102         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8103         { } /* end */
8104 };
8105
8106 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8107         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8108         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8109         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8110         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8111         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8113         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8115         { } /* end */
8116 };
8117
8118 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8119         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8120         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8121         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8122         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8123         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8124         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8125         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8126         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8127         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8128         { } /* end */
8129 };
8130
8131 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8132         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8134         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8135         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8136         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8137         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8138         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8139         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8140         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8141         { } /* end */
8142 };
8143
8144 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8145         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8146         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8147         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8148         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8149         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8150         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8151         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8152         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8153         { } /* end */
8154 };
8155
8156 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8157         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8158         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8159         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8160         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8161         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8162                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8163         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8164         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8165         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8166         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8167         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8168         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8169         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8170         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8171         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8172         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8173         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8174         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8175         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8176         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8177         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8178         { } /* end */
8179 };
8180
8181 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8182         /* Output mixers */
8183         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8184         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8185         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8186         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8187         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8188                 HDA_OUTPUT),
8189         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8190         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8191         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8192         /* Output switches */
8193         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8194         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8195         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8196         /* Boost mixers */
8197         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8198         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8199         /* Input mixers */
8200         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8201         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8202         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8203         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8204         { } /* end */
8205 };
8206
8207 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8208         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8209         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8210         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8211         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8212         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8213         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8214         { } /* end */
8215 };
8216
8217 static struct hda_bind_ctls alc883_bind_cap_vol = {
8218         .ops = &snd_hda_bind_vol,
8219         .values = {
8220                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8221                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8222                 0
8223         },
8224 };
8225
8226 static struct hda_bind_ctls alc883_bind_cap_switch = {
8227         .ops = &snd_hda_bind_sw,
8228         .values = {
8229                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8230                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8231                 0
8232         },
8233 };
8234
8235 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8236         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8237         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8238         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8239         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8240         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8241         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8242         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8243         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8244         { } /* end */
8245 };
8246
8247 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8248         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8249         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8250         {
8251                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8252                 /* .name = "Capture Source", */
8253                 .name = "Input Source",
8254                 .count = 1,
8255                 .info = alc_mux_enum_info,
8256                 .get = alc_mux_enum_get,
8257                 .put = alc_mux_enum_put,
8258         },
8259         { } /* end */
8260 };
8261
8262 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8263         {
8264                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8265                 .name = "Channel Mode",
8266                 .info = alc_ch_mode_info,
8267                 .get = alc_ch_mode_get,
8268                 .put = alc_ch_mode_put,
8269         },
8270         { } /* end */
8271 };
8272
8273 static struct hda_verb alc883_init_verbs[] = {
8274         /* ADC1: mute amp left and right */
8275         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8276         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8277         /* ADC2: mute amp left and right */
8278         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8279         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8280         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8281         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8282         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8283         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8284         /* Rear mixer */
8285         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8286         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8287         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8288         /* CLFE mixer */
8289         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8290         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8291         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8292         /* Side mixer */
8293         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8294         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8295         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8296
8297         /* mute analog input loopbacks */
8298         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8299         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8300         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8301         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8302         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8303
8304         /* Front Pin: output 0 (0x0c) */
8305         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8306         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8307         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8308         /* Rear Pin: output 1 (0x0d) */
8309         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8310         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8311         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8312         /* CLFE Pin: output 2 (0x0e) */
8313         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8314         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8315         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8316         /* Side Pin: output 3 (0x0f) */
8317         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8318         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8319         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8320         /* Mic (rear) pin: input vref at 80% */
8321         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8322         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8323         /* Front Mic pin: input vref at 80% */
8324         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8325         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8326         /* Line In pin: input */
8327         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8328         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8329         /* Line-2 In: Headphone output (output 0 - 0x0c) */
8330         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8331         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8332         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8333         /* CD pin widget for input */
8334         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8335
8336         /* FIXME: use matrix-type input source selection */
8337         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8338         /* Input mixer2 */
8339         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8340         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8341         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8342         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8343         /* Input mixer3 */
8344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8348         { }
8349 };
8350
8351 /* toggle speaker-output according to the hp-jack state */
8352 static void alc883_mitac_init_hook(struct hda_codec *codec)
8353 {
8354         struct alc_spec *spec = codec->spec;
8355
8356         spec->autocfg.hp_pins[0] = 0x15;
8357         spec->autocfg.speaker_pins[0] = 0x14;
8358         spec->autocfg.speaker_pins[1] = 0x17;
8359         alc_automute_amp(codec);
8360 }
8361
8362 /* auto-toggle front mic */
8363 /*
8364 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8365 {
8366         unsigned int present;
8367         unsigned char bits;
8368
8369         present = snd_hda_codec_read(codec, 0x18, 0,
8370                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8371         bits = present ? HDA_AMP_MUTE : 0;
8372         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8373 }
8374 */
8375
8376 static struct hda_verb alc883_mitac_verbs[] = {
8377         /* HP */
8378         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8379         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8380         /* Subwoofer */
8381         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8382         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8383
8384         /* enable unsolicited event */
8385         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8386         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8387
8388         { } /* end */
8389 };
8390
8391 static struct hda_verb alc883_clevo_m720_verbs[] = {
8392         /* HP */
8393         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8394         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8395         /* Int speaker */
8396         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8397         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8398
8399         /* enable unsolicited event */
8400         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8401         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8402
8403         { } /* end */
8404 };
8405
8406 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8407         /* HP */
8408         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8409         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8410         /* Subwoofer */
8411         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8412         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8413
8414         /* enable unsolicited event */
8415         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8416
8417         { } /* end */
8418 };
8419
8420 static struct hda_verb alc883_tagra_verbs[] = {
8421         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8422         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8423
8424         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8425         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8426
8427 /* Connect Line-Out side jack (SPDIF) to Side */
8428         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8429         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8430         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8431 /* Connect Mic jack to CLFE */
8432         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8433         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8434         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8435 /* Connect Line-in jack to Surround */
8436         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8437         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8438         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8439 /* Connect HP out jack to Front */
8440         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8441         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8442         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8443
8444         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8445
8446         { } /* end */
8447 };
8448
8449 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8450         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8451         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8452         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8453         { } /* end */
8454 };
8455
8456 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8457         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8458         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8459         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8460         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8461         { } /* end */
8462 };
8463
8464 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8465         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8466         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8467         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8468         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8469         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8470         { } /* end */
8471 };
8472
8473 static struct hda_verb alc883_haier_w66_verbs[] = {
8474         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8475         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8476
8477         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8478
8479         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8480         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8481         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8482         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8483         { } /* end */
8484 };
8485
8486 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8487         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8488         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8489         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8490         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8491         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8492         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8493         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8494         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8495         { } /* end */
8496 };
8497
8498 static struct hda_verb alc888_6st_dell_verbs[] = {
8499         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8500         { }
8501 };
8502
8503 static struct hda_verb alc883_vaiott_verbs[] = {
8504         /* HP */
8505         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8506         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8507
8508         /* enable unsolicited event */
8509         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8510
8511         { } /* end */
8512 };
8513
8514 static void alc888_3st_hp_init_hook(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         spec->autocfg.speaker_pins[1] = 0x16;
8521         spec->autocfg.speaker_pins[2] = 0x18;
8522         alc_automute_amp(codec);
8523 }
8524
8525 static struct hda_verb alc888_3st_hp_verbs[] = {
8526         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8527         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8528         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8529         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8530         { } /* end */
8531 };
8532
8533 /*
8534  * 2ch mode
8535  */
8536 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8537         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8538         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8539         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8540         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8541         { } /* end */
8542 };
8543
8544 /*
8545  * 4ch mode
8546  */
8547 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8548         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8549         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8550         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8551         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8552         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8553         { } /* end */
8554 };
8555
8556 /*
8557  * 6ch mode
8558  */
8559 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8560         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8561         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8562         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8563         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8564         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8565         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8566         { } /* end */
8567 };
8568
8569 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8570         { 2, alc888_3st_hp_2ch_init },
8571         { 4, alc888_3st_hp_4ch_init },
8572         { 6, alc888_3st_hp_6ch_init },
8573 };
8574
8575 /* toggle front-jack and RCA according to the hp-jack state */
8576 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8577 {
8578         unsigned int present;
8579
8580         present = snd_hda_codec_read(codec, 0x1b, 0,
8581                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8582         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8583                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8584         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8585                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8586 }
8587
8588 /* toggle RCA according to the front-jack state */
8589 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8590 {
8591         unsigned int present;
8592
8593         present = snd_hda_codec_read(codec, 0x14, 0,
8594                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8595         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8596                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8597 }
8598
8599 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8600                                              unsigned int res)
8601 {
8602         if ((res >> 26) == ALC880_HP_EVENT)
8603                 alc888_lenovo_ms7195_front_automute(codec);
8604         if ((res >> 26) == ALC880_FRONT_EVENT)
8605                 alc888_lenovo_ms7195_rca_automute(codec);
8606 }
8607
8608 static struct hda_verb alc883_medion_md2_verbs[] = {
8609         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8610         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8611
8612         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8613
8614         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8615         { } /* end */
8616 };
8617
8618 /* toggle speaker-output according to the hp-jack state */
8619 static void alc883_medion_md2_init_hook(struct hda_codec *codec)
8620 {
8621         struct alc_spec *spec = codec->spec;
8622
8623         spec->autocfg.hp_pins[0] = 0x14;
8624         spec->autocfg.speaker_pins[0] = 0x15;
8625         alc_automute_amp(codec);
8626 }
8627
8628 /* toggle speaker-output according to the hp-jack state */
8629 #define alc883_tagra_init_hook          alc882_targa_init_hook
8630 #define alc883_tagra_unsol_event        alc882_targa_unsol_event
8631
8632 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8633 {
8634         unsigned int present;
8635
8636         present = snd_hda_codec_read(codec, 0x18, 0,
8637                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8638         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8639                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8640 }
8641
8642 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8643 {
8644         struct alc_spec *spec = codec->spec;
8645
8646         spec->autocfg.hp_pins[0] = 0x15;
8647         spec->autocfg.speaker_pins[0] = 0x14;
8648         alc_automute_amp(codec);
8649         alc883_clevo_m720_mic_automute(codec);
8650 }
8651
8652 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8653                                            unsigned int res)
8654 {
8655         switch (res >> 26) {
8656         case ALC880_MIC_EVENT:
8657                 alc883_clevo_m720_mic_automute(codec);
8658                 break;
8659         default:
8660                 alc_automute_amp_unsol_event(codec, res);
8661                 break;
8662         }
8663 }
8664
8665 /* toggle speaker-output according to the hp-jack state */
8666 static void alc883_2ch_fujitsu_pi2515_init_hook(struct hda_codec *codec)
8667 {
8668         struct alc_spec *spec = codec->spec;
8669
8670         spec->autocfg.hp_pins[0] = 0x14;
8671         spec->autocfg.speaker_pins[0] = 0x15;
8672         alc_automute_amp(codec);
8673 }
8674
8675 static void alc883_haier_w66_init_hook(struct hda_codec *codec)
8676 {
8677         struct alc_spec *spec = codec->spec;
8678
8679         spec->autocfg.hp_pins[0] = 0x1b;
8680         spec->autocfg.speaker_pins[0] = 0x14;
8681         alc_automute_amp(codec);
8682 }
8683
8684 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8685 {
8686         unsigned int present;
8687         unsigned char bits;
8688
8689         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8690                 & AC_PINSENSE_PRESENCE;
8691         bits = present ? HDA_AMP_MUTE : 0;
8692         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8693                                  HDA_AMP_MUTE, bits);
8694 }
8695
8696 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8697 {
8698         unsigned int present;
8699         unsigned char bits;
8700
8701         present = snd_hda_codec_read(codec, 0x1b, 0,
8702                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8703         bits = present ? HDA_AMP_MUTE : 0;
8704         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8705                                  HDA_AMP_MUTE, bits);
8706         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8707                                  HDA_AMP_MUTE, bits);
8708 }
8709
8710 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8711                                            unsigned int res)
8712 {
8713         if ((res >> 26) == ALC880_HP_EVENT)
8714                 alc883_lenovo_101e_all_automute(codec);
8715         if ((res >> 26) == ALC880_FRONT_EVENT)
8716                 alc883_lenovo_101e_ispeaker_automute(codec);
8717 }
8718
8719 /* toggle speaker-output according to the hp-jack state */
8720 static void alc883_acer_aspire_init_hook(struct hda_codec *codec)
8721 {
8722         struct alc_spec *spec = codec->spec;
8723
8724         spec->autocfg.hp_pins[0] = 0x14;
8725         spec->autocfg.speaker_pins[0] = 0x15;
8726         spec->autocfg.speaker_pins[1] = 0x16;
8727         alc_automute_amp(codec);
8728 }
8729
8730 static struct hda_verb alc883_acer_eapd_verbs[] = {
8731         /* HP Pin: output 0 (0x0c) */
8732         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8733         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8734         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8735         /* Front Pin: output 0 (0x0c) */
8736         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8737         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8738         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8739         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8740         /* eanable EAPD on medion laptop */
8741         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8742         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8743         /* enable unsolicited event */
8744         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8745         { }
8746 };
8747
8748 static void alc888_6st_dell_init_hook(struct hda_codec *codec)
8749 {
8750         struct alc_spec *spec = codec->spec;
8751
8752         spec->autocfg.hp_pins[0] = 0x1b;
8753         spec->autocfg.speaker_pins[0] = 0x14;
8754         spec->autocfg.speaker_pins[1] = 0x15;
8755         spec->autocfg.speaker_pins[2] = 0x16;
8756         spec->autocfg.speaker_pins[3] = 0x17;
8757         alc_automute_amp(codec);
8758 }
8759
8760 static void alc888_lenovo_sky_init_hook(struct hda_codec *codec)
8761 {
8762         struct alc_spec *spec = codec->spec;
8763
8764         spec->autocfg.hp_pins[0] = 0x1b;
8765         spec->autocfg.speaker_pins[0] = 0x14;
8766         spec->autocfg.speaker_pins[1] = 0x15;
8767         spec->autocfg.speaker_pins[2] = 0x16;
8768         spec->autocfg.speaker_pins[3] = 0x17;
8769         spec->autocfg.speaker_pins[4] = 0x1a;
8770         alc_automute_amp(codec);
8771 }
8772
8773 static void alc883_vaiott_init_hook(struct hda_codec *codec)
8774 {
8775         struct alc_spec *spec = codec->spec;
8776
8777         spec->autocfg.hp_pins[0] = 0x15;
8778         spec->autocfg.speaker_pins[0] = 0x14;
8779         spec->autocfg.speaker_pins[1] = 0x17;
8780         alc_automute_amp(codec);
8781 }
8782
8783 /*
8784  * generic initialization of ADC, input mixers and output mixers
8785  */
8786 static struct hda_verb alc883_auto_init_verbs[] = {
8787         /*
8788          * Unmute ADC0-2 and set the default input to mic-in
8789          */
8790         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8791         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8792         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8793         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8794
8795         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8796          * mixer widget
8797          * Note: PASD motherboards uses the Line In 2 as the input for
8798          * front panel mic (mic 2)
8799          */
8800         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8801         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8802         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8803         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8804         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8805         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8806
8807         /*
8808          * Set up output mixers (0x0c - 0x0f)
8809          */
8810         /* set vol=0 to output mixers */
8811         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8812         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8813         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8814         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8815         /* set up input amps for analog loopback */
8816         /* Amp Indices: DAC = 0, mixer = 1 */
8817         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8818         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8819         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8820         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8821         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8822         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8823         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8824         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8825         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8826         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8827
8828         /* FIXME: use matrix-type input source selection */
8829         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8830         /* Input mixer1 */
8831         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8832         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8833         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8834         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8835         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8836         /* Input mixer2 */
8837         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8838         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8839         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8840         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8841         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8842
8843         { }
8844 };
8845
8846 static struct hda_verb alc888_asus_m90v_verbs[] = {
8847         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8848         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8849         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8850         /* enable unsolicited event */
8851         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8852         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8853         { } /* end */
8854 };
8855
8856 static void alc883_nb_mic_automute(struct hda_codec *codec)
8857 {
8858         unsigned int present;
8859
8860         present = snd_hda_codec_read(codec, 0x18, 0,
8861                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8862         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8863                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8864         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8865                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8866 }
8867
8868 static void alc883_M90V_init_hook(struct hda_codec *codec)
8869 {
8870         struct alc_spec *spec = codec->spec;
8871
8872         spec->autocfg.hp_pins[0] = 0x1b;
8873         spec->autocfg.speaker_pins[0] = 0x14;
8874         spec->autocfg.speaker_pins[1] = 0x15;
8875         spec->autocfg.speaker_pins[2] = 0x16;
8876         alc_automute_pin(codec);
8877 }
8878
8879 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8880                                            unsigned int res)
8881 {
8882         switch (res >> 26) {
8883         case ALC880_MIC_EVENT:
8884                 alc883_nb_mic_automute(codec);
8885                 break;
8886         default:
8887                 alc_sku_unsol_event(codec, res);
8888                 break;
8889         }
8890 }
8891
8892 static void alc883_mode2_inithook(struct hda_codec *codec)
8893 {
8894         alc883_M90V_init_hook(codec);
8895         alc883_nb_mic_automute(codec);
8896 }
8897
8898 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8899         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8900         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8901         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8902         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8903         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8904         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8905         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8906         /* enable unsolicited event */
8907         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8908         { } /* end */
8909 };
8910
8911 static void alc883_eee1601_inithook(struct hda_codec *codec)
8912 {
8913         struct alc_spec *spec = codec->spec;
8914
8915         spec->autocfg.hp_pins[0] = 0x14;
8916         spec->autocfg.speaker_pins[0] = 0x1b;
8917         alc_automute_pin(codec);
8918 }
8919
8920 static struct hda_verb alc889A_mb31_verbs[] = {
8921         /* Init rear pin (used as headphone output) */
8922         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8923         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8924         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8925         /* Init line pin (used as output in 4ch and 6ch mode) */
8926         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8927         /* Init line 2 pin (used as headphone out by default) */
8928         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8929         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
8930         { } /* end */
8931 };
8932
8933 /* Mute speakers according to the headphone jack state */
8934 static void alc889A_mb31_automute(struct hda_codec *codec)
8935 {
8936         unsigned int present;
8937
8938         /* Mute only in 2ch or 4ch mode */
8939         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8940             == 0x00) {
8941                 present = snd_hda_codec_read(codec, 0x15, 0,
8942                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8943                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
8944                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8945                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8946                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8947         }
8948 }
8949
8950 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8951 {
8952         if ((res >> 26) == ALC880_HP_EVENT)
8953                 alc889A_mb31_automute(codec);
8954 }
8955
8956 #ifdef CONFIG_SND_HDA_POWER_SAVE
8957 #define alc883_loopbacks        alc880_loopbacks
8958 #endif
8959
8960 /* pcm configuration: identiacal with ALC880 */
8961 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8962 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8963 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8964 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8965 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8966
8967 /*
8968  * configuration and preset
8969  */
8970 static const char *alc883_models[ALC883_MODEL_LAST] = {
8971         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8972         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8973         [ALC883_3ST_6ch]        = "3stack-6ch",
8974         [ALC883_6ST_DIG]        = "6stack-dig",
8975         [ALC883_TARGA_DIG]      = "targa-dig",
8976         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8977         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
8978         [ALC883_ACER]           = "acer",
8979         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8980         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8981         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
8982         [ALC883_MEDION]         = "medion",
8983         [ALC883_MEDION_MD2]     = "medion-md2",
8984         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8985         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8986         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8987         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8988         [ALC888_LENOVO_SKY] = "lenovo-sky",
8989         [ALC883_HAIER_W66]      = "haier-w66",
8990         [ALC888_3ST_HP]         = "3stack-hp",
8991         [ALC888_6ST_DELL]       = "6stack-dell",
8992         [ALC883_MITAC]          = "mitac",
8993         [ALC883_CLEVO_M720]     = "clevo-m720",
8994         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8995         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8996         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8997         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8998         [ALC889A_MB31]          = "mb31",
8999         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
9000         [ALC883_AUTO]           = "auto",
9001 };
9002
9003 static struct snd_pci_quirk alc883_cfg_tbl[] = {
9004         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
9005         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
9006         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
9007         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
9008         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
9009         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
9010         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
9011         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
9012                 ALC888_ACER_ASPIRE_4930G),
9013         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
9014                 ALC888_ACER_ASPIRE_4930G),
9015         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
9016                 ALC888_ACER_ASPIRE_8930G),
9017         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
9018                 ALC888_ACER_ASPIRE_8930G),
9019         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO),
9020         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO),
9021         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
9022                 ALC888_ACER_ASPIRE_4930G),
9023         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
9024                 ALC888_ACER_ASPIRE_4930G),
9025         /* default Acer -- disabled as it causes more problems.
9026          *    model=auto should work fine now
9027          */
9028         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
9029         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
9030         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
9031         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
9032         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
9033         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
9034         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
9035         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
9036         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
9037         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
9038         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
9039         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
9040         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
9041         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
9042         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
9043         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
9044         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
9045         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
9046         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
9047         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
9048         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
9049         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
9050         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
9051         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
9052         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
9053         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
9054         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
9055         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
9056         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
9057         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
9058         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
9059         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
9060         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
9061         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
9062         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
9063         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
9064         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
9065         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
9066         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
9067         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
9068         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
9069         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
9070         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
9071         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
9072         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
9073         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
9074         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
9075         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
9076         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
9077         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
9078         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
9079         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
9080                       ALC883_FUJITSU_PI2515),
9081         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
9082                 ALC888_FUJITSU_XA3530),
9083         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
9084         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9085         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9086         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9087         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
9088         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
9089         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
9090         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
9091         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
9092         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
9093         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
9094         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
9095         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
9096         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
9097         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
9098         {}
9099 };
9100
9101 static hda_nid_t alc883_slave_dig_outs[] = {
9102         ALC1200_DIGOUT_NID, 0,
9103 };
9104
9105 static hda_nid_t alc1200_slave_dig_outs[] = {
9106         ALC883_DIGOUT_NID, 0,
9107 };
9108
9109 static struct alc_config_preset alc883_presets[] = {
9110         [ALC883_3ST_2ch_DIG] = {
9111                 .mixers = { alc883_3ST_2ch_mixer },
9112                 .init_verbs = { alc883_init_verbs },
9113                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9114                 .dac_nids = alc883_dac_nids,
9115                 .dig_out_nid = ALC883_DIGOUT_NID,
9116                 .dig_in_nid = ALC883_DIGIN_NID,
9117                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9118                 .channel_mode = alc883_3ST_2ch_modes,
9119                 .input_mux = &alc883_capture_source,
9120         },
9121         [ALC883_3ST_6ch_DIG] = {
9122                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9123                 .init_verbs = { alc883_init_verbs },
9124                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9125                 .dac_nids = alc883_dac_nids,
9126                 .dig_out_nid = ALC883_DIGOUT_NID,
9127                 .dig_in_nid = ALC883_DIGIN_NID,
9128                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9129                 .channel_mode = alc883_3ST_6ch_modes,
9130                 .need_dac_fix = 1,
9131                 .input_mux = &alc883_capture_source,
9132         },
9133         [ALC883_3ST_6ch] = {
9134                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9135                 .init_verbs = { alc883_init_verbs },
9136                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9137                 .dac_nids = alc883_dac_nids,
9138                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9139                 .channel_mode = alc883_3ST_6ch_modes,
9140                 .need_dac_fix = 1,
9141                 .input_mux = &alc883_capture_source,
9142         },
9143         [ALC883_3ST_6ch_INTEL] = {
9144                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9145                 .init_verbs = { alc883_init_verbs },
9146                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9147                 .dac_nids = alc883_dac_nids,
9148                 .dig_out_nid = ALC883_DIGOUT_NID,
9149                 .dig_in_nid = ALC883_DIGIN_NID,
9150                 .slave_dig_outs = alc883_slave_dig_outs,
9151                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9152                 .channel_mode = alc883_3ST_6ch_intel_modes,
9153                 .need_dac_fix = 1,
9154                 .input_mux = &alc883_3stack_6ch_intel,
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_tagra_mixer, alc883_chmode_mixer },
9169                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
9170                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9171                 .dac_nids = alc883_dac_nids,
9172                 .dig_out_nid = ALC883_DIGOUT_NID,
9173                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9174                 .channel_mode = alc883_3ST_6ch_modes,
9175                 .need_dac_fix = 1,
9176                 .input_mux = &alc883_capture_source,
9177                 .unsol_event = alc883_tagra_unsol_event,
9178                 .init_hook = alc883_tagra_init_hook,
9179         },
9180         [ALC883_TARGA_2ch_DIG] = {
9181                 .mixers = { alc883_tagra_2ch_mixer},
9182                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
9183                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9184                 .dac_nids = alc883_dac_nids,
9185                 .adc_nids = alc883_adc_nids_alt,
9186                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9187                 .dig_out_nid = ALC883_DIGOUT_NID,
9188                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9189                 .channel_mode = alc883_3ST_2ch_modes,
9190                 .input_mux = &alc883_capture_source,
9191                 .unsol_event = alc883_tagra_unsol_event,
9192                 .init_hook = alc883_tagra_init_hook,
9193         },
9194         [ALC883_TARGA_8ch_DIG] = {
9195                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9196                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9197                                 alc883_tagra_verbs },
9198                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9199                 .dac_nids = alc883_dac_nids,
9200                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9201                 .adc_nids = alc883_adc_nids_rev,
9202                 .capsrc_nids = alc883_capsrc_nids_rev,
9203                 .dig_out_nid = ALC883_DIGOUT_NID,
9204                 .dig_in_nid = ALC883_DIGIN_NID,
9205                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9206                 .channel_mode = alc883_4ST_8ch_modes,
9207                 .need_dac_fix = 1,
9208                 .input_mux = &alc883_capture_source,
9209                 .unsol_event = alc883_tagra_unsol_event,
9210                 .init_hook = alc883_tagra_init_hook,
9211         },
9212         [ALC883_ACER] = {
9213                 .mixers = { alc883_base_mixer },
9214                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9215                  * and the headphone jack.  Turn this on and rely on the
9216                  * standard mute methods whenever the user wants to turn
9217                  * these outputs off.
9218                  */
9219                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9220                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9221                 .dac_nids = alc883_dac_nids,
9222                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9223                 .channel_mode = alc883_3ST_2ch_modes,
9224                 .input_mux = &alc883_capture_source,
9225         },
9226         [ALC883_ACER_ASPIRE] = {
9227                 .mixers = { alc883_acer_aspire_mixer },
9228                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9229                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9230                 .dac_nids = alc883_dac_nids,
9231                 .dig_out_nid = ALC883_DIGOUT_NID,
9232                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9233                 .channel_mode = alc883_3ST_2ch_modes,
9234                 .input_mux = &alc883_capture_source,
9235                 .unsol_event = alc_automute_amp_unsol_event,
9236                 .init_hook = alc883_acer_aspire_init_hook,
9237         },
9238         [ALC888_ACER_ASPIRE_4930G] = {
9239                 .mixers = { alc888_base_mixer,
9240                                 alc883_chmode_mixer },
9241                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9242                                 alc888_acer_aspire_4930g_verbs },
9243                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9244                 .dac_nids = alc883_dac_nids,
9245                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9246                 .adc_nids = alc883_adc_nids_rev,
9247                 .capsrc_nids = alc883_capsrc_nids_rev,
9248                 .dig_out_nid = ALC883_DIGOUT_NID,
9249                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9250                 .channel_mode = alc883_3ST_6ch_modes,
9251                 .need_dac_fix = 1,
9252                 .num_mux_defs =
9253                         ARRAY_SIZE(alc888_2_capture_sources),
9254                 .input_mux = alc888_2_capture_sources,
9255                 .unsol_event = alc_automute_amp_unsol_event,
9256                 .init_hook = alc888_acer_aspire_4930g_init_hook,
9257         },
9258         [ALC888_ACER_ASPIRE_8930G] = {
9259                 .mixers = { alc888_base_mixer,
9260                                 alc883_chmode_mixer },
9261                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9262                                 alc889_acer_aspire_8930g_verbs },
9263                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9264                 .dac_nids = alc883_dac_nids,
9265                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9266                 .adc_nids = alc889_adc_nids,
9267                 .capsrc_nids = alc889_capsrc_nids,
9268                 .dig_out_nid = ALC883_DIGOUT_NID,
9269                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9270                 .channel_mode = alc883_3ST_6ch_modes,
9271                 .need_dac_fix = 1,
9272                 .const_channel_count = 6,
9273                 .num_mux_defs =
9274                         ARRAY_SIZE(alc889_capture_sources),
9275                 .input_mux = alc889_capture_sources,
9276                 .unsol_event = alc_automute_amp_unsol_event,
9277                 .init_hook = alc889_acer_aspire_8930g_init_hook,
9278         },
9279         [ALC883_MEDION] = {
9280                 .mixers = { alc883_fivestack_mixer,
9281                             alc883_chmode_mixer },
9282                 .init_verbs = { alc883_init_verbs,
9283                                 alc883_medion_eapd_verbs },
9284                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9285                 .dac_nids = alc883_dac_nids,
9286                 .adc_nids = alc883_adc_nids_alt,
9287                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9288                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9289                 .channel_mode = alc883_sixstack_modes,
9290                 .input_mux = &alc883_capture_source,
9291         },
9292         [ALC883_MEDION_MD2] = {
9293                 .mixers = { alc883_medion_md2_mixer},
9294                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9295                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9296                 .dac_nids = alc883_dac_nids,
9297                 .dig_out_nid = ALC883_DIGOUT_NID,
9298                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9299                 .channel_mode = alc883_3ST_2ch_modes,
9300                 .input_mux = &alc883_capture_source,
9301                 .unsol_event = alc_automute_amp_unsol_event,
9302                 .init_hook = alc883_medion_md2_init_hook,
9303         },
9304         [ALC883_LAPTOP_EAPD] = {
9305                 .mixers = { alc883_base_mixer },
9306                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9307                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9308                 .dac_nids = alc883_dac_nids,
9309                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9310                 .channel_mode = alc883_3ST_2ch_modes,
9311                 .input_mux = &alc883_capture_source,
9312         },
9313         [ALC883_CLEVO_M720] = {
9314                 .mixers = { alc883_clevo_m720_mixer },
9315                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9316                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9317                 .dac_nids = alc883_dac_nids,
9318                 .dig_out_nid = ALC883_DIGOUT_NID,
9319                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9320                 .channel_mode = alc883_3ST_2ch_modes,
9321                 .input_mux = &alc883_capture_source,
9322                 .unsol_event = alc883_clevo_m720_unsol_event,
9323                 .init_hook = alc883_clevo_m720_init_hook,
9324         },
9325         [ALC883_LENOVO_101E_2ch] = {
9326                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9327                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9328                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9329                 .dac_nids = alc883_dac_nids,
9330                 .adc_nids = alc883_adc_nids_alt,
9331                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9332                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9333                 .channel_mode = alc883_3ST_2ch_modes,
9334                 .input_mux = &alc883_lenovo_101e_capture_source,
9335                 .unsol_event = alc883_lenovo_101e_unsol_event,
9336                 .init_hook = alc883_lenovo_101e_all_automute,
9337         },
9338         [ALC883_LENOVO_NB0763] = {
9339                 .mixers = { alc883_lenovo_nb0763_mixer },
9340                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9341                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9342                 .dac_nids = alc883_dac_nids,
9343                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9344                 .channel_mode = alc883_3ST_2ch_modes,
9345                 .need_dac_fix = 1,
9346                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9347                 .unsol_event = alc_automute_amp_unsol_event,
9348                 .init_hook = alc883_medion_md2_init_hook,
9349         },
9350         [ALC888_LENOVO_MS7195_DIG] = {
9351                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9352                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9353                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9354                 .dac_nids = alc883_dac_nids,
9355                 .dig_out_nid = ALC883_DIGOUT_NID,
9356                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9357                 .channel_mode = alc883_3ST_6ch_modes,
9358                 .need_dac_fix = 1,
9359                 .input_mux = &alc883_capture_source,
9360                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9361                 .init_hook = alc888_lenovo_ms7195_front_automute,
9362         },
9363         [ALC883_HAIER_W66] = {
9364                 .mixers = { alc883_tagra_2ch_mixer},
9365                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9366                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9367                 .dac_nids = alc883_dac_nids,
9368                 .dig_out_nid = ALC883_DIGOUT_NID,
9369                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9370                 .channel_mode = alc883_3ST_2ch_modes,
9371                 .input_mux = &alc883_capture_source,
9372                 .unsol_event = alc_automute_amp_unsol_event,
9373                 .init_hook = alc883_haier_w66_init_hook,
9374         },
9375         [ALC888_3ST_HP] = {
9376                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9377                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9378                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9379                 .dac_nids = alc883_dac_nids,
9380                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9381                 .channel_mode = alc888_3st_hp_modes,
9382                 .need_dac_fix = 1,
9383                 .input_mux = &alc883_capture_source,
9384                 .unsol_event = alc_automute_amp_unsol_event,
9385                 .init_hook = alc888_3st_hp_init_hook,
9386         },
9387         [ALC888_6ST_DELL] = {
9388                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9389                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9390                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9391                 .dac_nids = alc883_dac_nids,
9392                 .dig_out_nid = ALC883_DIGOUT_NID,
9393                 .dig_in_nid = ALC883_DIGIN_NID,
9394                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9395                 .channel_mode = alc883_sixstack_modes,
9396                 .input_mux = &alc883_capture_source,
9397                 .unsol_event = alc_automute_amp_unsol_event,
9398                 .init_hook = alc888_6st_dell_init_hook,
9399         },
9400         [ALC883_MITAC] = {
9401                 .mixers = { alc883_mitac_mixer },
9402                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9403                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9404                 .dac_nids = alc883_dac_nids,
9405                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9406                 .channel_mode = alc883_3ST_2ch_modes,
9407                 .input_mux = &alc883_capture_source,
9408                 .unsol_event = alc_automute_amp_unsol_event,
9409                 .init_hook = alc883_mitac_init_hook,
9410         },
9411         [ALC883_FUJITSU_PI2515] = {
9412                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9413                 .init_verbs = { alc883_init_verbs,
9414                                 alc883_2ch_fujitsu_pi2515_verbs},
9415                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9416                 .dac_nids = alc883_dac_nids,
9417                 .dig_out_nid = ALC883_DIGOUT_NID,
9418                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9419                 .channel_mode = alc883_3ST_2ch_modes,
9420                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9421                 .unsol_event = alc_automute_amp_unsol_event,
9422                 .init_hook = alc883_2ch_fujitsu_pi2515_init_hook,
9423         },
9424         [ALC888_FUJITSU_XA3530] = {
9425                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9426                 .init_verbs = { alc883_init_verbs,
9427                         alc888_fujitsu_xa3530_verbs },
9428                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9429                 .dac_nids = alc883_dac_nids,
9430                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9431                 .adc_nids = alc883_adc_nids_rev,
9432                 .capsrc_nids = alc883_capsrc_nids_rev,
9433                 .dig_out_nid = ALC883_DIGOUT_NID,
9434                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9435                 .channel_mode = alc888_4ST_8ch_intel_modes,
9436                 .num_mux_defs =
9437                         ARRAY_SIZE(alc888_2_capture_sources),
9438                 .input_mux = alc888_2_capture_sources,
9439                 .unsol_event = alc_automute_amp_unsol_event,
9440                 .init_hook = alc888_fujitsu_xa3530_init_hook,
9441         },
9442         [ALC888_LENOVO_SKY] = {
9443                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9444                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9445                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9446                 .dac_nids = alc883_dac_nids,
9447                 .dig_out_nid = ALC883_DIGOUT_NID,
9448                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9449                 .channel_mode = alc883_sixstack_modes,
9450                 .need_dac_fix = 1,
9451                 .input_mux = &alc883_lenovo_sky_capture_source,
9452                 .unsol_event = alc_automute_amp_unsol_event,
9453                 .init_hook = alc888_lenovo_sky_init_hook,
9454         },
9455         [ALC888_ASUS_M90V] = {
9456                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9457                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_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_3ST_6ch_modes),
9463                 .channel_mode = alc883_3ST_6ch_modes,
9464                 .need_dac_fix = 1,
9465                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9466                 .unsol_event = alc883_mode2_unsol_event,
9467                 .init_hook = alc883_mode2_inithook,
9468         },
9469         [ALC888_ASUS_EEE1601] = {
9470                 .mixers = { alc883_asus_eee1601_mixer },
9471                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9472                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9473                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9474                 .dac_nids = alc883_dac_nids,
9475                 .dig_out_nid = ALC883_DIGOUT_NID,
9476                 .dig_in_nid = ALC883_DIGIN_NID,
9477                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9478                 .channel_mode = alc883_3ST_2ch_modes,
9479                 .need_dac_fix = 1,
9480                 .input_mux = &alc883_asus_eee1601_capture_source,
9481                 .unsol_event = alc_sku_unsol_event,
9482                 .init_hook = alc883_eee1601_inithook,
9483         },
9484         [ALC1200_ASUS_P5Q] = {
9485                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9486                 .init_verbs = { alc883_init_verbs },
9487                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9488                 .dac_nids = alc883_dac_nids,
9489                 .dig_out_nid = ALC1200_DIGOUT_NID,
9490                 .dig_in_nid = ALC883_DIGIN_NID,
9491                 .slave_dig_outs = alc1200_slave_dig_outs,
9492                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9493                 .channel_mode = alc883_sixstack_modes,
9494                 .input_mux = &alc883_capture_source,
9495         },
9496         [ALC889A_MB31] = {
9497                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9498                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9499                         alc880_gpio1_init_verbs },
9500                 .adc_nids = alc883_adc_nids,
9501                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9502                 .dac_nids = alc883_dac_nids,
9503                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9504                 .channel_mode = alc889A_mb31_6ch_modes,
9505                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9506                 .input_mux = &alc889A_mb31_capture_source,
9507                 .dig_out_nid = ALC883_DIGOUT_NID,
9508                 .unsol_event = alc889A_mb31_unsol_event,
9509                 .init_hook = alc889A_mb31_automute,
9510         },
9511         [ALC883_SONY_VAIO_TT] = {
9512                 .mixers = { alc883_vaiott_mixer },
9513                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9514                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9515                 .dac_nids = alc883_dac_nids,
9516                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9517                 .channel_mode = alc883_3ST_2ch_modes,
9518                 .input_mux = &alc883_capture_source,
9519                 .unsol_event = alc_automute_amp_unsol_event,
9520                 .init_hook = alc883_vaiott_init_hook,
9521         },
9522 };
9523
9524
9525 /*
9526  * BIOS auto configuration
9527  */
9528 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
9529                                               hda_nid_t nid, int pin_type,
9530                                               int dac_idx)
9531 {
9532         /* set as output */
9533         struct alc_spec *spec = codec->spec;
9534         int idx;
9535
9536         alc_set_pin_output(codec, nid, pin_type);
9537         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9538                 idx = 4;
9539         else
9540                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9541         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9542
9543 }
9544
9545 static void alc883_auto_init_multi_out(struct hda_codec *codec)
9546 {
9547         struct alc_spec *spec = codec->spec;
9548         int i;
9549
9550         for (i = 0; i <= HDA_SIDE; i++) {
9551                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9552                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9553                 if (nid)
9554                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
9555                                                           i);
9556         }
9557 }
9558
9559 static void alc883_auto_init_hp_out(struct hda_codec *codec)
9560 {
9561         struct alc_spec *spec = codec->spec;
9562         hda_nid_t pin;
9563
9564         pin = spec->autocfg.hp_pins[0];
9565         if (pin) /* connect to front */
9566                 /* use dac 0 */
9567                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9568         pin = spec->autocfg.speaker_pins[0];
9569         if (pin)
9570                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9571 }
9572
9573 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
9574 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
9575
9576 static void alc883_auto_init_analog_input(struct hda_codec *codec)
9577 {
9578         struct alc_spec *spec = codec->spec;
9579         int i;
9580
9581         for (i = 0; i < AUTO_PIN_LAST; i++) {
9582                 hda_nid_t nid = spec->autocfg.input_pins[i];
9583                 if (alc883_is_input_pin(nid)) {
9584                         alc_set_input_pin(codec, nid, i);
9585                         if (nid != ALC883_PIN_CD_NID &&
9586                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
9587                                 snd_hda_codec_write(codec, nid, 0,
9588                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9589                                                     AMP_OUT_MUTE);
9590                 }
9591         }
9592 }
9593
9594 #define alc883_auto_init_input_src      alc882_auto_init_input_src
9595
9596 /* almost identical with ALC880 parser... */
9597 static int alc883_parse_auto_config(struct hda_codec *codec)
9598 {
9599         struct alc_spec *spec = codec->spec;
9600         int err = alc880_parse_auto_config(codec);
9601         struct auto_pin_cfg *cfg = &spec->autocfg;
9602         int i;
9603
9604         if (err < 0)
9605                 return err;
9606         else if (!err)
9607                 return 0; /* no config found */
9608
9609         err = alc_auto_add_mic_boost(codec);
9610         if (err < 0)
9611                 return err;
9612
9613         /* hack - override the init verbs */
9614         spec->init_verbs[0] = alc883_auto_init_verbs;
9615
9616         /* setup input_mux for ALC889 */
9617         if (codec->vendor_id == 0x10ec0889) {
9618                 /* digital-mic input pin is excluded in alc880_auto_create..()
9619                  * because it's under 0x18
9620                  */
9621                 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9622                     cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9623                         struct hda_input_mux *imux = &spec->private_imux[0];
9624                         for (i = 1; i < 3; i++)
9625                                 memcpy(&spec->private_imux[i],
9626                                        &spec->private_imux[0],
9627                                        sizeof(spec->private_imux[0]));
9628                         imux->items[imux->num_items].label = "Int DMic";
9629                         imux->items[imux->num_items].index = 0x0b;
9630                         imux->num_items++;
9631                         spec->num_mux_defs = 3;
9632                         spec->input_mux = spec->private_imux;
9633                 }
9634         }
9635
9636         return 1; /* config found */
9637 }
9638
9639 /* additional initialization for auto-configuration model */
9640 static void alc883_auto_init(struct hda_codec *codec)
9641 {
9642         struct alc_spec *spec = codec->spec;
9643         alc883_auto_init_multi_out(codec);
9644         alc883_auto_init_hp_out(codec);
9645         alc883_auto_init_analog_input(codec);
9646         alc883_auto_init_input_src(codec);
9647         if (spec->unsol_event)
9648                 alc_inithook(codec);
9649 }
9650
9651 static int patch_alc883(struct hda_codec *codec)
9652 {
9653         struct alc_spec *spec;
9654         int err, board_config;
9655
9656         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9657         if (spec == NULL)
9658                 return -ENOMEM;
9659
9660         codec->spec = spec;
9661
9662         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9663
9664         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9665                                                   alc883_models,
9666                                                   alc883_cfg_tbl);
9667         if (board_config < 0 || board_config >= ALC883_MODEL_LAST) {
9668                 /* Pick up systems that don't supply PCI SSID */
9669                 switch (codec->subsystem_id) {
9670                 case 0x106b3600: /* Macbook 3.1 */
9671                         board_config = ALC889A_MB31;
9672                         break;
9673                 default:
9674                         printk(KERN_INFO
9675                                 "hda_codec: Unknown model for %s, trying "
9676                                 "auto-probe from BIOS...\n", codec->chip_name);
9677                         board_config = ALC883_AUTO;
9678                 }
9679         }
9680
9681         if (board_config == ALC883_AUTO) {
9682                 /* automatic parse from the BIOS config */
9683                 err = alc883_parse_auto_config(codec);
9684                 if (err < 0) {
9685                         alc_free(codec);
9686                         return err;
9687                 } else if (!err) {
9688                         printk(KERN_INFO
9689                                "hda_codec: Cannot set up configuration "
9690                                "from BIOS.  Using base mode...\n");
9691                         board_config = ALC883_3ST_2ch_DIG;
9692                 }
9693         }
9694
9695         err = snd_hda_attach_beep_device(codec, 0x1);
9696         if (err < 0) {
9697                 alc_free(codec);
9698                 return err;
9699         }
9700
9701         if (board_config != ALC883_AUTO)
9702                 setup_preset(spec, &alc883_presets[board_config]);
9703
9704         switch (codec->vendor_id) {
9705         case 0x10ec0888:
9706                 if (!spec->num_adc_nids) {
9707                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9708                         spec->adc_nids = alc883_adc_nids;
9709                 }
9710                 if (!spec->capsrc_nids)
9711                         spec->capsrc_nids = alc883_capsrc_nids;
9712                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9713                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9714                 break;
9715         case 0x10ec0889:
9716                 if (!spec->num_adc_nids) {
9717                         spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9718                         spec->adc_nids = alc889_adc_nids;
9719                 }
9720                 if (!spec->capsrc_nids)
9721                         spec->capsrc_nids = alc889_capsrc_nids;
9722                 spec->capture_style = CAPT_1MUX_MIX; /* 1mux/Nmix-style
9723                                                         capture */
9724                 break;
9725         default:
9726                 if (!spec->num_adc_nids) {
9727                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9728                         spec->adc_nids = alc883_adc_nids;
9729                 }
9730                 if (!spec->capsrc_nids)
9731                         spec->capsrc_nids = alc883_capsrc_nids;
9732                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9733                 break;
9734         }
9735
9736         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9737         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9738         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9739
9740         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9741         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9742
9743         if (!spec->cap_mixer)
9744                 set_capture_mixer(spec);
9745         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9746
9747         spec->vmaster_nid = 0x0c;
9748
9749         codec->patch_ops = alc_patch_ops;
9750         if (board_config == ALC883_AUTO)
9751                 spec->init_hook = alc883_auto_init;
9752
9753 #ifdef CONFIG_SND_HDA_POWER_SAVE
9754         if (!spec->loopback.amplist)
9755                 spec->loopback.amplist = alc883_loopbacks;
9756 #endif
9757         codec->proc_widget_hook = print_realtek_coef;
9758
9759         return 0;
9760 }
9761
9762 /*
9763  * ALC262 support
9764  */
9765
9766 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9767 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9768
9769 #define alc262_dac_nids         alc260_dac_nids
9770 #define alc262_adc_nids         alc882_adc_nids
9771 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9772 #define alc262_capsrc_nids      alc882_capsrc_nids
9773 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9774
9775 #define alc262_modes            alc260_modes
9776 #define alc262_capture_source   alc882_capture_source
9777
9778 static hda_nid_t alc262_dmic_adc_nids[1] = {
9779         /* ADC0 */
9780         0x09
9781 };
9782
9783 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9784
9785 static struct snd_kcontrol_new alc262_base_mixer[] = {
9786         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9787         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9788         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9789         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9790         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9791         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9792         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9793         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9794         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9795         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9796         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9797         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9798         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9799         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9800         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9801         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9802         { } /* end */
9803 };
9804
9805 /* update HP, line and mono-out pins according to the master switch */
9806 static void alc262_hp_master_update(struct hda_codec *codec)
9807 {
9808         struct alc_spec *spec = codec->spec;
9809         int val = spec->master_sw;
9810
9811         /* HP & line-out */
9812         snd_hda_codec_write_cache(codec, 0x1b, 0,
9813                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9814                                   val ? PIN_HP : 0);
9815         snd_hda_codec_write_cache(codec, 0x15, 0,
9816                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9817                                   val ? PIN_HP : 0);
9818         /* mono (speaker) depending on the HP jack sense */
9819         val = val && !spec->jack_present;
9820         snd_hda_codec_write_cache(codec, 0x16, 0,
9821                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9822                                   val ? PIN_OUT : 0);
9823 }
9824
9825 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9826 {
9827         struct alc_spec *spec = codec->spec;
9828         unsigned int presence;
9829         presence = snd_hda_codec_read(codec, 0x1b, 0,
9830                                       AC_VERB_GET_PIN_SENSE, 0);
9831         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9832         alc262_hp_master_update(codec);
9833 }
9834
9835 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9836 {
9837         if ((res >> 26) != ALC880_HP_EVENT)
9838                 return;
9839         alc262_hp_bpc_automute(codec);
9840 }
9841
9842 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9843 {
9844         struct alc_spec *spec = codec->spec;
9845         unsigned int presence;
9846         presence = snd_hda_codec_read(codec, 0x15, 0,
9847                                       AC_VERB_GET_PIN_SENSE, 0);
9848         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9849         alc262_hp_master_update(codec);
9850 }
9851
9852 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9853                                            unsigned int res)
9854 {
9855         if ((res >> 26) != ALC880_HP_EVENT)
9856                 return;
9857         alc262_hp_wildwest_automute(codec);
9858 }
9859
9860 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
9861
9862 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9863                                    struct snd_ctl_elem_value *ucontrol)
9864 {
9865         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9866         struct alc_spec *spec = codec->spec;
9867         int val = !!*ucontrol->value.integer.value;
9868
9869         if (val == spec->master_sw)
9870                 return 0;
9871         spec->master_sw = val;
9872         alc262_hp_master_update(codec);
9873         return 1;
9874 }
9875
9876 #define ALC262_HP_MASTER_SWITCH                                 \
9877         {                                                       \
9878                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
9879                 .name = "Master Playback Switch",               \
9880                 .info = snd_ctl_boolean_mono_info,              \
9881                 .get = alc262_hp_master_sw_get,                 \
9882                 .put = alc262_hp_master_sw_put,                 \
9883         }
9884
9885 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9886         ALC262_HP_MASTER_SWITCH,
9887         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9888         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9889         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9890         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9891                               HDA_OUTPUT),
9892         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9893                             HDA_OUTPUT),
9894         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9895         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9896         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9897         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9898         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9899         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9900         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9901         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9902         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9903         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9904         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9905         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9906         { } /* end */
9907 };
9908
9909 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9910         ALC262_HP_MASTER_SWITCH,
9911         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9912         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9913         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9914         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9915         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9916                               HDA_OUTPUT),
9917         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9918                             HDA_OUTPUT),
9919         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9920         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9921         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9922         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9923         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9924         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9925         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9926         { } /* end */
9927 };
9928
9929 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9930         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9931         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9932         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9933         { } /* end */
9934 };
9935
9936 /* mute/unmute internal speaker according to the hp jack and mute state */
9937 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9938 {
9939         struct alc_spec *spec = codec->spec;
9940
9941         spec->autocfg.hp_pins[0] = 0x15;
9942         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
9943         alc_automute_amp(codec);
9944 }
9945
9946 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9947         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9948         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9949         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9950         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9951         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9952         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9953         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9954         { } /* end */
9955 };
9956
9957 static struct hda_verb alc262_hp_t5735_verbs[] = {
9958         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9959         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9960
9961         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9962         { }
9963 };
9964
9965 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9966         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9967         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9968         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9969         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9970         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9971         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9972         { } /* end */
9973 };
9974
9975 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9976         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9977         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9978         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9979         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9980         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9981         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9982         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9983         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9984         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9985         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9986         {}
9987 };
9988
9989 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9990         .num_items = 1,
9991         .items = {
9992                 { "Line", 0x1 },
9993         },
9994 };
9995
9996 /* bind hp and internal speaker mute (with plug check) as master switch */
9997 static void alc262_hippo_master_update(struct hda_codec *codec)
9998 {
9999         struct alc_spec *spec = codec->spec;
10000         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10001         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10002         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10003         unsigned int mute;
10004
10005         /* HP */
10006         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10007         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10008                                  HDA_AMP_MUTE, mute);
10009         /* mute internal speaker per jack sense */
10010         if (spec->jack_present)
10011                 mute = HDA_AMP_MUTE;
10012         if (line_nid)
10013                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10014                                          HDA_AMP_MUTE, mute);
10015         if (speaker_nid && speaker_nid != line_nid)
10016                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10017                                          HDA_AMP_MUTE, mute);
10018 }
10019
10020 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10021
10022 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10023                                       struct snd_ctl_elem_value *ucontrol)
10024 {
10025         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10026         struct alc_spec *spec = codec->spec;
10027         int val = !!*ucontrol->value.integer.value;
10028
10029         if (val == spec->master_sw)
10030                 return 0;
10031         spec->master_sw = val;
10032         alc262_hippo_master_update(codec);
10033         return 1;
10034 }
10035
10036 #define ALC262_HIPPO_MASTER_SWITCH                              \
10037         {                                                       \
10038                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10039                 .name = "Master Playback Switch",               \
10040                 .info = snd_ctl_boolean_mono_info,              \
10041                 .get = alc262_hippo_master_sw_get,              \
10042                 .put = alc262_hippo_master_sw_put,              \
10043         }
10044
10045 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10046         ALC262_HIPPO_MASTER_SWITCH,
10047         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10048         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10049         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10050         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10051         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10052         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10053         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10054         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10055         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10056         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10057         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10058         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10059         { } /* end */
10060 };
10061
10062 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10063         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10064         ALC262_HIPPO_MASTER_SWITCH,
10065         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10066         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10067         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10068         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10069         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10070         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10071         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10072         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10073         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10074         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10075         { } /* end */
10076 };
10077
10078 /* mute/unmute internal speaker according to the hp jack and mute state */
10079 static void alc262_hippo_automute(struct hda_codec *codec)
10080 {
10081         struct alc_spec *spec = codec->spec;
10082         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10083         unsigned int present;
10084
10085         /* need to execute and sync at first */
10086         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10087         present = snd_hda_codec_read(codec, hp_nid, 0,
10088                                      AC_VERB_GET_PIN_SENSE, 0);
10089         spec->jack_present = (present & 0x80000000) != 0;
10090         alc262_hippo_master_update(codec);
10091 }
10092
10093 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10094 {
10095         if ((res >> 26) != ALC880_HP_EVENT)
10096                 return;
10097         alc262_hippo_automute(codec);
10098 }
10099
10100 static void alc262_hippo_init_hook(struct hda_codec *codec)
10101 {
10102         struct alc_spec *spec = codec->spec;
10103
10104         spec->autocfg.hp_pins[0] = 0x15;
10105         spec->autocfg.speaker_pins[0] = 0x14;
10106         alc262_hippo_automute(codec);
10107 }
10108
10109 static void alc262_hippo1_init_hook(struct hda_codec *codec)
10110 {
10111         struct alc_spec *spec = codec->spec;
10112
10113         spec->autocfg.hp_pins[0] = 0x1b;
10114         spec->autocfg.speaker_pins[0] = 0x14;
10115         alc262_hippo_automute(codec);
10116 }
10117
10118
10119 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10120         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10121         ALC262_HIPPO_MASTER_SWITCH,
10122         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10123         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10124         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10125         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10126         { } /* end */
10127 };
10128
10129 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10130         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10131         ALC262_HIPPO_MASTER_SWITCH,
10132         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10133         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10134         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10135         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10136         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10137         { } /* end */
10138 };
10139
10140 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10141         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10142         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10143         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10144         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10145         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10146         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10147         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10148         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10149         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10150         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10151         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10152         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10153         { } /* end */
10154 };
10155
10156 static struct hda_verb alc262_tyan_verbs[] = {
10157         /* Headphone automute */
10158         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10159         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10160         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10161
10162         /* P11 AUX_IN, white 4-pin connector */
10163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10164         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10165         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10166         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10167
10168         {}
10169 };
10170
10171 /* unsolicited event for HP jack sensing */
10172 static void alc262_tyan_init_hook(struct hda_codec *codec)
10173 {
10174         struct alc_spec *spec = codec->spec;
10175
10176         spec->autocfg.hp_pins[0] = 0x1b;
10177         spec->autocfg.speaker_pins[0] = 0x15;
10178         alc_automute_amp(codec);
10179 }
10180
10181
10182 #define alc262_capture_mixer            alc882_capture_mixer
10183 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10184
10185 /*
10186  * generic initialization of ADC, input mixers and output mixers
10187  */
10188 static struct hda_verb alc262_init_verbs[] = {
10189         /*
10190          * Unmute ADC0-2 and set the default input to mic-in
10191          */
10192         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10193         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10194         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10195         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10196         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10197         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10198
10199         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10200          * mixer widget
10201          * Note: PASD motherboards uses the Line In 2 as the input for
10202          * front panel mic (mic 2)
10203          */
10204         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10205         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10206         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10207         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10208         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10209         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10210
10211         /*
10212          * Set up output mixers (0x0c - 0x0e)
10213          */
10214         /* set vol=0 to output mixers */
10215         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10216         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10217         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10218         /* set up input amps for analog loopback */
10219         /* Amp Indices: DAC = 0, mixer = 1 */
10220         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10221         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10222         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10223         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10224         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10225         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10226
10227         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10228         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10229         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10230         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10231         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10232         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10233
10234         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10235         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10236         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10237         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10238         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10239
10240         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10241         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10242
10243         /* FIXME: use matrix-type input source selection */
10244         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10245         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10246         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10247         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10248         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10249         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10250         /* Input mixer2 */
10251         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10252         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10253         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10254         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10255         /* Input mixer3 */
10256         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10257         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10258         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10259         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10260
10261         { }
10262 };
10263
10264 static struct hda_verb alc262_eapd_verbs[] = {
10265         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10266         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10267         { }
10268 };
10269
10270 static struct hda_verb alc262_hippo_unsol_verbs[] = {
10271         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10272         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10273         {}
10274 };
10275
10276 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10277         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10278         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10280
10281         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10282         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10283         {}
10284 };
10285
10286 static struct hda_verb alc262_sony_unsol_verbs[] = {
10287         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10288         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10289         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10290
10291         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10292         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10293         {}
10294 };
10295
10296 static struct hda_input_mux alc262_dmic_capture_source = {
10297         .num_items = 2,
10298         .items = {
10299                 { "Int DMic", 0x9 },
10300                 { "Mic", 0x0 },
10301         },
10302 };
10303
10304 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10305         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10306         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10307         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10308         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10309         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10310         { } /* end */
10311 };
10312
10313 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10314         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10315         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10316         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10317         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10318         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10319         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10320         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10321         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10322         {}
10323 };
10324
10325 static void alc262_dmic_automute(struct hda_codec *codec)
10326 {
10327         unsigned int present;
10328
10329         present = snd_hda_codec_read(codec, 0x18, 0,
10330                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10331         snd_hda_codec_write(codec, 0x22, 0,
10332                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
10333 }
10334
10335
10336 /* unsolicited event for HP jack sensing */
10337 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
10338                                        unsigned int res)
10339 {
10340         if ((res >> 26) == ALC880_MIC_EVENT)
10341                 alc262_dmic_automute(codec);
10342         else
10343                 alc_sku_unsol_event(codec, res);
10344 }
10345
10346 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
10347 {
10348         struct alc_spec *spec = codec->spec;
10349
10350         spec->autocfg.hp_pins[0] = 0x15;
10351         spec->autocfg.speaker_pins[0] = 0x14;
10352         alc_automute_pin(codec);
10353         alc262_dmic_automute(codec);
10354 }
10355
10356 /*
10357  * nec model
10358  *  0x15 = headphone
10359  *  0x16 = internal speaker
10360  *  0x18 = external mic
10361  */
10362
10363 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10364         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10365         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10366
10367         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10368         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10369         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10370
10371         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10372         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10373         { } /* end */
10374 };
10375
10376 static struct hda_verb alc262_nec_verbs[] = {
10377         /* Unmute Speaker */
10378         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10379
10380         /* Headphone */
10381         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10382         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10383
10384         /* External mic to headphone */
10385         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10386         /* External mic to speaker */
10387         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10388         {}
10389 };
10390
10391 /*
10392  * fujitsu model
10393  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10394  *  0x1b = port replicator headphone out
10395  */
10396
10397 #define ALC_HP_EVENT    0x37
10398
10399 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10400         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10401         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10402         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10403         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10404         {}
10405 };
10406
10407 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10408         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10409         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10410         {}
10411 };
10412
10413 static struct hda_input_mux alc262_fujitsu_capture_source = {
10414         .num_items = 3,
10415         .items = {
10416                 { "Mic", 0x0 },
10417                 { "Int Mic", 0x1 },
10418                 { "CD", 0x4 },
10419         },
10420 };
10421
10422 static struct hda_input_mux alc262_HP_capture_source = {
10423         .num_items = 5,
10424         .items = {
10425                 { "Mic", 0x0 },
10426                 { "Front Mic", 0x1 },
10427                 { "Line", 0x2 },
10428                 { "CD", 0x4 },
10429                 { "AUX IN", 0x6 },
10430         },
10431 };
10432
10433 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10434         .num_items = 4,
10435         .items = {
10436                 { "Mic", 0x0 },
10437                 { "Front Mic", 0x2 },
10438                 { "Line", 0x1 },
10439                 { "CD", 0x4 },
10440         },
10441 };
10442
10443 /* mute/unmute internal speaker according to the hp jacks and mute state */
10444 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10445 {
10446         struct alc_spec *spec = codec->spec;
10447         unsigned int mute;
10448
10449         if (force || !spec->sense_updated) {
10450                 unsigned int present;
10451                 /* need to execute and sync at first */
10452                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10453                 /* check laptop HP jack */
10454                 present = snd_hda_codec_read(codec, 0x14, 0,
10455                                              AC_VERB_GET_PIN_SENSE, 0);
10456                 /* need to execute and sync at first */
10457                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10458                 /* check docking HP jack */
10459                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10460                                               AC_VERB_GET_PIN_SENSE, 0);
10461                 if (present & AC_PINSENSE_PRESENCE)
10462                         spec->jack_present = 1;
10463                 else
10464                         spec->jack_present = 0;
10465                 spec->sense_updated = 1;
10466         }
10467         /* unmute internal speaker only if both HPs are unplugged and
10468          * master switch is on
10469          */
10470         if (spec->jack_present)
10471                 mute = HDA_AMP_MUTE;
10472         else
10473                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10474         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10475                                  HDA_AMP_MUTE, mute);
10476 }
10477
10478 /* unsolicited event for HP jack sensing */
10479 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10480                                        unsigned int res)
10481 {
10482         if ((res >> 26) != ALC_HP_EVENT)
10483                 return;
10484         alc262_fujitsu_automute(codec, 1);
10485 }
10486
10487 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10488 {
10489         alc262_fujitsu_automute(codec, 1);
10490 }
10491
10492 /* bind volumes of both NID 0x0c and 0x0d */
10493 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10494         .ops = &snd_hda_bind_vol,
10495         .values = {
10496                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10497                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10498                 0
10499         },
10500 };
10501
10502 /* mute/unmute internal speaker according to the hp jack and mute state */
10503 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10504 {
10505         struct alc_spec *spec = codec->spec;
10506         unsigned int mute;
10507
10508         if (force || !spec->sense_updated) {
10509                 unsigned int present_int_hp;
10510                 /* need to execute and sync at first */
10511                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10512                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10513                                         AC_VERB_GET_PIN_SENSE, 0);
10514                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10515                 spec->sense_updated = 1;
10516         }
10517         if (spec->jack_present) {
10518                 /* mute internal speaker */
10519                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10520                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10521                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10522                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10523         } else {
10524                 /* unmute internal speaker if necessary */
10525                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10526                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10527                                          HDA_AMP_MUTE, mute);
10528                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10529                                          HDA_AMP_MUTE, mute);
10530         }
10531 }
10532
10533 /* unsolicited event for HP jack sensing */
10534 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10535                                        unsigned int res)
10536 {
10537         if ((res >> 26) != ALC_HP_EVENT)
10538                 return;
10539         alc262_lenovo_3000_automute(codec, 1);
10540 }
10541
10542 /* bind hp and internal speaker mute (with plug check) */
10543 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10544                                          struct snd_ctl_elem_value *ucontrol)
10545 {
10546         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10547         long *valp = ucontrol->value.integer.value;
10548         int change;
10549
10550         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10551                                                  HDA_AMP_MUTE,
10552                                                  valp ? 0 : HDA_AMP_MUTE);
10553         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10554                                                  HDA_AMP_MUTE,
10555                                                  valp ? 0 : HDA_AMP_MUTE);
10556
10557         if (change)
10558                 alc262_fujitsu_automute(codec, 0);
10559         return change;
10560 }
10561
10562 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10563         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10564         {
10565                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10566                 .name = "Master Playback Switch",
10567                 .info = snd_hda_mixer_amp_switch_info,
10568                 .get = snd_hda_mixer_amp_switch_get,
10569                 .put = alc262_fujitsu_master_sw_put,
10570                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10571         },
10572         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10573         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10574         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10575         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10576         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10577         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10578         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10579         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10580         { } /* end */
10581 };
10582
10583 /* bind hp and internal speaker mute (with plug check) */
10584 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10585                                          struct snd_ctl_elem_value *ucontrol)
10586 {
10587         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10588         long *valp = ucontrol->value.integer.value;
10589         int change;
10590
10591         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10592                                                  HDA_AMP_MUTE,
10593                                                  valp ? 0 : HDA_AMP_MUTE);
10594
10595         if (change)
10596                 alc262_lenovo_3000_automute(codec, 0);
10597         return change;
10598 }
10599
10600 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10601         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10602         {
10603                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10604                 .name = "Master Playback Switch",
10605                 .info = snd_hda_mixer_amp_switch_info,
10606                 .get = snd_hda_mixer_amp_switch_get,
10607                 .put = alc262_lenovo_3000_master_sw_put,
10608                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10609         },
10610         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10611         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10612         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10613         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10614         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10615         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10616         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10617         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10618         { } /* end */
10619 };
10620
10621 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10622         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10623         ALC262_HIPPO_MASTER_SWITCH,
10624         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10625         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10626         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10627         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10628         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10629         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10630         { } /* end */
10631 };
10632
10633 /* additional init verbs for Benq laptops */
10634 static struct hda_verb alc262_EAPD_verbs[] = {
10635         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10636         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10637         {}
10638 };
10639
10640 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10641         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10642         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10643
10644         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10645         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10646         {}
10647 };
10648
10649 /* Samsung Q1 Ultra Vista model setup */
10650 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10651         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10652         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10653         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10654         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10655         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10656         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10657         { } /* end */
10658 };
10659
10660 static struct hda_verb alc262_ultra_verbs[] = {
10661         /* output mixer */
10662         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10663         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10664         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10665         /* speaker */
10666         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10667         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10668         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10669         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10670         /* HP */
10671         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10672         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10673         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10674         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10675         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10676         /* internal mic */
10677         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10678         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10679         /* ADC, choose mic */
10680         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10681         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10682         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10683         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10684         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10685         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10686         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10687         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10688         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10689         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10690         {}
10691 };
10692
10693 /* mute/unmute internal speaker according to the hp jack and mute state */
10694 static void alc262_ultra_automute(struct hda_codec *codec)
10695 {
10696         struct alc_spec *spec = codec->spec;
10697         unsigned int mute;
10698
10699         mute = 0;
10700         /* auto-mute only when HP is used as HP */
10701         if (!spec->cur_mux[0]) {
10702                 unsigned int present;
10703                 /* need to execute and sync at first */
10704                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10705                 present = snd_hda_codec_read(codec, 0x15, 0,
10706                                              AC_VERB_GET_PIN_SENSE, 0);
10707                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10708                 if (spec->jack_present)
10709                         mute = HDA_AMP_MUTE;
10710         }
10711         /* mute/unmute internal speaker */
10712         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10713                                  HDA_AMP_MUTE, mute);
10714         /* mute/unmute HP */
10715         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10716                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10717 }
10718
10719 /* unsolicited event for HP jack sensing */
10720 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10721                                        unsigned int res)
10722 {
10723         if ((res >> 26) != ALC880_HP_EVENT)
10724                 return;
10725         alc262_ultra_automute(codec);
10726 }
10727
10728 static struct hda_input_mux alc262_ultra_capture_source = {
10729         .num_items = 2,
10730         .items = {
10731                 { "Mic", 0x1 },
10732                 { "Headphone", 0x7 },
10733         },
10734 };
10735
10736 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10737                                      struct snd_ctl_elem_value *ucontrol)
10738 {
10739         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10740         struct alc_spec *spec = codec->spec;
10741         int ret;
10742
10743         ret = alc_mux_enum_put(kcontrol, ucontrol);
10744         if (!ret)
10745                 return 0;
10746         /* reprogram the HP pin as mic or HP according to the input source */
10747         snd_hda_codec_write_cache(codec, 0x15, 0,
10748                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10749                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10750         alc262_ultra_automute(codec); /* mute/unmute HP */
10751         return ret;
10752 }
10753
10754 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10755         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10756         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10757         {
10758                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10759                 .name = "Capture Source",
10760                 .info = alc_mux_enum_info,
10761                 .get = alc_mux_enum_get,
10762                 .put = alc262_ultra_mux_enum_put,
10763         },
10764         { } /* end */
10765 };
10766
10767 /* add playback controls from the parsed DAC table */
10768 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10769                                              const struct auto_pin_cfg *cfg)
10770 {
10771         hda_nid_t nid;
10772         int err;
10773
10774         spec->multiout.num_dacs = 1;    /* only use one dac */
10775         spec->multiout.dac_nids = spec->private_dac_nids;
10776         spec->multiout.dac_nids[0] = 2;
10777
10778         nid = cfg->line_out_pins[0];
10779         if (nid) {
10780                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10781                                   "Front Playback Volume",
10782                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10783                 if (err < 0)
10784                         return err;
10785                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10786                                   "Front Playback Switch",
10787                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10788                 if (err < 0)
10789                         return err;
10790         }
10791
10792         nid = cfg->speaker_pins[0];
10793         if (nid) {
10794                 if (nid == 0x16) {
10795                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10796                                           "Speaker Playback Volume",
10797                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10798                                                               HDA_OUTPUT));
10799                         if (err < 0)
10800                                 return err;
10801                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10802                                           "Speaker Playback Switch",
10803                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10804                                                               HDA_OUTPUT));
10805                         if (err < 0)
10806                                 return err;
10807                 } else {
10808                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10809                                           "Speaker Playback Switch",
10810                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10811                                                               HDA_OUTPUT));
10812                         if (err < 0)
10813                                 return err;
10814                 }
10815         }
10816         nid = cfg->hp_pins[0];
10817         if (nid) {
10818                 /* spec->multiout.hp_nid = 2; */
10819                 if (nid == 0x16) {
10820                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10821                                           "Headphone Playback Volume",
10822                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10823                                                               HDA_OUTPUT));
10824                         if (err < 0)
10825                                 return err;
10826                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10827                                           "Headphone Playback Switch",
10828                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10829                                                               HDA_OUTPUT));
10830                         if (err < 0)
10831                                 return err;
10832                 } else {
10833                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10834                                           "Headphone Playback Switch",
10835                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10836                                                               HDA_OUTPUT));
10837                         if (err < 0)
10838                                 return err;
10839                 }
10840         }
10841         return 0;
10842 }
10843
10844 /* identical with ALC880 */
10845 #define alc262_auto_create_analog_input_ctls \
10846         alc880_auto_create_analog_input_ctls
10847
10848 /*
10849  * generic initialization of ADC, input mixers and output mixers
10850  */
10851 static struct hda_verb alc262_volume_init_verbs[] = {
10852         /*
10853          * Unmute ADC0-2 and set the default input to mic-in
10854          */
10855         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10856         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10857         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10858         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10859         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10860         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10861
10862         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10863          * mixer widget
10864          * Note: PASD motherboards uses the Line In 2 as the input for
10865          * front panel mic (mic 2)
10866          */
10867         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10868         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10869         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10870         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10871         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10872         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10873
10874         /*
10875          * Set up output mixers (0x0c - 0x0f)
10876          */
10877         /* set vol=0 to output mixers */
10878         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10879         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10880         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10881
10882         /* set up input amps for analog loopback */
10883         /* Amp Indices: DAC = 0, mixer = 1 */
10884         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10885         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10886         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10887         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10888         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10889         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10890
10891         /* FIXME: use matrix-type input source selection */
10892         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10893         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10894         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10895         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10896         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10897         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10898         /* Input mixer2 */
10899         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10900         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10901         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10902         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10903         /* Input mixer3 */
10904         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10905         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10906         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10907         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10908
10909         { }
10910 };
10911
10912 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10913         /*
10914          * Unmute ADC0-2 and set the default input to mic-in
10915          */
10916         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10917         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10918         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10919         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10920         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10921         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10922
10923         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10924          * mixer widget
10925          * Note: PASD motherboards uses the Line In 2 as the input for
10926          * front panel mic (mic 2)
10927          */
10928         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10929         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10930         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10931         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10932         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10933         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10934         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10935         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10936
10937         /*
10938          * Set up output mixers (0x0c - 0x0e)
10939          */
10940         /* set vol=0 to output mixers */
10941         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10942         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10943         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10944
10945         /* set up input amps for analog loopback */
10946         /* Amp Indices: DAC = 0, mixer = 1 */
10947         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10948         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10949         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10950         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10951         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10952         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10953
10954         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10955         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10956         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10957
10958         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10959         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10960
10961         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10962         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10963
10964         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10965         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10966         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10967         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10968         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10969
10970         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10971         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10972         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10973         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10974         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10975         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10976
10977
10978         /* FIXME: use matrix-type input source selection */
10979         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
10980         /* Input mixer1: only unmute Mic */
10981         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10982         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
10983         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10984         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10985         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10986         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
10987         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
10988         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
10989         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
10990         /* Input mixer2 */
10991         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10992         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
10993         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10994         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10995         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10996         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
10997         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
10998         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
10999         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11000         /* Input mixer3 */
11001         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11002         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11003         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11004         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11005         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11006         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11007         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11008         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11009         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11010
11011         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11012
11013         { }
11014 };
11015
11016 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11017         /*
11018          * Unmute ADC0-2 and set the default input to mic-in
11019          */
11020         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11021         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11022         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11023         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11024         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11025         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11026
11027         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11028          * mixer widget
11029          * Note: PASD motherboards uses the Line In 2 as the input for front
11030          * panel mic (mic 2)
11031          */
11032         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11033         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11034         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11036         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11038         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11040         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11041         /*
11042          * Set up output mixers (0x0c - 0x0e)
11043          */
11044         /* set vol=0 to output mixers */
11045         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11046         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11047         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11048
11049         /* set up input amps for analog loopback */
11050         /* Amp Indices: DAC = 0, mixer = 1 */
11051         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11052         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11053         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11054         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11055         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11056         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11057
11058
11059         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11060         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11061         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11062         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11063         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11064         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11065         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11066
11067         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11068         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11069
11070         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11071         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11072
11073         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11074         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11075         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11076         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11077         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11078         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11079
11080         /* FIXME: use matrix-type input source selection */
11081         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11082         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11083         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11084         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11087         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11088         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11090         /* Input mixer2 */
11091         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11092         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11093         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11094         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11096         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11098         /* Input mixer3 */
11099         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11100         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11104         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11106
11107         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11108
11109         { }
11110 };
11111
11112 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11113
11114         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11115         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11116         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11117
11118         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11119         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11120         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11121         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11122
11123         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11124         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11125         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11126         {}
11127 };
11128
11129
11130 #ifdef CONFIG_SND_HDA_POWER_SAVE
11131 #define alc262_loopbacks        alc880_loopbacks
11132 #endif
11133
11134 /* pcm configuration: identiacal with ALC880 */
11135 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11136 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11137 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11138 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11139
11140 /*
11141  * BIOS auto configuration
11142  */
11143 static int alc262_parse_auto_config(struct hda_codec *codec)
11144 {
11145         struct alc_spec *spec = codec->spec;
11146         int err;
11147         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11148
11149         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11150                                            alc262_ignore);
11151         if (err < 0)
11152                 return err;
11153         if (!spec->autocfg.line_outs) {
11154                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11155                         spec->multiout.max_channels = 2;
11156                         spec->no_analog = 1;
11157                         goto dig_only;
11158                 }
11159                 return 0; /* can't find valid BIOS pin config */
11160         }
11161         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11162         if (err < 0)
11163                 return err;
11164         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
11165         if (err < 0)
11166                 return err;
11167
11168         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11169
11170  dig_only:
11171         if (spec->autocfg.dig_outs) {
11172                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11173                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11174         }
11175         if (spec->autocfg.dig_in_pin)
11176                 spec->dig_in_nid = ALC262_DIGIN_NID;
11177
11178         if (spec->kctls.list)
11179                 add_mixer(spec, spec->kctls.list);
11180
11181         add_verb(spec, alc262_volume_init_verbs);
11182         spec->num_mux_defs = 1;
11183         spec->input_mux = &spec->private_imux[0];
11184
11185         err = alc_auto_add_mic_boost(codec);
11186         if (err < 0)
11187                 return err;
11188
11189         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11190
11191         return 1;
11192 }
11193
11194 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11195 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11196 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11197 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11198
11199
11200 /* init callback for auto-configuration model -- overriding the default init */
11201 static void alc262_auto_init(struct hda_codec *codec)
11202 {
11203         struct alc_spec *spec = codec->spec;
11204         alc262_auto_init_multi_out(codec);
11205         alc262_auto_init_hp_out(codec);
11206         alc262_auto_init_analog_input(codec);
11207         alc262_auto_init_input_src(codec);
11208         if (spec->unsol_event)
11209                 alc_inithook(codec);
11210 }
11211
11212 /*
11213  * configuration and preset
11214  */
11215 static const char *alc262_models[ALC262_MODEL_LAST] = {
11216         [ALC262_BASIC]          = "basic",
11217         [ALC262_HIPPO]          = "hippo",
11218         [ALC262_HIPPO_1]        = "hippo_1",
11219         [ALC262_FUJITSU]        = "fujitsu",
11220         [ALC262_HP_BPC]         = "hp-bpc",
11221         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11222         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11223         [ALC262_HP_RP5700]      = "hp-rp5700",
11224         [ALC262_BENQ_ED8]       = "benq",
11225         [ALC262_BENQ_T31]       = "benq-t31",
11226         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11227         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11228         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11229         [ALC262_ULTRA]          = "ultra",
11230         [ALC262_LENOVO_3000]    = "lenovo-3000",
11231         [ALC262_NEC]            = "nec",
11232         [ALC262_TYAN]           = "tyan",
11233         [ALC262_AUTO]           = "auto",
11234 };
11235
11236 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11237         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11238         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11239         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11240                            ALC262_HP_BPC),
11241         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11242                            ALC262_HP_BPC),
11243         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11244                            ALC262_HP_BPC),
11245         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11246         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11247         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11248         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11249         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11250         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11251         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11252         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11253         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11254         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11255         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11256         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11257                       ALC262_HP_TC_T5735),
11258         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11259         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11260         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11261         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11262         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11263         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11264                            ALC262_SONY_ASSAMD),
11265         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11266                       ALC262_TOSHIBA_RX1),
11267         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11268         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11269         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11270         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11271         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11272                            ALC262_ULTRA),
11273         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11274         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11275         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11276         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11277         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11278         {}
11279 };
11280
11281 static struct alc_config_preset alc262_presets[] = {
11282         [ALC262_BASIC] = {
11283                 .mixers = { alc262_base_mixer },
11284                 .init_verbs = { alc262_init_verbs },
11285                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11286                 .dac_nids = alc262_dac_nids,
11287                 .hp_nid = 0x03,
11288                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11289                 .channel_mode = alc262_modes,
11290                 .input_mux = &alc262_capture_source,
11291         },
11292         [ALC262_HIPPO] = {
11293                 .mixers = { alc262_hippo_mixer },
11294                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
11295                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11296                 .dac_nids = alc262_dac_nids,
11297                 .hp_nid = 0x03,
11298                 .dig_out_nid = ALC262_DIGOUT_NID,
11299                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11300                 .channel_mode = alc262_modes,
11301                 .input_mux = &alc262_capture_source,
11302                 .unsol_event = alc262_hippo_unsol_event,
11303                 .init_hook = alc262_hippo_init_hook,
11304         },
11305         [ALC262_HIPPO_1] = {
11306                 .mixers = { alc262_hippo1_mixer },
11307                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11308                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11309                 .dac_nids = alc262_dac_nids,
11310                 .hp_nid = 0x02,
11311                 .dig_out_nid = ALC262_DIGOUT_NID,
11312                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11313                 .channel_mode = alc262_modes,
11314                 .input_mux = &alc262_capture_source,
11315                 .unsol_event = alc262_hippo_unsol_event,
11316                 .init_hook = alc262_hippo1_init_hook,
11317         },
11318         [ALC262_FUJITSU] = {
11319                 .mixers = { alc262_fujitsu_mixer },
11320                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11321                                 alc262_fujitsu_unsol_verbs },
11322                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11323                 .dac_nids = alc262_dac_nids,
11324                 .hp_nid = 0x03,
11325                 .dig_out_nid = ALC262_DIGOUT_NID,
11326                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11327                 .channel_mode = alc262_modes,
11328                 .input_mux = &alc262_fujitsu_capture_source,
11329                 .unsol_event = alc262_fujitsu_unsol_event,
11330                 .init_hook = alc262_fujitsu_init_hook,
11331         },
11332         [ALC262_HP_BPC] = {
11333                 .mixers = { alc262_HP_BPC_mixer },
11334                 .init_verbs = { alc262_HP_BPC_init_verbs },
11335                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11336                 .dac_nids = alc262_dac_nids,
11337                 .hp_nid = 0x03,
11338                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11339                 .channel_mode = alc262_modes,
11340                 .input_mux = &alc262_HP_capture_source,
11341                 .unsol_event = alc262_hp_bpc_unsol_event,
11342                 .init_hook = alc262_hp_bpc_automute,
11343         },
11344         [ALC262_HP_BPC_D7000_WF] = {
11345                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11346                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11347                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11348                 .dac_nids = alc262_dac_nids,
11349                 .hp_nid = 0x03,
11350                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11351                 .channel_mode = alc262_modes,
11352                 .input_mux = &alc262_HP_D7000_capture_source,
11353                 .unsol_event = alc262_hp_wildwest_unsol_event,
11354                 .init_hook = alc262_hp_wildwest_automute,
11355         },
11356         [ALC262_HP_BPC_D7000_WL] = {
11357                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11358                             alc262_HP_BPC_WildWest_option_mixer },
11359                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11360                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11361                 .dac_nids = alc262_dac_nids,
11362                 .hp_nid = 0x03,
11363                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11364                 .channel_mode = alc262_modes,
11365                 .input_mux = &alc262_HP_D7000_capture_source,
11366                 .unsol_event = alc262_hp_wildwest_unsol_event,
11367                 .init_hook = alc262_hp_wildwest_automute,
11368         },
11369         [ALC262_HP_TC_T5735] = {
11370                 .mixers = { alc262_hp_t5735_mixer },
11371                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11372                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11373                 .dac_nids = alc262_dac_nids,
11374                 .hp_nid = 0x03,
11375                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11376                 .channel_mode = alc262_modes,
11377                 .input_mux = &alc262_capture_source,
11378                 .unsol_event = alc_automute_amp_unsol_event,
11379                 .init_hook = alc262_hp_t5735_init_hook,
11380         },
11381         [ALC262_HP_RP5700] = {
11382                 .mixers = { alc262_hp_rp5700_mixer },
11383                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11384                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11385                 .dac_nids = alc262_dac_nids,
11386                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11387                 .channel_mode = alc262_modes,
11388                 .input_mux = &alc262_hp_rp5700_capture_source,
11389         },
11390         [ALC262_BENQ_ED8] = {
11391                 .mixers = { alc262_base_mixer },
11392                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11393                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11394                 .dac_nids = alc262_dac_nids,
11395                 .hp_nid = 0x03,
11396                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11397                 .channel_mode = alc262_modes,
11398                 .input_mux = &alc262_capture_source,
11399         },
11400         [ALC262_SONY_ASSAMD] = {
11401                 .mixers = { alc262_sony_mixer },
11402                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11403                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11404                 .dac_nids = alc262_dac_nids,
11405                 .hp_nid = 0x02,
11406                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11407                 .channel_mode = alc262_modes,
11408                 .input_mux = &alc262_capture_source,
11409                 .unsol_event = alc262_hippo_unsol_event,
11410                 .init_hook = alc262_hippo_init_hook,
11411         },
11412         [ALC262_BENQ_T31] = {
11413                 .mixers = { alc262_benq_t31_mixer },
11414                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
11415                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11416                 .dac_nids = alc262_dac_nids,
11417                 .hp_nid = 0x03,
11418                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11419                 .channel_mode = alc262_modes,
11420                 .input_mux = &alc262_capture_source,
11421                 .unsol_event = alc262_hippo_unsol_event,
11422                 .init_hook = alc262_hippo_init_hook,
11423         },
11424         [ALC262_ULTRA] = {
11425                 .mixers = { alc262_ultra_mixer },
11426                 .cap_mixer = alc262_ultra_capture_mixer,
11427                 .init_verbs = { alc262_ultra_verbs },
11428                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11429                 .dac_nids = alc262_dac_nids,
11430                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11431                 .channel_mode = alc262_modes,
11432                 .input_mux = &alc262_ultra_capture_source,
11433                 .adc_nids = alc262_adc_nids, /* ADC0 */
11434                 .capsrc_nids = alc262_capsrc_nids,
11435                 .num_adc_nids = 1, /* single ADC */
11436                 .unsol_event = alc262_ultra_unsol_event,
11437                 .init_hook = alc262_ultra_automute,
11438         },
11439         [ALC262_LENOVO_3000] = {
11440                 .mixers = { alc262_lenovo_3000_mixer },
11441                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11442                                 alc262_lenovo_3000_unsol_verbs },
11443                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11444                 .dac_nids = alc262_dac_nids,
11445                 .hp_nid = 0x03,
11446                 .dig_out_nid = ALC262_DIGOUT_NID,
11447                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11448                 .channel_mode = alc262_modes,
11449                 .input_mux = &alc262_fujitsu_capture_source,
11450                 .unsol_event = alc262_lenovo_3000_unsol_event,
11451         },
11452         [ALC262_NEC] = {
11453                 .mixers = { alc262_nec_mixer },
11454                 .init_verbs = { alc262_nec_verbs },
11455                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11456                 .dac_nids = alc262_dac_nids,
11457                 .hp_nid = 0x03,
11458                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11459                 .channel_mode = alc262_modes,
11460                 .input_mux = &alc262_capture_source,
11461         },
11462         [ALC262_TOSHIBA_S06] = {
11463                 .mixers = { alc262_toshiba_s06_mixer },
11464                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11465                                                         alc262_eapd_verbs },
11466                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11467                 .capsrc_nids = alc262_dmic_capsrc_nids,
11468                 .dac_nids = alc262_dac_nids,
11469                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11470                 .dig_out_nid = ALC262_DIGOUT_NID,
11471                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11472                 .channel_mode = alc262_modes,
11473                 .input_mux = &alc262_dmic_capture_source,
11474                 .unsol_event = alc262_toshiba_s06_unsol_event,
11475                 .init_hook = alc262_toshiba_s06_init_hook,
11476         },
11477         [ALC262_TOSHIBA_RX1] = {
11478                 .mixers = { alc262_toshiba_rx1_mixer },
11479                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11480                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11481                 .dac_nids = alc262_dac_nids,
11482                 .hp_nid = 0x03,
11483                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11484                 .channel_mode = alc262_modes,
11485                 .input_mux = &alc262_capture_source,
11486                 .unsol_event = alc262_hippo_unsol_event,
11487                 .init_hook = alc262_hippo_init_hook,
11488         },
11489         [ALC262_TYAN] = {
11490                 .mixers = { alc262_tyan_mixer },
11491                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11492                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11493                 .dac_nids = alc262_dac_nids,
11494                 .hp_nid = 0x02,
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 = alc_automute_amp_unsol_event,
11500                 .init_hook = alc262_tyan_init_hook,
11501         },
11502 };
11503
11504 static int patch_alc262(struct hda_codec *codec)
11505 {
11506         struct alc_spec *spec;
11507         int board_config;
11508         int err;
11509
11510         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11511         if (spec == NULL)
11512                 return -ENOMEM;
11513
11514         codec->spec = spec;
11515 #if 0
11516         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11517          * under-run
11518          */
11519         {
11520         int tmp;
11521         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11522         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11523         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11524         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11525         }
11526 #endif
11527
11528         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11529
11530         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11531                                                   alc262_models,
11532                                                   alc262_cfg_tbl);
11533
11534         if (board_config < 0) {
11535                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
11536                        "trying auto-probe from BIOS...\n", codec->chip_name);
11537                 board_config = ALC262_AUTO;
11538         }
11539
11540         if (board_config == ALC262_AUTO) {
11541                 /* automatic parse from the BIOS config */
11542                 err = alc262_parse_auto_config(codec);
11543                 if (err < 0) {
11544                         alc_free(codec);
11545                         return err;
11546                 } else if (!err) {
11547                         printk(KERN_INFO
11548                                "hda_codec: Cannot set up configuration "
11549                                "from BIOS.  Using base mode...\n");
11550                         board_config = ALC262_BASIC;
11551                 }
11552         }
11553
11554         if (!spec->no_analog) {
11555                 err = snd_hda_attach_beep_device(codec, 0x1);
11556                 if (err < 0) {
11557                         alc_free(codec);
11558                         return err;
11559                 }
11560         }
11561
11562         if (board_config != ALC262_AUTO)
11563                 setup_preset(spec, &alc262_presets[board_config]);
11564
11565         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11566         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11567
11568         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11569         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11570
11571         spec->capture_style = CAPT_MIX;
11572         if (!spec->adc_nids && spec->input_mux) {
11573                 /* check whether NID 0x07 is valid */
11574                 unsigned int wcap = get_wcaps(codec, 0x07);
11575
11576                 /* get type */
11577                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11578                 if (wcap != AC_WID_AUD_IN) {
11579                         spec->adc_nids = alc262_adc_nids_alt;
11580                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
11581                         spec->capsrc_nids = alc262_capsrc_nids_alt;
11582                 } else {
11583                         spec->adc_nids = alc262_adc_nids;
11584                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
11585                         spec->capsrc_nids = alc262_capsrc_nids;
11586                 }
11587         }
11588         if (!spec->cap_mixer && !spec->no_analog)
11589                 set_capture_mixer(spec);
11590         if (!spec->no_analog)
11591                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11592
11593         spec->vmaster_nid = 0x0c;
11594
11595         codec->patch_ops = alc_patch_ops;
11596         if (board_config == ALC262_AUTO)
11597                 spec->init_hook = alc262_auto_init;
11598 #ifdef CONFIG_SND_HDA_POWER_SAVE
11599         if (!spec->loopback.amplist)
11600                 spec->loopback.amplist = alc262_loopbacks;
11601 #endif
11602         codec->proc_widget_hook = print_realtek_coef;
11603
11604         return 0;
11605 }
11606
11607 /*
11608  *  ALC268 channel source setting (2 channel)
11609  */
11610 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11611 #define alc268_modes            alc260_modes
11612
11613 static hda_nid_t alc268_dac_nids[2] = {
11614         /* front, hp */
11615         0x02, 0x03
11616 };
11617
11618 static hda_nid_t alc268_adc_nids[2] = {
11619         /* ADC0-1 */
11620         0x08, 0x07
11621 };
11622
11623 static hda_nid_t alc268_adc_nids_alt[1] = {
11624         /* ADC0 */
11625         0x08
11626 };
11627
11628 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11629
11630 static struct snd_kcontrol_new alc268_base_mixer[] = {
11631         /* output mixer control */
11632         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11633         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11634         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11635         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11636         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11637         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11638         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11639         { }
11640 };
11641
11642 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11643         /* output mixer control */
11644         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11645         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11646         ALC262_HIPPO_MASTER_SWITCH,
11647         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11648         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11649         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11650         { }
11651 };
11652
11653 /* bind Beep switches of both NID 0x0f and 0x10 */
11654 static struct hda_bind_ctls alc268_bind_beep_sw = {
11655         .ops = &snd_hda_bind_sw,
11656         .values = {
11657                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11658                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11659                 0
11660         },
11661 };
11662
11663 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11664         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11665         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11666         { }
11667 };
11668
11669 static struct hda_verb alc268_eapd_verbs[] = {
11670         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11671         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11672         { }
11673 };
11674
11675 /* Toshiba specific */
11676 static struct hda_verb alc268_toshiba_verbs[] = {
11677         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11678         { } /* end */
11679 };
11680
11681 static struct hda_input_mux alc268_acer_lc_capture_source = {
11682         .num_items = 2,
11683         .items = {
11684                 { "i-Mic", 0x6 },
11685                 { "E-Mic", 0x0 },
11686         },
11687 };
11688
11689 /* Acer specific */
11690 /* bind volumes of both NID 0x02 and 0x03 */
11691 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11692         .ops = &snd_hda_bind_vol,
11693         .values = {
11694                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11695                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11696                 0
11697         },
11698 };
11699
11700 /* mute/unmute internal speaker according to the hp jack and mute state */
11701 static void alc268_acer_automute(struct hda_codec *codec, int force)
11702 {
11703         struct alc_spec *spec = codec->spec;
11704         unsigned int mute;
11705
11706         if (force || !spec->sense_updated) {
11707                 unsigned int present;
11708                 present = snd_hda_codec_read(codec, 0x14, 0,
11709                                          AC_VERB_GET_PIN_SENSE, 0);
11710                 spec->jack_present = (present & 0x80000000) != 0;
11711                 spec->sense_updated = 1;
11712         }
11713         if (spec->jack_present)
11714                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11715         else /* unmute internal speaker if necessary */
11716                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11717         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11718                                  HDA_AMP_MUTE, mute);
11719 }
11720
11721
11722 /* bind hp and internal speaker mute (with plug check) */
11723 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11724                                      struct snd_ctl_elem_value *ucontrol)
11725 {
11726         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11727         long *valp = ucontrol->value.integer.value;
11728         int change;
11729
11730         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11731                                           HDA_AMP_MUTE,
11732                                           valp[0] ? 0 : HDA_AMP_MUTE);
11733         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11734                                            HDA_AMP_MUTE,
11735                                            valp[1] ? 0 : HDA_AMP_MUTE);
11736         if (change)
11737                 alc268_acer_automute(codec, 0);
11738         return change;
11739 }
11740
11741 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11742         /* output mixer control */
11743         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11744         {
11745                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11746                 .name = "Master Playback Switch",
11747                 .info = snd_hda_mixer_amp_switch_info,
11748                 .get = snd_hda_mixer_amp_switch_get,
11749                 .put = alc268_acer_master_sw_put,
11750                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11751         },
11752         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11753         { }
11754 };
11755
11756 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11757         /* output mixer control */
11758         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11759         {
11760                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11761                 .name = "Master Playback Switch",
11762                 .info = snd_hda_mixer_amp_switch_info,
11763                 .get = snd_hda_mixer_amp_switch_get,
11764                 .put = alc268_acer_master_sw_put,
11765                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11766         },
11767         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11768         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11769         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11770         { }
11771 };
11772
11773 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11774         /* output mixer control */
11775         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11776         {
11777                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11778                 .name = "Master Playback Switch",
11779                 .info = snd_hda_mixer_amp_switch_info,
11780                 .get = snd_hda_mixer_amp_switch_get,
11781                 .put = alc268_acer_master_sw_put,
11782                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11783         },
11784         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11785         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11786         { }
11787 };
11788
11789 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11790         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11791         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11792         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11793         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11794         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11795         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11796         { }
11797 };
11798
11799 static struct hda_verb alc268_acer_verbs[] = {
11800         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11801         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11802         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11803         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11804         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11805         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11806         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11807         { }
11808 };
11809
11810 /* unsolicited event for HP jack sensing */
11811 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
11812 #define alc268_toshiba_init_hook        alc262_hippo_init_hook
11813
11814 static void alc268_acer_unsol_event(struct hda_codec *codec,
11815                                        unsigned int res)
11816 {
11817         if ((res >> 26) != ALC880_HP_EVENT)
11818                 return;
11819         alc268_acer_automute(codec, 1);
11820 }
11821
11822 static void alc268_acer_init_hook(struct hda_codec *codec)
11823 {
11824         alc268_acer_automute(codec, 1);
11825 }
11826
11827 /* toggle speaker-output according to the hp-jack state */
11828 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11829 {
11830         unsigned int present;
11831         unsigned char bits;
11832
11833         present = snd_hda_codec_read(codec, 0x15, 0,
11834                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11835         bits = present ? AMP_IN_MUTE(0) : 0;
11836         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11837                                 AMP_IN_MUTE(0), bits);
11838         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11839                                 AMP_IN_MUTE(0), bits);
11840 }
11841
11842
11843 static void alc268_acer_mic_automute(struct hda_codec *codec)
11844 {
11845         unsigned int present;
11846
11847         present = snd_hda_codec_read(codec, 0x18, 0,
11848                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11849         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11850                             present ? 0x0 : 0x6);
11851 }
11852
11853 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11854                                     unsigned int res)
11855 {
11856         if ((res >> 26) == ALC880_HP_EVENT)
11857                 alc268_aspire_one_speaker_automute(codec);
11858         if ((res >> 26) == ALC880_MIC_EVENT)
11859                 alc268_acer_mic_automute(codec);
11860 }
11861
11862 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11863 {
11864         alc268_aspire_one_speaker_automute(codec);
11865         alc268_acer_mic_automute(codec);
11866 }
11867
11868 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11869         /* output mixer control */
11870         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11871         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11872         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11873         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11874         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11875         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11876         { }
11877 };
11878
11879 static struct hda_verb alc268_dell_verbs[] = {
11880         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11881         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11882         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11883         { }
11884 };
11885
11886 /* mute/unmute internal speaker according to the hp jack and mute state */
11887 static void alc268_dell_init_hook(struct hda_codec *codec)
11888 {
11889         struct alc_spec *spec = codec->spec;
11890
11891         spec->autocfg.hp_pins[0] = 0x15;
11892         spec->autocfg.speaker_pins[0] = 0x14;
11893         alc_automute_pin(codec);
11894 }
11895
11896 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11897         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11898         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11899         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11900         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11901         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11902         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11903         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11904         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11905         { }
11906 };
11907
11908 static struct hda_verb alc267_quanta_il1_verbs[] = {
11909         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11910         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11911         { }
11912 };
11913
11914 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11915 {
11916         unsigned int present;
11917
11918         present = snd_hda_codec_read(codec, 0x18, 0,
11919                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11920         snd_hda_codec_write(codec, 0x23, 0,
11921                             AC_VERB_SET_CONNECT_SEL,
11922                             present ? 0x00 : 0x01);
11923 }
11924
11925 static void alc267_quanta_il1_init_hook(struct hda_codec *codec)
11926 {
11927         struct alc_spec *spec = codec->spec;
11928
11929         spec->autocfg.hp_pins[0] = 0x15;
11930         spec->autocfg.speaker_pins[0] = 0x14;
11931         alc_automute_pin(codec);
11932         alc267_quanta_il1_mic_automute(codec);
11933 }
11934
11935 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11936                                            unsigned int res)
11937 {
11938         switch (res >> 26) {
11939         case ALC880_MIC_EVENT:
11940                 alc267_quanta_il1_mic_automute(codec);
11941                 break;
11942         default:
11943                 alc_sku_unsol_event(codec, res);
11944                 break;
11945         }
11946 }
11947
11948 /*
11949  * generic initialization of ADC, input mixers and output mixers
11950  */
11951 static struct hda_verb alc268_base_init_verbs[] = {
11952         /* Unmute DAC0-1 and set vol = 0 */
11953         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11954         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11955
11956         /*
11957          * Set up output mixers (0x0c - 0x0e)
11958          */
11959         /* set vol=0 to output mixers */
11960         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11961         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11962
11963         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11964         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11965
11966         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11967         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11968         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11969         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11970         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11971         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11972         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11973         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11974
11975         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11977         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11978         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11979         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11980
11981         /* set PCBEEP vol = 0, mute connections */
11982         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11983         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11984         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11985
11986         /* Unmute Selector 23h,24h and set the default input to mic-in */
11987
11988         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11989         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11990         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11991         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11992
11993         { }
11994 };
11995
11996 /*
11997  * generic initialization of ADC, input mixers and output mixers
11998  */
11999 static struct hda_verb alc268_volume_init_verbs[] = {
12000         /* set output DAC */
12001         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12002         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12003
12004         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12005         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12006         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12007         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12008         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12009
12010         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12011         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12012         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12013
12014         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12015         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12016
12017         /* set PCBEEP vol = 0, mute connections */
12018         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12019         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12020         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12021
12022         { }
12023 };
12024
12025 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12026         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12027         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12028         {
12029                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12030                 /* The multiple "Capture Source" controls confuse alsamixer
12031                  * So call somewhat different..
12032                  */
12033                 /* .name = "Capture Source", */
12034                 .name = "Input Source",
12035                 .count = 1,
12036                 .info = alc_mux_enum_info,
12037                 .get = alc_mux_enum_get,
12038                 .put = alc_mux_enum_put,
12039         },
12040         { } /* end */
12041 };
12042
12043 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12044         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12045         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12046         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12047         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12048         {
12049                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12050                 /* The multiple "Capture Source" controls confuse alsamixer
12051                  * So call somewhat different..
12052                  */
12053                 /* .name = "Capture Source", */
12054                 .name = "Input Source",
12055                 .count = 2,
12056                 .info = alc_mux_enum_info,
12057                 .get = alc_mux_enum_get,
12058                 .put = alc_mux_enum_put,
12059         },
12060         { } /* end */
12061 };
12062
12063 static struct hda_input_mux alc268_capture_source = {
12064         .num_items = 4,
12065         .items = {
12066                 { "Mic", 0x0 },
12067                 { "Front Mic", 0x1 },
12068                 { "Line", 0x2 },
12069                 { "CD", 0x3 },
12070         },
12071 };
12072
12073 static struct hda_input_mux alc268_acer_capture_source = {
12074         .num_items = 3,
12075         .items = {
12076                 { "Mic", 0x0 },
12077                 { "Internal Mic", 0x1 },
12078                 { "Line", 0x2 },
12079         },
12080 };
12081
12082 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12083         .num_items = 3,
12084         .items = {
12085                 { "Mic", 0x0 },
12086                 { "Internal Mic", 0x6 },
12087                 { "Line", 0x2 },
12088         },
12089 };
12090
12091 #ifdef CONFIG_SND_DEBUG
12092 static struct snd_kcontrol_new alc268_test_mixer[] = {
12093         /* Volume widgets */
12094         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12095         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12096         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12097         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12098         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12099         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12100         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12101         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12102         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12103         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12104         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12105         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12106         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12107         /* The below appears problematic on some hardwares */
12108         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12109         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12110         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12111         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12112         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12113
12114         /* Modes for retasking pin widgets */
12115         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12116         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12117         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12118         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12119
12120         /* Controls for GPIO pins, assuming they are configured as outputs */
12121         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12122         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12123         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12124         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12125
12126         /* Switches to allow the digital SPDIF output pin to be enabled.
12127          * The ALC268 does not have an SPDIF input.
12128          */
12129         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12130
12131         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12132          * this output to turn on an external amplifier.
12133          */
12134         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12135         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12136
12137         { } /* end */
12138 };
12139 #endif
12140
12141 /* create input playback/capture controls for the given pin */
12142 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12143                                     const char *ctlname, int idx)
12144 {
12145         char name[32];
12146         int err;
12147
12148         sprintf(name, "%s Playback Volume", ctlname);
12149         if (nid == 0x14) {
12150                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12151                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
12152                                                       HDA_OUTPUT));
12153                 if (err < 0)
12154                         return err;
12155         } else if (nid == 0x15) {
12156                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12157                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
12158                                                       HDA_OUTPUT));
12159                 if (err < 0)
12160                         return err;
12161         } else
12162                 return -1;
12163         sprintf(name, "%s Playback Switch", ctlname);
12164         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12165                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12166         if (err < 0)
12167                 return err;
12168         return 0;
12169 }
12170
12171 /* add playback controls from the parsed DAC table */
12172 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12173                                              const struct auto_pin_cfg *cfg)
12174 {
12175         hda_nid_t nid;
12176         int err;
12177
12178         spec->multiout.num_dacs = 2;    /* only use one dac */
12179         spec->multiout.dac_nids = spec->private_dac_nids;
12180         spec->multiout.dac_nids[0] = 2;
12181         spec->multiout.dac_nids[1] = 3;
12182
12183         nid = cfg->line_out_pins[0];
12184         if (nid)
12185                 alc268_new_analog_output(spec, nid, "Front", 0);
12186
12187         nid = cfg->speaker_pins[0];
12188         if (nid == 0x1d) {
12189                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12190                                   "Speaker Playback Volume",
12191                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12192                 if (err < 0)
12193                         return err;
12194         }
12195         nid = cfg->hp_pins[0];
12196         if (nid)
12197                 alc268_new_analog_output(spec, nid, "Headphone", 0);
12198
12199         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12200         if (nid == 0x16) {
12201                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12202                                   "Mono Playback Switch",
12203                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
12204                 if (err < 0)
12205                         return err;
12206         }
12207         return 0;
12208 }
12209
12210 /* create playback/capture controls for input pins */
12211 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
12212                                                 const struct auto_pin_cfg *cfg)
12213 {
12214         struct hda_input_mux *imux = &spec->private_imux[0];
12215         int i, idx1;
12216
12217         for (i = 0; i < AUTO_PIN_LAST; i++) {
12218                 switch(cfg->input_pins[i]) {
12219                 case 0x18:
12220                         idx1 = 0;       /* Mic 1 */
12221                         break;
12222                 case 0x19:
12223                         idx1 = 1;       /* Mic 2 */
12224                         break;
12225                 case 0x1a:
12226                         idx1 = 2;       /* Line In */
12227                         break;
12228                 case 0x1c:
12229                         idx1 = 3;       /* CD */
12230                         break;
12231                 case 0x12:
12232                 case 0x13:
12233                         idx1 = 6;       /* digital mics */
12234                         break;
12235                 default:
12236                         continue;
12237                 }
12238                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12239                 imux->items[imux->num_items].index = idx1;
12240                 imux->num_items++;
12241         }
12242         return 0;
12243 }
12244
12245 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12246 {
12247         struct alc_spec *spec = codec->spec;
12248         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12249         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12250         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12251         unsigned int    dac_vol1, dac_vol2;
12252
12253         if (speaker_nid) {
12254                 snd_hda_codec_write(codec, speaker_nid, 0,
12255                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12256                 snd_hda_codec_write(codec, 0x0f, 0,
12257                                     AC_VERB_SET_AMP_GAIN_MUTE,
12258                                     AMP_IN_UNMUTE(1));
12259                 snd_hda_codec_write(codec, 0x10, 0,
12260                                     AC_VERB_SET_AMP_GAIN_MUTE,
12261                                     AMP_IN_UNMUTE(1));
12262         } else {
12263                 snd_hda_codec_write(codec, 0x0f, 0,
12264                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12265                 snd_hda_codec_write(codec, 0x10, 0,
12266                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12267         }
12268
12269         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12270         if (line_nid == 0x14)
12271                 dac_vol2 = AMP_OUT_ZERO;
12272         else if (line_nid == 0x15)
12273                 dac_vol1 = AMP_OUT_ZERO;
12274         if (hp_nid == 0x14)
12275                 dac_vol2 = AMP_OUT_ZERO;
12276         else if (hp_nid == 0x15)
12277                 dac_vol1 = AMP_OUT_ZERO;
12278         if (line_nid != 0x16 || hp_nid != 0x16 ||
12279             spec->autocfg.line_out_pins[1] != 0x16 ||
12280             spec->autocfg.line_out_pins[2] != 0x16)
12281                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12282
12283         snd_hda_codec_write(codec, 0x02, 0,
12284                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12285         snd_hda_codec_write(codec, 0x03, 0,
12286                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12287 }
12288
12289 /* pcm configuration: identiacal with ALC880 */
12290 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12291 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12292 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12293 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12294
12295 /*
12296  * BIOS auto configuration
12297  */
12298 static int alc268_parse_auto_config(struct hda_codec *codec)
12299 {
12300         struct alc_spec *spec = codec->spec;
12301         int err;
12302         static hda_nid_t alc268_ignore[] = { 0 };
12303
12304         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12305                                            alc268_ignore);
12306         if (err < 0)
12307                 return err;
12308         if (!spec->autocfg.line_outs) {
12309                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12310                         spec->multiout.max_channels = 2;
12311                         spec->no_analog = 1;
12312                         goto dig_only;
12313                 }
12314                 return 0; /* can't find valid BIOS pin config */
12315         }
12316         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12317         if (err < 0)
12318                 return err;
12319         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
12320         if (err < 0)
12321                 return err;
12322
12323         spec->multiout.max_channels = 2;
12324
12325  dig_only:
12326         /* digital only support output */
12327         if (spec->autocfg.dig_outs) {
12328                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12329                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12330         }
12331         if (spec->kctls.list)
12332                 add_mixer(spec, spec->kctls.list);
12333
12334         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12335                 add_mixer(spec, alc268_beep_mixer);
12336
12337         add_verb(spec, alc268_volume_init_verbs);
12338         spec->num_mux_defs = 1;
12339         spec->input_mux = &spec->private_imux[0];
12340
12341         err = alc_auto_add_mic_boost(codec);
12342         if (err < 0)
12343                 return err;
12344
12345         return 1;
12346 }
12347
12348 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
12349 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
12350 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12351
12352 /* init callback for auto-configuration model -- overriding the default init */
12353 static void alc268_auto_init(struct hda_codec *codec)
12354 {
12355         struct alc_spec *spec = codec->spec;
12356         alc268_auto_init_multi_out(codec);
12357         alc268_auto_init_hp_out(codec);
12358         alc268_auto_init_mono_speaker_out(codec);
12359         alc268_auto_init_analog_input(codec);
12360         if (spec->unsol_event)
12361                 alc_inithook(codec);
12362 }
12363
12364 /*
12365  * configuration and preset
12366  */
12367 static const char *alc268_models[ALC268_MODEL_LAST] = {
12368         [ALC267_QUANTA_IL1]     = "quanta-il1",
12369         [ALC268_3ST]            = "3stack",
12370         [ALC268_TOSHIBA]        = "toshiba",
12371         [ALC268_ACER]           = "acer",
12372         [ALC268_ACER_DMIC]      = "acer-dmic",
12373         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12374         [ALC268_DELL]           = "dell",
12375         [ALC268_ZEPTO]          = "zepto",
12376 #ifdef CONFIG_SND_DEBUG
12377         [ALC268_TEST]           = "test",
12378 #endif
12379         [ALC268_AUTO]           = "auto",
12380 };
12381
12382 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12383         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12384         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12385         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12386         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12387         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12388         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12389                                                 ALC268_ACER_ASPIRE_ONE),
12390         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12391         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12392         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12393                            ALC268_TOSHIBA),
12394         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12395         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12396         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12397                            ALC268_TOSHIBA),
12398         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12399         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12400         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12401         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12402         {}
12403 };
12404
12405 static struct alc_config_preset alc268_presets[] = {
12406         [ALC267_QUANTA_IL1] = {
12407                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
12408                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12409                                 alc267_quanta_il1_verbs },
12410                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12411                 .dac_nids = alc268_dac_nids,
12412                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12413                 .adc_nids = alc268_adc_nids_alt,
12414                 .hp_nid = 0x03,
12415                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12416                 .channel_mode = alc268_modes,
12417                 .input_mux = &alc268_capture_source,
12418                 .unsol_event = alc267_quanta_il1_unsol_event,
12419                 .init_hook = alc267_quanta_il1_init_hook,
12420         },
12421         [ALC268_3ST] = {
12422                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12423                             alc268_beep_mixer },
12424                 .init_verbs = { alc268_base_init_verbs },
12425                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12426                 .dac_nids = alc268_dac_nids,
12427                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12428                 .adc_nids = alc268_adc_nids_alt,
12429                 .capsrc_nids = alc268_capsrc_nids,
12430                 .hp_nid = 0x03,
12431                 .dig_out_nid = ALC268_DIGOUT_NID,
12432                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12433                 .channel_mode = alc268_modes,
12434                 .input_mux = &alc268_capture_source,
12435         },
12436         [ALC268_TOSHIBA] = {
12437                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12438                             alc268_beep_mixer },
12439                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12440                                 alc268_toshiba_verbs },
12441                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12442                 .dac_nids = alc268_dac_nids,
12443                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12444                 .adc_nids = alc268_adc_nids_alt,
12445                 .capsrc_nids = alc268_capsrc_nids,
12446                 .hp_nid = 0x03,
12447                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12448                 .channel_mode = alc268_modes,
12449                 .input_mux = &alc268_capture_source,
12450                 .unsol_event = alc268_toshiba_unsol_event,
12451                 .init_hook = alc268_toshiba_init_hook,
12452         },
12453         [ALC268_ACER] = {
12454                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12455                             alc268_beep_mixer },
12456                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12457                                 alc268_acer_verbs },
12458                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12459                 .dac_nids = alc268_dac_nids,
12460                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12461                 .adc_nids = alc268_adc_nids_alt,
12462                 .capsrc_nids = alc268_capsrc_nids,
12463                 .hp_nid = 0x02,
12464                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12465                 .channel_mode = alc268_modes,
12466                 .input_mux = &alc268_acer_capture_source,
12467                 .unsol_event = alc268_acer_unsol_event,
12468                 .init_hook = alc268_acer_init_hook,
12469         },
12470         [ALC268_ACER_DMIC] = {
12471                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12472                             alc268_beep_mixer },
12473                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12474                                 alc268_acer_verbs },
12475                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12476                 .dac_nids = alc268_dac_nids,
12477                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12478                 .adc_nids = alc268_adc_nids_alt,
12479                 .capsrc_nids = alc268_capsrc_nids,
12480                 .hp_nid = 0x02,
12481                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12482                 .channel_mode = alc268_modes,
12483                 .input_mux = &alc268_acer_dmic_capture_source,
12484                 .unsol_event = alc268_acer_unsol_event,
12485                 .init_hook = alc268_acer_init_hook,
12486         },
12487         [ALC268_ACER_ASPIRE_ONE] = {
12488                 .mixers = { alc268_acer_aspire_one_mixer,
12489                             alc268_beep_mixer,
12490                             alc268_capture_alt_mixer },
12491                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12492                                 alc268_acer_aspire_one_verbs },
12493                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12494                 .dac_nids = alc268_dac_nids,
12495                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12496                 .adc_nids = alc268_adc_nids_alt,
12497                 .capsrc_nids = alc268_capsrc_nids,
12498                 .hp_nid = 0x03,
12499                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12500                 .channel_mode = alc268_modes,
12501                 .input_mux = &alc268_acer_lc_capture_source,
12502                 .unsol_event = alc268_acer_lc_unsol_event,
12503                 .init_hook = alc268_acer_lc_init_hook,
12504         },
12505         [ALC268_DELL] = {
12506                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
12507                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12508                                 alc268_dell_verbs },
12509                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12510                 .dac_nids = alc268_dac_nids,
12511                 .hp_nid = 0x02,
12512                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12513                 .channel_mode = alc268_modes,
12514                 .unsol_event = alc_sku_unsol_event,
12515                 .init_hook = alc268_dell_init_hook,
12516                 .input_mux = &alc268_capture_source,
12517         },
12518         [ALC268_ZEPTO] = {
12519                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12520                             alc268_beep_mixer },
12521                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12522                                 alc268_toshiba_verbs },
12523                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12524                 .dac_nids = alc268_dac_nids,
12525                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12526                 .adc_nids = alc268_adc_nids_alt,
12527                 .capsrc_nids = alc268_capsrc_nids,
12528                 .hp_nid = 0x03,
12529                 .dig_out_nid = ALC268_DIGOUT_NID,
12530                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12531                 .channel_mode = alc268_modes,
12532                 .input_mux = &alc268_capture_source,
12533                 .unsol_event = alc268_toshiba_unsol_event,
12534                 .init_hook = alc268_toshiba_init_hook
12535         },
12536 #ifdef CONFIG_SND_DEBUG
12537         [ALC268_TEST] = {
12538                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12539                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12540                                 alc268_volume_init_verbs },
12541                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12542                 .dac_nids = alc268_dac_nids,
12543                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12544                 .adc_nids = alc268_adc_nids_alt,
12545                 .capsrc_nids = alc268_capsrc_nids,
12546                 .hp_nid = 0x03,
12547                 .dig_out_nid = ALC268_DIGOUT_NID,
12548                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12549                 .channel_mode = alc268_modes,
12550                 .input_mux = &alc268_capture_source,
12551         },
12552 #endif
12553 };
12554
12555 static int patch_alc268(struct hda_codec *codec)
12556 {
12557         struct alc_spec *spec;
12558         int board_config;
12559         int i, has_beep, err;
12560
12561         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12562         if (spec == NULL)
12563                 return -ENOMEM;
12564
12565         codec->spec = spec;
12566
12567         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12568                                                   alc268_models,
12569                                                   alc268_cfg_tbl);
12570
12571         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12572                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
12573                        "trying auto-probe from BIOS...\n", codec->chip_name);
12574                 board_config = ALC268_AUTO;
12575         }
12576
12577         if (board_config == ALC268_AUTO) {
12578                 /* automatic parse from the BIOS config */
12579                 err = alc268_parse_auto_config(codec);
12580                 if (err < 0) {
12581                         alc_free(codec);
12582                         return err;
12583                 } else if (!err) {
12584                         printk(KERN_INFO
12585                                "hda_codec: Cannot set up configuration "
12586                                "from BIOS.  Using base mode...\n");
12587                         board_config = ALC268_3ST;
12588                 }
12589         }
12590
12591         if (board_config != ALC268_AUTO)
12592                 setup_preset(spec, &alc268_presets[board_config]);
12593
12594         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12595         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12596         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12597
12598         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12599
12600         has_beep = 0;
12601         for (i = 0; i < spec->num_mixers; i++) {
12602                 if (spec->mixers[i] == alc268_beep_mixer) {
12603                         has_beep = 1;
12604                         break;
12605                 }
12606         }
12607
12608         if (has_beep) {
12609                 err = snd_hda_attach_beep_device(codec, 0x1);
12610                 if (err < 0) {
12611                         alc_free(codec);
12612                         return err;
12613                 }
12614                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12615                         /* override the amp caps for beep generator */
12616                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12617                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12618                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12619                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12620                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12621         }
12622
12623         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12624                 /* check whether NID 0x07 is valid */
12625                 unsigned int wcap = get_wcaps(codec, 0x07);
12626                 int i;
12627
12628                 /* get type */
12629                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
12630                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12631                         spec->adc_nids = alc268_adc_nids_alt;
12632                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12633                         add_mixer(spec, alc268_capture_alt_mixer);
12634                 } else {
12635                         spec->adc_nids = alc268_adc_nids;
12636                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12637                         add_mixer(spec, alc268_capture_mixer);
12638                 }
12639                 spec->capsrc_nids = alc268_capsrc_nids;
12640                 /* set default input source */
12641                 for (i = 0; i < spec->num_adc_nids; i++)
12642                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12643                                 0, AC_VERB_SET_CONNECT_SEL,
12644                                 spec->input_mux->items[0].index);
12645         }
12646
12647         spec->vmaster_nid = 0x02;
12648
12649         codec->patch_ops = alc_patch_ops;
12650         if (board_config == ALC268_AUTO)
12651                 spec->init_hook = alc268_auto_init;
12652
12653         codec->proc_widget_hook = print_realtek_coef;
12654
12655         return 0;
12656 }
12657
12658 /*
12659  *  ALC269 channel source setting (2 channel)
12660  */
12661 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12662
12663 #define alc269_dac_nids         alc260_dac_nids
12664
12665 static hda_nid_t alc269_adc_nids[1] = {
12666         /* ADC1 */
12667         0x08,
12668 };
12669
12670 static hda_nid_t alc269_capsrc_nids[1] = {
12671         0x23,
12672 };
12673
12674 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12675  *       not a mux!
12676  */
12677
12678 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12679         .num_items = 2,
12680         .items = {
12681                 { "i-Mic", 0x5 },
12682                 { "e-Mic", 0x0 },
12683         },
12684 };
12685
12686 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12687         .num_items = 2,
12688         .items = {
12689                 { "i-Mic", 0x1 },
12690                 { "e-Mic", 0x0 },
12691         },
12692 };
12693
12694 #define alc269_modes            alc260_modes
12695 #define alc269_capture_source   alc880_lg_lw_capture_source
12696
12697 static struct snd_kcontrol_new alc269_base_mixer[] = {
12698         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12699         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12700         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12701         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12702         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12703         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12704         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12705         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12706         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12707         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12708         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12709         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12710         { } /* end */
12711 };
12712
12713 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12714         /* output mixer control */
12715         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12716         {
12717                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12718                 .name = "Master Playback Switch",
12719                 .info = snd_hda_mixer_amp_switch_info,
12720                 .get = snd_hda_mixer_amp_switch_get,
12721                 .put = alc268_acer_master_sw_put,
12722                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12723         },
12724         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12725         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12726         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12727         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12728         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12729         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12730         { }
12731 };
12732
12733 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12734         /* output mixer control */
12735         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12736         {
12737                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12738                 .name = "Master Playback Switch",
12739                 .info = snd_hda_mixer_amp_switch_info,
12740                 .get = snd_hda_mixer_amp_switch_get,
12741                 .put = alc268_acer_master_sw_put,
12742                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12743         },
12744         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12745         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12746         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12747         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12748         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12749         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12750         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12751         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12752         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12753         { }
12754 };
12755
12756 /* bind volumes of both NID 0x0c and 0x0d */
12757 static struct hda_bind_ctls alc269_epc_bind_vol = {
12758         .ops = &snd_hda_bind_vol,
12759         .values = {
12760                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12761                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12762                 0
12763         },
12764 };
12765
12766 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12767         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12768         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12769         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12770         { } /* end */
12771 };
12772
12773 /* capture mixer elements */
12774 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12775         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12776         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12777         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12778         { } /* end */
12779 };
12780
12781 /* FSC amilo */
12782 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12783         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12784         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12785         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12786         { } /* end */
12787 };
12788
12789 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12790         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12791         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12792         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12793         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12794         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12795         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12796         { }
12797 };
12798
12799 static struct hda_verb alc269_lifebook_verbs[] = {
12800         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12801         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12802         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12803         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12804         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12805         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12806         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12807         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12808         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12809         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12810         { }
12811 };
12812
12813 /* toggle speaker-output according to the hp-jack state */
12814 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12815 {
12816         unsigned int present;
12817         unsigned char bits;
12818
12819         present = snd_hda_codec_read(codec, 0x15, 0,
12820                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12821         bits = present ? AMP_IN_MUTE(0) : 0;
12822         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12823                         AMP_IN_MUTE(0), bits);
12824         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12825                         AMP_IN_MUTE(0), bits);
12826
12827         snd_hda_codec_write(codec, 0x20, 0,
12828                         AC_VERB_SET_COEF_INDEX, 0x0c);
12829         snd_hda_codec_write(codec, 0x20, 0,
12830                         AC_VERB_SET_PROC_COEF, 0x680);
12831
12832         snd_hda_codec_write(codec, 0x20, 0,
12833                         AC_VERB_SET_COEF_INDEX, 0x0c);
12834         snd_hda_codec_write(codec, 0x20, 0,
12835                         AC_VERB_SET_PROC_COEF, 0x480);
12836 }
12837
12838 /* toggle speaker-output according to the hp-jacks state */
12839 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12840 {
12841         unsigned int present;
12842         unsigned char bits;
12843
12844         /* Check laptop headphone socket */
12845         present = snd_hda_codec_read(codec, 0x15, 0,
12846                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12847
12848         /* Check port replicator headphone socket */
12849         present |= snd_hda_codec_read(codec, 0x1a, 0,
12850                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12851
12852         bits = present ? AMP_IN_MUTE(0) : 0;
12853         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12854                         AMP_IN_MUTE(0), bits);
12855         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12856                         AMP_IN_MUTE(0), bits);
12857
12858         snd_hda_codec_write(codec, 0x20, 0,
12859                         AC_VERB_SET_COEF_INDEX, 0x0c);
12860         snd_hda_codec_write(codec, 0x20, 0,
12861                         AC_VERB_SET_PROC_COEF, 0x680);
12862
12863         snd_hda_codec_write(codec, 0x20, 0,
12864                         AC_VERB_SET_COEF_INDEX, 0x0c);
12865         snd_hda_codec_write(codec, 0x20, 0,
12866                         AC_VERB_SET_PROC_COEF, 0x480);
12867 }
12868
12869 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12870 {
12871         unsigned int present;
12872
12873         present = snd_hda_codec_read(codec, 0x18, 0,
12874                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12875         snd_hda_codec_write(codec, 0x23, 0,
12876                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12877 }
12878
12879 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12880 {
12881         unsigned int present_laptop;
12882         unsigned int present_dock;
12883
12884         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12885                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12886
12887         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12888                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12889
12890         /* Laptop mic port overrides dock mic port, design decision */
12891         if (present_dock)
12892                 snd_hda_codec_write(codec, 0x23, 0,
12893                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12894         if (present_laptop)
12895                 snd_hda_codec_write(codec, 0x23, 0,
12896                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12897         if (!present_dock && !present_laptop)
12898                 snd_hda_codec_write(codec, 0x23, 0,
12899                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12900 }
12901
12902 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12903                                     unsigned int res)
12904 {
12905         if ((res >> 26) == ALC880_HP_EVENT)
12906                 alc269_quanta_fl1_speaker_automute(codec);
12907         if ((res >> 26) == ALC880_MIC_EVENT)
12908                 alc269_quanta_fl1_mic_automute(codec);
12909 }
12910
12911 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12912                                         unsigned int res)
12913 {
12914         if ((res >> 26) == ALC880_HP_EVENT)
12915                 alc269_lifebook_speaker_automute(codec);
12916         if ((res >> 26) == ALC880_MIC_EVENT)
12917                 alc269_lifebook_mic_autoswitch(codec);
12918 }
12919
12920 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12921 {
12922         alc269_quanta_fl1_speaker_automute(codec);
12923         alc269_quanta_fl1_mic_automute(codec);
12924 }
12925
12926 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12927 {
12928         alc269_lifebook_speaker_automute(codec);
12929         alc269_lifebook_mic_autoswitch(codec);
12930 }
12931
12932 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12933         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12934         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12935         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12936         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12937         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12938         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12939         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12940         {}
12941 };
12942
12943 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12944         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12945         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12946         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12947         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12948         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12949         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12950         {}
12951 };
12952
12953 /* toggle speaker-output according to the hp-jack state */
12954 static void alc269_speaker_automute(struct hda_codec *codec)
12955 {
12956         unsigned int present;
12957         unsigned char bits;
12958
12959         present = snd_hda_codec_read(codec, 0x15, 0,
12960                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12961         bits = present ? AMP_IN_MUTE(0) : 0;
12962         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12963                                 AMP_IN_MUTE(0), bits);
12964         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12965                                 AMP_IN_MUTE(0), bits);
12966 }
12967
12968 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12969 {
12970         unsigned int present;
12971
12972         present = snd_hda_codec_read(codec, 0x18, 0,
12973                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12974         snd_hda_codec_write(codec, 0x23, 0,
12975                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12976 }
12977
12978 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12979 {
12980         unsigned int present;
12981
12982         present = snd_hda_codec_read(codec, 0x18, 0,
12983                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12984         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12985                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12986         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12987                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12988 }
12989
12990 /* unsolicited event for HP jack sensing */
12991 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12992                                      unsigned int res)
12993 {
12994         if ((res >> 26) == ALC880_HP_EVENT)
12995                 alc269_speaker_automute(codec);
12996
12997         if ((res >> 26) == ALC880_MIC_EVENT)
12998                 alc269_eeepc_dmic_automute(codec);
12999 }
13000
13001 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
13002 {
13003         alc269_speaker_automute(codec);
13004         alc269_eeepc_dmic_automute(codec);
13005 }
13006
13007 /* unsolicited event for HP jack sensing */
13008 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
13009                                      unsigned int res)
13010 {
13011         if ((res >> 26) == ALC880_HP_EVENT)
13012                 alc269_speaker_automute(codec);
13013
13014         if ((res >> 26) == ALC880_MIC_EVENT)
13015                 alc269_eeepc_amic_automute(codec);
13016 }
13017
13018 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
13019 {
13020         alc269_speaker_automute(codec);
13021         alc269_eeepc_amic_automute(codec);
13022 }
13023
13024 /*
13025  * generic initialization of ADC, input mixers and output mixers
13026  */
13027 static struct hda_verb alc269_init_verbs[] = {
13028         /*
13029          * Unmute ADC0 and set the default input to mic-in
13030          */
13031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13032
13033         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13034          * analog-loopback mixer widget
13035          * Note: PASD motherboards uses the Line In 2 as the input for
13036          * front panel mic (mic 2)
13037          */
13038         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13040         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13041         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13042         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13043         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13044
13045         /*
13046          * Set up output mixers (0x0c - 0x0e)
13047          */
13048         /* set vol=0 to output mixers */
13049         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13050         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13051
13052         /* set up input amps for analog loopback */
13053         /* Amp Indices: DAC = 0, mixer = 1 */
13054         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13055         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13056         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13057         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13058         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13059         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13060
13061         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13062         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13063         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13064         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13065         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13066         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13067         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13068
13069         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13070         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13071         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13072         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13073         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13074         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13075         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13076
13077         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13078         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13079
13080         /* FIXME: use matrix-type input source selection */
13081         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13082         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13083         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13084         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13087
13088         /* set EAPD */
13089         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13090         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13091         { }
13092 };
13093
13094 /* add playback controls from the parsed DAC table */
13095 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
13096                                              const struct auto_pin_cfg *cfg)
13097 {
13098         hda_nid_t nid;
13099         int err;
13100
13101         spec->multiout.num_dacs = 1;    /* only use one dac */
13102         spec->multiout.dac_nids = spec->private_dac_nids;
13103         spec->multiout.dac_nids[0] = 2;
13104
13105         nid = cfg->line_out_pins[0];
13106         if (nid) {
13107                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13108                                   "Front Playback Volume",
13109                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
13110                 if (err < 0)
13111                         return err;
13112                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13113                                   "Front Playback Switch",
13114                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13115                 if (err < 0)
13116                         return err;
13117         }
13118
13119         nid = cfg->speaker_pins[0];
13120         if (nid) {
13121                 if (!cfg->line_out_pins[0]) {
13122                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13123                                           "Speaker Playback Volume",
13124                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13125                                                               HDA_OUTPUT));
13126                         if (err < 0)
13127                                 return err;
13128                 }
13129                 if (nid == 0x16) {
13130                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13131                                           "Speaker Playback Switch",
13132                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13133                                                               HDA_OUTPUT));
13134                         if (err < 0)
13135                                 return err;
13136                 } else {
13137                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13138                                           "Speaker Playback Switch",
13139                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13140                                                               HDA_OUTPUT));
13141                         if (err < 0)
13142                                 return err;
13143                 }
13144         }
13145         nid = cfg->hp_pins[0];
13146         if (nid) {
13147                 /* spec->multiout.hp_nid = 2; */
13148                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
13149                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13150                                           "Headphone Playback Volume",
13151                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13152                                                               HDA_OUTPUT));
13153                         if (err < 0)
13154                                 return err;
13155                 }
13156                 if (nid == 0x16) {
13157                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13158                                           "Headphone Playback Switch",
13159                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13160                                                               HDA_OUTPUT));
13161                         if (err < 0)
13162                                 return err;
13163                 } else {
13164                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13165                                           "Headphone Playback Switch",
13166                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13167                                                               HDA_OUTPUT));
13168                         if (err < 0)
13169                                 return err;
13170                 }
13171         }
13172         return 0;
13173 }
13174
13175 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
13176                                                 const struct auto_pin_cfg *cfg)
13177 {
13178         int err;
13179
13180         err = alc880_auto_create_analog_input_ctls(spec, cfg);
13181         if (err < 0)
13182                 return err;
13183         /* digital-mic input pin is excluded in alc880_auto_create..()
13184          * because it's under 0x18
13185          */
13186         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
13187             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
13188                 struct hda_input_mux *imux = &spec->private_imux[0];
13189                 imux->items[imux->num_items].label = "Int Mic";
13190                 imux->items[imux->num_items].index = 0x05;
13191                 imux->num_items++;
13192         }
13193         return 0;
13194 }
13195
13196 #ifdef CONFIG_SND_HDA_POWER_SAVE
13197 #define alc269_loopbacks        alc880_loopbacks
13198 #endif
13199
13200 /* pcm configuration: identiacal with ALC880 */
13201 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13202 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13203 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13204 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13205
13206 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13207         .substreams = 1,
13208         .channels_min = 2,
13209         .channels_max = 8,
13210         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13211         /* NID is set in alc_build_pcms */
13212         .ops = {
13213                 .open = alc880_playback_pcm_open,
13214                 .prepare = alc880_playback_pcm_prepare,
13215                 .cleanup = alc880_playback_pcm_cleanup
13216         },
13217 };
13218
13219 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13220         .substreams = 1,
13221         .channels_min = 2,
13222         .channels_max = 2,
13223         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13224         /* NID is set in alc_build_pcms */
13225 };
13226
13227 /*
13228  * BIOS auto configuration
13229  */
13230 static int alc269_parse_auto_config(struct hda_codec *codec)
13231 {
13232         struct alc_spec *spec = codec->spec;
13233         int err;
13234         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13235
13236         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13237                                            alc269_ignore);
13238         if (err < 0)
13239                 return err;
13240
13241         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13242         if (err < 0)
13243                 return err;
13244         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
13245         if (err < 0)
13246                 return err;
13247
13248         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13249
13250         if (spec->autocfg.dig_outs)
13251                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13252
13253         if (spec->kctls.list)
13254                 add_mixer(spec, spec->kctls.list);
13255
13256         add_verb(spec, alc269_init_verbs);
13257         spec->num_mux_defs = 1;
13258         spec->input_mux = &spec->private_imux[0];
13259         /* set default input source */
13260         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13261                                   0, AC_VERB_SET_CONNECT_SEL,
13262                                   spec->input_mux->items[0].index);
13263
13264         err = alc_auto_add_mic_boost(codec);
13265         if (err < 0)
13266                 return err;
13267
13268         if (!spec->cap_mixer && !spec->no_analog)
13269                 set_capture_mixer(spec);
13270
13271         return 1;
13272 }
13273
13274 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
13275 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
13276 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13277
13278
13279 /* init callback for auto-configuration model -- overriding the default init */
13280 static void alc269_auto_init(struct hda_codec *codec)
13281 {
13282         struct alc_spec *spec = codec->spec;
13283         alc269_auto_init_multi_out(codec);
13284         alc269_auto_init_hp_out(codec);
13285         alc269_auto_init_analog_input(codec);
13286         if (spec->unsol_event)
13287                 alc_inithook(codec);
13288 }
13289
13290 /*
13291  * configuration and preset
13292  */
13293 static const char *alc269_models[ALC269_MODEL_LAST] = {
13294         [ALC269_BASIC]                  = "basic",
13295         [ALC269_QUANTA_FL1]             = "quanta",
13296         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13297         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13298         [ALC269_FUJITSU]                = "fujitsu",
13299         [ALC269_LIFEBOOK]               = "lifebook"
13300 };
13301
13302 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13303         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13304         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13305                       ALC269_ASUS_EEEPC_P703),
13306         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13307         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13308         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13309         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13310         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13311         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13312         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13313                       ALC269_ASUS_EEEPC_P901),
13314         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13315                       ALC269_ASUS_EEEPC_P901),
13316         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13317         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13318         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13319         {}
13320 };
13321
13322 static struct alc_config_preset alc269_presets[] = {
13323         [ALC269_BASIC] = {
13324                 .mixers = { alc269_base_mixer },
13325                 .init_verbs = { alc269_init_verbs },
13326                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13327                 .dac_nids = alc269_dac_nids,
13328                 .hp_nid = 0x03,
13329                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13330                 .channel_mode = alc269_modes,
13331                 .input_mux = &alc269_capture_source,
13332         },
13333         [ALC269_QUANTA_FL1] = {
13334                 .mixers = { alc269_quanta_fl1_mixer },
13335                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13336                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13337                 .dac_nids = alc269_dac_nids,
13338                 .hp_nid = 0x03,
13339                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13340                 .channel_mode = alc269_modes,
13341                 .input_mux = &alc269_capture_source,
13342                 .unsol_event = alc269_quanta_fl1_unsol_event,
13343                 .init_hook = alc269_quanta_fl1_init_hook,
13344         },
13345         [ALC269_ASUS_EEEPC_P703] = {
13346                 .mixers = { alc269_eeepc_mixer },
13347                 .cap_mixer = alc269_epc_capture_mixer,
13348                 .init_verbs = { alc269_init_verbs,
13349                                 alc269_eeepc_amic_init_verbs },
13350                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13351                 .dac_nids = alc269_dac_nids,
13352                 .hp_nid = 0x03,
13353                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13354                 .channel_mode = alc269_modes,
13355                 .input_mux = &alc269_eeepc_amic_capture_source,
13356                 .unsol_event = alc269_eeepc_amic_unsol_event,
13357                 .init_hook = alc269_eeepc_amic_inithook,
13358         },
13359         [ALC269_ASUS_EEEPC_P901] = {
13360                 .mixers = { alc269_eeepc_mixer },
13361                 .cap_mixer = alc269_epc_capture_mixer,
13362                 .init_verbs = { alc269_init_verbs,
13363                                 alc269_eeepc_dmic_init_verbs },
13364                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13365                 .dac_nids = alc269_dac_nids,
13366                 .hp_nid = 0x03,
13367                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13368                 .channel_mode = alc269_modes,
13369                 .input_mux = &alc269_eeepc_dmic_capture_source,
13370                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13371                 .init_hook = alc269_eeepc_dmic_inithook,
13372         },
13373         [ALC269_FUJITSU] = {
13374                 .mixers = { alc269_fujitsu_mixer },
13375                 .cap_mixer = alc269_epc_capture_mixer,
13376                 .init_verbs = { alc269_init_verbs,
13377                                 alc269_eeepc_dmic_init_verbs },
13378                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13379                 .dac_nids = alc269_dac_nids,
13380                 .hp_nid = 0x03,
13381                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13382                 .channel_mode = alc269_modes,
13383                 .input_mux = &alc269_eeepc_dmic_capture_source,
13384                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13385                 .init_hook = alc269_eeepc_dmic_inithook,
13386         },
13387         [ALC269_LIFEBOOK] = {
13388                 .mixers = { alc269_lifebook_mixer },
13389                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13390                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13391                 .dac_nids = alc269_dac_nids,
13392                 .hp_nid = 0x03,
13393                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13394                 .channel_mode = alc269_modes,
13395                 .input_mux = &alc269_capture_source,
13396                 .unsol_event = alc269_lifebook_unsol_event,
13397                 .init_hook = alc269_lifebook_init_hook,
13398         },
13399 };
13400
13401 static int patch_alc269(struct hda_codec *codec)
13402 {
13403         struct alc_spec *spec;
13404         int board_config;
13405         int err;
13406
13407         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13408         if (spec == NULL)
13409                 return -ENOMEM;
13410
13411         codec->spec = spec;
13412
13413         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13414
13415         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13416                                                   alc269_models,
13417                                                   alc269_cfg_tbl);
13418
13419         if (board_config < 0) {
13420                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
13421                        "trying auto-probe from BIOS...\n", codec->chip_name);
13422                 board_config = ALC269_AUTO;
13423         }
13424
13425         if (board_config == ALC269_AUTO) {
13426                 /* automatic parse from the BIOS config */
13427                 err = alc269_parse_auto_config(codec);
13428                 if (err < 0) {
13429                         alc_free(codec);
13430                         return err;
13431                 } else if (!err) {
13432                         printk(KERN_INFO
13433                                "hda_codec: Cannot set up configuration "
13434                                "from BIOS.  Using base mode...\n");
13435                         board_config = ALC269_BASIC;
13436                 }
13437         }
13438
13439         err = snd_hda_attach_beep_device(codec, 0x1);
13440         if (err < 0) {
13441                 alc_free(codec);
13442                 return err;
13443         }
13444
13445         if (board_config != ALC269_AUTO)
13446                 setup_preset(spec, &alc269_presets[board_config]);
13447
13448         if (codec->subsystem_id == 0x17aa3bf8) {
13449                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13450                  * fix the sample rate of analog I/O to 44.1kHz
13451                  */
13452                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13453                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13454         } else {
13455                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13456                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13457         }
13458         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13459         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13460
13461         spec->adc_nids = alc269_adc_nids;
13462         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13463         spec->capsrc_nids = alc269_capsrc_nids;
13464         if (!spec->cap_mixer)
13465                 set_capture_mixer(spec);
13466         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13467
13468         codec->patch_ops = alc_patch_ops;
13469         if (board_config == ALC269_AUTO)
13470                 spec->init_hook = alc269_auto_init;
13471 #ifdef CONFIG_SND_HDA_POWER_SAVE
13472         if (!spec->loopback.amplist)
13473                 spec->loopback.amplist = alc269_loopbacks;
13474 #endif
13475         codec->proc_widget_hook = print_realtek_coef;
13476
13477         return 0;
13478 }
13479
13480 /*
13481  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13482  */
13483
13484 /*
13485  * set the path ways for 2 channel output
13486  * need to set the codec line out and mic 1 pin widgets to inputs
13487  */
13488 static struct hda_verb alc861_threestack_ch2_init[] = {
13489         /* set pin widget 1Ah (line in) for input */
13490         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13491         /* set pin widget 18h (mic1/2) for input, for mic also enable
13492          * the vref
13493          */
13494         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13495
13496         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13497 #if 0
13498         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13499         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13500 #endif
13501         { } /* end */
13502 };
13503 /*
13504  * 6ch mode
13505  * need to set the codec line out and mic 1 pin widgets to outputs
13506  */
13507 static struct hda_verb alc861_threestack_ch6_init[] = {
13508         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13509         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13510         /* set pin widget 18h (mic1) for output (CLFE)*/
13511         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13512
13513         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13514         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13515
13516         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13517 #if 0
13518         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13519         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13520 #endif
13521         { } /* end */
13522 };
13523
13524 static struct hda_channel_mode alc861_threestack_modes[2] = {
13525         { 2, alc861_threestack_ch2_init },
13526         { 6, alc861_threestack_ch6_init },
13527 };
13528 /* Set mic1 as input and unmute the mixer */
13529 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13530         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13531         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13532         { } /* end */
13533 };
13534 /* Set mic1 as output and mute mixer */
13535 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13536         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13537         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13538         { } /* end */
13539 };
13540
13541 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13542         { 2, alc861_uniwill_m31_ch2_init },
13543         { 4, alc861_uniwill_m31_ch4_init },
13544 };
13545
13546 /* Set mic1 and line-in as input and unmute the mixer */
13547 static struct hda_verb alc861_asus_ch2_init[] = {
13548         /* set pin widget 1Ah (line in) for input */
13549         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13550         /* set pin widget 18h (mic1/2) for input, for mic also enable
13551          * the vref
13552          */
13553         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13554
13555         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13556 #if 0
13557         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13558         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13559 #endif
13560         { } /* end */
13561 };
13562 /* Set mic1 nad line-in as output and mute mixer */
13563 static struct hda_verb alc861_asus_ch6_init[] = {
13564         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13565         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13566         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13567         /* set pin widget 18h (mic1) for output (CLFE)*/
13568         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13569         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13570         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13571         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13572
13573         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13574 #if 0
13575         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13576         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13577 #endif
13578         { } /* end */
13579 };
13580
13581 static struct hda_channel_mode alc861_asus_modes[2] = {
13582         { 2, alc861_asus_ch2_init },
13583         { 6, alc861_asus_ch6_init },
13584 };
13585
13586 /* patch-ALC861 */
13587
13588 static struct snd_kcontrol_new alc861_base_mixer[] = {
13589         /* output mixer control */
13590         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13591         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13592         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13593         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13594         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13595
13596         /*Input mixer control */
13597         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13598            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13599         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13600         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13601         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13602         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13603         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13604         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13605         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13606         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13607
13608         { } /* end */
13609 };
13610
13611 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13612         /* output mixer control */
13613         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13614         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13615         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13616         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13617         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13618
13619         /* Input mixer control */
13620         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13621            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13622         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13623         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13624         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13625         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13626         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13627         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13628         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13629         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13630
13631         {
13632                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13633                 .name = "Channel Mode",
13634                 .info = alc_ch_mode_info,
13635                 .get = alc_ch_mode_get,
13636                 .put = alc_ch_mode_put,
13637                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13638         },
13639         { } /* end */
13640 };
13641
13642 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13643         /* output mixer control */
13644         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13645         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13646         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13647
13648         { } /* end */
13649 };
13650
13651 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13652         /* output mixer control */
13653         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13654         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13655         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13656         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13657         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13658
13659         /* Input mixer control */
13660         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13661            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13662         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13663         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13664         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13665         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13666         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13667         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13668         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13669         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13670
13671         {
13672                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13673                 .name = "Channel Mode",
13674                 .info = alc_ch_mode_info,
13675                 .get = alc_ch_mode_get,
13676                 .put = alc_ch_mode_put,
13677                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13678         },
13679         { } /* end */
13680 };
13681
13682 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13683         /* output mixer control */
13684         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13685         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13686         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13687         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13688         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13689
13690         /* Input mixer control */
13691         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13692         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13693         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13694         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13695         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13696         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13697         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13698         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13699         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13700         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13701
13702         {
13703                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13704                 .name = "Channel Mode",
13705                 .info = alc_ch_mode_info,
13706                 .get = alc_ch_mode_get,
13707                 .put = alc_ch_mode_put,
13708                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13709         },
13710         { }
13711 };
13712
13713 /* additional mixer */
13714 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13715         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13716         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13717         { }
13718 };
13719
13720 /*
13721  * generic initialization of ADC, input mixers and output mixers
13722  */
13723 static struct hda_verb alc861_base_init_verbs[] = {
13724         /*
13725          * Unmute ADC0 and set the default input to mic-in
13726          */
13727         /* port-A for surround (rear panel) */
13728         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13729         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13730         /* port-B for mic-in (rear panel) with vref */
13731         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13732         /* port-C for line-in (rear panel) */
13733         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13734         /* port-D for Front */
13735         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13736         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13737         /* port-E for HP out (front panel) */
13738         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13739         /* route front PCM to HP */
13740         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13741         /* port-F for mic-in (front panel) with vref */
13742         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13743         /* port-G for CLFE (rear panel) */
13744         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13745         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13746         /* port-H for side (rear panel) */
13747         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13748         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13749         /* CD-in */
13750         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13751         /* route front mic to ADC1*/
13752         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13753         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13754
13755         /* Unmute DAC0~3 & spdif out*/
13756         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13757         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13758         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13759         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13760         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13761
13762         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13763         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13764         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13765         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13766         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13767
13768         /* Unmute Stereo Mixer 15 */
13769         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13770         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13771         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13772         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13773
13774         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13775         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13776         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13777         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13778         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13779         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13780         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13781         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13782         /* hp used DAC 3 (Front) */
13783         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13784         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13785
13786         { }
13787 };
13788
13789 static struct hda_verb alc861_threestack_init_verbs[] = {
13790         /*
13791          * Unmute ADC0 and set the default input to mic-in
13792          */
13793         /* port-A for surround (rear panel) */
13794         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13795         /* port-B for mic-in (rear panel) with vref */
13796         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13797         /* port-C for line-in (rear panel) */
13798         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13799         /* port-D for Front */
13800         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13801         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13802         /* port-E for HP out (front panel) */
13803         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13804         /* route front PCM to HP */
13805         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13806         /* port-F for mic-in (front panel) with vref */
13807         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13808         /* port-G for CLFE (rear panel) */
13809         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13810         /* port-H for side (rear panel) */
13811         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13812         /* CD-in */
13813         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13814         /* route front mic to ADC1*/
13815         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13816         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13817         /* Unmute DAC0~3 & spdif out*/
13818         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13819         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13820         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13821         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13822         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13823
13824         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13825         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13826         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13827         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13828         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13829
13830         /* Unmute Stereo Mixer 15 */
13831         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13832         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13833         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13834         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13835
13836         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13837         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13838         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13839         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13840         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13841         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13842         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13843         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13844         /* hp used DAC 3 (Front) */
13845         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13846         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13847         { }
13848 };
13849
13850 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13851         /*
13852          * Unmute ADC0 and set the default input to mic-in
13853          */
13854         /* port-A for surround (rear panel) */
13855         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13856         /* port-B for mic-in (rear panel) with vref */
13857         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13858         /* port-C for line-in (rear panel) */
13859         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13860         /* port-D for Front */
13861         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13862         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13863         /* port-E for HP out (front panel) */
13864         /* this has to be set to VREF80 */
13865         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13866         /* route front PCM to HP */
13867         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13868         /* port-F for mic-in (front panel) with vref */
13869         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13870         /* port-G for CLFE (rear panel) */
13871         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13872         /* port-H for side (rear panel) */
13873         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13874         /* CD-in */
13875         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13876         /* route front mic to ADC1*/
13877         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13878         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13879         /* Unmute DAC0~3 & spdif out*/
13880         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13881         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13882         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13883         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13884         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13885
13886         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13887         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13888         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13889         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13890         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13891
13892         /* Unmute Stereo Mixer 15 */
13893         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13894         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13895         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13896         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13897
13898         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13899         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13900         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13901         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13902         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13903         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13904         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13905         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13906         /* hp used DAC 3 (Front) */
13907         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13908         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13909         { }
13910 };
13911
13912 static struct hda_verb alc861_asus_init_verbs[] = {
13913         /*
13914          * Unmute ADC0 and set the default input to mic-in
13915          */
13916         /* port-A for surround (rear panel)
13917          * according to codec#0 this is the HP jack
13918          */
13919         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13920         /* route front PCM to HP */
13921         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13922         /* port-B for mic-in (rear panel) with vref */
13923         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13924         /* port-C for line-in (rear panel) */
13925         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13926         /* port-D for Front */
13927         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13928         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13929         /* port-E for HP out (front panel) */
13930         /* this has to be set to VREF80 */
13931         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13932         /* route front PCM to HP */
13933         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13934         /* port-F for mic-in (front panel) with vref */
13935         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13936         /* port-G for CLFE (rear panel) */
13937         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13938         /* port-H for side (rear panel) */
13939         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13940         /* CD-in */
13941         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13942         /* route front mic to ADC1*/
13943         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13944         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13945         /* Unmute DAC0~3 & spdif out*/
13946         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13947         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13948         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13949         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13950         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13951         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13952         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13953         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13954         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13955         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13956
13957         /* Unmute Stereo Mixer 15 */
13958         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13959         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13960         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13961         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13962
13963         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13964         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13965         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13966         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13967         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13968         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13969         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13970         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13971         /* hp used DAC 3 (Front) */
13972         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13973         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13974         { }
13975 };
13976
13977 /* additional init verbs for ASUS laptops */
13978 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13979         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13980         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13981         { }
13982 };
13983
13984 /*
13985  * generic initialization of ADC, input mixers and output mixers
13986  */
13987 static struct hda_verb alc861_auto_init_verbs[] = {
13988         /*
13989          * Unmute ADC0 and set the default input to mic-in
13990          */
13991         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13992         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13993
13994         /* Unmute DAC0~3 & spdif out*/
13995         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13996         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13997         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13998         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13999         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14000
14001         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14002         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14003         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14004         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14005         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14006
14007         /* Unmute Stereo Mixer 15 */
14008         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14009         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14010         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14011         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14012
14013         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14014         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14015         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14016         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14017         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14018         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14019         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14020         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14021
14022         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14023         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14024         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14025         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14026         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14027         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14028         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14029         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14030
14031         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14032
14033         { }
14034 };
14035
14036 static struct hda_verb alc861_toshiba_init_verbs[] = {
14037         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14038
14039         { }
14040 };
14041
14042 /* toggle speaker-output according to the hp-jack state */
14043 static void alc861_toshiba_automute(struct hda_codec *codec)
14044 {
14045         unsigned int present;
14046
14047         present = snd_hda_codec_read(codec, 0x0f, 0,
14048                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14049         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14050                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14051         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14052                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14053 }
14054
14055 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14056                                        unsigned int res)
14057 {
14058         if ((res >> 26) == ALC880_HP_EVENT)
14059                 alc861_toshiba_automute(codec);
14060 }
14061
14062 /* pcm configuration: identiacal with ALC880 */
14063 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14064 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14065 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14066 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14067
14068
14069 #define ALC861_DIGOUT_NID       0x07
14070
14071 static struct hda_channel_mode alc861_8ch_modes[1] = {
14072         { 8, NULL }
14073 };
14074
14075 static hda_nid_t alc861_dac_nids[4] = {
14076         /* front, surround, clfe, side */
14077         0x03, 0x06, 0x05, 0x04
14078 };
14079
14080 static hda_nid_t alc660_dac_nids[3] = {
14081         /* front, clfe, surround */
14082         0x03, 0x05, 0x06
14083 };
14084
14085 static hda_nid_t alc861_adc_nids[1] = {
14086         /* ADC0-2 */
14087         0x08,
14088 };
14089
14090 static struct hda_input_mux alc861_capture_source = {
14091         .num_items = 5,
14092         .items = {
14093                 { "Mic", 0x0 },
14094                 { "Front Mic", 0x3 },
14095                 { "Line", 0x1 },
14096                 { "CD", 0x4 },
14097                 { "Mixer", 0x5 },
14098         },
14099 };
14100
14101 /* fill in the dac_nids table from the parsed pin configuration */
14102 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
14103                                      const struct auto_pin_cfg *cfg)
14104 {
14105         int i;
14106         hda_nid_t nid;
14107
14108         spec->multiout.dac_nids = spec->private_dac_nids;
14109         for (i = 0; i < cfg->line_outs; i++) {
14110                 nid = cfg->line_out_pins[i];
14111                 if (nid) {
14112                         if (i >= ARRAY_SIZE(alc861_dac_nids))
14113                                 continue;
14114                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
14115                 }
14116         }
14117         spec->multiout.num_dacs = cfg->line_outs;
14118         return 0;
14119 }
14120
14121 /* add playback controls from the parsed DAC table */
14122 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
14123                                              const struct auto_pin_cfg *cfg)
14124 {
14125         char name[32];
14126         static const char *chname[4] = {
14127                 "Front", "Surround", NULL /*CLFE*/, "Side"
14128         };
14129         hda_nid_t nid;
14130         int i, idx, err;
14131
14132         for (i = 0; i < cfg->line_outs; i++) {
14133                 nid = spec->multiout.dac_nids[i];
14134                 if (!nid)
14135                         continue;
14136                 if (nid == 0x05) {
14137                         /* Center/LFE */
14138                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14139                                           "Center Playback Switch",
14140                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14141                                                               HDA_OUTPUT));
14142                         if (err < 0)
14143                                 return err;
14144                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14145                                           "LFE Playback Switch",
14146                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14147                                                               HDA_OUTPUT));
14148                         if (err < 0)
14149                                 return err;
14150                 } else {
14151                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
14152                              idx++)
14153                                 if (nid == alc861_dac_nids[idx])
14154                                         break;
14155                         sprintf(name, "%s Playback Switch", chname[idx]);
14156                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14157                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14158                                                               HDA_OUTPUT));
14159                         if (err < 0)
14160                                 return err;
14161                 }
14162         }
14163         return 0;
14164 }
14165
14166 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
14167 {
14168         int err;
14169         hda_nid_t nid;
14170
14171         if (!pin)
14172                 return 0;
14173
14174         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14175                 nid = 0x03;
14176                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
14177                                   "Headphone Playback Switch",
14178                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14179                 if (err < 0)
14180                         return err;
14181                 spec->multiout.hp_nid = nid;
14182         }
14183         return 0;
14184 }
14185
14186 /* create playback/capture controls for input pins */
14187 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
14188                                                 const struct auto_pin_cfg *cfg)
14189 {
14190         struct hda_input_mux *imux = &spec->private_imux[0];
14191         int i, err, idx, idx1;
14192
14193         for (i = 0; i < AUTO_PIN_LAST; i++) {
14194                 switch (cfg->input_pins[i]) {
14195                 case 0x0c:
14196                         idx1 = 1;
14197                         idx = 2;        /* Line In */
14198                         break;
14199                 case 0x0f:
14200                         idx1 = 2;
14201                         idx = 2;        /* Line In */
14202                         break;
14203                 case 0x0d:
14204                         idx1 = 0;
14205                         idx = 1;        /* Mic In */
14206                         break;
14207                 case 0x10:
14208                         idx1 = 3;
14209                         idx = 1;        /* Mic In */
14210                         break;
14211                 case 0x11:
14212                         idx1 = 4;
14213                         idx = 0;        /* CD */
14214                         break;
14215                 default:
14216                         continue;
14217                 }
14218
14219                 err = new_analog_input(spec, cfg->input_pins[i],
14220                                        auto_pin_cfg_labels[i], idx, 0x15);
14221                 if (err < 0)
14222                         return err;
14223
14224                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
14225                 imux->items[imux->num_items].index = idx1;
14226                 imux->num_items++;
14227         }
14228         return 0;
14229 }
14230
14231 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14232                                               hda_nid_t nid,
14233                                               int pin_type, int dac_idx)
14234 {
14235         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14236                             pin_type);
14237         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14238                             AMP_OUT_UNMUTE);
14239 }
14240
14241 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14242 {
14243         struct alc_spec *spec = codec->spec;
14244         int i;
14245
14246         for (i = 0; i < spec->autocfg.line_outs; i++) {
14247                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14248                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14249                 if (nid)
14250                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14251                                                           spec->multiout.dac_nids[i]);
14252         }
14253 }
14254
14255 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14256 {
14257         struct alc_spec *spec = codec->spec;
14258         hda_nid_t pin;
14259
14260         pin = spec->autocfg.hp_pins[0];
14261         if (pin) /* connect to front */
14262                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
14263                                                   spec->multiout.dac_nids[0]);
14264         pin = spec->autocfg.speaker_pins[0];
14265         if (pin)
14266                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14267 }
14268
14269 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14270 {
14271         struct alc_spec *spec = codec->spec;
14272         int i;
14273
14274         for (i = 0; i < AUTO_PIN_LAST; i++) {
14275                 hda_nid_t nid = spec->autocfg.input_pins[i];
14276                 if (nid >= 0x0c && nid <= 0x11)
14277                         alc_set_input_pin(codec, nid, i);
14278         }
14279 }
14280
14281 /* parse the BIOS configuration and set up the alc_spec */
14282 /* return 1 if successful, 0 if the proper config is not found,
14283  * or a negative error code
14284  */
14285 static int alc861_parse_auto_config(struct hda_codec *codec)
14286 {
14287         struct alc_spec *spec = codec->spec;
14288         int err;
14289         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14290
14291         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14292                                            alc861_ignore);
14293         if (err < 0)
14294                 return err;
14295         if (!spec->autocfg.line_outs)
14296                 return 0; /* can't find valid BIOS pin config */
14297
14298         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
14299         if (err < 0)
14300                 return err;
14301         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
14302         if (err < 0)
14303                 return err;
14304         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
14305         if (err < 0)
14306                 return err;
14307         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
14308         if (err < 0)
14309                 return err;
14310
14311         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14312
14313         if (spec->autocfg.dig_outs)
14314                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14315
14316         if (spec->kctls.list)
14317                 add_mixer(spec, spec->kctls.list);
14318
14319         add_verb(spec, alc861_auto_init_verbs);
14320
14321         spec->num_mux_defs = 1;
14322         spec->input_mux = &spec->private_imux[0];
14323
14324         spec->adc_nids = alc861_adc_nids;
14325         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14326         set_capture_mixer(spec);
14327
14328         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14329
14330         return 1;
14331 }
14332
14333 /* additional initialization for auto-configuration model */
14334 static void alc861_auto_init(struct hda_codec *codec)
14335 {
14336         struct alc_spec *spec = codec->spec;
14337         alc861_auto_init_multi_out(codec);
14338         alc861_auto_init_hp_out(codec);
14339         alc861_auto_init_analog_input(codec);
14340         if (spec->unsol_event)
14341                 alc_inithook(codec);
14342 }
14343
14344 #ifdef CONFIG_SND_HDA_POWER_SAVE
14345 static struct hda_amp_list alc861_loopbacks[] = {
14346         { 0x15, HDA_INPUT, 0 },
14347         { 0x15, HDA_INPUT, 1 },
14348         { 0x15, HDA_INPUT, 2 },
14349         { 0x15, HDA_INPUT, 3 },
14350         { } /* end */
14351 };
14352 #endif
14353
14354
14355 /*
14356  * configuration and preset
14357  */
14358 static const char *alc861_models[ALC861_MODEL_LAST] = {
14359         [ALC861_3ST]            = "3stack",
14360         [ALC660_3ST]            = "3stack-660",
14361         [ALC861_3ST_DIG]        = "3stack-dig",
14362         [ALC861_6ST_DIG]        = "6stack-dig",
14363         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14364         [ALC861_TOSHIBA]        = "toshiba",
14365         [ALC861_ASUS]           = "asus",
14366         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14367         [ALC861_AUTO]           = "auto",
14368 };
14369
14370 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14371         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14372         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14373         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14374         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14375         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14376         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14377         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14378         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14379          *        Any other models that need this preset?
14380          */
14381         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14382         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14383         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14384         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14385         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14386         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14387         /* FIXME: the below seems conflict */
14388         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14389         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14390         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14391         {}
14392 };
14393
14394 static struct alc_config_preset alc861_presets[] = {
14395         [ALC861_3ST] = {
14396                 .mixers = { alc861_3ST_mixer },
14397                 .init_verbs = { alc861_threestack_init_verbs },
14398                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14399                 .dac_nids = alc861_dac_nids,
14400                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14401                 .channel_mode = alc861_threestack_modes,
14402                 .need_dac_fix = 1,
14403                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14404                 .adc_nids = alc861_adc_nids,
14405                 .input_mux = &alc861_capture_source,
14406         },
14407         [ALC861_3ST_DIG] = {
14408                 .mixers = { alc861_base_mixer },
14409                 .init_verbs = { alc861_threestack_init_verbs },
14410                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14411                 .dac_nids = alc861_dac_nids,
14412                 .dig_out_nid = ALC861_DIGOUT_NID,
14413                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14414                 .channel_mode = alc861_threestack_modes,
14415                 .need_dac_fix = 1,
14416                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14417                 .adc_nids = alc861_adc_nids,
14418                 .input_mux = &alc861_capture_source,
14419         },
14420         [ALC861_6ST_DIG] = {
14421                 .mixers = { alc861_base_mixer },
14422                 .init_verbs = { alc861_base_init_verbs },
14423                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14424                 .dac_nids = alc861_dac_nids,
14425                 .dig_out_nid = ALC861_DIGOUT_NID,
14426                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14427                 .channel_mode = alc861_8ch_modes,
14428                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14429                 .adc_nids = alc861_adc_nids,
14430                 .input_mux = &alc861_capture_source,
14431         },
14432         [ALC660_3ST] = {
14433                 .mixers = { alc861_3ST_mixer },
14434                 .init_verbs = { alc861_threestack_init_verbs },
14435                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14436                 .dac_nids = alc660_dac_nids,
14437                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14438                 .channel_mode = alc861_threestack_modes,
14439                 .need_dac_fix = 1,
14440                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14441                 .adc_nids = alc861_adc_nids,
14442                 .input_mux = &alc861_capture_source,
14443         },
14444         [ALC861_UNIWILL_M31] = {
14445                 .mixers = { alc861_uniwill_m31_mixer },
14446                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14447                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14448                 .dac_nids = alc861_dac_nids,
14449                 .dig_out_nid = ALC861_DIGOUT_NID,
14450                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14451                 .channel_mode = alc861_uniwill_m31_modes,
14452                 .need_dac_fix = 1,
14453                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14454                 .adc_nids = alc861_adc_nids,
14455                 .input_mux = &alc861_capture_source,
14456         },
14457         [ALC861_TOSHIBA] = {
14458                 .mixers = { alc861_toshiba_mixer },
14459                 .init_verbs = { alc861_base_init_verbs,
14460                                 alc861_toshiba_init_verbs },
14461                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14462                 .dac_nids = alc861_dac_nids,
14463                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14464                 .channel_mode = alc883_3ST_2ch_modes,
14465                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14466                 .adc_nids = alc861_adc_nids,
14467                 .input_mux = &alc861_capture_source,
14468                 .unsol_event = alc861_toshiba_unsol_event,
14469                 .init_hook = alc861_toshiba_automute,
14470         },
14471         [ALC861_ASUS] = {
14472                 .mixers = { alc861_asus_mixer },
14473                 .init_verbs = { alc861_asus_init_verbs },
14474                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14475                 .dac_nids = alc861_dac_nids,
14476                 .dig_out_nid = ALC861_DIGOUT_NID,
14477                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14478                 .channel_mode = alc861_asus_modes,
14479                 .need_dac_fix = 1,
14480                 .hp_nid = 0x06,
14481                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14482                 .adc_nids = alc861_adc_nids,
14483                 .input_mux = &alc861_capture_source,
14484         },
14485         [ALC861_ASUS_LAPTOP] = {
14486                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14487                 .init_verbs = { alc861_asus_init_verbs,
14488                                 alc861_asus_laptop_init_verbs },
14489                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14490                 .dac_nids = alc861_dac_nids,
14491                 .dig_out_nid = ALC861_DIGOUT_NID,
14492                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14493                 .channel_mode = alc883_3ST_2ch_modes,
14494                 .need_dac_fix = 1,
14495                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14496                 .adc_nids = alc861_adc_nids,
14497                 .input_mux = &alc861_capture_source,
14498         },
14499 };
14500
14501
14502 static int patch_alc861(struct hda_codec *codec)
14503 {
14504         struct alc_spec *spec;
14505         int board_config;
14506         int err;
14507
14508         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14509         if (spec == NULL)
14510                 return -ENOMEM;
14511
14512         codec->spec = spec;
14513
14514         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14515                                                   alc861_models,
14516                                                   alc861_cfg_tbl);
14517
14518         if (board_config < 0) {
14519                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
14520                        "trying auto-probe from BIOS...\n", codec->chip_name);
14521                 board_config = ALC861_AUTO;
14522         }
14523
14524         if (board_config == ALC861_AUTO) {
14525                 /* automatic parse from the BIOS config */
14526                 err = alc861_parse_auto_config(codec);
14527                 if (err < 0) {
14528                         alc_free(codec);
14529                         return err;
14530                 } else if (!err) {
14531                         printk(KERN_INFO
14532                                "hda_codec: Cannot set up configuration "
14533                                "from BIOS.  Using base mode...\n");
14534                    board_config = ALC861_3ST_DIG;
14535                 }
14536         }
14537
14538         err = snd_hda_attach_beep_device(codec, 0x23);
14539         if (err < 0) {
14540                 alc_free(codec);
14541                 return err;
14542         }
14543
14544         if (board_config != ALC861_AUTO)
14545                 setup_preset(spec, &alc861_presets[board_config]);
14546
14547         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14548         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14549
14550         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14551         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14552
14553         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14554
14555         spec->vmaster_nid = 0x03;
14556
14557         codec->patch_ops = alc_patch_ops;
14558         if (board_config == ALC861_AUTO)
14559                 spec->init_hook = alc861_auto_init;
14560 #ifdef CONFIG_SND_HDA_POWER_SAVE
14561         if (!spec->loopback.amplist)
14562                 spec->loopback.amplist = alc861_loopbacks;
14563 #endif
14564         codec->proc_widget_hook = print_realtek_coef;
14565
14566         return 0;
14567 }
14568
14569 /*
14570  * ALC861-VD support
14571  *
14572  * Based on ALC882
14573  *
14574  * In addition, an independent DAC
14575  */
14576 #define ALC861VD_DIGOUT_NID     0x06
14577
14578 static hda_nid_t alc861vd_dac_nids[4] = {
14579         /* front, surr, clfe, side surr */
14580         0x02, 0x03, 0x04, 0x05
14581 };
14582
14583 /* dac_nids for ALC660vd are in a different order - according to
14584  * Realtek's driver.
14585  * This should probably tesult in a different mixer for 6stack models
14586  * of ALC660vd codecs, but for now there is only 3stack mixer
14587  * - and it is the same as in 861vd.
14588  * adc_nids in ALC660vd are (is) the same as in 861vd
14589  */
14590 static hda_nid_t alc660vd_dac_nids[3] = {
14591         /* front, rear, clfe, rear_surr */
14592         0x02, 0x04, 0x03
14593 };
14594
14595 static hda_nid_t alc861vd_adc_nids[1] = {
14596         /* ADC0 */
14597         0x09,
14598 };
14599
14600 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14601
14602 /* input MUX */
14603 /* FIXME: should be a matrix-type input source selection */
14604 static struct hda_input_mux alc861vd_capture_source = {
14605         .num_items = 4,
14606         .items = {
14607                 { "Mic", 0x0 },
14608                 { "Front Mic", 0x1 },
14609                 { "Line", 0x2 },
14610                 { "CD", 0x4 },
14611         },
14612 };
14613
14614 static struct hda_input_mux alc861vd_dallas_capture_source = {
14615         .num_items = 2,
14616         .items = {
14617                 { "Ext Mic", 0x0 },
14618                 { "Int Mic", 0x1 },
14619         },
14620 };
14621
14622 static struct hda_input_mux alc861vd_hp_capture_source = {
14623         .num_items = 2,
14624         .items = {
14625                 { "Front Mic", 0x0 },
14626                 { "ATAPI Mic", 0x1 },
14627         },
14628 };
14629
14630 /*
14631  * 2ch mode
14632  */
14633 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14634         { 2, NULL }
14635 };
14636
14637 /*
14638  * 6ch mode
14639  */
14640 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14641         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14642         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14643         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14644         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14645         { } /* end */
14646 };
14647
14648 /*
14649  * 8ch mode
14650  */
14651 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14652         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14653         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14654         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14655         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14656         { } /* end */
14657 };
14658
14659 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14660         { 6, alc861vd_6stack_ch6_init },
14661         { 8, alc861vd_6stack_ch8_init },
14662 };
14663
14664 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14665         {
14666                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14667                 .name = "Channel Mode",
14668                 .info = alc_ch_mode_info,
14669                 .get = alc_ch_mode_get,
14670                 .put = alc_ch_mode_put,
14671         },
14672         { } /* end */
14673 };
14674
14675 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14676  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14677  */
14678 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14679         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14680         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14681
14682         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14683         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14684
14685         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14686                                 HDA_OUTPUT),
14687         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14688                                 HDA_OUTPUT),
14689         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14690         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14691
14692         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14693         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14694
14695         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14696
14697         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14698         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14699         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14700
14701         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14702         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14703         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14704
14705         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14706         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14707
14708         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14709         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14710
14711         { } /* end */
14712 };
14713
14714 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14715         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14716         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14717
14718         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14719
14720         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14721         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14722         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14723
14724         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14725         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14726         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14727
14728         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14729         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14730
14731         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14732         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14733
14734         { } /* end */
14735 };
14736
14737 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14738         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14739         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14740         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14741
14742         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14743
14744         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14745         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14746         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14747
14748         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14749         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14750         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14751
14752         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14753         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14754
14755         { } /* end */
14756 };
14757
14758 /* Pin assignment: Speaker=0x14, HP = 0x15,
14759  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14760  */
14761 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14762         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14763         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14764         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14765         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14766         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14767         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14768         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14769         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14770         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14771         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14772         { } /* end */
14773 };
14774
14775 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14776  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14777  */
14778 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14779         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14780         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14781         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14782         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14783         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14784         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14785         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14786         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14787
14788         { } /* end */
14789 };
14790
14791 /*
14792  * generic initialization of ADC, input mixers and output mixers
14793  */
14794 static struct hda_verb alc861vd_volume_init_verbs[] = {
14795         /*
14796          * Unmute ADC0 and set the default input to mic-in
14797          */
14798         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14799         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14800
14801         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14802          * the analog-loopback mixer widget
14803          */
14804         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14805         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14806         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14807         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14808         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14809         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14810
14811         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14812         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14813         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14814         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14815         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14816
14817         /*
14818          * Set up output mixers (0x02 - 0x05)
14819          */
14820         /* set vol=0 to output mixers */
14821         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14822         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14823         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14824         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14825
14826         /* set up input amps for analog loopback */
14827         /* Amp Indices: DAC = 0, mixer = 1 */
14828         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14829         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14830         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14831         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14832         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14833         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14834         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14835         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14836
14837         { }
14838 };
14839
14840 /*
14841  * 3-stack pin configuration:
14842  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14843  */
14844 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14845         /*
14846          * Set pin mode and muting
14847          */
14848         /* set front pin widgets 0x14 for output */
14849         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14850         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14851         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14852
14853         /* Mic (rear) pin: input vref at 80% */
14854         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14855         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14856         /* Front Mic pin: input vref at 80% */
14857         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14858         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14859         /* Line In pin: input */
14860         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14861         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14862         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14863         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14864         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14865         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14866         /* CD pin widget for input */
14867         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14868
14869         { }
14870 };
14871
14872 /*
14873  * 6-stack pin configuration:
14874  */
14875 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14876         /*
14877          * Set pin mode and muting
14878          */
14879         /* set front pin widgets 0x14 for output */
14880         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14881         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14882         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14883
14884         /* Rear Pin: output 1 (0x0d) */
14885         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14886         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14887         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14888         /* CLFE Pin: output 2 (0x0e) */
14889         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14890         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14891         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14892         /* Side Pin: output 3 (0x0f) */
14893         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14894         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14895         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14896
14897         /* Mic (rear) pin: input vref at 80% */
14898         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14899         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14900         /* Front Mic pin: input vref at 80% */
14901         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14902         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14903         /* Line In pin: input */
14904         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14905         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14906         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14907         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14908         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14909         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14910         /* CD pin widget for input */
14911         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14912
14913         { }
14914 };
14915
14916 static struct hda_verb alc861vd_eapd_verbs[] = {
14917         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14918         { }
14919 };
14920
14921 static struct hda_verb alc660vd_eapd_verbs[] = {
14922         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14923         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14924         { }
14925 };
14926
14927 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14928         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14929         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14930         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14931         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14932         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14933         {}
14934 };
14935
14936 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14937 {
14938         unsigned int present;
14939         unsigned char bits;
14940
14941         present = snd_hda_codec_read(codec, 0x18, 0,
14942                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14943         bits = present ? HDA_AMP_MUTE : 0;
14944         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14945                                  HDA_AMP_MUTE, bits);
14946 }
14947
14948 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
14949 {
14950         struct alc_spec *spec = codec->spec;
14951
14952         spec->autocfg.hp_pins[0] = 0x1b;
14953         spec->autocfg.speaker_pins[0] = 0x14;
14954         alc_automute_amp(codec);
14955         alc861vd_lenovo_mic_automute(codec);
14956 }
14957
14958 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14959                                         unsigned int res)
14960 {
14961         switch (res >> 26) {
14962         case ALC880_MIC_EVENT:
14963                 alc861vd_lenovo_mic_automute(codec);
14964                 break;
14965         default:
14966                 alc_automute_amp_unsol_event(codec, res);
14967                 break;
14968         }
14969 }
14970
14971 static struct hda_verb alc861vd_dallas_verbs[] = {
14972         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14973         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14974         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14975         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14976
14977         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14978         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14979         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14980         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14981         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14982         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14983         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14984         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14985
14986         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14987         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14988         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14989         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14990         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14991         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14992         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14993         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14994
14995         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14996         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14997         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14998         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14999         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15000         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15001         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15002         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15003
15004         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15005         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15006         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15007         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15008
15009         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15010         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15011         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15012
15013         { } /* end */
15014 };
15015
15016 /* toggle speaker-output according to the hp-jack state */
15017 static void alc861vd_dallas_init_hook(struct hda_codec *codec)
15018 {
15019         struct alc_spec *spec = codec->spec;
15020
15021         spec->autocfg.hp_pins[0] = 0x15;
15022         spec->autocfg.speaker_pins[0] = 0x14;
15023         alc_automute_amp(codec);
15024 }
15025
15026 #ifdef CONFIG_SND_HDA_POWER_SAVE
15027 #define alc861vd_loopbacks      alc880_loopbacks
15028 #endif
15029
15030 /* pcm configuration: identiacal with ALC880 */
15031 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15032 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15033 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15034 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15035
15036 /*
15037  * configuration and preset
15038  */
15039 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15040         [ALC660VD_3ST]          = "3stack-660",
15041         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15042         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15043         [ALC861VD_3ST]          = "3stack",
15044         [ALC861VD_3ST_DIG]      = "3stack-digout",
15045         [ALC861VD_6ST_DIG]      = "6stack-digout",
15046         [ALC861VD_LENOVO]       = "lenovo",
15047         [ALC861VD_DALLAS]       = "dallas",
15048         [ALC861VD_HP]           = "hp",
15049         [ALC861VD_AUTO]         = "auto",
15050 };
15051
15052 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15053         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15054         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15055         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15056         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
15057         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15058         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15059         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15060         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15061         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15062         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
15063         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15064         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15065         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15066         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15067         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15068         {}
15069 };
15070
15071 static struct alc_config_preset alc861vd_presets[] = {
15072         [ALC660VD_3ST] = {
15073                 .mixers = { alc861vd_3st_mixer },
15074                 .init_verbs = { alc861vd_volume_init_verbs,
15075                                  alc861vd_3stack_init_verbs },
15076                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15077                 .dac_nids = alc660vd_dac_nids,
15078                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15079                 .channel_mode = alc861vd_3stack_2ch_modes,
15080                 .input_mux = &alc861vd_capture_source,
15081         },
15082         [ALC660VD_3ST_DIG] = {
15083                 .mixers = { alc861vd_3st_mixer },
15084                 .init_verbs = { alc861vd_volume_init_verbs,
15085                                  alc861vd_3stack_init_verbs },
15086                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15087                 .dac_nids = alc660vd_dac_nids,
15088                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15089                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15090                 .channel_mode = alc861vd_3stack_2ch_modes,
15091                 .input_mux = &alc861vd_capture_source,
15092         },
15093         [ALC861VD_3ST] = {
15094                 .mixers = { alc861vd_3st_mixer },
15095                 .init_verbs = { alc861vd_volume_init_verbs,
15096                                  alc861vd_3stack_init_verbs },
15097                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15098                 .dac_nids = alc861vd_dac_nids,
15099                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15100                 .channel_mode = alc861vd_3stack_2ch_modes,
15101                 .input_mux = &alc861vd_capture_source,
15102         },
15103         [ALC861VD_3ST_DIG] = {
15104                 .mixers = { alc861vd_3st_mixer },
15105                 .init_verbs = { alc861vd_volume_init_verbs,
15106                                  alc861vd_3stack_init_verbs },
15107                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15108                 .dac_nids = alc861vd_dac_nids,
15109                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15110                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15111                 .channel_mode = alc861vd_3stack_2ch_modes,
15112                 .input_mux = &alc861vd_capture_source,
15113         },
15114         [ALC861VD_6ST_DIG] = {
15115                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15116                 .init_verbs = { alc861vd_volume_init_verbs,
15117                                 alc861vd_6stack_init_verbs },
15118                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15119                 .dac_nids = alc861vd_dac_nids,
15120                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15121                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15122                 .channel_mode = alc861vd_6stack_modes,
15123                 .input_mux = &alc861vd_capture_source,
15124         },
15125         [ALC861VD_LENOVO] = {
15126                 .mixers = { alc861vd_lenovo_mixer },
15127                 .init_verbs = { alc861vd_volume_init_verbs,
15128                                 alc861vd_3stack_init_verbs,
15129                                 alc861vd_eapd_verbs,
15130                                 alc861vd_lenovo_unsol_verbs },
15131                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15132                 .dac_nids = alc660vd_dac_nids,
15133                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15134                 .channel_mode = alc861vd_3stack_2ch_modes,
15135                 .input_mux = &alc861vd_capture_source,
15136                 .unsol_event = alc861vd_lenovo_unsol_event,
15137                 .init_hook = alc861vd_lenovo_init_hook,
15138         },
15139         [ALC861VD_DALLAS] = {
15140                 .mixers = { alc861vd_dallas_mixer },
15141                 .init_verbs = { alc861vd_dallas_verbs },
15142                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15143                 .dac_nids = alc861vd_dac_nids,
15144                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15145                 .channel_mode = alc861vd_3stack_2ch_modes,
15146                 .input_mux = &alc861vd_dallas_capture_source,
15147                 .unsol_event = alc_automute_amp_unsol_event,
15148                 .init_hook = alc861vd_dallas_init_hook,
15149         },
15150         [ALC861VD_HP] = {
15151                 .mixers = { alc861vd_hp_mixer },
15152                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15153                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15154                 .dac_nids = alc861vd_dac_nids,
15155                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15156                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15157                 .channel_mode = alc861vd_3stack_2ch_modes,
15158                 .input_mux = &alc861vd_hp_capture_source,
15159                 .unsol_event = alc_automute_amp_unsol_event,
15160                 .init_hook = alc861vd_dallas_init_hook,
15161         },
15162         [ALC660VD_ASUS_V1S] = {
15163                 .mixers = { alc861vd_lenovo_mixer },
15164                 .init_verbs = { alc861vd_volume_init_verbs,
15165                                 alc861vd_3stack_init_verbs,
15166                                 alc861vd_eapd_verbs,
15167                                 alc861vd_lenovo_unsol_verbs },
15168                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15169                 .dac_nids = alc660vd_dac_nids,
15170                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15171                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15172                 .channel_mode = alc861vd_3stack_2ch_modes,
15173                 .input_mux = &alc861vd_capture_source,
15174                 .unsol_event = alc861vd_lenovo_unsol_event,
15175                 .init_hook = alc861vd_lenovo_init_hook,
15176         },
15177 };
15178
15179 /*
15180  * BIOS auto configuration
15181  */
15182 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15183                                 hda_nid_t nid, int pin_type, int dac_idx)
15184 {
15185         alc_set_pin_output(codec, nid, pin_type);
15186 }
15187
15188 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15189 {
15190         struct alc_spec *spec = codec->spec;
15191         int i;
15192
15193         for (i = 0; i <= HDA_SIDE; i++) {
15194                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15195                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15196                 if (nid)
15197                         alc861vd_auto_set_output_and_unmute(codec, nid,
15198                                                             pin_type, i);
15199         }
15200 }
15201
15202
15203 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15204 {
15205         struct alc_spec *spec = codec->spec;
15206         hda_nid_t pin;
15207
15208         pin = spec->autocfg.hp_pins[0];
15209         if (pin) /* connect to front and  use dac 0 */
15210                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15211         pin = spec->autocfg.speaker_pins[0];
15212         if (pin)
15213                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15214 }
15215
15216 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
15217 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15218
15219 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15220 {
15221         struct alc_spec *spec = codec->spec;
15222         int i;
15223
15224         for (i = 0; i < AUTO_PIN_LAST; i++) {
15225                 hda_nid_t nid = spec->autocfg.input_pins[i];
15226                 if (alc861vd_is_input_pin(nid)) {
15227                         alc_set_input_pin(codec, nid, i);
15228                         if (nid != ALC861VD_PIN_CD_NID &&
15229                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15230                                 snd_hda_codec_write(codec, nid, 0,
15231                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15232                                                 AMP_OUT_MUTE);
15233                 }
15234         }
15235 }
15236
15237 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15238
15239 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15240 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15241
15242 /* add playback controls from the parsed DAC table */
15243 /* Based on ALC880 version. But ALC861VD has separate,
15244  * different NIDs for mute/unmute switch and volume control */
15245 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15246                                              const struct auto_pin_cfg *cfg)
15247 {
15248         char name[32];
15249         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15250         hda_nid_t nid_v, nid_s;
15251         int i, err;
15252
15253         for (i = 0; i < cfg->line_outs; i++) {
15254                 if (!spec->multiout.dac_nids[i])
15255                         continue;
15256                 nid_v = alc861vd_idx_to_mixer_vol(
15257                                 alc880_dac_to_idx(
15258                                         spec->multiout.dac_nids[i]));
15259                 nid_s = alc861vd_idx_to_mixer_switch(
15260                                 alc880_dac_to_idx(
15261                                         spec->multiout.dac_nids[i]));
15262
15263                 if (i == 2) {
15264                         /* Center/LFE */
15265                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15266                                           "Center Playback Volume",
15267                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15268                                                               HDA_OUTPUT));
15269                         if (err < 0)
15270                                 return err;
15271                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15272                                           "LFE Playback Volume",
15273                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15274                                                               HDA_OUTPUT));
15275                         if (err < 0)
15276                                 return err;
15277                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15278                                           "Center Playback Switch",
15279                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15280                                                               HDA_INPUT));
15281                         if (err < 0)
15282                                 return err;
15283                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15284                                           "LFE Playback Switch",
15285                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15286                                                               HDA_INPUT));
15287                         if (err < 0)
15288                                 return err;
15289                 } else {
15290                         sprintf(name, "%s Playback Volume", chname[i]);
15291                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15292                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15293                                                               HDA_OUTPUT));
15294                         if (err < 0)
15295                                 return err;
15296                         sprintf(name, "%s Playback Switch", chname[i]);
15297                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15298                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15299                                                               HDA_INPUT));
15300                         if (err < 0)
15301                                 return err;
15302                 }
15303         }
15304         return 0;
15305 }
15306
15307 /* add playback controls for speaker and HP outputs */
15308 /* Based on ALC880 version. But ALC861VD has separate,
15309  * different NIDs for mute/unmute switch and volume control */
15310 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15311                                         hda_nid_t pin, const char *pfx)
15312 {
15313         hda_nid_t nid_v, nid_s;
15314         int err;
15315         char name[32];
15316
15317         if (!pin)
15318                 return 0;
15319
15320         if (alc880_is_fixed_pin(pin)) {
15321                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15322                 /* specify the DAC as the extra output */
15323                 if (!spec->multiout.hp_nid)
15324                         spec->multiout.hp_nid = nid_v;
15325                 else
15326                         spec->multiout.extra_out_nid[0] = nid_v;
15327                 /* control HP volume/switch on the output mixer amp */
15328                 nid_v = alc861vd_idx_to_mixer_vol(
15329                                 alc880_fixed_pin_idx(pin));
15330                 nid_s = alc861vd_idx_to_mixer_switch(
15331                                 alc880_fixed_pin_idx(pin));
15332
15333                 sprintf(name, "%s Playback Volume", pfx);
15334                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15335                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15336                 if (err < 0)
15337                         return err;
15338                 sprintf(name, "%s Playback Switch", pfx);
15339                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15340                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15341                 if (err < 0)
15342                         return err;
15343         } else if (alc880_is_multi_pin(pin)) {
15344                 /* set manual connection */
15345                 /* we have only a switch on HP-out PIN */
15346                 sprintf(name, "%s Playback Switch", pfx);
15347                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15348                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15349                 if (err < 0)
15350                         return err;
15351         }
15352         return 0;
15353 }
15354
15355 /* parse the BIOS configuration and set up the alc_spec
15356  * return 1 if successful, 0 if the proper config is not found,
15357  * or a negative error code
15358  * Based on ALC880 version - had to change it to override
15359  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15360 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15361 {
15362         struct alc_spec *spec = codec->spec;
15363         int err;
15364         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15365
15366         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15367                                            alc861vd_ignore);
15368         if (err < 0)
15369                 return err;
15370         if (!spec->autocfg.line_outs)
15371                 return 0; /* can't find valid BIOS pin config */
15372
15373         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15374         if (err < 0)
15375                 return err;
15376         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15377         if (err < 0)
15378                 return err;
15379         err = alc861vd_auto_create_extra_out(spec,
15380                                              spec->autocfg.speaker_pins[0],
15381                                              "Speaker");
15382         if (err < 0)
15383                 return err;
15384         err = alc861vd_auto_create_extra_out(spec,
15385                                              spec->autocfg.hp_pins[0],
15386                                              "Headphone");
15387         if (err < 0)
15388                 return err;
15389         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
15390         if (err < 0)
15391                 return err;
15392
15393         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15394
15395         if (spec->autocfg.dig_outs)
15396                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15397
15398         if (spec->kctls.list)
15399                 add_mixer(spec, spec->kctls.list);
15400
15401         add_verb(spec, alc861vd_volume_init_verbs);
15402
15403         spec->num_mux_defs = 1;
15404         spec->input_mux = &spec->private_imux[0];
15405
15406         err = alc_auto_add_mic_boost(codec);
15407         if (err < 0)
15408                 return err;
15409
15410         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15411
15412         return 1;
15413 }
15414
15415 /* additional initialization for auto-configuration model */
15416 static void alc861vd_auto_init(struct hda_codec *codec)
15417 {
15418         struct alc_spec *spec = codec->spec;
15419         alc861vd_auto_init_multi_out(codec);
15420         alc861vd_auto_init_hp_out(codec);
15421         alc861vd_auto_init_analog_input(codec);
15422         alc861vd_auto_init_input_src(codec);
15423         if (spec->unsol_event)
15424                 alc_inithook(codec);
15425 }
15426
15427 static int patch_alc861vd(struct hda_codec *codec)
15428 {
15429         struct alc_spec *spec;
15430         int err, board_config;
15431
15432         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15433         if (spec == NULL)
15434                 return -ENOMEM;
15435
15436         codec->spec = spec;
15437
15438         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15439                                                   alc861vd_models,
15440                                                   alc861vd_cfg_tbl);
15441
15442         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15443                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
15444                        "trying auto-probe from BIOS...\n", codec->chip_name);
15445                 board_config = ALC861VD_AUTO;
15446         }
15447
15448         if (board_config == ALC861VD_AUTO) {
15449                 /* automatic parse from the BIOS config */
15450                 err = alc861vd_parse_auto_config(codec);
15451                 if (err < 0) {
15452                         alc_free(codec);
15453                         return err;
15454                 } else if (!err) {
15455                         printk(KERN_INFO
15456                                "hda_codec: Cannot set up configuration "
15457                                "from BIOS.  Using base mode...\n");
15458                         board_config = ALC861VD_3ST;
15459                 }
15460         }
15461
15462         err = snd_hda_attach_beep_device(codec, 0x23);
15463         if (err < 0) {
15464                 alc_free(codec);
15465                 return err;
15466         }
15467
15468         if (board_config != ALC861VD_AUTO)
15469                 setup_preset(spec, &alc861vd_presets[board_config]);
15470
15471         if (codec->vendor_id == 0x10ec0660) {
15472                 /* always turn on EAPD */
15473                 add_verb(spec, alc660vd_eapd_verbs);
15474         }
15475
15476         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15477         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15478
15479         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15480         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15481
15482         spec->adc_nids = alc861vd_adc_nids;
15483         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15484         spec->capsrc_nids = alc861vd_capsrc_nids;
15485         spec->capture_style = CAPT_MIX;
15486
15487         set_capture_mixer(spec);
15488         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15489
15490         spec->vmaster_nid = 0x02;
15491
15492         codec->patch_ops = alc_patch_ops;
15493
15494         if (board_config == ALC861VD_AUTO)
15495                 spec->init_hook = alc861vd_auto_init;
15496 #ifdef CONFIG_SND_HDA_POWER_SAVE
15497         if (!spec->loopback.amplist)
15498                 spec->loopback.amplist = alc861vd_loopbacks;
15499 #endif
15500         codec->proc_widget_hook = print_realtek_coef;
15501
15502         return 0;
15503 }
15504
15505 /*
15506  * ALC662 support
15507  *
15508  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15509  * configuration.  Each pin widget can choose any input DACs and a mixer.
15510  * Each ADC is connected from a mixer of all inputs.  This makes possible
15511  * 6-channel independent captures.
15512  *
15513  * In addition, an independent DAC for the multi-playback (not used in this
15514  * driver yet).
15515  */
15516 #define ALC662_DIGOUT_NID       0x06
15517 #define ALC662_DIGIN_NID        0x0a
15518
15519 static hda_nid_t alc662_dac_nids[4] = {
15520         /* front, rear, clfe, rear_surr */
15521         0x02, 0x03, 0x04
15522 };
15523
15524 static hda_nid_t alc272_dac_nids[2] = {
15525         0x02, 0x03
15526 };
15527
15528 static hda_nid_t alc662_adc_nids[1] = {
15529         /* ADC1-2 */
15530         0x09,
15531 };
15532
15533 static hda_nid_t alc272_adc_nids[1] = {
15534         /* ADC1-2 */
15535         0x08,
15536 };
15537
15538 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
15539 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15540
15541
15542 /* input MUX */
15543 /* FIXME: should be a matrix-type input source selection */
15544 static struct hda_input_mux alc662_capture_source = {
15545         .num_items = 4,
15546         .items = {
15547                 { "Mic", 0x0 },
15548                 { "Front Mic", 0x1 },
15549                 { "Line", 0x2 },
15550                 { "CD", 0x4 },
15551         },
15552 };
15553
15554 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15555         .num_items = 2,
15556         .items = {
15557                 { "Mic", 0x1 },
15558                 { "Line", 0x2 },
15559         },
15560 };
15561
15562 static struct hda_input_mux alc662_eeepc_capture_source = {
15563         .num_items = 2,
15564         .items = {
15565                 { "i-Mic", 0x1 },
15566                 { "e-Mic", 0x0 },
15567         },
15568 };
15569
15570 static struct hda_input_mux alc663_capture_source = {
15571         .num_items = 3,
15572         .items = {
15573                 { "Mic", 0x0 },
15574                 { "Front Mic", 0x1 },
15575                 { "Line", 0x2 },
15576         },
15577 };
15578
15579 static struct hda_input_mux alc663_m51va_capture_source = {
15580         .num_items = 2,
15581         .items = {
15582                 { "Ext-Mic", 0x0 },
15583                 { "D-Mic", 0x9 },
15584         },
15585 };
15586
15587 #if 1 /* set to 0 for testing other input sources below */
15588 static struct hda_input_mux alc272_nc10_capture_source = {
15589         .num_items = 2,
15590         .items = {
15591                 { "Autoselect Mic", 0x0 },
15592                 { "Internal Mic", 0x1 },
15593         },
15594 };
15595 #else
15596 static struct hda_input_mux alc272_nc10_capture_source = {
15597         .num_items = 16,
15598         .items = {
15599                 { "Autoselect Mic", 0x0 },
15600                 { "Internal Mic", 0x1 },
15601                 { "In-0x02", 0x2 },
15602                 { "In-0x03", 0x3 },
15603                 { "In-0x04", 0x4 },
15604                 { "In-0x05", 0x5 },
15605                 { "In-0x06", 0x6 },
15606                 { "In-0x07", 0x7 },
15607                 { "In-0x08", 0x8 },
15608                 { "In-0x09", 0x9 },
15609                 { "In-0x0a", 0x0a },
15610                 { "In-0x0b", 0x0b },
15611                 { "In-0x0c", 0x0c },
15612                 { "In-0x0d", 0x0d },
15613                 { "In-0x0e", 0x0e },
15614                 { "In-0x0f", 0x0f },
15615         },
15616 };
15617 #endif
15618
15619 /*
15620  * 2ch mode
15621  */
15622 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15623         { 2, NULL }
15624 };
15625
15626 /*
15627  * 2ch mode
15628  */
15629 static struct hda_verb alc662_3ST_ch2_init[] = {
15630         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15631         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15632         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15633         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15634         { } /* end */
15635 };
15636
15637 /*
15638  * 6ch mode
15639  */
15640 static struct hda_verb alc662_3ST_ch6_init[] = {
15641         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15642         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15643         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15644         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15645         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15646         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15647         { } /* end */
15648 };
15649
15650 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15651         { 2, alc662_3ST_ch2_init },
15652         { 6, alc662_3ST_ch6_init },
15653 };
15654
15655 /*
15656  * 2ch mode
15657  */
15658 static struct hda_verb alc662_sixstack_ch6_init[] = {
15659         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15660         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15661         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15662         { } /* end */
15663 };
15664
15665 /*
15666  * 6ch mode
15667  */
15668 static struct hda_verb alc662_sixstack_ch8_init[] = {
15669         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15670         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15671         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15672         { } /* end */
15673 };
15674
15675 static struct hda_channel_mode alc662_5stack_modes[2] = {
15676         { 2, alc662_sixstack_ch6_init },
15677         { 6, alc662_sixstack_ch8_init },
15678 };
15679
15680 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15681  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15682  */
15683
15684 static struct snd_kcontrol_new alc662_base_mixer[] = {
15685         /* output mixer control */
15686         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15687         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15688         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15689         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15690         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15691         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15692         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15693         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15694         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15695
15696         /*Input mixer control */
15697         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15698         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15699         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15700         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15701         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15702         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15703         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15704         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15705         { } /* end */
15706 };
15707
15708 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15709         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15710         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15711         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15712         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15713         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15714         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15715         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15716         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15717         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15718         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15719         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15720         { } /* end */
15721 };
15722
15723 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15724         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15725         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15726         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15727         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15728         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15729         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15730         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15731         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15732         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15733         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15734         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15735         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15736         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15737         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15738         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15739         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15740         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15741         { } /* end */
15742 };
15743
15744 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15745         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15746         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15747         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15748         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15749         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15750         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15751         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15752         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15753         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15754         { } /* end */
15755 };
15756
15757 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15758         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15759         ALC262_HIPPO_MASTER_SWITCH,
15760
15761         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15762         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15763         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15764
15765         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15766         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15767         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15768         { } /* end */
15769 };
15770
15771 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15772         ALC262_HIPPO_MASTER_SWITCH,
15773         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15774         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15775         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15776         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15777         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15778         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15779         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15780         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15781         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15782         { } /* end */
15783 };
15784
15785 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15786         .ops = &snd_hda_bind_vol,
15787         .values = {
15788                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15789                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15790                 0
15791         },
15792 };
15793
15794 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15795         .ops = &snd_hda_bind_sw,
15796         .values = {
15797                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15798                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15799                 0
15800         },
15801 };
15802
15803 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15804         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15805         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15806         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15807         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15808         { } /* end */
15809 };
15810
15811 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15812         .ops = &snd_hda_bind_sw,
15813         .values = {
15814                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15815                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15816                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15817                 0
15818         },
15819 };
15820
15821 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15822         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15823         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15824         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15825         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15826         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15827         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15828
15829         { } /* end */
15830 };
15831
15832 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15833         .ops = &snd_hda_bind_sw,
15834         .values = {
15835                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15836                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15837                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15838                 0
15839         },
15840 };
15841
15842 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15843         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15844         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15845         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15846         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15847         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15848         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15849         { } /* end */
15850 };
15851
15852 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15853         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15854         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15855         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15856         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15857         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15858         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15859         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15860         { } /* end */
15861 };
15862
15863 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15864         .ops = &snd_hda_bind_vol,
15865         .values = {
15866                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15867                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15868                 0
15869         },
15870 };
15871
15872 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15873         .ops = &snd_hda_bind_sw,
15874         .values = {
15875                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15876                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15877                 0
15878         },
15879 };
15880
15881 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15882         HDA_BIND_VOL("Master Playback Volume",
15883                                 &alc663_asus_two_bind_master_vol),
15884         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15885         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15886         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15887         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15888         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15889         { } /* end */
15890 };
15891
15892 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15893         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15894         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15895         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15897         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15898         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15899         { } /* end */
15900 };
15901
15902 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15903         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15904         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15905         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15906         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15907         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15908
15909         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15910         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15911         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15912         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15913         { } /* end */
15914 };
15915
15916 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15917         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15918         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15919         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15920
15921         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15922         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15923         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15924         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15925         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15926         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15927         { } /* end */
15928 };
15929
15930 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15931         {
15932                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15933                 .name = "Channel Mode",
15934                 .info = alc_ch_mode_info,
15935                 .get = alc_ch_mode_get,
15936                 .put = alc_ch_mode_put,
15937         },
15938         { } /* end */
15939 };
15940
15941 static struct hda_verb alc662_init_verbs[] = {
15942         /* ADC: mute amp left and right */
15943         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15944         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15945         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15946
15947         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15948         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15949         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15950         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15951         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15952
15953         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15954         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15955         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15956         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15957         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15958         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15959
15960         /* Front Pin: output 0 (0x0c) */
15961         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15962         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15963
15964         /* Rear Pin: output 1 (0x0d) */
15965         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15966         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15967
15968         /* CLFE Pin: output 2 (0x0e) */
15969         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15970         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15971
15972         /* Mic (rear) pin: input vref at 80% */
15973         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15974         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15975         /* Front Mic pin: input vref at 80% */
15976         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15977         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15978         /* Line In pin: input */
15979         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15980         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15981         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15982         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15983         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15984         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15985         /* CD pin widget for input */
15986         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15987
15988         /* FIXME: use matrix-type input source selection */
15989         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15990         /* Input mixer */
15991         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15992         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15993
15994         /* always trun on EAPD */
15995         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15996         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15997
15998         { }
15999 };
16000
16001 static struct hda_verb alc662_sue_init_verbs[] = {
16002         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16003         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16004         {}
16005 };
16006
16007 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16008         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16009         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16010         {}
16011 };
16012
16013 /* Set Unsolicited Event*/
16014 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16015         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16016         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16017         {}
16018 };
16019
16020 /*
16021  * generic initialization of ADC, input mixers and output mixers
16022  */
16023 static struct hda_verb alc662_auto_init_verbs[] = {
16024         /*
16025          * Unmute ADC and set the default input to mic-in
16026          */
16027         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16028         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16029
16030         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16031          * mixer widget
16032          * Note: PASD motherboards uses the Line In 2 as the input for front
16033          * panel mic (mic 2)
16034          */
16035         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16036         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16038         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16040         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16041
16042         /*
16043          * Set up output mixers (0x0c - 0x0f)
16044          */
16045         /* set vol=0 to output mixers */
16046         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16047         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16048         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16049
16050         /* set up input amps for analog loopback */
16051         /* Amp Indices: DAC = 0, mixer = 1 */
16052         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16053         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16054         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16055         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16056         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16057         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16058
16059
16060         /* FIXME: use matrix-type input source selection */
16061         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16062         /* Input mixer */
16063         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16064         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16065         { }
16066 };
16067
16068 /* additional verbs for ALC663 */
16069 static struct hda_verb alc663_auto_init_verbs[] = {
16070         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16071         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16072         { }
16073 };
16074
16075 static struct hda_verb alc663_m51va_init_verbs[] = {
16076         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16077         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16078         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16079         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16080         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16081         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16082         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16083         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16084         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16085         {}
16086 };
16087
16088 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16089         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16090         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16091         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16092         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16093         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16094         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16095         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16096         {}
16097 };
16098
16099 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16100         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16101         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16102         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16103         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16106         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16107         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16108         {}
16109 };
16110
16111 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16112         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16113         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16114         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16115         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16116         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16117         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16118         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16119         {}
16120 };
16121
16122 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16123         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16124         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16125         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16126         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16127         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16128         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16129         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16130         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16131         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16132         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16133         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16134         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16135         {}
16136 };
16137
16138 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16139         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16140         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16141         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16142         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16143         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16144         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16145         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16146         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16147         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16148         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16149         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16150         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16151         {}
16152 };
16153
16154 static struct hda_verb alc663_g71v_init_verbs[] = {
16155         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16156         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16157         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16158
16159         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16160         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16161         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16162
16163         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16164         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16165         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16166         {}
16167 };
16168
16169 static struct hda_verb alc663_g50v_init_verbs[] = {
16170         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16171         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16172         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16173
16174         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16175         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16176         {}
16177 };
16178
16179 static struct hda_verb alc662_ecs_init_verbs[] = {
16180         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16181         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16182         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16183         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16184         {}
16185 };
16186
16187 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16188         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16189         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16190         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16191         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16192         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16193         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16194         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16195         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16196         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16197         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16198         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16199         {}
16200 };
16201
16202 static struct hda_verb alc272_dell_init_verbs[] = {
16203         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16204         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16205         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16206         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16207         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16208         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16209         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16210         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16211         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16212         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16213         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16214         {}
16215 };
16216
16217 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16218         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16219         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16220         { } /* end */
16221 };
16222
16223 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16224         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16225         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16226         { } /* end */
16227 };
16228
16229 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16230 {
16231         unsigned int present;
16232         unsigned char bits;
16233
16234         present = snd_hda_codec_read(codec, 0x14, 0,
16235                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16236         bits = present ? HDA_AMP_MUTE : 0;
16237         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16238                                  HDA_AMP_MUTE, bits);
16239 }
16240
16241 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16242 {
16243         unsigned int present;
16244         unsigned char bits;
16245
16246         present = snd_hda_codec_read(codec, 0x1b, 0,
16247                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16248         bits = present ? HDA_AMP_MUTE : 0;
16249         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16250                                  HDA_AMP_MUTE, bits);
16251         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16252                                  HDA_AMP_MUTE, bits);
16253 }
16254
16255 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16256                                            unsigned int res)
16257 {
16258         if ((res >> 26) == ALC880_HP_EVENT)
16259                 alc662_lenovo_101e_all_automute(codec);
16260         if ((res >> 26) == ALC880_FRONT_EVENT)
16261                 alc662_lenovo_101e_ispeaker_automute(codec);
16262 }
16263
16264 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
16265 {
16266         unsigned int present;
16267
16268         present = snd_hda_codec_read(codec, 0x18, 0,
16269                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16270         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16271                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16272         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16273                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16274         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16275                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16276         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16277                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16278 }
16279
16280 /* unsolicited event for HP jack sensing */
16281 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16282                                      unsigned int res)
16283 {
16284         if ((res >> 26) == ALC880_MIC_EVENT)
16285                 alc662_eeepc_mic_automute(codec);
16286         else
16287                 alc262_hippo_unsol_event(codec, res);
16288 }
16289
16290 static void alc662_eeepc_inithook(struct hda_codec *codec)
16291 {
16292         alc262_hippo1_init_hook(codec);
16293         alc662_eeepc_mic_automute(codec);
16294 }
16295
16296 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
16297 {
16298         struct alc_spec *spec = codec->spec;
16299
16300         spec->autocfg.hp_pins[0] = 0x14;
16301         spec->autocfg.speaker_pins[0] = 0x1b;
16302         alc262_hippo_master_update(codec);
16303 }
16304
16305 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16306 {
16307         unsigned int present;
16308         unsigned char bits;
16309
16310         present = snd_hda_codec_read(codec, 0x21, 0,
16311                         AC_VERB_GET_PIN_SENSE, 0)
16312                         & AC_PINSENSE_PRESENCE;
16313         bits = present ? HDA_AMP_MUTE : 0;
16314         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16315                                 AMP_IN_MUTE(0), bits);
16316         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16317                                 AMP_IN_MUTE(0), bits);
16318 }
16319
16320 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16321 {
16322         unsigned int present;
16323         unsigned char bits;
16324
16325         present = snd_hda_codec_read(codec, 0x21, 0,
16326                         AC_VERB_GET_PIN_SENSE, 0)
16327                         & AC_PINSENSE_PRESENCE;
16328         bits = present ? HDA_AMP_MUTE : 0;
16329         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16330                                 AMP_IN_MUTE(0), bits);
16331         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16332                                 AMP_IN_MUTE(0), bits);
16333         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16334                                 AMP_IN_MUTE(0), bits);
16335         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16336                                 AMP_IN_MUTE(0), bits);
16337 }
16338
16339 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16340 {
16341         unsigned int present;
16342         unsigned char bits;
16343
16344         present = snd_hda_codec_read(codec, 0x15, 0,
16345                         AC_VERB_GET_PIN_SENSE, 0)
16346                         & AC_PINSENSE_PRESENCE;
16347         bits = present ? HDA_AMP_MUTE : 0;
16348         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16349                                 AMP_IN_MUTE(0), bits);
16350         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16351                                 AMP_IN_MUTE(0), bits);
16352         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16353                                 AMP_IN_MUTE(0), bits);
16354         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16355                                 AMP_IN_MUTE(0), bits);
16356 }
16357
16358 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16359 {
16360         unsigned int present;
16361         unsigned char bits;
16362
16363         present = snd_hda_codec_read(codec, 0x1b, 0,
16364                         AC_VERB_GET_PIN_SENSE, 0)
16365                         & AC_PINSENSE_PRESENCE;
16366         bits = present ? 0 : PIN_OUT;
16367         snd_hda_codec_write(codec, 0x14, 0,
16368                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16369 }
16370
16371 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16372 {
16373         unsigned int present1, present2;
16374
16375         present1 = snd_hda_codec_read(codec, 0x21, 0,
16376                         AC_VERB_GET_PIN_SENSE, 0)
16377                         & AC_PINSENSE_PRESENCE;
16378         present2 = snd_hda_codec_read(codec, 0x15, 0,
16379                         AC_VERB_GET_PIN_SENSE, 0)
16380                         & AC_PINSENSE_PRESENCE;
16381
16382         if (present1 || present2) {
16383                 snd_hda_codec_write_cache(codec, 0x14, 0,
16384                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16385         } else {
16386                 snd_hda_codec_write_cache(codec, 0x14, 0,
16387                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16388         }
16389 }
16390
16391 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16392 {
16393         unsigned int present1, present2;
16394
16395         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16396                                 AC_VERB_GET_PIN_SENSE, 0)
16397                                 & AC_PINSENSE_PRESENCE;
16398         present2 = snd_hda_codec_read(codec, 0x15, 0,
16399                                 AC_VERB_GET_PIN_SENSE, 0)
16400                                 & AC_PINSENSE_PRESENCE;
16401
16402         if (present1 || present2) {
16403                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16404                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16405                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16406                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16407         } else {
16408                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16409                                 AMP_IN_MUTE(0), 0);
16410                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16411                                 AMP_IN_MUTE(0), 0);
16412         }
16413 }
16414
16415 static void alc663_m51va_mic_automute(struct hda_codec *codec)
16416 {
16417         unsigned int present;
16418
16419         present = snd_hda_codec_read(codec, 0x18, 0,
16420                         AC_VERB_GET_PIN_SENSE, 0)
16421                         & AC_PINSENSE_PRESENCE;
16422         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16423                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16424         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16425                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16426         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16427                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16428         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16429                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16430 }
16431
16432 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16433                                            unsigned int res)
16434 {
16435         switch (res >> 26) {
16436         case ALC880_HP_EVENT:
16437                 alc663_m51va_speaker_automute(codec);
16438                 break;
16439         case ALC880_MIC_EVENT:
16440                 alc663_m51va_mic_automute(codec);
16441                 break;
16442         }
16443 }
16444
16445 static void alc663_m51va_inithook(struct hda_codec *codec)
16446 {
16447         alc663_m51va_speaker_automute(codec);
16448         alc663_m51va_mic_automute(codec);
16449 }
16450
16451 /* ***************** Mode1 ******************************/
16452 static void alc663_mode1_unsol_event(struct hda_codec *codec,
16453                                            unsigned int res)
16454 {
16455         switch (res >> 26) {
16456         case ALC880_HP_EVENT:
16457                 alc663_m51va_speaker_automute(codec);
16458                 break;
16459         case ALC880_MIC_EVENT:
16460                 alc662_eeepc_mic_automute(codec);
16461                 break;
16462         }
16463 }
16464
16465 static void alc663_mode1_inithook(struct hda_codec *codec)
16466 {
16467         alc663_m51va_speaker_automute(codec);
16468         alc662_eeepc_mic_automute(codec);
16469 }
16470 /* ***************** Mode2 ******************************/
16471 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16472                                            unsigned int res)
16473 {
16474         switch (res >> 26) {
16475         case ALC880_HP_EVENT:
16476                 alc662_f5z_speaker_automute(codec);
16477                 break;
16478         case ALC880_MIC_EVENT:
16479                 alc662_eeepc_mic_automute(codec);
16480                 break;
16481         }
16482 }
16483
16484 static void alc662_mode2_inithook(struct hda_codec *codec)
16485 {
16486         alc662_f5z_speaker_automute(codec);
16487         alc662_eeepc_mic_automute(codec);
16488 }
16489 /* ***************** Mode3 ******************************/
16490 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16491                                            unsigned int res)
16492 {
16493         switch (res >> 26) {
16494         case ALC880_HP_EVENT:
16495                 alc663_two_hp_m1_speaker_automute(codec);
16496                 break;
16497         case ALC880_MIC_EVENT:
16498                 alc662_eeepc_mic_automute(codec);
16499                 break;
16500         }
16501 }
16502
16503 static void alc663_mode3_inithook(struct hda_codec *codec)
16504 {
16505         alc663_two_hp_m1_speaker_automute(codec);
16506         alc662_eeepc_mic_automute(codec);
16507 }
16508 /* ***************** Mode4 ******************************/
16509 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16510                                            unsigned int res)
16511 {
16512         switch (res >> 26) {
16513         case ALC880_HP_EVENT:
16514                 alc663_21jd_two_speaker_automute(codec);
16515                 break;
16516         case ALC880_MIC_EVENT:
16517                 alc662_eeepc_mic_automute(codec);
16518                 break;
16519         }
16520 }
16521
16522 static void alc663_mode4_inithook(struct hda_codec *codec)
16523 {
16524         alc663_21jd_two_speaker_automute(codec);
16525         alc662_eeepc_mic_automute(codec);
16526 }
16527 /* ***************** Mode5 ******************************/
16528 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16529                                            unsigned int res)
16530 {
16531         switch (res >> 26) {
16532         case ALC880_HP_EVENT:
16533                 alc663_15jd_two_speaker_automute(codec);
16534                 break;
16535         case ALC880_MIC_EVENT:
16536                 alc662_eeepc_mic_automute(codec);
16537                 break;
16538         }
16539 }
16540
16541 static void alc663_mode5_inithook(struct hda_codec *codec)
16542 {
16543         alc663_15jd_two_speaker_automute(codec);
16544         alc662_eeepc_mic_automute(codec);
16545 }
16546 /* ***************** Mode6 ******************************/
16547 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16548                                            unsigned int res)
16549 {
16550         switch (res >> 26) {
16551         case ALC880_HP_EVENT:
16552                 alc663_two_hp_m2_speaker_automute(codec);
16553                 break;
16554         case ALC880_MIC_EVENT:
16555                 alc662_eeepc_mic_automute(codec);
16556                 break;
16557         }
16558 }
16559
16560 static void alc663_mode6_inithook(struct hda_codec *codec)
16561 {
16562         alc663_two_hp_m2_speaker_automute(codec);
16563         alc662_eeepc_mic_automute(codec);
16564 }
16565
16566 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16567 {
16568         unsigned int present;
16569         unsigned char bits;
16570
16571         present = snd_hda_codec_read(codec, 0x21, 0,
16572                                      AC_VERB_GET_PIN_SENSE, 0)
16573                 & AC_PINSENSE_PRESENCE;
16574         bits = present ? HDA_AMP_MUTE : 0;
16575         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16576                                  HDA_AMP_MUTE, bits);
16577         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16578                                  HDA_AMP_MUTE, bits);
16579 }
16580
16581 static void alc663_g71v_front_automute(struct hda_codec *codec)
16582 {
16583         unsigned int present;
16584         unsigned char bits;
16585
16586         present = snd_hda_codec_read(codec, 0x15, 0,
16587                                      AC_VERB_GET_PIN_SENSE, 0)
16588                 & AC_PINSENSE_PRESENCE;
16589         bits = present ? HDA_AMP_MUTE : 0;
16590         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16591                                  HDA_AMP_MUTE, bits);
16592 }
16593
16594 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16595                                            unsigned int res)
16596 {
16597         switch (res >> 26) {
16598         case ALC880_HP_EVENT:
16599                 alc663_g71v_hp_automute(codec);
16600                 break;
16601         case ALC880_FRONT_EVENT:
16602                 alc663_g71v_front_automute(codec);
16603                 break;
16604         case ALC880_MIC_EVENT:
16605                 alc662_eeepc_mic_automute(codec);
16606                 break;
16607         }
16608 }
16609
16610 static void alc663_g71v_inithook(struct hda_codec *codec)
16611 {
16612         alc663_g71v_front_automute(codec);
16613         alc663_g71v_hp_automute(codec);
16614         alc662_eeepc_mic_automute(codec);
16615 }
16616
16617 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16618                                            unsigned int res)
16619 {
16620         switch (res >> 26) {
16621         case ALC880_HP_EVENT:
16622                 alc663_m51va_speaker_automute(codec);
16623                 break;
16624         case ALC880_MIC_EVENT:
16625                 alc662_eeepc_mic_automute(codec);
16626                 break;
16627         }
16628 }
16629
16630 static void alc663_g50v_inithook(struct hda_codec *codec)
16631 {
16632         alc663_m51va_speaker_automute(codec);
16633         alc662_eeepc_mic_automute(codec);
16634 }
16635
16636 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16637         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16638         ALC262_HIPPO_MASTER_SWITCH,
16639
16640         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16641         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16642         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16643
16644         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16645         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16646         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16647         { } /* end */
16648 };
16649
16650 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16651         /* Master Playback automatically created from Speaker and Headphone */
16652         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16653         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16654         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16655         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16656
16657         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16658         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16659         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16660
16661         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16662         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16663         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16664         { } /* end */
16665 };
16666
16667 #ifdef CONFIG_SND_HDA_POWER_SAVE
16668 #define alc662_loopbacks        alc880_loopbacks
16669 #endif
16670
16671
16672 /* pcm configuration: identiacal with ALC880 */
16673 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16674 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16675 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16676 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16677
16678 /*
16679  * configuration and preset
16680  */
16681 static const char *alc662_models[ALC662_MODEL_LAST] = {
16682         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16683         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16684         [ALC662_3ST_6ch]        = "3stack-6ch",
16685         [ALC662_5ST_DIG]        = "6stack-dig",
16686         [ALC662_LENOVO_101E]    = "lenovo-101e",
16687         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16688         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16689         [ALC662_ECS] = "ecs",
16690         [ALC663_ASUS_M51VA] = "m51va",
16691         [ALC663_ASUS_G71V] = "g71v",
16692         [ALC663_ASUS_H13] = "h13",
16693         [ALC663_ASUS_G50V] = "g50v",
16694         [ALC663_ASUS_MODE1] = "asus-mode1",
16695         [ALC662_ASUS_MODE2] = "asus-mode2",
16696         [ALC663_ASUS_MODE3] = "asus-mode3",
16697         [ALC663_ASUS_MODE4] = "asus-mode4",
16698         [ALC663_ASUS_MODE5] = "asus-mode5",
16699         [ALC663_ASUS_MODE6] = "asus-mode6",
16700         [ALC272_DELL]           = "dell",
16701         [ALC272_DELL_ZM1]       = "dell-zm1",
16702         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16703         [ALC662_AUTO]           = "auto",
16704 };
16705
16706 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16707         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16708         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16709         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16710         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16711         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16712         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16713         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16714         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16715         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16716         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16717         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16718         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16719         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16720         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16721         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16722         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16723         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16724         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16725         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16726         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16727         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16728         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16729         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16730         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16731         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16732         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16733         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16734         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16735         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16736         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16737         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16738         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16739         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16740         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16741         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16742         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16743         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16744         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16745         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16746         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16747         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16748         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16749         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16750         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16751         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16752         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16753         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16754         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16755         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16756         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16757         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16758         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16759                       ALC662_3ST_6ch_DIG),
16760         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16761         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16762                       ALC662_3ST_6ch_DIG),
16763         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16764         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16765         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16766         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16767                                         ALC662_3ST_6ch_DIG),
16768         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16769                            ALC663_ASUS_H13),
16770         {}
16771 };
16772
16773 static struct alc_config_preset alc662_presets[] = {
16774         [ALC662_3ST_2ch_DIG] = {
16775                 .mixers = { alc662_3ST_2ch_mixer },
16776                 .init_verbs = { alc662_init_verbs },
16777                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16778                 .dac_nids = alc662_dac_nids,
16779                 .dig_out_nid = ALC662_DIGOUT_NID,
16780                 .dig_in_nid = ALC662_DIGIN_NID,
16781                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16782                 .channel_mode = alc662_3ST_2ch_modes,
16783                 .input_mux = &alc662_capture_source,
16784         },
16785         [ALC662_3ST_6ch_DIG] = {
16786                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16787                 .init_verbs = { alc662_init_verbs },
16788                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16789                 .dac_nids = alc662_dac_nids,
16790                 .dig_out_nid = ALC662_DIGOUT_NID,
16791                 .dig_in_nid = ALC662_DIGIN_NID,
16792                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16793                 .channel_mode = alc662_3ST_6ch_modes,
16794                 .need_dac_fix = 1,
16795                 .input_mux = &alc662_capture_source,
16796         },
16797         [ALC662_3ST_6ch] = {
16798                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16799                 .init_verbs = { alc662_init_verbs },
16800                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16801                 .dac_nids = alc662_dac_nids,
16802                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16803                 .channel_mode = alc662_3ST_6ch_modes,
16804                 .need_dac_fix = 1,
16805                 .input_mux = &alc662_capture_source,
16806         },
16807         [ALC662_5ST_DIG] = {
16808                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16809                 .init_verbs = { alc662_init_verbs },
16810                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16811                 .dac_nids = alc662_dac_nids,
16812                 .dig_out_nid = ALC662_DIGOUT_NID,
16813                 .dig_in_nid = ALC662_DIGIN_NID,
16814                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16815                 .channel_mode = alc662_5stack_modes,
16816                 .input_mux = &alc662_capture_source,
16817         },
16818         [ALC662_LENOVO_101E] = {
16819                 .mixers = { alc662_lenovo_101e_mixer },
16820                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16821                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16822                 .dac_nids = alc662_dac_nids,
16823                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16824                 .channel_mode = alc662_3ST_2ch_modes,
16825                 .input_mux = &alc662_lenovo_101e_capture_source,
16826                 .unsol_event = alc662_lenovo_101e_unsol_event,
16827                 .init_hook = alc662_lenovo_101e_all_automute,
16828         },
16829         [ALC662_ASUS_EEEPC_P701] = {
16830                 .mixers = { alc662_eeepc_p701_mixer },
16831                 .init_verbs = { alc662_init_verbs,
16832                                 alc662_eeepc_sue_init_verbs },
16833                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16834                 .dac_nids = alc662_dac_nids,
16835                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16836                 .channel_mode = alc662_3ST_2ch_modes,
16837                 .input_mux = &alc662_eeepc_capture_source,
16838                 .unsol_event = alc662_eeepc_unsol_event,
16839                 .init_hook = alc662_eeepc_inithook,
16840         },
16841         [ALC662_ASUS_EEEPC_EP20] = {
16842                 .mixers = { alc662_eeepc_ep20_mixer,
16843                             alc662_chmode_mixer },
16844                 .init_verbs = { alc662_init_verbs,
16845                                 alc662_eeepc_ep20_sue_init_verbs },
16846                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16847                 .dac_nids = alc662_dac_nids,
16848                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16849                 .channel_mode = alc662_3ST_6ch_modes,
16850                 .input_mux = &alc662_lenovo_101e_capture_source,
16851                 .unsol_event = alc662_eeepc_unsol_event,
16852                 .init_hook = alc662_eeepc_ep20_inithook,
16853         },
16854         [ALC662_ECS] = {
16855                 .mixers = { alc662_ecs_mixer },
16856                 .init_verbs = { alc662_init_verbs,
16857                                 alc662_ecs_init_verbs },
16858                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16859                 .dac_nids = alc662_dac_nids,
16860                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16861                 .channel_mode = alc662_3ST_2ch_modes,
16862                 .input_mux = &alc662_eeepc_capture_source,
16863                 .unsol_event = alc662_eeepc_unsol_event,
16864                 .init_hook = alc662_eeepc_inithook,
16865         },
16866         [ALC663_ASUS_M51VA] = {
16867                 .mixers = { alc663_m51va_mixer },
16868                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16869                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16870                 .dac_nids = alc662_dac_nids,
16871                 .dig_out_nid = ALC662_DIGOUT_NID,
16872                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16873                 .channel_mode = alc662_3ST_2ch_modes,
16874                 .input_mux = &alc663_m51va_capture_source,
16875                 .unsol_event = alc663_m51va_unsol_event,
16876                 .init_hook = alc663_m51va_inithook,
16877         },
16878         [ALC663_ASUS_G71V] = {
16879                 .mixers = { alc663_g71v_mixer },
16880                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16881                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16882                 .dac_nids = alc662_dac_nids,
16883                 .dig_out_nid = ALC662_DIGOUT_NID,
16884                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16885                 .channel_mode = alc662_3ST_2ch_modes,
16886                 .input_mux = &alc662_eeepc_capture_source,
16887                 .unsol_event = alc663_g71v_unsol_event,
16888                 .init_hook = alc663_g71v_inithook,
16889         },
16890         [ALC663_ASUS_H13] = {
16891                 .mixers = { alc663_m51va_mixer },
16892                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16893                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16894                 .dac_nids = alc662_dac_nids,
16895                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16896                 .channel_mode = alc662_3ST_2ch_modes,
16897                 .input_mux = &alc663_m51va_capture_source,
16898                 .unsol_event = alc663_m51va_unsol_event,
16899                 .init_hook = alc663_m51va_inithook,
16900         },
16901         [ALC663_ASUS_G50V] = {
16902                 .mixers = { alc663_g50v_mixer },
16903                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16904                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16905                 .dac_nids = alc662_dac_nids,
16906                 .dig_out_nid = ALC662_DIGOUT_NID,
16907                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16908                 .channel_mode = alc662_3ST_6ch_modes,
16909                 .input_mux = &alc663_capture_source,
16910                 .unsol_event = alc663_g50v_unsol_event,
16911                 .init_hook = alc663_g50v_inithook,
16912         },
16913         [ALC663_ASUS_MODE1] = {
16914                 .mixers = { alc663_m51va_mixer },
16915                 .cap_mixer = alc662_auto_capture_mixer,
16916                 .init_verbs = { alc662_init_verbs,
16917                                 alc663_21jd_amic_init_verbs },
16918                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16919                 .hp_nid = 0x03,
16920                 .dac_nids = alc662_dac_nids,
16921                 .dig_out_nid = ALC662_DIGOUT_NID,
16922                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16923                 .channel_mode = alc662_3ST_2ch_modes,
16924                 .input_mux = &alc662_eeepc_capture_source,
16925                 .unsol_event = alc663_mode1_unsol_event,
16926                 .init_hook = alc663_mode1_inithook,
16927         },
16928         [ALC662_ASUS_MODE2] = {
16929                 .mixers = { alc662_1bjd_mixer },
16930                 .cap_mixer = alc662_auto_capture_mixer,
16931                 .init_verbs = { alc662_init_verbs,
16932                                 alc662_1bjd_amic_init_verbs },
16933                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16934                 .dac_nids = alc662_dac_nids,
16935                 .dig_out_nid = ALC662_DIGOUT_NID,
16936                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16937                 .channel_mode = alc662_3ST_2ch_modes,
16938                 .input_mux = &alc662_eeepc_capture_source,
16939                 .unsol_event = alc662_mode2_unsol_event,
16940                 .init_hook = alc662_mode2_inithook,
16941         },
16942         [ALC663_ASUS_MODE3] = {
16943                 .mixers = { alc663_two_hp_m1_mixer },
16944                 .cap_mixer = alc662_auto_capture_mixer,
16945                 .init_verbs = { alc662_init_verbs,
16946                                 alc663_two_hp_amic_m1_init_verbs },
16947                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16948                 .hp_nid = 0x03,
16949                 .dac_nids = alc662_dac_nids,
16950                 .dig_out_nid = ALC662_DIGOUT_NID,
16951                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16952                 .channel_mode = alc662_3ST_2ch_modes,
16953                 .input_mux = &alc662_eeepc_capture_source,
16954                 .unsol_event = alc663_mode3_unsol_event,
16955                 .init_hook = alc663_mode3_inithook,
16956         },
16957         [ALC663_ASUS_MODE4] = {
16958                 .mixers = { alc663_asus_21jd_clfe_mixer },
16959                 .cap_mixer = alc662_auto_capture_mixer,
16960                 .init_verbs = { alc662_init_verbs,
16961                                 alc663_21jd_amic_init_verbs},
16962                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16963                 .hp_nid = 0x03,
16964                 .dac_nids = alc662_dac_nids,
16965                 .dig_out_nid = ALC662_DIGOUT_NID,
16966                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16967                 .channel_mode = alc662_3ST_2ch_modes,
16968                 .input_mux = &alc662_eeepc_capture_source,
16969                 .unsol_event = alc663_mode4_unsol_event,
16970                 .init_hook = alc663_mode4_inithook,
16971         },
16972         [ALC663_ASUS_MODE5] = {
16973                 .mixers = { alc663_asus_15jd_clfe_mixer },
16974                 .cap_mixer = alc662_auto_capture_mixer,
16975                 .init_verbs = { alc662_init_verbs,
16976                                 alc663_15jd_amic_init_verbs },
16977                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16978                 .hp_nid = 0x03,
16979                 .dac_nids = alc662_dac_nids,
16980                 .dig_out_nid = ALC662_DIGOUT_NID,
16981                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16982                 .channel_mode = alc662_3ST_2ch_modes,
16983                 .input_mux = &alc662_eeepc_capture_source,
16984                 .unsol_event = alc663_mode5_unsol_event,
16985                 .init_hook = alc663_mode5_inithook,
16986         },
16987         [ALC663_ASUS_MODE6] = {
16988                 .mixers = { alc663_two_hp_m2_mixer },
16989                 .cap_mixer = alc662_auto_capture_mixer,
16990                 .init_verbs = { alc662_init_verbs,
16991                                 alc663_two_hp_amic_m2_init_verbs },
16992                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16993                 .hp_nid = 0x03,
16994                 .dac_nids = alc662_dac_nids,
16995                 .dig_out_nid = ALC662_DIGOUT_NID,
16996                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16997                 .channel_mode = alc662_3ST_2ch_modes,
16998                 .input_mux = &alc662_eeepc_capture_source,
16999                 .unsol_event = alc663_mode6_unsol_event,
17000                 .init_hook = alc663_mode6_inithook,
17001         },
17002         [ALC272_DELL] = {
17003                 .mixers = { alc663_m51va_mixer },
17004                 .cap_mixer = alc272_auto_capture_mixer,
17005                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17006                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17007                 .dac_nids = alc662_dac_nids,
17008                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17009                 .adc_nids = alc272_adc_nids,
17010                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17011                 .capsrc_nids = alc272_capsrc_nids,
17012                 .channel_mode = alc662_3ST_2ch_modes,
17013                 .input_mux = &alc663_m51va_capture_source,
17014                 .unsol_event = alc663_m51va_unsol_event,
17015                 .init_hook = alc663_m51va_inithook,
17016         },
17017         [ALC272_DELL_ZM1] = {
17018                 .mixers = { alc663_m51va_mixer },
17019                 .cap_mixer = alc662_auto_capture_mixer,
17020                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17021                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17022                 .dac_nids = alc662_dac_nids,
17023                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17024                 .adc_nids = alc662_adc_nids,
17025                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
17026                 .capsrc_nids = alc662_capsrc_nids,
17027                 .channel_mode = alc662_3ST_2ch_modes,
17028                 .input_mux = &alc663_m51va_capture_source,
17029                 .unsol_event = alc663_m51va_unsol_event,
17030                 .init_hook = alc663_m51va_inithook,
17031         },
17032         [ALC272_SAMSUNG_NC10] = {
17033                 .mixers = { alc272_nc10_mixer },
17034                 .init_verbs = { alc662_init_verbs,
17035                                 alc663_21jd_amic_init_verbs },
17036                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17037                 .dac_nids = alc272_dac_nids,
17038                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17039                 .channel_mode = alc662_3ST_2ch_modes,
17040                 .input_mux = &alc272_nc10_capture_source,
17041                 .unsol_event = alc663_mode4_unsol_event,
17042                 .init_hook = alc663_mode4_inithook,
17043         },
17044 };
17045
17046
17047 /*
17048  * BIOS auto configuration
17049  */
17050
17051 /* add playback controls from the parsed DAC table */
17052 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
17053                                              const struct auto_pin_cfg *cfg)
17054 {
17055         char name[32];
17056         static const char *chname[4] = {
17057                 "Front", "Surround", NULL /*CLFE*/, "Side"
17058         };
17059         hda_nid_t nid;
17060         int i, err;
17061
17062         for (i = 0; i < cfg->line_outs; i++) {
17063                 if (!spec->multiout.dac_nids[i])
17064                         continue;
17065                 nid = alc880_idx_to_dac(i);
17066                 if (i == 2) {
17067                         /* Center/LFE */
17068                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
17069                                           "Center Playback Volume",
17070                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
17071                                                               HDA_OUTPUT));
17072                         if (err < 0)
17073                                 return err;
17074                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
17075                                           "LFE Playback Volume",
17076                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
17077                                                               HDA_OUTPUT));
17078                         if (err < 0)
17079                                 return err;
17080                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
17081                                           "Center Playback Switch",
17082                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
17083                                                               HDA_INPUT));
17084                         if (err < 0)
17085                                 return err;
17086                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
17087                                           "LFE Playback Switch",
17088                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
17089                                                               HDA_INPUT));
17090                         if (err < 0)
17091                                 return err;
17092                 } else {
17093                         sprintf(name, "%s Playback Volume", chname[i]);
17094                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17095                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
17096                                                               HDA_OUTPUT));
17097                         if (err < 0)
17098                                 return err;
17099                         sprintf(name, "%s Playback Switch", chname[i]);
17100                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17101                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
17102                                                     3, 0, HDA_INPUT));
17103                         if (err < 0)
17104                                 return err;
17105                 }
17106         }
17107         return 0;
17108 }
17109
17110 /* add playback controls for speaker and HP outputs */
17111 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
17112                                         const char *pfx)
17113 {
17114         hda_nid_t nid;
17115         int err;
17116         char name[32];
17117
17118         if (!pin)
17119                 return 0;
17120
17121         if (pin == 0x17) {
17122                 /* ALC663 has a mono output pin on 0x17 */
17123                 sprintf(name, "%s Playback Switch", pfx);
17124                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17125                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
17126                 return err;
17127         }
17128
17129         if (alc880_is_fixed_pin(pin)) {
17130                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17131                 /* printk(KERN_DEBUG "DAC nid=%x\n",nid); */
17132                 /* specify the DAC as the extra output */
17133                 if (!spec->multiout.hp_nid)
17134                         spec->multiout.hp_nid = nid;
17135                 else
17136                         spec->multiout.extra_out_nid[0] = nid;
17137                 /* control HP volume/switch on the output mixer amp */
17138                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17139                 sprintf(name, "%s Playback Volume", pfx);
17140                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17141                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
17142                 if (err < 0)
17143                         return err;
17144                 sprintf(name, "%s Playback Switch", pfx);
17145                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
17146                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
17147                 if (err < 0)
17148                         return err;
17149         } else if (alc880_is_multi_pin(pin)) {
17150                 /* set manual connection */
17151                 /* we have only a switch on HP-out PIN */
17152                 sprintf(name, "%s Playback Switch", pfx);
17153                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17154                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17155                 if (err < 0)
17156                         return err;
17157         }
17158         return 0;
17159 }
17160
17161 /* return the index of the src widget from the connection list of the nid.
17162  * return -1 if not found
17163  */
17164 static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
17165                                 hda_nid_t src)
17166 {
17167         hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
17168         int i, conns;
17169
17170         conns = snd_hda_get_connections(codec, nid, conn_list,
17171                                         ARRAY_SIZE(conn_list));
17172         if (conns < 0)
17173                 return -1;
17174         for (i = 0; i < conns; i++)
17175                 if (conn_list[i] == src)
17176                         return i;
17177         return -1;
17178 }
17179
17180 static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
17181 {
17182         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
17183         return (pincap & AC_PINCAP_IN) != 0;
17184 }
17185
17186 /* create playback/capture controls for input pins */
17187 static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec,
17188                                                 const struct auto_pin_cfg *cfg)
17189 {
17190         struct alc_spec *spec = codec->spec;
17191         struct hda_input_mux *imux = &spec->private_imux[0];
17192         int i, err, idx;
17193
17194         for (i = 0; i < AUTO_PIN_LAST; i++) {
17195                 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
17196                         idx = alc662_input_pin_idx(codec, 0x0b,
17197                                                    cfg->input_pins[i]);
17198                         if (idx >= 0) {
17199                                 err = new_analog_input(spec, cfg->input_pins[i],
17200                                                        auto_pin_cfg_labels[i],
17201                                                        idx, 0x0b);
17202                                 if (err < 0)
17203                                         return err;
17204                         }
17205                         idx = alc662_input_pin_idx(codec, 0x22,
17206                                                    cfg->input_pins[i]);
17207                         if (idx >= 0) {
17208                                 imux->items[imux->num_items].label =
17209                                         auto_pin_cfg_labels[i];
17210                                 imux->items[imux->num_items].index = idx;
17211                                 imux->num_items++;
17212                         }
17213                 }
17214         }
17215         return 0;
17216 }
17217
17218 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17219                                               hda_nid_t nid, int pin_type,
17220                                               int dac_idx)
17221 {
17222         alc_set_pin_output(codec, nid, pin_type);
17223         /* need the manual connection? */
17224         if (alc880_is_multi_pin(nid)) {
17225                 struct alc_spec *spec = codec->spec;
17226                 int idx = alc880_multi_pin_idx(nid);
17227                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
17228                                     AC_VERB_SET_CONNECT_SEL,
17229                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
17230         }
17231 }
17232
17233 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17234 {
17235         struct alc_spec *spec = codec->spec;
17236         int i;
17237
17238         for (i = 0; i <= HDA_SIDE; i++) {
17239                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17240                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
17241                 if (nid)
17242                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17243                                                           i);
17244         }
17245 }
17246
17247 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17248 {
17249         struct alc_spec *spec = codec->spec;
17250         hda_nid_t pin;
17251
17252         pin = spec->autocfg.hp_pins[0];
17253         if (pin) /* connect to front */
17254                 /* use dac 0 */
17255                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
17256         pin = spec->autocfg.speaker_pins[0];
17257         if (pin)
17258                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
17259 }
17260
17261 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17262
17263 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17264 {
17265         struct alc_spec *spec = codec->spec;
17266         int i;
17267
17268         for (i = 0; i < AUTO_PIN_LAST; i++) {
17269                 hda_nid_t nid = spec->autocfg.input_pins[i];
17270                 if (alc662_is_input_pin(codec, nid)) {
17271                         alc_set_input_pin(codec, nid, i);
17272                         if (nid != ALC662_PIN_CD_NID &&
17273                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17274                                 snd_hda_codec_write(codec, nid, 0,
17275                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17276                                                     AMP_OUT_MUTE);
17277                 }
17278         }
17279 }
17280
17281 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17282
17283 static int alc662_parse_auto_config(struct hda_codec *codec)
17284 {
17285         struct alc_spec *spec = codec->spec;
17286         int err;
17287         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17288
17289         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17290                                            alc662_ignore);
17291         if (err < 0)
17292                 return err;
17293         if (!spec->autocfg.line_outs)
17294                 return 0; /* can't find valid BIOS pin config */
17295
17296         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
17297         if (err < 0)
17298                 return err;
17299         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
17300         if (err < 0)
17301                 return err;
17302         err = alc662_auto_create_extra_out(spec,
17303                                            spec->autocfg.speaker_pins[0],
17304                                            "Speaker");
17305         if (err < 0)
17306                 return err;
17307         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
17308                                            "Headphone");
17309         if (err < 0)
17310                 return err;
17311         err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg);
17312         if (err < 0)
17313                 return err;
17314
17315         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17316
17317         if (spec->autocfg.dig_outs)
17318                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17319
17320         if (spec->kctls.list)
17321                 add_mixer(spec, spec->kctls.list);
17322
17323         spec->num_mux_defs = 1;
17324         spec->input_mux = &spec->private_imux[0];
17325
17326         add_verb(spec, alc662_auto_init_verbs);
17327         if (codec->vendor_id == 0x10ec0663)
17328                 add_verb(spec, alc663_auto_init_verbs);
17329
17330         err = alc_auto_add_mic_boost(codec);
17331         if (err < 0)
17332                 return err;
17333
17334         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17335
17336         return 1;
17337 }
17338
17339 /* additional initialization for auto-configuration model */
17340 static void alc662_auto_init(struct hda_codec *codec)
17341 {
17342         struct alc_spec *spec = codec->spec;
17343         alc662_auto_init_multi_out(codec);
17344         alc662_auto_init_hp_out(codec);
17345         alc662_auto_init_analog_input(codec);
17346         alc662_auto_init_input_src(codec);
17347         if (spec->unsol_event)
17348                 alc_inithook(codec);
17349 }
17350
17351 static int patch_alc662(struct hda_codec *codec)
17352 {
17353         struct alc_spec *spec;
17354         int err, board_config;
17355
17356         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17357         if (!spec)
17358                 return -ENOMEM;
17359
17360         codec->spec = spec;
17361
17362         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17363
17364         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17365                                                   alc662_models,
17366                                                   alc662_cfg_tbl);
17367         if (board_config < 0) {
17368                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
17369                        "trying auto-probe from BIOS...\n", codec->chip_name);
17370                 board_config = ALC662_AUTO;
17371         }
17372
17373         if (board_config == ALC662_AUTO) {
17374                 /* automatic parse from the BIOS config */
17375                 err = alc662_parse_auto_config(codec);
17376                 if (err < 0) {
17377                         alc_free(codec);
17378                         return err;
17379                 } else if (!err) {
17380                         printk(KERN_INFO
17381                                "hda_codec: Cannot set up configuration "
17382                                "from BIOS.  Using base mode...\n");
17383                         board_config = ALC662_3ST_2ch_DIG;
17384                 }
17385         }
17386
17387         err = snd_hda_attach_beep_device(codec, 0x1);
17388         if (err < 0) {
17389                 alc_free(codec);
17390                 return err;
17391         }
17392
17393         if (board_config != ALC662_AUTO)
17394                 setup_preset(spec, &alc662_presets[board_config]);
17395
17396         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17397         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17398
17399         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17400         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17401
17402         spec->adc_nids = alc662_adc_nids;
17403         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17404         spec->capsrc_nids = alc662_capsrc_nids;
17405         spec->capture_style = CAPT_MIX;
17406
17407         if (!spec->cap_mixer)
17408                 set_capture_mixer(spec);
17409         if (codec->vendor_id == 0x10ec0662)
17410                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17411         else
17412                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17413
17414         spec->vmaster_nid = 0x02;
17415
17416         codec->patch_ops = alc_patch_ops;
17417         if (board_config == ALC662_AUTO)
17418                 spec->init_hook = alc662_auto_init;
17419 #ifdef CONFIG_SND_HDA_POWER_SAVE
17420         if (!spec->loopback.amplist)
17421                 spec->loopback.amplist = alc662_loopbacks;
17422 #endif
17423         codec->proc_widget_hook = print_realtek_coef;
17424
17425         return 0;
17426 }
17427
17428 /*
17429  * patch entries
17430  */
17431 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17432         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17433         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17434         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17435         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17436         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17437         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17438         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17439           .patch = patch_alc861 },
17440         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17441         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17442         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17443         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17444           .patch = patch_alc883 },
17445         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17446           .patch = patch_alc662 },
17447         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17448         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17449         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17450         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
17451         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17452           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17453         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17454           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17455         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17456         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
17457         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17458           .patch = patch_alc883 },
17459         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
17460         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
17461         {} /* terminator */
17462 };
17463
17464 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17465
17466 MODULE_LICENSE("GPL");
17467 MODULE_DESCRIPTION("Realtek HD-audio codec");
17468
17469 static struct hda_codec_preset_list realtek_list = {
17470         .preset = snd_hda_preset_realtek,
17471         .owner = THIS_MODULE,
17472 };
17473
17474 static int __init patch_realtek_init(void)
17475 {
17476         return snd_hda_add_codec_preset(&realtek_list);
17477 }
17478
17479 static void __exit patch_realtek_exit(void)
17480 {
17481         snd_hda_delete_codec_preset(&realtek_list);
17482 }
17483
17484 module_init(patch_realtek_init)
17485 module_exit(patch_realtek_exit)