ALSA: hda - Clean up name string creation in patch_realtek.c
[cascardo/linux.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_TARGA_8ch_DIG,
218         ALC883_ACER,
219         ALC883_ACER_ASPIRE,
220         ALC888_ACER_ASPIRE_4930G,
221         ALC888_ACER_ASPIRE_6530G,
222         ALC888_ACER_ASPIRE_8930G,
223         ALC888_ACER_ASPIRE_7730G,
224         ALC883_MEDION,
225         ALC883_MEDION_MD2,
226         ALC883_LAPTOP_EAPD,
227         ALC883_LENOVO_101E_2ch,
228         ALC883_LENOVO_NB0763,
229         ALC888_LENOVO_MS7195_DIG,
230         ALC888_LENOVO_SKY,
231         ALC883_HAIER_W66,
232         ALC888_3ST_HP,
233         ALC888_6ST_DELL,
234         ALC883_MITAC,
235         ALC883_CLEVO_M540R,
236         ALC883_CLEVO_M720,
237         ALC883_FUJITSU_PI2515,
238         ALC888_FUJITSU_XA3530,
239         ALC883_3ST_6ch_INTEL,
240         ALC889A_INTEL,
241         ALC889_INTEL,
242         ALC888_ASUS_M90V,
243         ALC888_ASUS_EEE1601,
244         ALC889A_MB31,
245         ALC1200_ASUS_P5Q,
246         ALC883_SONY_VAIO_TT,
247         ALC882_AUTO,
248         ALC882_MODEL_LAST,
249 };
250
251 /* for GPIO Poll */
252 #define GPIO_MASK       0x03
253
254 /* extra amp-initialization sequence types */
255 enum {
256         ALC_INIT_NONE,
257         ALC_INIT_DEFAULT,
258         ALC_INIT_GPIO1,
259         ALC_INIT_GPIO2,
260         ALC_INIT_GPIO3,
261 };
262
263 struct alc_mic_route {
264         hda_nid_t pin;
265         unsigned char mux_idx;
266         unsigned char amix_idx;
267 };
268
269 #define MUX_IDX_UNDEF   ((unsigned char)-1)
270
271 struct alc_spec {
272         /* codec parameterization */
273         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
274         unsigned int num_mixers;
275         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
276         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
277
278         const struct hda_verb *init_verbs[5];   /* initialization verbs
279                                                  * don't forget NULL
280                                                  * termination!
281                                                  */
282         unsigned int num_init_verbs;
283
284         char stream_name_analog[32];    /* analog PCM stream */
285         struct hda_pcm_stream *stream_analog_playback;
286         struct hda_pcm_stream *stream_analog_capture;
287         struct hda_pcm_stream *stream_analog_alt_playback;
288         struct hda_pcm_stream *stream_analog_alt_capture;
289
290         char stream_name_digital[32];   /* digital PCM stream */
291         struct hda_pcm_stream *stream_digital_playback;
292         struct hda_pcm_stream *stream_digital_capture;
293
294         /* playback */
295         struct hda_multi_out multiout;  /* playback set-up
296                                          * max_channels, dacs must be set
297                                          * dig_out_nid and hp_nid are optional
298                                          */
299         hda_nid_t alt_dac_nid;
300         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
301         int dig_out_type;
302
303         /* capture */
304         unsigned int num_adc_nids;
305         hda_nid_t *adc_nids;
306         hda_nid_t *capsrc_nids;
307         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
308
309         /* capture source */
310         unsigned int num_mux_defs;
311         const struct hda_input_mux *input_mux;
312         unsigned int cur_mux[3];
313         struct alc_mic_route ext_mic;
314         struct alc_mic_route int_mic;
315
316         /* channel model */
317         const struct hda_channel_mode *channel_mode;
318         int num_channel_mode;
319         int need_dac_fix;
320         int const_channel_count;
321         int ext_channel_count;
322
323         /* PCM information */
324         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
325
326         /* dynamic controls, init_verbs and input_mux */
327         struct auto_pin_cfg autocfg;
328         struct snd_array kctls;
329         struct hda_input_mux private_imux[3];
330         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
331         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
332         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
333
334         /* hooks */
335         void (*init_hook)(struct hda_codec *codec);
336         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
337
338         /* for pin sensing */
339         unsigned int sense_updated: 1;
340         unsigned int jack_present: 1;
341         unsigned int master_sw: 1;
342         unsigned int auto_mic:1;
343
344         /* other flags */
345         unsigned int no_analog :1; /* digital I/O only */
346         int init_amp;
347
348         /* for virtual master */
349         hda_nid_t vmaster_nid;
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_loopback_check loopback;
352 #endif
353
354         /* for PLL fix */
355         hda_nid_t pll_nid;
356         unsigned int pll_coef_idx, pll_coef_bit;
357 };
358
359 /*
360  * configuration template - to be copied to the spec instance
361  */
362 struct alc_config_preset {
363         struct snd_kcontrol_new *mixers[5]; /* should be identical size
364                                              * with spec
365                                              */
366         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
367         const struct hda_verb *init_verbs[5];
368         unsigned int num_dacs;
369         hda_nid_t *dac_nids;
370         hda_nid_t dig_out_nid;          /* optional */
371         hda_nid_t hp_nid;               /* optional */
372         hda_nid_t *slave_dig_outs;
373         unsigned int num_adc_nids;
374         hda_nid_t *adc_nids;
375         hda_nid_t *capsrc_nids;
376         hda_nid_t dig_in_nid;
377         unsigned int num_channel_mode;
378         const struct hda_channel_mode *channel_mode;
379         int need_dac_fix;
380         int const_channel_count;
381         unsigned int num_mux_defs;
382         const struct hda_input_mux *input_mux;
383         void (*unsol_event)(struct hda_codec *, unsigned int);
384         void (*setup)(struct hda_codec *);
385         void (*init_hook)(struct hda_codec *);
386 #ifdef CONFIG_SND_HDA_POWER_SAVE
387         struct hda_amp_list *loopbacks;
388 #endif
389 };
390
391
392 /*
393  * input MUX handling
394  */
395 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
396                              struct snd_ctl_elem_info *uinfo)
397 {
398         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399         struct alc_spec *spec = codec->spec;
400         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
401         if (mux_idx >= spec->num_mux_defs)
402                 mux_idx = 0;
403         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
404 }
405
406 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
407                             struct snd_ctl_elem_value *ucontrol)
408 {
409         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410         struct alc_spec *spec = codec->spec;
411         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412
413         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
414         return 0;
415 }
416
417 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
418                             struct snd_ctl_elem_value *ucontrol)
419 {
420         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
421         struct alc_spec *spec = codec->spec;
422         const struct hda_input_mux *imux;
423         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
424         unsigned int mux_idx;
425         hda_nid_t nid = spec->capsrc_nids ?
426                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
427         unsigned int type;
428
429         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
430         imux = &spec->input_mux[mux_idx];
431
432         type = get_wcaps_type(get_wcaps(codec, nid));
433         if (type == AC_WID_AUD_MIX) {
434                 /* Matrix-mixer style (e.g. ALC882) */
435                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
436                 unsigned int i, idx;
437
438                 idx = ucontrol->value.enumerated.item[0];
439                 if (idx >= imux->num_items)
440                         idx = imux->num_items - 1;
441                 if (*cur_val == idx)
442                         return 0;
443                 for (i = 0; i < imux->num_items; i++) {
444                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
445                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
446                                                  imux->items[i].index,
447                                                  HDA_AMP_MUTE, v);
448                 }
449                 *cur_val = idx;
450                 return 1;
451         } else {
452                 /* MUX style (e.g. ALC880) */
453                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
454                                              &spec->cur_mux[adc_idx]);
455         }
456 }
457
458 /*
459  * channel mode setting
460  */
461 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
462                             struct snd_ctl_elem_info *uinfo)
463 {
464         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465         struct alc_spec *spec = codec->spec;
466         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
467                                     spec->num_channel_mode);
468 }
469
470 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
471                            struct snd_ctl_elem_value *ucontrol)
472 {
473         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474         struct alc_spec *spec = codec->spec;
475         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
476                                    spec->num_channel_mode,
477                                    spec->ext_channel_count);
478 }
479
480 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
481                            struct snd_ctl_elem_value *ucontrol)
482 {
483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
484         struct alc_spec *spec = codec->spec;
485         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
486                                       spec->num_channel_mode,
487                                       &spec->ext_channel_count);
488         if (err >= 0 && !spec->const_channel_count) {
489                 spec->multiout.max_channels = spec->ext_channel_count;
490                 if (spec->need_dac_fix)
491                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
492         }
493         return err;
494 }
495
496 /*
497  * Control the mode of pin widget settings via the mixer.  "pc" is used
498  * instead of "%" to avoid consequences of accidently treating the % as
499  * being part of a format specifier.  Maximum allowed length of a value is
500  * 63 characters plus NULL terminator.
501  *
502  * Note: some retasking pin complexes seem to ignore requests for input
503  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
504  * are requested.  Therefore order this list so that this behaviour will not
505  * cause problems when mixer clients move through the enum sequentially.
506  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
507  * March 2006.
508  */
509 static char *alc_pin_mode_names[] = {
510         "Mic 50pc bias", "Mic 80pc bias",
511         "Line in", "Line out", "Headphone out",
512 };
513 static unsigned char alc_pin_mode_values[] = {
514         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
515 };
516 /* The control can present all 5 options, or it can limit the options based
517  * in the pin being assumed to be exclusively an input or an output pin.  In
518  * addition, "input" pins may or may not process the mic bias option
519  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
520  * accept requests for bias as of chip versions up to March 2006) and/or
521  * wiring in the computer.
522  */
523 #define ALC_PIN_DIR_IN              0x00
524 #define ALC_PIN_DIR_OUT             0x01
525 #define ALC_PIN_DIR_INOUT           0x02
526 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
527 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
528
529 /* Info about the pin modes supported by the different pin direction modes.
530  * For each direction the minimum and maximum values are given.
531  */
532 static signed char alc_pin_mode_dir_info[5][2] = {
533         { 0, 2 },    /* ALC_PIN_DIR_IN */
534         { 3, 4 },    /* ALC_PIN_DIR_OUT */
535         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
536         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
537         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
538 };
539 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
540 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
541 #define alc_pin_mode_n_items(_dir) \
542         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
543
544 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
545                              struct snd_ctl_elem_info *uinfo)
546 {
547         unsigned int item_num = uinfo->value.enumerated.item;
548         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
549
550         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
551         uinfo->count = 1;
552         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
553
554         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
555                 item_num = alc_pin_mode_min(dir);
556         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
557         return 0;
558 }
559
560 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
561                             struct snd_ctl_elem_value *ucontrol)
562 {
563         unsigned int i;
564         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565         hda_nid_t nid = kcontrol->private_value & 0xffff;
566         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
567         long *valp = ucontrol->value.integer.value;
568         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
569                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
570                                                  0x00);
571
572         /* Find enumerated value for current pinctl setting */
573         i = alc_pin_mode_min(dir);
574         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
575                 i++;
576         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
577         return 0;
578 }
579
580 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
581                             struct snd_ctl_elem_value *ucontrol)
582 {
583         signed int change;
584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585         hda_nid_t nid = kcontrol->private_value & 0xffff;
586         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
587         long val = *ucontrol->value.integer.value;
588         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
589                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
590                                                  0x00);
591
592         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
593                 val = alc_pin_mode_min(dir);
594
595         change = pinctl != alc_pin_mode_values[val];
596         if (change) {
597                 /* Set pin mode to that requested */
598                 snd_hda_codec_write_cache(codec, nid, 0,
599                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
600                                           alc_pin_mode_values[val]);
601
602                 /* Also enable the retasking pin's input/output as required
603                  * for the requested pin mode.  Enum values of 2 or less are
604                  * input modes.
605                  *
606                  * Dynamically switching the input/output buffers probably
607                  * reduces noise slightly (particularly on input) so we'll
608                  * do it.  However, having both input and output buffers
609                  * enabled simultaneously doesn't seem to be problematic if
610                  * this turns out to be necessary in the future.
611                  */
612                 if (val <= 2) {
613                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
614                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
615                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
616                                                  HDA_AMP_MUTE, 0);
617                 } else {
618                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
619                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
620                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
621                                                  HDA_AMP_MUTE, 0);
622                 }
623         }
624         return change;
625 }
626
627 #define ALC_PIN_MODE(xname, nid, dir) \
628         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
629           .info = alc_pin_mode_info, \
630           .get = alc_pin_mode_get, \
631           .put = alc_pin_mode_put, \
632           .private_value = nid | (dir<<16) }
633
634 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
635  * together using a mask with more than one bit set.  This control is
636  * currently used only by the ALC260 test model.  At this stage they are not
637  * needed for any "production" models.
638  */
639 #ifdef CONFIG_SND_DEBUG
640 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
641
642 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
643                              struct snd_ctl_elem_value *ucontrol)
644 {
645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646         hda_nid_t nid = kcontrol->private_value & 0xffff;
647         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
648         long *valp = ucontrol->value.integer.value;
649         unsigned int val = snd_hda_codec_read(codec, nid, 0,
650                                               AC_VERB_GET_GPIO_DATA, 0x00);
651
652         *valp = (val & mask) != 0;
653         return 0;
654 }
655 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
656                              struct snd_ctl_elem_value *ucontrol)
657 {
658         signed int change;
659         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660         hda_nid_t nid = kcontrol->private_value & 0xffff;
661         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
662         long val = *ucontrol->value.integer.value;
663         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
664                                                     AC_VERB_GET_GPIO_DATA,
665                                                     0x00);
666
667         /* Set/unset the masked GPIO bit(s) as needed */
668         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
669         if (val == 0)
670                 gpio_data &= ~mask;
671         else
672                 gpio_data |= mask;
673         snd_hda_codec_write_cache(codec, nid, 0,
674                                   AC_VERB_SET_GPIO_DATA, gpio_data);
675
676         return change;
677 }
678 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
679         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
680           .info = alc_gpio_data_info, \
681           .get = alc_gpio_data_get, \
682           .put = alc_gpio_data_put, \
683           .private_value = nid | (mask<<16) }
684 #endif   /* CONFIG_SND_DEBUG */
685
686 /* A switch control to allow the enabling of the digital IO pins on the
687  * ALC260.  This is incredibly simplistic; the intention of this control is
688  * to provide something in the test model allowing digital outputs to be
689  * identified if present.  If models are found which can utilise these
690  * outputs a more complete mixer control can be devised for those models if
691  * necessary.
692  */
693 #ifdef CONFIG_SND_DEBUG
694 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
695
696 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
697                               struct snd_ctl_elem_value *ucontrol)
698 {
699         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700         hda_nid_t nid = kcontrol->private_value & 0xffff;
701         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
702         long *valp = ucontrol->value.integer.value;
703         unsigned int val = snd_hda_codec_read(codec, nid, 0,
704                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
705
706         *valp = (val & mask) != 0;
707         return 0;
708 }
709 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
710                               struct snd_ctl_elem_value *ucontrol)
711 {
712         signed int change;
713         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714         hda_nid_t nid = kcontrol->private_value & 0xffff;
715         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
716         long val = *ucontrol->value.integer.value;
717         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
718                                                     AC_VERB_GET_DIGI_CONVERT_1,
719                                                     0x00);
720
721         /* Set/unset the masked control bit(s) as needed */
722         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
723         if (val==0)
724                 ctrl_data &= ~mask;
725         else
726                 ctrl_data |= mask;
727         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
728                                   ctrl_data);
729
730         return change;
731 }
732 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
733         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
734           .info = alc_spdif_ctrl_info, \
735           .get = alc_spdif_ctrl_get, \
736           .put = alc_spdif_ctrl_put, \
737           .private_value = nid | (mask<<16) }
738 #endif   /* CONFIG_SND_DEBUG */
739
740 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
741  * Again, this is only used in the ALC26x test models to help identify when
742  * the EAPD line must be asserted for features to work.
743  */
744 #ifdef CONFIG_SND_DEBUG
745 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
746
747 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
748                               struct snd_ctl_elem_value *ucontrol)
749 {
750         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751         hda_nid_t nid = kcontrol->private_value & 0xffff;
752         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
753         long *valp = ucontrol->value.integer.value;
754         unsigned int val = snd_hda_codec_read(codec, nid, 0,
755                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
756
757         *valp = (val & mask) != 0;
758         return 0;
759 }
760
761 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
762                               struct snd_ctl_elem_value *ucontrol)
763 {
764         int change;
765         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766         hda_nid_t nid = kcontrol->private_value & 0xffff;
767         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
768         long val = *ucontrol->value.integer.value;
769         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
770                                                     AC_VERB_GET_EAPD_BTLENABLE,
771                                                     0x00);
772
773         /* Set/unset the masked control bit(s) as needed */
774         change = (!val ? 0 : mask) != (ctrl_data & mask);
775         if (!val)
776                 ctrl_data &= ~mask;
777         else
778                 ctrl_data |= mask;
779         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
780                                   ctrl_data);
781
782         return change;
783 }
784
785 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
786         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
787           .info = alc_eapd_ctrl_info, \
788           .get = alc_eapd_ctrl_get, \
789           .put = alc_eapd_ctrl_put, \
790           .private_value = nid | (mask<<16) }
791 #endif   /* CONFIG_SND_DEBUG */
792
793 /*
794  * set up the input pin config (depending on the given auto-pin type)
795  */
796 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
797                               int auto_pin_type)
798 {
799         unsigned int val = PIN_IN;
800
801         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
802                 unsigned int pincap;
803                 pincap = snd_hda_query_pin_caps(codec, nid);
804                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
805                 if (pincap & AC_PINCAP_VREF_80)
806                         val = PIN_VREF80;
807                 else if (pincap & AC_PINCAP_VREF_50)
808                         val = PIN_VREF50;
809                 else if (pincap & AC_PINCAP_VREF_100)
810                         val = PIN_VREF100;
811                 else if (pincap & AC_PINCAP_VREF_GRD)
812                         val = PIN_VREFGRD;
813         }
814         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
815 }
816
817 /*
818  */
819 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
820 {
821         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
822                 return;
823         spec->mixers[spec->num_mixers++] = mix;
824 }
825
826 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
827 {
828         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
829                 return;
830         spec->init_verbs[spec->num_init_verbs++] = verb;
831 }
832
833 #ifdef CONFIG_PROC_FS
834 /*
835  * hook for proc
836  */
837 static void print_realtek_coef(struct snd_info_buffer *buffer,
838                                struct hda_codec *codec, hda_nid_t nid)
839 {
840         int coeff;
841
842         if (nid != 0x20)
843                 return;
844         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
845         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
846         coeff = snd_hda_codec_read(codec, nid, 0,
847                                    AC_VERB_GET_COEF_INDEX, 0);
848         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
849 }
850 #else
851 #define print_realtek_coef      NULL
852 #endif
853
854 /*
855  * set up from the preset table
856  */
857 static void setup_preset(struct hda_codec *codec,
858                          const struct alc_config_preset *preset)
859 {
860         struct alc_spec *spec = codec->spec;
861         int i;
862
863         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
864                 add_mixer(spec, preset->mixers[i]);
865         spec->cap_mixer = preset->cap_mixer;
866         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
867              i++)
868                 add_verb(spec, preset->init_verbs[i]);
869
870         spec->channel_mode = preset->channel_mode;
871         spec->num_channel_mode = preset->num_channel_mode;
872         spec->need_dac_fix = preset->need_dac_fix;
873         spec->const_channel_count = preset->const_channel_count;
874
875         if (preset->const_channel_count)
876                 spec->multiout.max_channels = preset->const_channel_count;
877         else
878                 spec->multiout.max_channels = spec->channel_mode[0].channels;
879         spec->ext_channel_count = spec->channel_mode[0].channels;
880
881         spec->multiout.num_dacs = preset->num_dacs;
882         spec->multiout.dac_nids = preset->dac_nids;
883         spec->multiout.dig_out_nid = preset->dig_out_nid;
884         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
885         spec->multiout.hp_nid = preset->hp_nid;
886
887         spec->num_mux_defs = preset->num_mux_defs;
888         if (!spec->num_mux_defs)
889                 spec->num_mux_defs = 1;
890         spec->input_mux = preset->input_mux;
891
892         spec->num_adc_nids = preset->num_adc_nids;
893         spec->adc_nids = preset->adc_nids;
894         spec->capsrc_nids = preset->capsrc_nids;
895         spec->dig_in_nid = preset->dig_in_nid;
896
897         spec->unsol_event = preset->unsol_event;
898         spec->init_hook = preset->init_hook;
899 #ifdef CONFIG_SND_HDA_POWER_SAVE
900         spec->loopback.amplist = preset->loopbacks;
901 #endif
902
903         if (preset->setup)
904                 preset->setup(codec);
905 }
906
907 /* Enable GPIO mask and set output */
908 static struct hda_verb alc_gpio1_init_verbs[] = {
909         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
910         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
911         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
912         { }
913 };
914
915 static struct hda_verb alc_gpio2_init_verbs[] = {
916         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
917         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
918         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
919         { }
920 };
921
922 static struct hda_verb alc_gpio3_init_verbs[] = {
923         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
924         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
925         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
926         { }
927 };
928
929 /*
930  * Fix hardware PLL issue
931  * On some codecs, the analog PLL gating control must be off while
932  * the default value is 1.
933  */
934 static void alc_fix_pll(struct hda_codec *codec)
935 {
936         struct alc_spec *spec = codec->spec;
937         unsigned int val;
938
939         if (!spec->pll_nid)
940                 return;
941         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
942                             spec->pll_coef_idx);
943         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
944                                  AC_VERB_GET_PROC_COEF, 0);
945         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
946                             spec->pll_coef_idx);
947         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
948                             val & ~(1 << spec->pll_coef_bit));
949 }
950
951 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
952                              unsigned int coef_idx, unsigned int coef_bit)
953 {
954         struct alc_spec *spec = codec->spec;
955         spec->pll_nid = nid;
956         spec->pll_coef_idx = coef_idx;
957         spec->pll_coef_bit = coef_bit;
958         alc_fix_pll(codec);
959 }
960
961 static void alc_automute_pin(struct hda_codec *codec)
962 {
963         struct alc_spec *spec = codec->spec;
964         unsigned int present, pincap;
965         unsigned int nid = spec->autocfg.hp_pins[0];
966         int i;
967
968         pincap = snd_hda_query_pin_caps(codec, nid);
969         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
970                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
971         present = snd_hda_codec_read(codec, nid, 0,
972                                      AC_VERB_GET_PIN_SENSE, 0);
973         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
974         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
975                 nid = spec->autocfg.speaker_pins[i];
976                 if (!nid)
977                         break;
978                 snd_hda_codec_write(codec, nid, 0,
979                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
980                                     spec->jack_present ? 0 : PIN_OUT);
981         }
982 }
983
984 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
985                                 hda_nid_t nid)
986 {
987         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
988         int i, nums;
989
990         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
991         for (i = 0; i < nums; i++)
992                 if (conn[i] == nid)
993                         return i;
994         return -1;
995 }
996
997 static void alc_mic_automute(struct hda_codec *codec)
998 {
999         struct alc_spec *spec = codec->spec;
1000         struct alc_mic_route *dead, *alive;
1001         unsigned int present, type;
1002         hda_nid_t cap_nid;
1003
1004         if (!spec->auto_mic)
1005                 return;
1006         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1007                 return;
1008         if (snd_BUG_ON(!spec->adc_nids))
1009                 return;
1010
1011         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1012
1013         present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
1014                                      AC_VERB_GET_PIN_SENSE, 0);
1015         present &= AC_PINSENSE_PRESENCE;
1016         if (present) {
1017                 alive = &spec->ext_mic;
1018                 dead = &spec->int_mic;
1019         } else {
1020                 alive = &spec->int_mic;
1021                 dead = &spec->ext_mic;
1022         }
1023
1024         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1025         if (type == AC_WID_AUD_MIX) {
1026                 /* Matrix-mixer style (e.g. ALC882) */
1027                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1028                                          alive->mux_idx,
1029                                          HDA_AMP_MUTE, 0);
1030                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1031                                          dead->mux_idx,
1032                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1033         } else {
1034                 /* MUX style (e.g. ALC880) */
1035                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1036                                           AC_VERB_SET_CONNECT_SEL,
1037                                           alive->mux_idx);
1038         }
1039
1040         /* FIXME: analog mixer */
1041 }
1042
1043 /* unsolicited event for HP jack sensing */
1044 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1045 {
1046         if (codec->vendor_id == 0x10ec0880)
1047                 res >>= 28;
1048         else
1049                 res >>= 26;
1050         switch (res) {
1051         case ALC880_HP_EVENT:
1052                 alc_automute_pin(codec);
1053                 break;
1054         case ALC880_MIC_EVENT:
1055                 alc_mic_automute(codec);
1056                 break;
1057         }
1058 }
1059
1060 static void alc_inithook(struct hda_codec *codec)
1061 {
1062         alc_automute_pin(codec);
1063         alc_mic_automute(codec);
1064 }
1065
1066 /* additional initialization for ALC888 variants */
1067 static void alc888_coef_init(struct hda_codec *codec)
1068 {
1069         unsigned int tmp;
1070
1071         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1072         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1073         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1074         if ((tmp & 0xf0) == 0x20)
1075                 /* alc888S-VC */
1076                 snd_hda_codec_read(codec, 0x20, 0,
1077                                    AC_VERB_SET_PROC_COEF, 0x830);
1078          else
1079                  /* alc888-VB */
1080                  snd_hda_codec_read(codec, 0x20, 0,
1081                                     AC_VERB_SET_PROC_COEF, 0x3030);
1082 }
1083
1084 static void alc889_coef_init(struct hda_codec *codec)
1085 {
1086         unsigned int tmp;
1087
1088         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1089         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1090         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1091         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1092 }
1093
1094 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1095 {
1096         unsigned int tmp;
1097
1098         switch (type) {
1099         case ALC_INIT_GPIO1:
1100                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1101                 break;
1102         case ALC_INIT_GPIO2:
1103                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1104                 break;
1105         case ALC_INIT_GPIO3:
1106                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1107                 break;
1108         case ALC_INIT_DEFAULT:
1109                 switch (codec->vendor_id) {
1110                 case 0x10ec0260:
1111                         snd_hda_codec_write(codec, 0x0f, 0,
1112                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1113                         snd_hda_codec_write(codec, 0x10, 0,
1114                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1115                         break;
1116                 case 0x10ec0262:
1117                 case 0x10ec0267:
1118                 case 0x10ec0268:
1119                 case 0x10ec0269:
1120                 case 0x10ec0272:
1121                 case 0x10ec0660:
1122                 case 0x10ec0662:
1123                 case 0x10ec0663:
1124                 case 0x10ec0862:
1125                 case 0x10ec0889:
1126                         snd_hda_codec_write(codec, 0x14, 0,
1127                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1128                         snd_hda_codec_write(codec, 0x15, 0,
1129                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1130                         break;
1131                 }
1132                 switch (codec->vendor_id) {
1133                 case 0x10ec0260:
1134                         snd_hda_codec_write(codec, 0x1a, 0,
1135                                             AC_VERB_SET_COEF_INDEX, 7);
1136                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1137                                                  AC_VERB_GET_PROC_COEF, 0);
1138                         snd_hda_codec_write(codec, 0x1a, 0,
1139                                             AC_VERB_SET_COEF_INDEX, 7);
1140                         snd_hda_codec_write(codec, 0x1a, 0,
1141                                             AC_VERB_SET_PROC_COEF,
1142                                             tmp | 0x2010);
1143                         break;
1144                 case 0x10ec0262:
1145                 case 0x10ec0880:
1146                 case 0x10ec0882:
1147                 case 0x10ec0883:
1148                 case 0x10ec0885:
1149                 case 0x10ec0887:
1150                 case 0x10ec0889:
1151                         alc889_coef_init(codec);
1152                         break;
1153                 case 0x10ec0888:
1154                         alc888_coef_init(codec);
1155                         break;
1156                 case 0x10ec0267:
1157                 case 0x10ec0268:
1158                         snd_hda_codec_write(codec, 0x20, 0,
1159                                             AC_VERB_SET_COEF_INDEX, 7);
1160                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1161                                                  AC_VERB_GET_PROC_COEF, 0);
1162                         snd_hda_codec_write(codec, 0x20, 0,
1163                                             AC_VERB_SET_COEF_INDEX, 7);
1164                         snd_hda_codec_write(codec, 0x20, 0,
1165                                             AC_VERB_SET_PROC_COEF,
1166                                             tmp | 0x3000);
1167                         break;
1168                 }
1169                 break;
1170         }
1171 }
1172
1173 static void alc_init_auto_hp(struct hda_codec *codec)
1174 {
1175         struct alc_spec *spec = codec->spec;
1176
1177         if (!spec->autocfg.hp_pins[0])
1178                 return;
1179
1180         if (!spec->autocfg.speaker_pins[0]) {
1181                 if (spec->autocfg.line_out_pins[0] &&
1182                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1183                         spec->autocfg.speaker_pins[0] =
1184                                 spec->autocfg.line_out_pins[0];
1185                 else
1186                         return;
1187         }
1188
1189         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1190                     spec->autocfg.hp_pins[0]);
1191         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1192                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1193                                   AC_USRSP_EN | ALC880_HP_EVENT);
1194         spec->unsol_event = alc_sku_unsol_event;
1195 }
1196
1197 static void alc_init_auto_mic(struct hda_codec *codec)
1198 {
1199         struct alc_spec *spec = codec->spec;
1200         struct auto_pin_cfg *cfg = &spec->autocfg;
1201         hda_nid_t fixed, ext;
1202         int i;
1203
1204         /* there must be only two mic inputs exclusively */
1205         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1206                 if (cfg->input_pins[i])
1207                         return;
1208
1209         fixed = ext = 0;
1210         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1211                 hda_nid_t nid = cfg->input_pins[i];
1212                 unsigned int defcfg;
1213                 if (!nid)
1214                         return;
1215                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1216                 switch (get_defcfg_connect(defcfg)) {
1217                 case AC_JACK_PORT_FIXED:
1218                         if (fixed)
1219                                 return; /* already occupied */
1220                         fixed = nid;
1221                         break;
1222                 case AC_JACK_PORT_COMPLEX:
1223                         if (ext)
1224                                 return; /* already occupied */
1225                         ext = nid;
1226                         break;
1227                 default:
1228                         return; /* invalid entry */
1229                 }
1230         }
1231         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1232                 return; /* no unsol support */
1233         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1234                     ext, fixed);
1235         spec->ext_mic.pin = ext;
1236         spec->int_mic.pin = fixed;
1237         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1238         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1239         spec->auto_mic = 1;
1240         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1241                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1242                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1243         spec->unsol_event = alc_sku_unsol_event;
1244 }
1245
1246 /* check subsystem ID and set up device-specific initialization;
1247  * return 1 if initialized, 0 if invalid SSID
1248  */
1249 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1250  *      31 ~ 16 :       Manufacture ID
1251  *      15 ~ 8  :       SKU ID
1252  *      7  ~ 0  :       Assembly ID
1253  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1254  */
1255 static int alc_subsystem_id(struct hda_codec *codec,
1256                             hda_nid_t porta, hda_nid_t porte,
1257                             hda_nid_t portd)
1258 {
1259         unsigned int ass, tmp, i;
1260         unsigned nid;
1261         struct alc_spec *spec = codec->spec;
1262
1263         ass = codec->subsystem_id & 0xffff;
1264         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1265                 goto do_sku;
1266
1267         /* invalid SSID, check the special NID pin defcfg instead */
1268         /*
1269          * 31~30        : port connectivity
1270          * 29~21        : reserve
1271          * 20           : PCBEEP input
1272          * 19~16        : Check sum (15:1)
1273          * 15~1         : Custom
1274          * 0            : override
1275         */
1276         nid = 0x1d;
1277         if (codec->vendor_id == 0x10ec0260)
1278                 nid = 0x17;
1279         ass = snd_hda_codec_get_pincfg(codec, nid);
1280         snd_printd("realtek: No valid SSID, "
1281                    "checking pincfg 0x%08x for NID 0x%x\n",
1282                    ass, nid);
1283         if (!(ass & 1) && !(ass & 0x100000))
1284                 return 0;
1285         if ((ass >> 30) != 1)   /* no physical connection */
1286                 return 0;
1287
1288         /* check sum */
1289         tmp = 0;
1290         for (i = 1; i < 16; i++) {
1291                 if ((ass >> i) & 1)
1292                         tmp++;
1293         }
1294         if (((ass >> 16) & 0xf) != tmp)
1295                 return 0;
1296 do_sku:
1297         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1298                    ass & 0xffff, codec->vendor_id);
1299         /*
1300          * 0 : override
1301          * 1 :  Swap Jack
1302          * 2 : 0 --> Desktop, 1 --> Laptop
1303          * 3~5 : External Amplifier control
1304          * 7~6 : Reserved
1305         */
1306         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1307         switch (tmp) {
1308         case 1:
1309                 spec->init_amp = ALC_INIT_GPIO1;
1310                 break;
1311         case 3:
1312                 spec->init_amp = ALC_INIT_GPIO2;
1313                 break;
1314         case 7:
1315                 spec->init_amp = ALC_INIT_GPIO3;
1316                 break;
1317         case 5:
1318                 spec->init_amp = ALC_INIT_DEFAULT;
1319                 break;
1320         }
1321
1322         /* is laptop or Desktop and enable the function "Mute internal speaker
1323          * when the external headphone out jack is plugged"
1324          */
1325         if (!(ass & 0x8000))
1326                 return 1;
1327         /*
1328          * 10~8 : Jack location
1329          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1330          * 14~13: Resvered
1331          * 15   : 1 --> enable the function "Mute internal speaker
1332          *              when the external headphone out jack is plugged"
1333          */
1334         if (!spec->autocfg.hp_pins[0]) {
1335                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1336                 if (tmp == 0)
1337                         spec->autocfg.hp_pins[0] = porta;
1338                 else if (tmp == 1)
1339                         spec->autocfg.hp_pins[0] = porte;
1340                 else if (tmp == 2)
1341                         spec->autocfg.hp_pins[0] = portd;
1342                 else
1343                         return 1;
1344         }
1345
1346         alc_init_auto_hp(codec);
1347         alc_init_auto_mic(codec);
1348         return 1;
1349 }
1350
1351 static void alc_ssid_check(struct hda_codec *codec,
1352                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1353 {
1354         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1355                 struct alc_spec *spec = codec->spec;
1356                 snd_printd("realtek: "
1357                            "Enable default setup for auto mode as fallback\n");
1358                 spec->init_amp = ALC_INIT_DEFAULT;
1359                 alc_init_auto_hp(codec);
1360                 alc_init_auto_mic(codec);
1361         }
1362 }
1363
1364 /*
1365  * Fix-up pin default configurations
1366  */
1367
1368 struct alc_pincfg {
1369         hda_nid_t nid;
1370         u32 val;
1371 };
1372
1373 static void alc_fix_pincfg(struct hda_codec *codec,
1374                            const struct snd_pci_quirk *quirk,
1375                            const struct alc_pincfg **pinfix)
1376 {
1377         const struct alc_pincfg *cfg;
1378
1379         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1380         if (!quirk)
1381                 return;
1382
1383         cfg = pinfix[quirk->value];
1384         for (; cfg->nid; cfg++)
1385                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1386 }
1387
1388 /*
1389  * ALC888
1390  */
1391
1392 /*
1393  * 2ch mode
1394  */
1395 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1396 /* Mic-in jack as mic in */
1397         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1398         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1399 /* Line-in jack as Line in */
1400         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1401         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1402 /* Line-Out as Front */
1403         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1404         { } /* end */
1405 };
1406
1407 /*
1408  * 4ch mode
1409  */
1410 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1411 /* Mic-in jack as mic in */
1412         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1413         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1414 /* Line-in jack as Surround */
1415         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1416         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1417 /* Line-Out as Front */
1418         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1419         { } /* end */
1420 };
1421
1422 /*
1423  * 6ch mode
1424  */
1425 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1426 /* Mic-in jack as CLFE */
1427         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1428         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1429 /* Line-in jack as Surround */
1430         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1431         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1432 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1433         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1434         { } /* end */
1435 };
1436
1437 /*
1438  * 8ch mode
1439  */
1440 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1441 /* Mic-in jack as CLFE */
1442         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1443         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1444 /* Line-in jack as Surround */
1445         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1446         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1447 /* Line-Out as Side */
1448         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1449         { } /* end */
1450 };
1451
1452 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1453         { 2, alc888_4ST_ch2_intel_init },
1454         { 4, alc888_4ST_ch4_intel_init },
1455         { 6, alc888_4ST_ch6_intel_init },
1456         { 8, alc888_4ST_ch8_intel_init },
1457 };
1458
1459 /*
1460  * ALC888 Fujitsu Siemens Amillo xa3530
1461  */
1462
1463 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1464 /* Front Mic: set to PIN_IN (empty by default) */
1465         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1466 /* Connect Internal HP to Front */
1467         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1469         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1470 /* Connect Bass HP to Front */
1471         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1472         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1474 /* Connect Line-Out side jack (SPDIF) to Side */
1475         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1476         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1477         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1478 /* Connect Mic jack to CLFE */
1479         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1480         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1481         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1482 /* Connect Line-in jack to Surround */
1483         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1484         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1485         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1486 /* Connect HP out jack to Front */
1487         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1489         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1490 /* Enable unsolicited event for HP jack and Line-out jack */
1491         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1492         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1493         {}
1494 };
1495
1496 static void alc_automute_amp(struct hda_codec *codec)
1497 {
1498         struct alc_spec *spec = codec->spec;
1499         unsigned int val, mute, pincap;
1500         hda_nid_t nid;
1501         int i;
1502
1503         spec->jack_present = 0;
1504         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1505                 nid = spec->autocfg.hp_pins[i];
1506                 if (!nid)
1507                         break;
1508                 pincap = snd_hda_query_pin_caps(codec, nid);
1509                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1510                         snd_hda_codec_read(codec, nid, 0,
1511                                            AC_VERB_SET_PIN_SENSE, 0);
1512                 val = snd_hda_codec_read(codec, nid, 0,
1513                                          AC_VERB_GET_PIN_SENSE, 0);
1514                 if (val & AC_PINSENSE_PRESENCE) {
1515                         spec->jack_present = 1;
1516                         break;
1517                 }
1518         }
1519
1520         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1521         /* Toggle internal speakers muting */
1522         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1523                 nid = spec->autocfg.speaker_pins[i];
1524                 if (!nid)
1525                         break;
1526                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1527                                          HDA_AMP_MUTE, mute);
1528         }
1529 }
1530
1531 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1532                                          unsigned int res)
1533 {
1534         if (codec->vendor_id == 0x10ec0880)
1535                 res >>= 28;
1536         else
1537                 res >>= 26;
1538         if (res == ALC880_HP_EVENT)
1539                 alc_automute_amp(codec);
1540 }
1541
1542 static void alc889_automute_setup(struct hda_codec *codec)
1543 {
1544         struct alc_spec *spec = codec->spec;
1545
1546         spec->autocfg.hp_pins[0] = 0x15;
1547         spec->autocfg.speaker_pins[0] = 0x14;
1548         spec->autocfg.speaker_pins[1] = 0x16;
1549         spec->autocfg.speaker_pins[2] = 0x17;
1550         spec->autocfg.speaker_pins[3] = 0x19;
1551         spec->autocfg.speaker_pins[4] = 0x1a;
1552 }
1553
1554 static void alc889_intel_init_hook(struct hda_codec *codec)
1555 {
1556         alc889_coef_init(codec);
1557         alc_automute_amp(codec);
1558 }
1559
1560 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1561 {
1562         struct alc_spec *spec = codec->spec;
1563
1564         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1565         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1566         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1567         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1568 }
1569
1570 /*
1571  * ALC888 Acer Aspire 4930G model
1572  */
1573
1574 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1575 /* Front Mic: set to PIN_IN (empty by default) */
1576         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1577 /* Unselect Front Mic by default in input mixer 3 */
1578         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1579 /* Enable unsolicited event for HP jack */
1580         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1581 /* Connect Internal HP to front */
1582         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1583         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1584         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1585 /* Connect HP out to front */
1586         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1587         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1588         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1589         { }
1590 };
1591
1592 /*
1593  * ALC888 Acer Aspire 6530G model
1594  */
1595
1596 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1597 /* Bias voltage on for external mic port */
1598         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1599 /* Front Mic: set to PIN_IN (empty by default) */
1600         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1601 /* Unselect Front Mic by default in input mixer 3 */
1602         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1603 /* Enable unsolicited event for HP jack */
1604         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1605 /* Enable speaker output */
1606         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1607         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1608 /* Enable headphone output */
1609         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1610         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1611         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1612         { }
1613 };
1614
1615 /*
1616  * ALC889 Acer Aspire 8930G model
1617  */
1618
1619 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1620 /* Front Mic: set to PIN_IN (empty by default) */
1621         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1622 /* Unselect Front Mic by default in input mixer 3 */
1623         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1624 /* Enable unsolicited event for HP jack */
1625         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1626 /* Connect Internal Front to Front */
1627         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1628         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1629         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1630 /* Connect Internal Rear to Rear */
1631         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1632         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1633         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1634 /* Connect Internal CLFE to CLFE */
1635         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1636         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1637         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1638 /* Connect HP out to Front */
1639         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1640         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1641         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1642 /* Enable all DACs */
1643 /*  DAC DISABLE/MUTE 1? */
1644 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1645         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1646         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1647 /*  DAC DISABLE/MUTE 2? */
1648 /*  some bit here disables the other DACs. Init=0x4900 */
1649         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1650         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1651 /* Enable amplifiers */
1652         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1653         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1654 /* DMIC fix
1655  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1656  * which makes the stereo useless. However, either the mic or the ALC889
1657  * makes the signal become a difference/sum signal instead of standard
1658  * stereo, which is annoying. So instead we flip this bit which makes the
1659  * codec replicate the sum signal to both channels, turning it into a
1660  * normal mono mic.
1661  */
1662 /*  DMIC_CONTROL? Init value = 0x0001 */
1663         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1664         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1665         { }
1666 };
1667
1668 static struct hda_input_mux alc888_2_capture_sources[2] = {
1669         /* Front mic only available on one ADC */
1670         {
1671                 .num_items = 4,
1672                 .items = {
1673                         { "Mic", 0x0 },
1674                         { "Line", 0x2 },
1675                         { "CD", 0x4 },
1676                         { "Front Mic", 0xb },
1677                 },
1678         },
1679         {
1680                 .num_items = 3,
1681                 .items = {
1682                         { "Mic", 0x0 },
1683                         { "Line", 0x2 },
1684                         { "CD", 0x4 },
1685                 },
1686         }
1687 };
1688
1689 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1690         /* Interal mic only available on one ADC */
1691         {
1692                 .num_items = 5,
1693                 .items = {
1694                         { "Ext Mic", 0x0 },
1695                         { "Line In", 0x2 },
1696                         { "CD", 0x4 },
1697                         { "Input Mix", 0xa },
1698                         { "Int Mic", 0xb },
1699                 },
1700         },
1701         {
1702                 .num_items = 4,
1703                 .items = {
1704                         { "Ext Mic", 0x0 },
1705                         { "Line In", 0x2 },
1706                         { "CD", 0x4 },
1707                         { "Input Mix", 0xa },
1708                 },
1709         }
1710 };
1711
1712 static struct hda_input_mux alc889_capture_sources[3] = {
1713         /* Digital mic only available on first "ADC" */
1714         {
1715                 .num_items = 5,
1716                 .items = {
1717                         { "Mic", 0x0 },
1718                         { "Line", 0x2 },
1719                         { "CD", 0x4 },
1720                         { "Front Mic", 0xb },
1721                         { "Input Mix", 0xa },
1722                 },
1723         },
1724         {
1725                 .num_items = 4,
1726                 .items = {
1727                         { "Mic", 0x0 },
1728                         { "Line", 0x2 },
1729                         { "CD", 0x4 },
1730                         { "Input Mix", 0xa },
1731                 },
1732         },
1733         {
1734                 .num_items = 4,
1735                 .items = {
1736                         { "Mic", 0x0 },
1737                         { "Line", 0x2 },
1738                         { "CD", 0x4 },
1739                         { "Input Mix", 0xa },
1740                 },
1741         }
1742 };
1743
1744 static struct snd_kcontrol_new alc888_base_mixer[] = {
1745         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1746         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1747         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1748         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1749         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1750                 HDA_OUTPUT),
1751         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1752         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1753         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1754         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1755         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1756         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1757         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1758         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1759         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1760         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1761         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1762         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1763         { } /* end */
1764 };
1765
1766 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1767 {
1768         struct alc_spec *spec = codec->spec;
1769
1770         spec->autocfg.hp_pins[0] = 0x15;
1771         spec->autocfg.speaker_pins[0] = 0x14;
1772 }
1773
1774 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1775 {
1776         struct alc_spec *spec = codec->spec;
1777
1778         spec->autocfg.hp_pins[0] = 0x15;
1779         spec->autocfg.speaker_pins[0] = 0x14;
1780         spec->autocfg.speaker_pins[1] = 0x16;
1781         spec->autocfg.speaker_pins[2] = 0x17;
1782 }
1783
1784 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1785 {
1786         struct alc_spec *spec = codec->spec;
1787
1788         spec->autocfg.hp_pins[0] = 0x15;
1789         spec->autocfg.speaker_pins[0] = 0x14;
1790         spec->autocfg.speaker_pins[1] = 0x16;
1791         spec->autocfg.speaker_pins[2] = 0x1b;
1792 }
1793
1794 /*
1795  * ALC880 3-stack model
1796  *
1797  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1798  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1799  *                 F-Mic = 0x1b, HP = 0x19
1800  */
1801
1802 static hda_nid_t alc880_dac_nids[4] = {
1803         /* front, rear, clfe, rear_surr */
1804         0x02, 0x05, 0x04, 0x03
1805 };
1806
1807 static hda_nid_t alc880_adc_nids[3] = {
1808         /* ADC0-2 */
1809         0x07, 0x08, 0x09,
1810 };
1811
1812 /* The datasheet says the node 0x07 is connected from inputs,
1813  * but it shows zero connection in the real implementation on some devices.
1814  * Note: this is a 915GAV bug, fixed on 915GLV
1815  */
1816 static hda_nid_t alc880_adc_nids_alt[2] = {
1817         /* ADC1-2 */
1818         0x08, 0x09,
1819 };
1820
1821 #define ALC880_DIGOUT_NID       0x06
1822 #define ALC880_DIGIN_NID        0x0a
1823
1824 static struct hda_input_mux alc880_capture_source = {
1825         .num_items = 4,
1826         .items = {
1827                 { "Mic", 0x0 },
1828                 { "Front Mic", 0x3 },
1829                 { "Line", 0x2 },
1830                 { "CD", 0x4 },
1831         },
1832 };
1833
1834 /* channel source setting (2/6 channel selection for 3-stack) */
1835 /* 2ch mode */
1836 static struct hda_verb alc880_threestack_ch2_init[] = {
1837         /* set line-in to input, mute it */
1838         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1839         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1840         /* set mic-in to input vref 80%, mute it */
1841         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1842         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1843         { } /* end */
1844 };
1845
1846 /* 6ch mode */
1847 static struct hda_verb alc880_threestack_ch6_init[] = {
1848         /* set line-in to output, unmute it */
1849         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1850         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1851         /* set mic-in to output, unmute it */
1852         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1853         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1854         { } /* end */
1855 };
1856
1857 static struct hda_channel_mode alc880_threestack_modes[2] = {
1858         { 2, alc880_threestack_ch2_init },
1859         { 6, alc880_threestack_ch6_init },
1860 };
1861
1862 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1863         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1864         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1865         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1866         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1867         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1868         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1869         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1870         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1871         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1872         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1873         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1874         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1875         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1876         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1877         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1878         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1879         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1880         {
1881                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1882                 .name = "Channel Mode",
1883                 .info = alc_ch_mode_info,
1884                 .get = alc_ch_mode_get,
1885                 .put = alc_ch_mode_put,
1886         },
1887         { } /* end */
1888 };
1889
1890 /* capture mixer elements */
1891 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1892                             struct snd_ctl_elem_info *uinfo)
1893 {
1894         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1895         struct alc_spec *spec = codec->spec;
1896         int err;
1897
1898         mutex_lock(&codec->control_mutex);
1899         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1900                                                       HDA_INPUT);
1901         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1902         mutex_unlock(&codec->control_mutex);
1903         return err;
1904 }
1905
1906 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1907                            unsigned int size, unsigned int __user *tlv)
1908 {
1909         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1910         struct alc_spec *spec = codec->spec;
1911         int err;
1912
1913         mutex_lock(&codec->control_mutex);
1914         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1915                                                       HDA_INPUT);
1916         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1917         mutex_unlock(&codec->control_mutex);
1918         return err;
1919 }
1920
1921 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1922                              struct snd_ctl_elem_value *ucontrol);
1923
1924 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1925                                  struct snd_ctl_elem_value *ucontrol,
1926                                  getput_call_t func)
1927 {
1928         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1929         struct alc_spec *spec = codec->spec;
1930         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1931         int err;
1932
1933         mutex_lock(&codec->control_mutex);
1934         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1935                                                       3, 0, HDA_INPUT);
1936         err = func(kcontrol, ucontrol);
1937         mutex_unlock(&codec->control_mutex);
1938         return err;
1939 }
1940
1941 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1942                            struct snd_ctl_elem_value *ucontrol)
1943 {
1944         return alc_cap_getput_caller(kcontrol, ucontrol,
1945                                      snd_hda_mixer_amp_volume_get);
1946 }
1947
1948 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1949                            struct snd_ctl_elem_value *ucontrol)
1950 {
1951         return alc_cap_getput_caller(kcontrol, ucontrol,
1952                                      snd_hda_mixer_amp_volume_put);
1953 }
1954
1955 /* capture mixer elements */
1956 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1957
1958 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1959                           struct snd_ctl_elem_value *ucontrol)
1960 {
1961         return alc_cap_getput_caller(kcontrol, ucontrol,
1962                                      snd_hda_mixer_amp_switch_get);
1963 }
1964
1965 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1966                           struct snd_ctl_elem_value *ucontrol)
1967 {
1968         return alc_cap_getput_caller(kcontrol, ucontrol,
1969                                      snd_hda_mixer_amp_switch_put);
1970 }
1971
1972 #define _DEFINE_CAPMIX(num) \
1973         { \
1974                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1975                 .name = "Capture Switch", \
1976                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1977                 .count = num, \
1978                 .info = alc_cap_sw_info, \
1979                 .get = alc_cap_sw_get, \
1980                 .put = alc_cap_sw_put, \
1981         }, \
1982         { \
1983                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1984                 .name = "Capture Volume", \
1985                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1986                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1987                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1988                 .count = num, \
1989                 .info = alc_cap_vol_info, \
1990                 .get = alc_cap_vol_get, \
1991                 .put = alc_cap_vol_put, \
1992                 .tlv = { .c = alc_cap_vol_tlv }, \
1993         }
1994
1995 #define _DEFINE_CAPSRC(num) \
1996         { \
1997                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1998                 /* .name = "Capture Source", */ \
1999                 .name = "Input Source", \
2000                 .count = num, \
2001                 .info = alc_mux_enum_info, \
2002                 .get = alc_mux_enum_get, \
2003                 .put = alc_mux_enum_put, \
2004         }
2005
2006 #define DEFINE_CAPMIX(num) \
2007 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2008         _DEFINE_CAPMIX(num),                                  \
2009         _DEFINE_CAPSRC(num),                                  \
2010         { } /* end */                                         \
2011 }
2012
2013 #define DEFINE_CAPMIX_NOSRC(num) \
2014 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2015         _DEFINE_CAPMIX(num),                                        \
2016         { } /* end */                                               \
2017 }
2018
2019 /* up to three ADCs */
2020 DEFINE_CAPMIX(1);
2021 DEFINE_CAPMIX(2);
2022 DEFINE_CAPMIX(3);
2023 DEFINE_CAPMIX_NOSRC(1);
2024 DEFINE_CAPMIX_NOSRC(2);
2025 DEFINE_CAPMIX_NOSRC(3);
2026
2027 /*
2028  * ALC880 5-stack model
2029  *
2030  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2031  *      Side = 0x02 (0xd)
2032  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2033  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2034  */
2035
2036 /* additional mixers to alc880_three_stack_mixer */
2037 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2038         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2039         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2040         { } /* end */
2041 };
2042
2043 /* channel source setting (6/8 channel selection for 5-stack) */
2044 /* 6ch mode */
2045 static struct hda_verb alc880_fivestack_ch6_init[] = {
2046         /* set line-in to input, mute it */
2047         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2048         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2049         { } /* end */
2050 };
2051
2052 /* 8ch mode */
2053 static struct hda_verb alc880_fivestack_ch8_init[] = {
2054         /* set line-in to output, unmute it */
2055         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2056         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2057         { } /* end */
2058 };
2059
2060 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2061         { 6, alc880_fivestack_ch6_init },
2062         { 8, alc880_fivestack_ch8_init },
2063 };
2064
2065
2066 /*
2067  * ALC880 6-stack model
2068  *
2069  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2070  *      Side = 0x05 (0x0f)
2071  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2072  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2073  */
2074
2075 static hda_nid_t alc880_6st_dac_nids[4] = {
2076         /* front, rear, clfe, rear_surr */
2077         0x02, 0x03, 0x04, 0x05
2078 };
2079
2080 static struct hda_input_mux alc880_6stack_capture_source = {
2081         .num_items = 4,
2082         .items = {
2083                 { "Mic", 0x0 },
2084                 { "Front Mic", 0x1 },
2085                 { "Line", 0x2 },
2086                 { "CD", 0x4 },
2087         },
2088 };
2089
2090 /* fixed 8-channels */
2091 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2092         { 8, NULL },
2093 };
2094
2095 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2096         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2097         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2098         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2099         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2100         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2101         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2102         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2103         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2104         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2105         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2106         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2107         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2108         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2109         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2110         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2111         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2112         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2113         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2114         {
2115                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2116                 .name = "Channel Mode",
2117                 .info = alc_ch_mode_info,
2118                 .get = alc_ch_mode_get,
2119                 .put = alc_ch_mode_put,
2120         },
2121         { } /* end */
2122 };
2123
2124
2125 /*
2126  * ALC880 W810 model
2127  *
2128  * W810 has rear IO for:
2129  * Front (DAC 02)
2130  * Surround (DAC 03)
2131  * Center/LFE (DAC 04)
2132  * Digital out (06)
2133  *
2134  * The system also has a pair of internal speakers, and a headphone jack.
2135  * These are both connected to Line2 on the codec, hence to DAC 02.
2136  *
2137  * There is a variable resistor to control the speaker or headphone
2138  * volume. This is a hardware-only device without a software API.
2139  *
2140  * Plugging headphones in will disable the internal speakers. This is
2141  * implemented in hardware, not via the driver using jack sense. In
2142  * a similar fashion, plugging into the rear socket marked "front" will
2143  * disable both the speakers and headphones.
2144  *
2145  * For input, there's a microphone jack, and an "audio in" jack.
2146  * These may not do anything useful with this driver yet, because I
2147  * haven't setup any initialization verbs for these yet...
2148  */
2149
2150 static hda_nid_t alc880_w810_dac_nids[3] = {
2151         /* front, rear/surround, clfe */
2152         0x02, 0x03, 0x04
2153 };
2154
2155 /* fixed 6 channels */
2156 static struct hda_channel_mode alc880_w810_modes[1] = {
2157         { 6, NULL }
2158 };
2159
2160 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2161 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2162         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2163         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2164         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2165         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2166         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2167         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2168         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2169         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2170         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2171         { } /* end */
2172 };
2173
2174
2175 /*
2176  * Z710V model
2177  *
2178  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2179  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2180  *                 Line = 0x1a
2181  */
2182
2183 static hda_nid_t alc880_z71v_dac_nids[1] = {
2184         0x02
2185 };
2186 #define ALC880_Z71V_HP_DAC      0x03
2187
2188 /* fixed 2 channels */
2189 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2190         { 2, NULL }
2191 };
2192
2193 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2194         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2195         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2196         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2197         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2198         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2199         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2200         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2201         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2202         { } /* end */
2203 };
2204
2205
2206 /*
2207  * ALC880 F1734 model
2208  *
2209  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2210  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2211  */
2212
2213 static hda_nid_t alc880_f1734_dac_nids[1] = {
2214         0x03
2215 };
2216 #define ALC880_F1734_HP_DAC     0x02
2217
2218 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2219         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2220         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2221         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2222         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2223         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2224         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2225         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2226         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2227         { } /* end */
2228 };
2229
2230 static struct hda_input_mux alc880_f1734_capture_source = {
2231         .num_items = 2,
2232         .items = {
2233                 { "Mic", 0x1 },
2234                 { "CD", 0x4 },
2235         },
2236 };
2237
2238
2239 /*
2240  * ALC880 ASUS model
2241  *
2242  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2243  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2244  *  Mic = 0x18, Line = 0x1a
2245  */
2246
2247 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2248 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2249
2250 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2251         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2252         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2253         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2254         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2255         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2256         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2257         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2258         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2259         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2260         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2261         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2262         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2263         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2264         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2265         {
2266                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2267                 .name = "Channel Mode",
2268                 .info = alc_ch_mode_info,
2269                 .get = alc_ch_mode_get,
2270                 .put = alc_ch_mode_put,
2271         },
2272         { } /* end */
2273 };
2274
2275 /*
2276  * ALC880 ASUS W1V model
2277  *
2278  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2279  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2280  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2281  */
2282
2283 /* additional mixers to alc880_asus_mixer */
2284 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2285         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2286         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2287         { } /* end */
2288 };
2289
2290 /* TCL S700 */
2291 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2292         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2293         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2294         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2295         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2296         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2297         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2298         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2299         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2300         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2301         { } /* end */
2302 };
2303
2304 /* Uniwill */
2305 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2306         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2307         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2308         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2309         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2310         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2311         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2312         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2313         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2314         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2315         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2316         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2317         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2318         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2319         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2320         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2321         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2322         {
2323                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2324                 .name = "Channel Mode",
2325                 .info = alc_ch_mode_info,
2326                 .get = alc_ch_mode_get,
2327                 .put = alc_ch_mode_put,
2328         },
2329         { } /* end */
2330 };
2331
2332 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2333         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2334         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2335         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2336         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2337         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2338         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2339         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2340         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2341         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2342         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2343         { } /* end */
2344 };
2345
2346 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2347         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2348         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2349         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2350         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2351         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2352         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2353         { } /* end */
2354 };
2355
2356 /*
2357  * virtual master controls
2358  */
2359
2360 /*
2361  * slave controls for virtual master
2362  */
2363 static const char *alc_slave_vols[] = {
2364         "Front Playback Volume",
2365         "Surround Playback Volume",
2366         "Center Playback Volume",
2367         "LFE Playback Volume",
2368         "Side Playback Volume",
2369         "Headphone Playback Volume",
2370         "Speaker Playback Volume",
2371         "Mono Playback Volume",
2372         "Line-Out Playback Volume",
2373         "PCM Playback Volume",
2374         NULL,
2375 };
2376
2377 static const char *alc_slave_sws[] = {
2378         "Front Playback Switch",
2379         "Surround Playback Switch",
2380         "Center Playback Switch",
2381         "LFE Playback Switch",
2382         "Side Playback Switch",
2383         "Headphone Playback Switch",
2384         "Speaker Playback Switch",
2385         "Mono Playback Switch",
2386         "IEC958 Playback Switch",
2387         NULL,
2388 };
2389
2390 /*
2391  * build control elements
2392  */
2393
2394 static void alc_free_kctls(struct hda_codec *codec);
2395
2396 /* additional beep mixers; the actual parameters are overwritten at build */
2397 static struct snd_kcontrol_new alc_beep_mixer[] = {
2398         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2399         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2400         { } /* end */
2401 };
2402
2403 static int alc_build_controls(struct hda_codec *codec)
2404 {
2405         struct alc_spec *spec = codec->spec;
2406         int err;
2407         int i;
2408
2409         for (i = 0; i < spec->num_mixers; i++) {
2410                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2411                 if (err < 0)
2412                         return err;
2413         }
2414         if (spec->cap_mixer) {
2415                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2416                 if (err < 0)
2417                         return err;
2418         }
2419         if (spec->multiout.dig_out_nid) {
2420                 err = snd_hda_create_spdif_out_ctls(codec,
2421                                                     spec->multiout.dig_out_nid);
2422                 if (err < 0)
2423                         return err;
2424                 if (!spec->no_analog) {
2425                         err = snd_hda_create_spdif_share_sw(codec,
2426                                                             &spec->multiout);
2427                         if (err < 0)
2428                                 return err;
2429                         spec->multiout.share_spdif = 1;
2430                 }
2431         }
2432         if (spec->dig_in_nid) {
2433                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2434                 if (err < 0)
2435                         return err;
2436         }
2437
2438         /* create beep controls if needed */
2439         if (spec->beep_amp) {
2440                 struct snd_kcontrol_new *knew;
2441                 for (knew = alc_beep_mixer; knew->name; knew++) {
2442                         struct snd_kcontrol *kctl;
2443                         kctl = snd_ctl_new1(knew, codec);
2444                         if (!kctl)
2445                                 return -ENOMEM;
2446                         kctl->private_value = spec->beep_amp;
2447                         err = snd_hda_ctl_add(codec, kctl);
2448                         if (err < 0)
2449                                 return err;
2450                 }
2451         }
2452
2453         /* if we have no master control, let's create it */
2454         if (!spec->no_analog &&
2455             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2456                 unsigned int vmaster_tlv[4];
2457                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2458                                         HDA_OUTPUT, vmaster_tlv);
2459                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2460                                           vmaster_tlv, alc_slave_vols);
2461                 if (err < 0)
2462                         return err;
2463         }
2464         if (!spec->no_analog &&
2465             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2466                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2467                                           NULL, alc_slave_sws);
2468                 if (err < 0)
2469                         return err;
2470         }
2471
2472         alc_free_kctls(codec); /* no longer needed */
2473         return 0;
2474 }
2475
2476
2477 /*
2478  * initialize the codec volumes, etc
2479  */
2480
2481 /*
2482  * generic initialization of ADC, input mixers and output mixers
2483  */
2484 static struct hda_verb alc880_volume_init_verbs[] = {
2485         /*
2486          * Unmute ADC0-2 and set the default input to mic-in
2487          */
2488         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2489         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2490         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2491         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2492         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2494
2495         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2496          * mixer widget
2497          * Note: PASD motherboards uses the Line In 2 as the input for front
2498          * panel mic (mic 2)
2499          */
2500         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2501         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2502         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2503         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2504         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2505         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2506         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2507         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2508
2509         /*
2510          * Set up output mixers (0x0c - 0x0f)
2511          */
2512         /* set vol=0 to output mixers */
2513         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2514         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2515         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2516         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2517         /* set up input amps for analog loopback */
2518         /* Amp Indices: DAC = 0, mixer = 1 */
2519         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2520         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2521         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2522         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2523         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2524         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2525         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2526         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2527
2528         { }
2529 };
2530
2531 /*
2532  * 3-stack pin configuration:
2533  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2534  */
2535 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2536         /*
2537          * preset connection lists of input pins
2538          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2539          */
2540         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2541         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2542         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2543
2544         /*
2545          * Set pin mode and muting
2546          */
2547         /* set front pin widgets 0x14 for output */
2548         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2549         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2550         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2551         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2552         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2553         /* Mic2 (as headphone out) for HP output */
2554         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2555         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2556         /* Line In pin widget for input */
2557         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2558         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2559         /* Line2 (as front mic) pin widget for input and vref at 80% */
2560         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2561         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2562         /* CD pin widget for input */
2563         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2564
2565         { }
2566 };
2567
2568 /*
2569  * 5-stack pin configuration:
2570  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2571  * line-in/side = 0x1a, f-mic = 0x1b
2572  */
2573 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2574         /*
2575          * preset connection lists of input pins
2576          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2577          */
2578         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2579         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2580
2581         /*
2582          * Set pin mode and muting
2583          */
2584         /* set pin widgets 0x14-0x17 for output */
2585         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2586         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2587         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2588         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2589         /* unmute pins for output (no gain on this amp) */
2590         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2591         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2592         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2593         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2594
2595         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2596         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2597         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2598         /* Mic2 (as headphone out) for HP output */
2599         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2600         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2601         /* Line In pin widget for input */
2602         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2603         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2604         /* Line2 (as front mic) pin widget for input and vref at 80% */
2605         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2606         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2607         /* CD pin widget for input */
2608         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2609
2610         { }
2611 };
2612
2613 /*
2614  * W810 pin configuration:
2615  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2616  */
2617 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2618         /* hphone/speaker input selector: front DAC */
2619         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2620
2621         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2622         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2623         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2624         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2625         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2626         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2627
2628         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2629         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2630
2631         { }
2632 };
2633
2634 /*
2635  * Z71V pin configuration:
2636  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2637  */
2638 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2639         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2640         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2641         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2642         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2643
2644         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2645         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2646         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2647         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2648
2649         { }
2650 };
2651
2652 /*
2653  * 6-stack pin configuration:
2654  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2655  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2656  */
2657 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2658         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2659
2660         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2661         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2662         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2663         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2664         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2665         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2666         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2667         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2668
2669         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2670         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2671         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2672         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2673         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2674         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2675         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2676         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2677         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2678
2679         { }
2680 };
2681
2682 /*
2683  * Uniwill pin configuration:
2684  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2685  * line = 0x1a
2686  */
2687 static struct hda_verb alc880_uniwill_init_verbs[] = {
2688         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2689
2690         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2691         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2692         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2693         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2694         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2695         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2696         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2697         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2698         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2699         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2700         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2701         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2702         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2703         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2704
2705         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2706         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2707         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2708         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2709         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2710         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2711         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2712         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2713         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2714
2715         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2716         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2717
2718         { }
2719 };
2720
2721 /*
2722 * Uniwill P53
2723 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2724  */
2725 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2726         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2727
2728         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2729         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2730         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2731         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2732         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2733         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2734         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2735         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2736         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2737         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2738         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2739         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2740
2741         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2742         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2743         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2744         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2745         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2746         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2747
2748         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2749         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2750
2751         { }
2752 };
2753
2754 static struct hda_verb alc880_beep_init_verbs[] = {
2755         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2756         { }
2757 };
2758
2759 /* auto-toggle front mic */
2760 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2761 {
2762         unsigned int present;
2763         unsigned char bits;
2764
2765         present = snd_hda_codec_read(codec, 0x18, 0,
2766                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2767         bits = present ? HDA_AMP_MUTE : 0;
2768         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2769 }
2770
2771 static void alc880_uniwill_setup(struct hda_codec *codec)
2772 {
2773         struct alc_spec *spec = codec->spec;
2774
2775         spec->autocfg.hp_pins[0] = 0x14;
2776         spec->autocfg.speaker_pins[0] = 0x15;
2777         spec->autocfg.speaker_pins[0] = 0x16;
2778 }
2779
2780 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2781 {
2782         alc_automute_amp(codec);
2783         alc880_uniwill_mic_automute(codec);
2784 }
2785
2786 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2787                                        unsigned int res)
2788 {
2789         /* Looks like the unsol event is incompatible with the standard
2790          * definition.  4bit tag is placed at 28 bit!
2791          */
2792         switch (res >> 28) {
2793         case ALC880_MIC_EVENT:
2794                 alc880_uniwill_mic_automute(codec);
2795                 break;
2796         default:
2797                 alc_automute_amp_unsol_event(codec, res);
2798                 break;
2799         }
2800 }
2801
2802 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2803 {
2804         struct alc_spec *spec = codec->spec;
2805
2806         spec->autocfg.hp_pins[0] = 0x14;
2807         spec->autocfg.speaker_pins[0] = 0x15;
2808 }
2809
2810 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2811 {
2812         unsigned int present;
2813
2814         present = snd_hda_codec_read(codec, 0x21, 0,
2815                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2816         present &= HDA_AMP_VOLMASK;
2817         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2818                                  HDA_AMP_VOLMASK, present);
2819         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2820                                  HDA_AMP_VOLMASK, present);
2821 }
2822
2823 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2824                                            unsigned int res)
2825 {
2826         /* Looks like the unsol event is incompatible with the standard
2827          * definition.  4bit tag is placed at 28 bit!
2828          */
2829         if ((res >> 28) == ALC880_DCVOL_EVENT)
2830                 alc880_uniwill_p53_dcvol_automute(codec);
2831         else
2832                 alc_automute_amp_unsol_event(codec, res);
2833 }
2834
2835 /*
2836  * F1734 pin configuration:
2837  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2838  */
2839 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2840         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2841         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2842         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2843         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2844         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2845
2846         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2847         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2848         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2849         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2850
2851         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2852         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2853         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2854         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2855         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2856         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2857         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2858         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2859         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2860
2861         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2862         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2863
2864         { }
2865 };
2866
2867 /*
2868  * ASUS pin configuration:
2869  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2870  */
2871 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2872         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2873         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2874         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2875         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2876
2877         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2878         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2879         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2880         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2881         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2882         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2883         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2884         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2885
2886         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2887         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2888         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2889         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2890         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2891         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2892         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2893         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2894         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2895
2896         { }
2897 };
2898
2899 /* Enable GPIO mask and set output */
2900 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2901 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2902 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2903
2904 /* Clevo m520g init */
2905 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2906         /* headphone output */
2907         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2908         /* line-out */
2909         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2911         /* Line-in */
2912         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2913         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2914         /* CD */
2915         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2916         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2917         /* Mic1 (rear panel) */
2918         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2919         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2920         /* Mic2 (front panel) */
2921         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2922         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2923         /* headphone */
2924         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2925         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2926         /* change to EAPD mode */
2927         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2928         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2929
2930         { }
2931 };
2932
2933 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2934         /* change to EAPD mode */
2935         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2936         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2937
2938         /* Headphone output */
2939         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2940         /* Front output*/
2941         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2942         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2943
2944         /* Line In pin widget for input */
2945         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2946         /* CD pin widget for input */
2947         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2948         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2949         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2950
2951         /* change to EAPD mode */
2952         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2953         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2954
2955         { }
2956 };
2957
2958 /*
2959  * LG m1 express dual
2960  *
2961  * Pin assignment:
2962  *   Rear Line-In/Out (blue): 0x14
2963  *   Build-in Mic-In: 0x15
2964  *   Speaker-out: 0x17
2965  *   HP-Out (green): 0x1b
2966  *   Mic-In/Out (red): 0x19
2967  *   SPDIF-Out: 0x1e
2968  */
2969
2970 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2971 static hda_nid_t alc880_lg_dac_nids[3] = {
2972         0x05, 0x02, 0x03
2973 };
2974
2975 /* seems analog CD is not working */
2976 static struct hda_input_mux alc880_lg_capture_source = {
2977         .num_items = 3,
2978         .items = {
2979                 { "Mic", 0x1 },
2980                 { "Line", 0x5 },
2981                 { "Internal Mic", 0x6 },
2982         },
2983 };
2984
2985 /* 2,4,6 channel modes */
2986 static struct hda_verb alc880_lg_ch2_init[] = {
2987         /* set line-in and mic-in to input */
2988         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2989         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2990         { }
2991 };
2992
2993 static struct hda_verb alc880_lg_ch4_init[] = {
2994         /* set line-in to out and mic-in to input */
2995         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2996         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2997         { }
2998 };
2999
3000 static struct hda_verb alc880_lg_ch6_init[] = {
3001         /* set line-in and mic-in to output */
3002         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3003         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3004         { }
3005 };
3006
3007 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3008         { 2, alc880_lg_ch2_init },
3009         { 4, alc880_lg_ch4_init },
3010         { 6, alc880_lg_ch6_init },
3011 };
3012
3013 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3014         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3015         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3016         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3017         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3018         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3019         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3020         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3021         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3022         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3023         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3024         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3025         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3026         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3027         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3028         {
3029                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3030                 .name = "Channel Mode",
3031                 .info = alc_ch_mode_info,
3032                 .get = alc_ch_mode_get,
3033                 .put = alc_ch_mode_put,
3034         },
3035         { } /* end */
3036 };
3037
3038 static struct hda_verb alc880_lg_init_verbs[] = {
3039         /* set capture source to mic-in */
3040         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3041         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3042         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3043         /* mute all amp mixer inputs */
3044         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3045         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3046         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3047         /* line-in to input */
3048         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3049         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3050         /* built-in mic */
3051         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3052         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3053         /* speaker-out */
3054         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3055         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3056         /* mic-in to input */
3057         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3058         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3059         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3060         /* HP-out */
3061         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3062         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3063         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3064         /* jack sense */
3065         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3066         { }
3067 };
3068
3069 /* toggle speaker-output according to the hp-jack state */
3070 static void alc880_lg_setup(struct hda_codec *codec)
3071 {
3072         struct alc_spec *spec = codec->spec;
3073
3074         spec->autocfg.hp_pins[0] = 0x1b;
3075         spec->autocfg.speaker_pins[0] = 0x17;
3076 }
3077
3078 /*
3079  * LG LW20
3080  *
3081  * Pin assignment:
3082  *   Speaker-out: 0x14
3083  *   Mic-In: 0x18
3084  *   Built-in Mic-In: 0x19
3085  *   Line-In: 0x1b
3086  *   HP-Out: 0x1a
3087  *   SPDIF-Out: 0x1e
3088  */
3089
3090 static struct hda_input_mux alc880_lg_lw_capture_source = {
3091         .num_items = 3,
3092         .items = {
3093                 { "Mic", 0x0 },
3094                 { "Internal Mic", 0x1 },
3095                 { "Line In", 0x2 },
3096         },
3097 };
3098
3099 #define alc880_lg_lw_modes alc880_threestack_modes
3100
3101 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3102         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3103         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3104         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3105         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3106         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3107         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3108         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3109         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3110         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3111         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3113         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3114         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3115         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3116         {
3117                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3118                 .name = "Channel Mode",
3119                 .info = alc_ch_mode_info,
3120                 .get = alc_ch_mode_get,
3121                 .put = alc_ch_mode_put,
3122         },
3123         { } /* end */
3124 };
3125
3126 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3127         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3128         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3129         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3130
3131         /* set capture source to mic-in */
3132         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3133         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3134         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3136         /* speaker-out */
3137         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3138         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3139         /* HP-out */
3140         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3141         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3142         /* mic-in to input */
3143         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3144         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3145         /* built-in mic */
3146         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3147         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3148         /* jack sense */
3149         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3150         { }
3151 };
3152
3153 /* toggle speaker-output according to the hp-jack state */
3154 static void alc880_lg_lw_setup(struct hda_codec *codec)
3155 {
3156         struct alc_spec *spec = codec->spec;
3157
3158         spec->autocfg.hp_pins[0] = 0x1b;
3159         spec->autocfg.speaker_pins[0] = 0x14;
3160 }
3161
3162 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3163         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3164         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3165         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3166         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3167         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3168         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3169         { } /* end */
3170 };
3171
3172 static struct hda_input_mux alc880_medion_rim_capture_source = {
3173         .num_items = 2,
3174         .items = {
3175                 { "Mic", 0x0 },
3176                 { "Internal Mic", 0x1 },
3177         },
3178 };
3179
3180 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3181         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3182
3183         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3184         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3185
3186         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3187         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3188         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3189         /* Mic2 (as headphone out) for HP output */
3190         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3191         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3192         /* Internal Speaker */
3193         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3194         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3195
3196         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3197         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3198
3199         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3200         { }
3201 };
3202
3203 /* toggle speaker-output according to the hp-jack state */
3204 static void alc880_medion_rim_automute(struct hda_codec *codec)
3205 {
3206         struct alc_spec *spec = codec->spec;
3207         alc_automute_amp(codec);
3208         /* toggle EAPD */
3209         if (spec->jack_present)
3210                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3211         else
3212                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3213 }
3214
3215 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3216                                           unsigned int res)
3217 {
3218         /* Looks like the unsol event is incompatible with the standard
3219          * definition.  4bit tag is placed at 28 bit!
3220          */
3221         if ((res >> 28) == ALC880_HP_EVENT)
3222                 alc880_medion_rim_automute(codec);
3223 }
3224
3225 static void alc880_medion_rim_setup(struct hda_codec *codec)
3226 {
3227         struct alc_spec *spec = codec->spec;
3228
3229         spec->autocfg.hp_pins[0] = 0x14;
3230         spec->autocfg.speaker_pins[0] = 0x1b;
3231 }
3232
3233 #ifdef CONFIG_SND_HDA_POWER_SAVE
3234 static struct hda_amp_list alc880_loopbacks[] = {
3235         { 0x0b, HDA_INPUT, 0 },
3236         { 0x0b, HDA_INPUT, 1 },
3237         { 0x0b, HDA_INPUT, 2 },
3238         { 0x0b, HDA_INPUT, 3 },
3239         { 0x0b, HDA_INPUT, 4 },
3240         { } /* end */
3241 };
3242
3243 static struct hda_amp_list alc880_lg_loopbacks[] = {
3244         { 0x0b, HDA_INPUT, 1 },
3245         { 0x0b, HDA_INPUT, 6 },
3246         { 0x0b, HDA_INPUT, 7 },
3247         { } /* end */
3248 };
3249 #endif
3250
3251 /*
3252  * Common callbacks
3253  */
3254
3255 static int alc_init(struct hda_codec *codec)
3256 {
3257         struct alc_spec *spec = codec->spec;
3258         unsigned int i;
3259
3260         alc_fix_pll(codec);
3261         alc_auto_init_amp(codec, spec->init_amp);
3262
3263         for (i = 0; i < spec->num_init_verbs; i++)
3264                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3265
3266         if (spec->init_hook)
3267                 spec->init_hook(codec);
3268
3269         return 0;
3270 }
3271
3272 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3273 {
3274         struct alc_spec *spec = codec->spec;
3275
3276         if (spec->unsol_event)
3277                 spec->unsol_event(codec, res);
3278 }
3279
3280 #ifdef CONFIG_SND_HDA_POWER_SAVE
3281 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3282 {
3283         struct alc_spec *spec = codec->spec;
3284         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3285 }
3286 #endif
3287
3288 /*
3289  * Analog playback callbacks
3290  */
3291 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3292                                     struct hda_codec *codec,
3293                                     struct snd_pcm_substream *substream)
3294 {
3295         struct alc_spec *spec = codec->spec;
3296         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3297                                              hinfo);
3298 }
3299
3300 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3301                                        struct hda_codec *codec,
3302                                        unsigned int stream_tag,
3303                                        unsigned int format,
3304                                        struct snd_pcm_substream *substream)
3305 {
3306         struct alc_spec *spec = codec->spec;
3307         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3308                                                 stream_tag, format, substream);
3309 }
3310
3311 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3312                                        struct hda_codec *codec,
3313                                        struct snd_pcm_substream *substream)
3314 {
3315         struct alc_spec *spec = codec->spec;
3316         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3317 }
3318
3319 /*
3320  * Digital out
3321  */
3322 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3323                                         struct hda_codec *codec,
3324                                         struct snd_pcm_substream *substream)
3325 {
3326         struct alc_spec *spec = codec->spec;
3327         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3328 }
3329
3330 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3331                                            struct hda_codec *codec,
3332                                            unsigned int stream_tag,
3333                                            unsigned int format,
3334                                            struct snd_pcm_substream *substream)
3335 {
3336         struct alc_spec *spec = codec->spec;
3337         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3338                                              stream_tag, format, substream);
3339 }
3340
3341 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3342                                            struct hda_codec *codec,
3343                                            struct snd_pcm_substream *substream)
3344 {
3345         struct alc_spec *spec = codec->spec;
3346         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3347 }
3348
3349 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3350                                          struct hda_codec *codec,
3351                                          struct snd_pcm_substream *substream)
3352 {
3353         struct alc_spec *spec = codec->spec;
3354         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3355 }
3356
3357 /*
3358  * Analog capture
3359  */
3360 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3361                                       struct hda_codec *codec,
3362                                       unsigned int stream_tag,
3363                                       unsigned int format,
3364                                       struct snd_pcm_substream *substream)
3365 {
3366         struct alc_spec *spec = codec->spec;
3367
3368         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3369                                    stream_tag, 0, format);
3370         return 0;
3371 }
3372
3373 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3374                                       struct hda_codec *codec,
3375                                       struct snd_pcm_substream *substream)
3376 {
3377         struct alc_spec *spec = codec->spec;
3378
3379         snd_hda_codec_cleanup_stream(codec,
3380                                      spec->adc_nids[substream->number + 1]);
3381         return 0;
3382 }
3383
3384
3385 /*
3386  */
3387 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3388         .substreams = 1,
3389         .channels_min = 2,
3390         .channels_max = 8,
3391         /* NID is set in alc_build_pcms */
3392         .ops = {
3393                 .open = alc880_playback_pcm_open,
3394                 .prepare = alc880_playback_pcm_prepare,
3395                 .cleanup = alc880_playback_pcm_cleanup
3396         },
3397 };
3398
3399 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3400         .substreams = 1,
3401         .channels_min = 2,
3402         .channels_max = 2,
3403         /* NID is set in alc_build_pcms */
3404 };
3405
3406 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3407         .substreams = 1,
3408         .channels_min = 2,
3409         .channels_max = 2,
3410         /* NID is set in alc_build_pcms */
3411 };
3412
3413 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3414         .substreams = 2, /* can be overridden */
3415         .channels_min = 2,
3416         .channels_max = 2,
3417         /* NID is set in alc_build_pcms */
3418         .ops = {
3419                 .prepare = alc880_alt_capture_pcm_prepare,
3420                 .cleanup = alc880_alt_capture_pcm_cleanup
3421         },
3422 };
3423
3424 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3425         .substreams = 1,
3426         .channels_min = 2,
3427         .channels_max = 2,
3428         /* NID is set in alc_build_pcms */
3429         .ops = {
3430                 .open = alc880_dig_playback_pcm_open,
3431                 .close = alc880_dig_playback_pcm_close,
3432                 .prepare = alc880_dig_playback_pcm_prepare,
3433                 .cleanup = alc880_dig_playback_pcm_cleanup
3434         },
3435 };
3436
3437 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3438         .substreams = 1,
3439         .channels_min = 2,
3440         .channels_max = 2,
3441         /* NID is set in alc_build_pcms */
3442 };
3443
3444 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3445 static struct hda_pcm_stream alc_pcm_null_stream = {
3446         .substreams = 0,
3447         .channels_min = 0,
3448         .channels_max = 0,
3449 };
3450
3451 static int alc_build_pcms(struct hda_codec *codec)
3452 {
3453         struct alc_spec *spec = codec->spec;
3454         struct hda_pcm *info = spec->pcm_rec;
3455         int i;
3456
3457         codec->num_pcms = 1;
3458         codec->pcm_info = info;
3459
3460         if (spec->no_analog)
3461                 goto skip_analog;
3462
3463         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3464                  "%s Analog", codec->chip_name);
3465         info->name = spec->stream_name_analog;
3466         
3467         if (spec->stream_analog_playback) {
3468                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3469                         return -EINVAL;
3470                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3471                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3472         }
3473         if (spec->stream_analog_capture) {
3474                 if (snd_BUG_ON(!spec->adc_nids))
3475                         return -EINVAL;
3476                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3477                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3478         }
3479
3480         if (spec->channel_mode) {
3481                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3482                 for (i = 0; i < spec->num_channel_mode; i++) {
3483                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3484                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3485                         }
3486                 }
3487         }
3488
3489  skip_analog:
3490         /* SPDIF for stream index #1 */
3491         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3492                 snprintf(spec->stream_name_digital,
3493                          sizeof(spec->stream_name_digital),
3494                          "%s Digital", codec->chip_name);
3495                 codec->num_pcms = 2;
3496                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3497                 info = spec->pcm_rec + 1;
3498                 info->name = spec->stream_name_digital;
3499                 if (spec->dig_out_type)
3500                         info->pcm_type = spec->dig_out_type;
3501                 else
3502                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3503                 if (spec->multiout.dig_out_nid &&
3504                     spec->stream_digital_playback) {
3505                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3506                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3507                 }
3508                 if (spec->dig_in_nid &&
3509                     spec->stream_digital_capture) {
3510                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3511                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3512                 }
3513                 /* FIXME: do we need this for all Realtek codec models? */
3514                 codec->spdif_status_reset = 1;
3515         }
3516
3517         if (spec->no_analog)
3518                 return 0;
3519
3520         /* If the use of more than one ADC is requested for the current
3521          * model, configure a second analog capture-only PCM.
3522          */
3523         /* Additional Analaog capture for index #2 */
3524         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3525             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3526                 codec->num_pcms = 3;
3527                 info = spec->pcm_rec + 2;
3528                 info->name = spec->stream_name_analog;
3529                 if (spec->alt_dac_nid) {
3530                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3531                                 *spec->stream_analog_alt_playback;
3532                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3533                                 spec->alt_dac_nid;
3534                 } else {
3535                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3536                                 alc_pcm_null_stream;
3537                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3538                 }
3539                 if (spec->num_adc_nids > 1) {
3540                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3541                                 *spec->stream_analog_alt_capture;
3542                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3543                                 spec->adc_nids[1];
3544                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3545                                 spec->num_adc_nids - 1;
3546                 } else {
3547                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3548                                 alc_pcm_null_stream;
3549                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3550                 }
3551         }
3552
3553         return 0;
3554 }
3555
3556 static void alc_free_kctls(struct hda_codec *codec)
3557 {
3558         struct alc_spec *spec = codec->spec;
3559
3560         if (spec->kctls.list) {
3561                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3562                 int i;
3563                 for (i = 0; i < spec->kctls.used; i++)
3564                         kfree(kctl[i].name);
3565         }
3566         snd_array_free(&spec->kctls);
3567 }
3568
3569 static void alc_free(struct hda_codec *codec)
3570 {
3571         struct alc_spec *spec = codec->spec;
3572
3573         if (!spec)
3574                 return;
3575
3576         alc_free_kctls(codec);
3577         kfree(spec);
3578         snd_hda_detach_beep_device(codec);
3579 }
3580
3581 #ifdef SND_HDA_NEEDS_RESUME
3582 static int alc_resume(struct hda_codec *codec)
3583 {
3584         codec->patch_ops.init(codec);
3585         snd_hda_codec_resume_amp(codec);
3586         snd_hda_codec_resume_cache(codec);
3587         return 0;
3588 }
3589 #endif
3590
3591 /*
3592  */
3593 static struct hda_codec_ops alc_patch_ops = {
3594         .build_controls = alc_build_controls,
3595         .build_pcms = alc_build_pcms,
3596         .init = alc_init,
3597         .free = alc_free,
3598         .unsol_event = alc_unsol_event,
3599 #ifdef SND_HDA_NEEDS_RESUME
3600         .resume = alc_resume,
3601 #endif
3602 #ifdef CONFIG_SND_HDA_POWER_SAVE
3603         .check_power_status = alc_check_power_status,
3604 #endif
3605 };
3606
3607
3608 /*
3609  * Test configuration for debugging
3610  *
3611  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3612  * enum controls.
3613  */
3614 #ifdef CONFIG_SND_DEBUG
3615 static hda_nid_t alc880_test_dac_nids[4] = {
3616         0x02, 0x03, 0x04, 0x05
3617 };
3618
3619 static struct hda_input_mux alc880_test_capture_source = {
3620         .num_items = 7,
3621         .items = {
3622                 { "In-1", 0x0 },
3623                 { "In-2", 0x1 },
3624                 { "In-3", 0x2 },
3625                 { "In-4", 0x3 },
3626                 { "CD", 0x4 },
3627                 { "Front", 0x5 },
3628                 { "Surround", 0x6 },
3629         },
3630 };
3631
3632 static struct hda_channel_mode alc880_test_modes[4] = {
3633         { 2, NULL },
3634         { 4, NULL },
3635         { 6, NULL },
3636         { 8, NULL },
3637 };
3638
3639 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3640                                  struct snd_ctl_elem_info *uinfo)
3641 {
3642         static char *texts[] = {
3643                 "N/A", "Line Out", "HP Out",
3644                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3645         };
3646         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3647         uinfo->count = 1;
3648         uinfo->value.enumerated.items = 8;
3649         if (uinfo->value.enumerated.item >= 8)
3650                 uinfo->value.enumerated.item = 7;
3651         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3652         return 0;
3653 }
3654
3655 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3656                                 struct snd_ctl_elem_value *ucontrol)
3657 {
3658         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3659         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3660         unsigned int pin_ctl, item = 0;
3661
3662         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3663                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3664         if (pin_ctl & AC_PINCTL_OUT_EN) {
3665                 if (pin_ctl & AC_PINCTL_HP_EN)
3666                         item = 2;
3667                 else
3668                         item = 1;
3669         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3670                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3671                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3672                 case AC_PINCTL_VREF_50:  item = 4; break;
3673                 case AC_PINCTL_VREF_GRD: item = 5; break;
3674                 case AC_PINCTL_VREF_80:  item = 6; break;
3675                 case AC_PINCTL_VREF_100: item = 7; break;
3676                 }
3677         }
3678         ucontrol->value.enumerated.item[0] = item;
3679         return 0;
3680 }
3681
3682 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3683                                 struct snd_ctl_elem_value *ucontrol)
3684 {
3685         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3686         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3687         static unsigned int ctls[] = {
3688                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3689                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3690                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3691                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3692                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3693                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3694         };
3695         unsigned int old_ctl, new_ctl;
3696
3697         old_ctl = snd_hda_codec_read(codec, nid, 0,
3698                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3699         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3700         if (old_ctl != new_ctl) {
3701                 int val;
3702                 snd_hda_codec_write_cache(codec, nid, 0,
3703                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3704                                           new_ctl);
3705                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3706                         HDA_AMP_MUTE : 0;
3707                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3708                                          HDA_AMP_MUTE, val);
3709                 return 1;
3710         }
3711         return 0;
3712 }
3713
3714 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3715                                  struct snd_ctl_elem_info *uinfo)
3716 {
3717         static char *texts[] = {
3718                 "Front", "Surround", "CLFE", "Side"
3719         };
3720         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3721         uinfo->count = 1;
3722         uinfo->value.enumerated.items = 4;
3723         if (uinfo->value.enumerated.item >= 4)
3724                 uinfo->value.enumerated.item = 3;
3725         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3726         return 0;
3727 }
3728
3729 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3730                                 struct snd_ctl_elem_value *ucontrol)
3731 {
3732         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3733         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3734         unsigned int sel;
3735
3736         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3737         ucontrol->value.enumerated.item[0] = sel & 3;
3738         return 0;
3739 }
3740
3741 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3742                                 struct snd_ctl_elem_value *ucontrol)
3743 {
3744         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3745         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3746         unsigned int sel;
3747
3748         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3749         if (ucontrol->value.enumerated.item[0] != sel) {
3750                 sel = ucontrol->value.enumerated.item[0] & 3;
3751                 snd_hda_codec_write_cache(codec, nid, 0,
3752                                           AC_VERB_SET_CONNECT_SEL, sel);
3753                 return 1;
3754         }
3755         return 0;
3756 }
3757
3758 #define PIN_CTL_TEST(xname,nid) {                       \
3759                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3760                         .name = xname,                 \
3761                         .info = alc_test_pin_ctl_info, \
3762                         .get = alc_test_pin_ctl_get,   \
3763                         .put = alc_test_pin_ctl_put,   \
3764                         .private_value = nid           \
3765                         }
3766
3767 #define PIN_SRC_TEST(xname,nid) {                       \
3768                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3769                         .name = xname,                 \
3770                         .info = alc_test_pin_src_info, \
3771                         .get = alc_test_pin_src_get,   \
3772                         .put = alc_test_pin_src_put,   \
3773                         .private_value = nid           \
3774                         }
3775
3776 static struct snd_kcontrol_new alc880_test_mixer[] = {
3777         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3778         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3779         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3780         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3781         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3782         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3783         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3784         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3785         PIN_CTL_TEST("Front Pin Mode", 0x14),
3786         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3787         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3788         PIN_CTL_TEST("Side Pin Mode", 0x17),
3789         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3790         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3791         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3792         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3793         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3794         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3795         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3796         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3797         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3798         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3799         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3800         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3801         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3802         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3803         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3804         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3805         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3806         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3807         {
3808                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3809                 .name = "Channel Mode",
3810                 .info = alc_ch_mode_info,
3811                 .get = alc_ch_mode_get,
3812                 .put = alc_ch_mode_put,
3813         },
3814         { } /* end */
3815 };
3816
3817 static struct hda_verb alc880_test_init_verbs[] = {
3818         /* Unmute inputs of 0x0c - 0x0f */
3819         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3820         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3821         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3822         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3823         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3824         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3825         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3826         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3827         /* Vol output for 0x0c-0x0f */
3828         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3829         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3830         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3831         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3832         /* Set output pins 0x14-0x17 */
3833         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3834         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3835         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3836         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3837         /* Unmute output pins 0x14-0x17 */
3838         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3839         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3840         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3841         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3842         /* Set input pins 0x18-0x1c */
3843         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3844         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3845         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3846         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3847         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3848         /* Mute input pins 0x18-0x1b */
3849         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3850         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3851         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3852         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3853         /* ADC set up */
3854         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3855         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3856         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3857         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3858         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3859         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3860         /* Analog input/passthru */
3861         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3862         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3863         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3864         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3865         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3866         { }
3867 };
3868 #endif
3869
3870 /*
3871  */
3872
3873 static const char *alc880_models[ALC880_MODEL_LAST] = {
3874         [ALC880_3ST]            = "3stack",
3875         [ALC880_TCL_S700]       = "tcl",
3876         [ALC880_3ST_DIG]        = "3stack-digout",
3877         [ALC880_CLEVO]          = "clevo",
3878         [ALC880_5ST]            = "5stack",
3879         [ALC880_5ST_DIG]        = "5stack-digout",
3880         [ALC880_W810]           = "w810",
3881         [ALC880_Z71V]           = "z71v",
3882         [ALC880_6ST]            = "6stack",
3883         [ALC880_6ST_DIG]        = "6stack-digout",
3884         [ALC880_ASUS]           = "asus",
3885         [ALC880_ASUS_W1V]       = "asus-w1v",
3886         [ALC880_ASUS_DIG]       = "asus-dig",
3887         [ALC880_ASUS_DIG2]      = "asus-dig2",
3888         [ALC880_UNIWILL_DIG]    = "uniwill",
3889         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3890         [ALC880_FUJITSU]        = "fujitsu",
3891         [ALC880_F1734]          = "F1734",
3892         [ALC880_LG]             = "lg",
3893         [ALC880_LG_LW]          = "lg-lw",
3894         [ALC880_MEDION_RIM]     = "medion",
3895 #ifdef CONFIG_SND_DEBUG
3896         [ALC880_TEST]           = "test",
3897 #endif
3898         [ALC880_AUTO]           = "auto",
3899 };
3900
3901 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3902         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3903         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3904         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3905         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3906         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3907         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3908         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3909         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3910         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3911         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3912         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3913         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3914         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3915         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3916         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3917         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3918         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3919         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3920         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3921         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3922         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3923         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3924         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3925         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3926         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3927         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3928         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3929         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3930         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3931         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3932         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3933         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3934         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3935         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3936         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3937         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3938         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3939         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3940         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3941         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3942         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3943         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3944         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3945         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3946         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3947         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3948         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3949         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3950         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3951         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3952         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3953         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3954         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3955         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3956         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3957         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3958         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3959         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3960         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3961         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3962         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3963         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3964         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3965         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3966         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3967         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3968         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3969         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3970         /* default Intel */
3971         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3972         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3973         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3974         {}
3975 };
3976
3977 /*
3978  * ALC880 codec presets
3979  */
3980 static struct alc_config_preset alc880_presets[] = {
3981         [ALC880_3ST] = {
3982                 .mixers = { alc880_three_stack_mixer },
3983                 .init_verbs = { alc880_volume_init_verbs,
3984                                 alc880_pin_3stack_init_verbs },
3985                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3986                 .dac_nids = alc880_dac_nids,
3987                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3988                 .channel_mode = alc880_threestack_modes,
3989                 .need_dac_fix = 1,
3990                 .input_mux = &alc880_capture_source,
3991         },
3992         [ALC880_3ST_DIG] = {
3993                 .mixers = { alc880_three_stack_mixer },
3994                 .init_verbs = { alc880_volume_init_verbs,
3995                                 alc880_pin_3stack_init_verbs },
3996                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3997                 .dac_nids = alc880_dac_nids,
3998                 .dig_out_nid = ALC880_DIGOUT_NID,
3999                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4000                 .channel_mode = alc880_threestack_modes,
4001                 .need_dac_fix = 1,
4002                 .input_mux = &alc880_capture_source,
4003         },
4004         [ALC880_TCL_S700] = {
4005                 .mixers = { alc880_tcl_s700_mixer },
4006                 .init_verbs = { alc880_volume_init_verbs,
4007                                 alc880_pin_tcl_S700_init_verbs,
4008                                 alc880_gpio2_init_verbs },
4009                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4010                 .dac_nids = alc880_dac_nids,
4011                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4012                 .num_adc_nids = 1, /* single ADC */
4013                 .hp_nid = 0x03,
4014                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4015                 .channel_mode = alc880_2_jack_modes,
4016                 .input_mux = &alc880_capture_source,
4017         },
4018         [ALC880_5ST] = {
4019                 .mixers = { alc880_three_stack_mixer,
4020                             alc880_five_stack_mixer},
4021                 .init_verbs = { alc880_volume_init_verbs,
4022                                 alc880_pin_5stack_init_verbs },
4023                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4024                 .dac_nids = alc880_dac_nids,
4025                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4026                 .channel_mode = alc880_fivestack_modes,
4027                 .input_mux = &alc880_capture_source,
4028         },
4029         [ALC880_5ST_DIG] = {
4030                 .mixers = { alc880_three_stack_mixer,
4031                             alc880_five_stack_mixer },
4032                 .init_verbs = { alc880_volume_init_verbs,
4033                                 alc880_pin_5stack_init_verbs },
4034                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4035                 .dac_nids = alc880_dac_nids,
4036                 .dig_out_nid = ALC880_DIGOUT_NID,
4037                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4038                 .channel_mode = alc880_fivestack_modes,
4039                 .input_mux = &alc880_capture_source,
4040         },
4041         [ALC880_6ST] = {
4042                 .mixers = { alc880_six_stack_mixer },
4043                 .init_verbs = { alc880_volume_init_verbs,
4044                                 alc880_pin_6stack_init_verbs },
4045                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4046                 .dac_nids = alc880_6st_dac_nids,
4047                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4048                 .channel_mode = alc880_sixstack_modes,
4049                 .input_mux = &alc880_6stack_capture_source,
4050         },
4051         [ALC880_6ST_DIG] = {
4052                 .mixers = { alc880_six_stack_mixer },
4053                 .init_verbs = { alc880_volume_init_verbs,
4054                                 alc880_pin_6stack_init_verbs },
4055                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4056                 .dac_nids = alc880_6st_dac_nids,
4057                 .dig_out_nid = ALC880_DIGOUT_NID,
4058                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4059                 .channel_mode = alc880_sixstack_modes,
4060                 .input_mux = &alc880_6stack_capture_source,
4061         },
4062         [ALC880_W810] = {
4063                 .mixers = { alc880_w810_base_mixer },
4064                 .init_verbs = { alc880_volume_init_verbs,
4065                                 alc880_pin_w810_init_verbs,
4066                                 alc880_gpio2_init_verbs },
4067                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4068                 .dac_nids = alc880_w810_dac_nids,
4069                 .dig_out_nid = ALC880_DIGOUT_NID,
4070                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4071                 .channel_mode = alc880_w810_modes,
4072                 .input_mux = &alc880_capture_source,
4073         },
4074         [ALC880_Z71V] = {
4075                 .mixers = { alc880_z71v_mixer },
4076                 .init_verbs = { alc880_volume_init_verbs,
4077                                 alc880_pin_z71v_init_verbs },
4078                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4079                 .dac_nids = alc880_z71v_dac_nids,
4080                 .dig_out_nid = ALC880_DIGOUT_NID,
4081                 .hp_nid = 0x03,
4082                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4083                 .channel_mode = alc880_2_jack_modes,
4084                 .input_mux = &alc880_capture_source,
4085         },
4086         [ALC880_F1734] = {
4087                 .mixers = { alc880_f1734_mixer },
4088                 .init_verbs = { alc880_volume_init_verbs,
4089                                 alc880_pin_f1734_init_verbs },
4090                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4091                 .dac_nids = alc880_f1734_dac_nids,
4092                 .hp_nid = 0x02,
4093                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4094                 .channel_mode = alc880_2_jack_modes,
4095                 .input_mux = &alc880_f1734_capture_source,
4096                 .unsol_event = alc880_uniwill_p53_unsol_event,
4097                 .setup = alc880_uniwill_p53_setup,
4098                 .init_hook = alc_automute_amp,
4099         },
4100         [ALC880_ASUS] = {
4101                 .mixers = { alc880_asus_mixer },
4102                 .init_verbs = { alc880_volume_init_verbs,
4103                                 alc880_pin_asus_init_verbs,
4104                                 alc880_gpio1_init_verbs },
4105                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4106                 .dac_nids = alc880_asus_dac_nids,
4107                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4108                 .channel_mode = alc880_asus_modes,
4109                 .need_dac_fix = 1,
4110                 .input_mux = &alc880_capture_source,
4111         },
4112         [ALC880_ASUS_DIG] = {
4113                 .mixers = { alc880_asus_mixer },
4114                 .init_verbs = { alc880_volume_init_verbs,
4115                                 alc880_pin_asus_init_verbs,
4116                                 alc880_gpio1_init_verbs },
4117                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4118                 .dac_nids = alc880_asus_dac_nids,
4119                 .dig_out_nid = ALC880_DIGOUT_NID,
4120                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4121                 .channel_mode = alc880_asus_modes,
4122                 .need_dac_fix = 1,
4123                 .input_mux = &alc880_capture_source,
4124         },
4125         [ALC880_ASUS_DIG2] = {
4126                 .mixers = { alc880_asus_mixer },
4127                 .init_verbs = { alc880_volume_init_verbs,
4128                                 alc880_pin_asus_init_verbs,
4129                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4130                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4131                 .dac_nids = alc880_asus_dac_nids,
4132                 .dig_out_nid = ALC880_DIGOUT_NID,
4133                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4134                 .channel_mode = alc880_asus_modes,
4135                 .need_dac_fix = 1,
4136                 .input_mux = &alc880_capture_source,
4137         },
4138         [ALC880_ASUS_W1V] = {
4139                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4140                 .init_verbs = { alc880_volume_init_verbs,
4141                                 alc880_pin_asus_init_verbs,
4142                                 alc880_gpio1_init_verbs },
4143                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4144                 .dac_nids = alc880_asus_dac_nids,
4145                 .dig_out_nid = ALC880_DIGOUT_NID,
4146                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4147                 .channel_mode = alc880_asus_modes,
4148                 .need_dac_fix = 1,
4149                 .input_mux = &alc880_capture_source,
4150         },
4151         [ALC880_UNIWILL_DIG] = {
4152                 .mixers = { alc880_asus_mixer },
4153                 .init_verbs = { alc880_volume_init_verbs,
4154                                 alc880_pin_asus_init_verbs },
4155                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4156                 .dac_nids = alc880_asus_dac_nids,
4157                 .dig_out_nid = ALC880_DIGOUT_NID,
4158                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4159                 .channel_mode = alc880_asus_modes,
4160                 .need_dac_fix = 1,
4161                 .input_mux = &alc880_capture_source,
4162         },
4163         [ALC880_UNIWILL] = {
4164                 .mixers = { alc880_uniwill_mixer },
4165                 .init_verbs = { alc880_volume_init_verbs,
4166                                 alc880_uniwill_init_verbs },
4167                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4168                 .dac_nids = alc880_asus_dac_nids,
4169                 .dig_out_nid = ALC880_DIGOUT_NID,
4170                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4171                 .channel_mode = alc880_threestack_modes,
4172                 .need_dac_fix = 1,
4173                 .input_mux = &alc880_capture_source,
4174                 .unsol_event = alc880_uniwill_unsol_event,
4175                 .setup = alc880_uniwill_setup,
4176                 .init_hook = alc880_uniwill_init_hook,
4177         },
4178         [ALC880_UNIWILL_P53] = {
4179                 .mixers = { alc880_uniwill_p53_mixer },
4180                 .init_verbs = { alc880_volume_init_verbs,
4181                                 alc880_uniwill_p53_init_verbs },
4182                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4183                 .dac_nids = alc880_asus_dac_nids,
4184                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4185                 .channel_mode = alc880_threestack_modes,
4186                 .input_mux = &alc880_capture_source,
4187                 .unsol_event = alc880_uniwill_p53_unsol_event,
4188                 .setup = alc880_uniwill_p53_setup,
4189                 .init_hook = alc_automute_amp,
4190         },
4191         [ALC880_FUJITSU] = {
4192                 .mixers = { alc880_fujitsu_mixer },
4193                 .init_verbs = { alc880_volume_init_verbs,
4194                                 alc880_uniwill_p53_init_verbs,
4195                                 alc880_beep_init_verbs },
4196                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4197                 .dac_nids = alc880_dac_nids,
4198                 .dig_out_nid = ALC880_DIGOUT_NID,
4199                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4200                 .channel_mode = alc880_2_jack_modes,
4201                 .input_mux = &alc880_capture_source,
4202                 .unsol_event = alc880_uniwill_p53_unsol_event,
4203                 .setup = alc880_uniwill_p53_setup,
4204                 .init_hook = alc_automute_amp,
4205         },
4206         [ALC880_CLEVO] = {
4207                 .mixers = { alc880_three_stack_mixer },
4208                 .init_verbs = { alc880_volume_init_verbs,
4209                                 alc880_pin_clevo_init_verbs },
4210                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4211                 .dac_nids = alc880_dac_nids,
4212                 .hp_nid = 0x03,
4213                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4214                 .channel_mode = alc880_threestack_modes,
4215                 .need_dac_fix = 1,
4216                 .input_mux = &alc880_capture_source,
4217         },
4218         [ALC880_LG] = {
4219                 .mixers = { alc880_lg_mixer },
4220                 .init_verbs = { alc880_volume_init_verbs,
4221                                 alc880_lg_init_verbs },
4222                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4223                 .dac_nids = alc880_lg_dac_nids,
4224                 .dig_out_nid = ALC880_DIGOUT_NID,
4225                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4226                 .channel_mode = alc880_lg_ch_modes,
4227                 .need_dac_fix = 1,
4228                 .input_mux = &alc880_lg_capture_source,
4229                 .unsol_event = alc_automute_amp_unsol_event,
4230                 .setup = alc880_lg_setup,
4231                 .init_hook = alc_automute_amp,
4232 #ifdef CONFIG_SND_HDA_POWER_SAVE
4233                 .loopbacks = alc880_lg_loopbacks,
4234 #endif
4235         },
4236         [ALC880_LG_LW] = {
4237                 .mixers = { alc880_lg_lw_mixer },
4238                 .init_verbs = { alc880_volume_init_verbs,
4239                                 alc880_lg_lw_init_verbs },
4240                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4241                 .dac_nids = alc880_dac_nids,
4242                 .dig_out_nid = ALC880_DIGOUT_NID,
4243                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4244                 .channel_mode = alc880_lg_lw_modes,
4245                 .input_mux = &alc880_lg_lw_capture_source,
4246                 .unsol_event = alc_automute_amp_unsol_event,
4247                 .setup = alc880_lg_lw_setup,
4248                 .init_hook = alc_automute_amp,
4249         },
4250         [ALC880_MEDION_RIM] = {
4251                 .mixers = { alc880_medion_rim_mixer },
4252                 .init_verbs = { alc880_volume_init_verbs,
4253                                 alc880_medion_rim_init_verbs,
4254                                 alc_gpio2_init_verbs },
4255                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4256                 .dac_nids = alc880_dac_nids,
4257                 .dig_out_nid = ALC880_DIGOUT_NID,
4258                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4259                 .channel_mode = alc880_2_jack_modes,
4260                 .input_mux = &alc880_medion_rim_capture_source,
4261                 .unsol_event = alc880_medion_rim_unsol_event,
4262                 .setup = alc880_medion_rim_setup,
4263                 .init_hook = alc880_medion_rim_automute,
4264         },
4265 #ifdef CONFIG_SND_DEBUG
4266         [ALC880_TEST] = {
4267                 .mixers = { alc880_test_mixer },
4268                 .init_verbs = { alc880_test_init_verbs },
4269                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4270                 .dac_nids = alc880_test_dac_nids,
4271                 .dig_out_nid = ALC880_DIGOUT_NID,
4272                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4273                 .channel_mode = alc880_test_modes,
4274                 .input_mux = &alc880_test_capture_source,
4275         },
4276 #endif
4277 };
4278
4279 /*
4280  * Automatic parse of I/O pins from the BIOS configuration
4281  */
4282
4283 enum {
4284         ALC_CTL_WIDGET_VOL,
4285         ALC_CTL_WIDGET_MUTE,
4286         ALC_CTL_BIND_MUTE,
4287 };
4288 static struct snd_kcontrol_new alc880_control_templates[] = {
4289         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4290         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4291         HDA_BIND_MUTE(NULL, 0, 0, 0),
4292 };
4293
4294 /* add dynamic controls */
4295 static int add_control(struct alc_spec *spec, int type, const char *name,
4296                        unsigned long val)
4297 {
4298         struct snd_kcontrol_new *knew;
4299
4300         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4301         knew = snd_array_new(&spec->kctls);
4302         if (!knew)
4303                 return -ENOMEM;
4304         *knew = alc880_control_templates[type];
4305         knew->name = kstrdup(name, GFP_KERNEL);
4306         if (!knew->name)
4307                 return -ENOMEM;
4308         knew->private_value = val;
4309         return 0;
4310 }
4311
4312 static int add_control_with_pfx(struct alc_spec *spec, int type,
4313                                 const char *pfx, const char *dir,
4314                                 const char *sfx, unsigned long val)
4315 {
4316         char name[32];
4317         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4318         return add_control(spec, type, name, val);
4319 }
4320
4321 #define add_pb_vol_ctrl(spec, type, pfx, val) \
4322         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4323 #define add_pb_sw_ctrl(spec, type, pfx, val) \
4324         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4325
4326 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4327 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4328 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4329 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4330 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4331 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4332 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4333 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4334 #define ALC880_PIN_CD_NID               0x1c
4335
4336 /* fill in the dac_nids table from the parsed pin configuration */
4337 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4338                                      const struct auto_pin_cfg *cfg)
4339 {
4340         hda_nid_t nid;
4341         int assigned[4];
4342         int i, j;
4343
4344         memset(assigned, 0, sizeof(assigned));
4345         spec->multiout.dac_nids = spec->private_dac_nids;
4346
4347         /* check the pins hardwired to audio widget */
4348         for (i = 0; i < cfg->line_outs; i++) {
4349                 nid = cfg->line_out_pins[i];
4350                 if (alc880_is_fixed_pin(nid)) {
4351                         int idx = alc880_fixed_pin_idx(nid);
4352                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4353                         assigned[idx] = 1;
4354                 }
4355         }
4356         /* left pins can be connect to any audio widget */
4357         for (i = 0; i < cfg->line_outs; i++) {
4358                 nid = cfg->line_out_pins[i];
4359                 if (alc880_is_fixed_pin(nid))
4360                         continue;
4361                 /* search for an empty channel */
4362                 for (j = 0; j < cfg->line_outs; j++) {
4363                         if (!assigned[j]) {
4364                                 spec->multiout.dac_nids[i] =
4365                                         alc880_idx_to_dac(j);
4366                                 assigned[j] = 1;
4367                                 break;
4368                         }
4369                 }
4370         }
4371         spec->multiout.num_dacs = cfg->line_outs;
4372         return 0;
4373 }
4374
4375 /* add playback controls from the parsed DAC table */
4376 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4377                                              const struct auto_pin_cfg *cfg)
4378 {
4379         static const char *chname[4] = {
4380                 "Front", "Surround", NULL /*CLFE*/, "Side"
4381         };
4382         hda_nid_t nid;
4383         int i, err;
4384
4385         for (i = 0; i < cfg->line_outs; i++) {
4386                 if (!spec->multiout.dac_nids[i])
4387                         continue;
4388                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4389                 if (i == 2) {
4390                         /* Center/LFE */
4391                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4392                                               "Center",
4393                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4394                                                               HDA_OUTPUT));
4395                         if (err < 0)
4396                                 return err;
4397                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4398                                               "LFE",
4399                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4400                                                               HDA_OUTPUT));
4401                         if (err < 0)
4402                                 return err;
4403                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4404                                              "Center",
4405                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4406                                                               HDA_INPUT));
4407                         if (err < 0)
4408                                 return err;
4409                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4410                                              "LFE",
4411                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4412                                                               HDA_INPUT));
4413                         if (err < 0)
4414                                 return err;
4415                 } else {
4416                         const char *pfx;
4417                         if (cfg->line_outs == 1 &&
4418                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4419                                 pfx = "Speaker";
4420                         else
4421                                 pfx = chname[i];
4422                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4423                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4424                                                               HDA_OUTPUT));
4425                         if (err < 0)
4426                                 return err;
4427                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4428                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4429                                                               HDA_INPUT));
4430                         if (err < 0)
4431                                 return err;
4432                 }
4433         }
4434         return 0;
4435 }
4436
4437 /* add playback controls for speaker and HP outputs */
4438 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4439                                         const char *pfx)
4440 {
4441         hda_nid_t nid;
4442         int err;
4443
4444         if (!pin)
4445                 return 0;
4446
4447         if (alc880_is_fixed_pin(pin)) {
4448                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4449                 /* specify the DAC as the extra output */
4450                 if (!spec->multiout.hp_nid)
4451                         spec->multiout.hp_nid = nid;
4452                 else
4453                         spec->multiout.extra_out_nid[0] = nid;
4454                 /* control HP volume/switch on the output mixer amp */
4455                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4456                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4457                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4458                 if (err < 0)
4459                         return err;
4460                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4461                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4462                 if (err < 0)
4463                         return err;
4464         } else if (alc880_is_multi_pin(pin)) {
4465                 /* set manual connection */
4466                 /* we have only a switch on HP-out PIN */
4467                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4468                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4469                 if (err < 0)
4470                         return err;
4471         }
4472         return 0;
4473 }
4474
4475 /* create input playback/capture controls for the given pin */
4476 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4477                             const char *ctlname,
4478                             int idx, hda_nid_t mix_nid)
4479 {
4480         int err;
4481
4482         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4483                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4484         if (err < 0)
4485                 return err;
4486         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4487                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4488         if (err < 0)
4489                 return err;
4490         return 0;
4491 }
4492
4493 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4494 {
4495         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4496         return (pincap & AC_PINCAP_IN) != 0;
4497 }
4498
4499 /* create playback/capture controls for input pins */
4500 static int alc_auto_create_input_ctls(struct hda_codec *codec,
4501                                       const struct auto_pin_cfg *cfg,
4502                                       hda_nid_t mixer,
4503                                       hda_nid_t cap1, hda_nid_t cap2)
4504 {
4505         struct alc_spec *spec = codec->spec;
4506         struct hda_input_mux *imux = &spec->private_imux[0];
4507         int i, err, idx;
4508
4509         for (i = 0; i < AUTO_PIN_LAST; i++) {
4510                 hda_nid_t pin;
4511
4512                 pin = cfg->input_pins[i];
4513                 if (!alc_is_input_pin(codec, pin))
4514                         continue;
4515
4516                 if (mixer) {
4517                         idx = get_connection_index(codec, mixer, pin);
4518                         if (idx >= 0) {
4519                                 err = new_analog_input(spec, pin,
4520                                                        auto_pin_cfg_labels[i],
4521                                                        idx, mixer);
4522                                 if (err < 0)
4523                                         return err;
4524                         }
4525                 }
4526
4527                 if (!cap1)
4528                         continue;
4529                 idx = get_connection_index(codec, cap1, pin);
4530                 if (idx < 0 && cap2)
4531                         idx = get_connection_index(codec, cap2, pin);
4532                 if (idx >= 0) {
4533                         imux->items[imux->num_items].label =
4534                                 auto_pin_cfg_labels[i];
4535                         imux->items[imux->num_items].index = idx;
4536                         imux->num_items++;
4537                 }
4538         }
4539         return 0;
4540 }
4541
4542 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4543                                                 const struct auto_pin_cfg *cfg)
4544 {
4545         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4546 }
4547
4548 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4549                                unsigned int pin_type)
4550 {
4551         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4552                             pin_type);
4553         /* unmute pin */
4554         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4555                             AMP_OUT_UNMUTE);
4556 }
4557
4558 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4559                                               hda_nid_t nid, int pin_type,
4560                                               int dac_idx)
4561 {
4562         alc_set_pin_output(codec, nid, pin_type);
4563         /* need the manual connection? */
4564         if (alc880_is_multi_pin(nid)) {
4565                 struct alc_spec *spec = codec->spec;
4566                 int idx = alc880_multi_pin_idx(nid);
4567                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4568                                     AC_VERB_SET_CONNECT_SEL,
4569                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4570         }
4571 }
4572
4573 static int get_pin_type(int line_out_type)
4574 {
4575         if (line_out_type == AUTO_PIN_HP_OUT)
4576                 return PIN_HP;
4577         else
4578                 return PIN_OUT;
4579 }
4580
4581 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4582 {
4583         struct alc_spec *spec = codec->spec;
4584         int i;
4585
4586         for (i = 0; i < spec->autocfg.line_outs; i++) {
4587                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4588                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4589                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4590         }
4591 }
4592
4593 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4594 {
4595         struct alc_spec *spec = codec->spec;
4596         hda_nid_t pin;
4597
4598         pin = spec->autocfg.speaker_pins[0];
4599         if (pin) /* connect to front */
4600                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4601         pin = spec->autocfg.hp_pins[0];
4602         if (pin) /* connect to front */
4603                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4604 }
4605
4606 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4607 {
4608         struct alc_spec *spec = codec->spec;
4609         int i;
4610
4611         for (i = 0; i < AUTO_PIN_LAST; i++) {
4612                 hda_nid_t nid = spec->autocfg.input_pins[i];
4613                 if (alc_is_input_pin(codec, nid)) {
4614                         alc_set_input_pin(codec, nid, i);
4615                         if (nid != ALC880_PIN_CD_NID &&
4616                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4617                                 snd_hda_codec_write(codec, nid, 0,
4618                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4619                                                     AMP_OUT_MUTE);
4620                 }
4621         }
4622 }
4623
4624 /* parse the BIOS configuration and set up the alc_spec */
4625 /* return 1 if successful, 0 if the proper config is not found,
4626  * or a negative error code
4627  */
4628 static int alc880_parse_auto_config(struct hda_codec *codec)
4629 {
4630         struct alc_spec *spec = codec->spec;
4631         int i, err;
4632         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4633
4634         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4635                                            alc880_ignore);
4636         if (err < 0)
4637                 return err;
4638         if (!spec->autocfg.line_outs)
4639                 return 0; /* can't find valid BIOS pin config */
4640
4641         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4642         if (err < 0)
4643                 return err;
4644         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4645         if (err < 0)
4646                 return err;
4647         err = alc880_auto_create_extra_out(spec,
4648                                            spec->autocfg.speaker_pins[0],
4649                                            "Speaker");
4650         if (err < 0)
4651                 return err;
4652         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4653                                            "Headphone");
4654         if (err < 0)
4655                 return err;
4656         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4657         if (err < 0)
4658                 return err;
4659
4660         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4661
4662         /* check multiple SPDIF-out (for recent codecs) */
4663         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4664                 hda_nid_t dig_nid;
4665                 err = snd_hda_get_connections(codec,
4666                                               spec->autocfg.dig_out_pins[i],
4667                                               &dig_nid, 1);
4668                 if (err < 0)
4669                         continue;
4670                 if (!i)
4671                         spec->multiout.dig_out_nid = dig_nid;
4672                 else {
4673                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4674                         spec->slave_dig_outs[i - 1] = dig_nid;
4675                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4676                                 break;
4677                 }
4678         }
4679         if (spec->autocfg.dig_in_pin)
4680                 spec->dig_in_nid = ALC880_DIGIN_NID;
4681
4682         if (spec->kctls.list)
4683                 add_mixer(spec, spec->kctls.list);
4684
4685         add_verb(spec, alc880_volume_init_verbs);
4686
4687         spec->num_mux_defs = 1;
4688         spec->input_mux = &spec->private_imux[0];
4689
4690         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4691
4692         return 1;
4693 }
4694
4695 /* additional initialization for auto-configuration model */
4696 static void alc880_auto_init(struct hda_codec *codec)
4697 {
4698         struct alc_spec *spec = codec->spec;
4699         alc880_auto_init_multi_out(codec);
4700         alc880_auto_init_extra_out(codec);
4701         alc880_auto_init_analog_input(codec);
4702         if (spec->unsol_event)
4703                 alc_inithook(codec);
4704 }
4705
4706 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4707  * one of two digital mic pins, e.g. on ALC272
4708  */
4709 static void fixup_automic_adc(struct hda_codec *codec)
4710 {
4711         struct alc_spec *spec = codec->spec;
4712         int i;
4713
4714         for (i = 0; i < spec->num_adc_nids; i++) {
4715                 hda_nid_t cap = spec->capsrc_nids ?
4716                         spec->capsrc_nids[i] : spec->adc_nids[i];
4717                 int iidx, eidx;
4718
4719                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4720                 if (iidx < 0)
4721                         continue;
4722                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4723                 if (eidx < 0)
4724                         continue;
4725                 spec->int_mic.mux_idx = iidx;
4726                 spec->ext_mic.mux_idx = eidx;
4727                 if (spec->capsrc_nids)
4728                         spec->capsrc_nids += i;
4729                 spec->adc_nids += i;
4730                 spec->num_adc_nids = 1;
4731                 return;
4732         }
4733         snd_printd(KERN_INFO "hda_codec: %s: "
4734                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4735                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4736         spec->auto_mic = 0; /* disable auto-mic to be sure */
4737 }
4738
4739 static void set_capture_mixer(struct hda_codec *codec)
4740 {
4741         struct alc_spec *spec = codec->spec;
4742         static struct snd_kcontrol_new *caps[2][3] = {
4743                 { alc_capture_mixer_nosrc1,
4744                   alc_capture_mixer_nosrc2,
4745                   alc_capture_mixer_nosrc3 },
4746                 { alc_capture_mixer1,
4747                   alc_capture_mixer2,
4748                   alc_capture_mixer3 },
4749         };
4750         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4751                 int mux;
4752                 if (spec->auto_mic) {
4753                         mux = 0;
4754                         fixup_automic_adc(codec);
4755                 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4756                         mux = 1;
4757                 else
4758                         mux = 0;
4759                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4760         }
4761 }
4762
4763 #define set_beep_amp(spec, nid, idx, dir) \
4764         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4765
4766 /*
4767  * OK, here we have finally the patch for ALC880
4768  */
4769
4770 static int patch_alc880(struct hda_codec *codec)
4771 {
4772         struct alc_spec *spec;
4773         int board_config;
4774         int err;
4775
4776         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4777         if (spec == NULL)
4778                 return -ENOMEM;
4779
4780         codec->spec = spec;
4781
4782         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4783                                                   alc880_models,
4784                                                   alc880_cfg_tbl);
4785         if (board_config < 0) {
4786                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4787                        codec->chip_name);
4788                 board_config = ALC880_AUTO;
4789         }
4790
4791         if (board_config == ALC880_AUTO) {
4792                 /* automatic parse from the BIOS config */
4793                 err = alc880_parse_auto_config(codec);
4794                 if (err < 0) {
4795                         alc_free(codec);
4796                         return err;
4797                 } else if (!err) {
4798                         printk(KERN_INFO
4799                                "hda_codec: Cannot set up configuration "
4800                                "from BIOS.  Using 3-stack mode...\n");
4801                         board_config = ALC880_3ST;
4802                 }
4803         }
4804
4805         err = snd_hda_attach_beep_device(codec, 0x1);
4806         if (err < 0) {
4807                 alc_free(codec);
4808                 return err;
4809         }
4810
4811         if (board_config != ALC880_AUTO)
4812                 setup_preset(codec, &alc880_presets[board_config]);
4813
4814         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4815         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4816         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4817
4818         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4819         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4820
4821         if (!spec->adc_nids && spec->input_mux) {
4822                 /* check whether NID 0x07 is valid */
4823                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4824                 /* get type */
4825                 wcap = get_wcaps_type(wcap);
4826                 if (wcap != AC_WID_AUD_IN) {
4827                         spec->adc_nids = alc880_adc_nids_alt;
4828                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4829                 } else {
4830                         spec->adc_nids = alc880_adc_nids;
4831                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4832                 }
4833         }
4834         set_capture_mixer(codec);
4835         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4836
4837         spec->vmaster_nid = 0x0c;
4838
4839         codec->patch_ops = alc_patch_ops;
4840         if (board_config == ALC880_AUTO)
4841                 spec->init_hook = alc880_auto_init;
4842 #ifdef CONFIG_SND_HDA_POWER_SAVE
4843         if (!spec->loopback.amplist)
4844                 spec->loopback.amplist = alc880_loopbacks;
4845 #endif
4846         codec->proc_widget_hook = print_realtek_coef;
4847
4848         return 0;
4849 }
4850
4851
4852 /*
4853  * ALC260 support
4854  */
4855
4856 static hda_nid_t alc260_dac_nids[1] = {
4857         /* front */
4858         0x02,
4859 };
4860
4861 static hda_nid_t alc260_adc_nids[1] = {
4862         /* ADC0 */
4863         0x04,
4864 };
4865
4866 static hda_nid_t alc260_adc_nids_alt[1] = {
4867         /* ADC1 */
4868         0x05,
4869 };
4870
4871 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4872  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4873  */
4874 static hda_nid_t alc260_dual_adc_nids[2] = {
4875         /* ADC0, ADC1 */
4876         0x04, 0x05
4877 };
4878
4879 #define ALC260_DIGOUT_NID       0x03
4880 #define ALC260_DIGIN_NID        0x06
4881
4882 static struct hda_input_mux alc260_capture_source = {
4883         .num_items = 4,
4884         .items = {
4885                 { "Mic", 0x0 },
4886                 { "Front Mic", 0x1 },
4887                 { "Line", 0x2 },
4888                 { "CD", 0x4 },
4889         },
4890 };
4891
4892 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4893  * headphone jack and the internal CD lines since these are the only pins at
4894  * which audio can appear.  For flexibility, also allow the option of
4895  * recording the mixer output on the second ADC (ADC0 doesn't have a
4896  * connection to the mixer output).
4897  */
4898 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4899         {
4900                 .num_items = 3,
4901                 .items = {
4902                         { "Mic/Line", 0x0 },
4903                         { "CD", 0x4 },
4904                         { "Headphone", 0x2 },
4905                 },
4906         },
4907         {
4908                 .num_items = 4,
4909                 .items = {
4910                         { "Mic/Line", 0x0 },
4911                         { "CD", 0x4 },
4912                         { "Headphone", 0x2 },
4913                         { "Mixer", 0x5 },
4914                 },
4915         },
4916
4917 };
4918
4919 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4920  * the Fujitsu S702x, but jacks are marked differently.
4921  */
4922 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4923         {
4924                 .num_items = 4,
4925                 .items = {
4926                         { "Mic", 0x0 },
4927                         { "Line", 0x2 },
4928                         { "CD", 0x4 },
4929                         { "Headphone", 0x5 },
4930                 },
4931         },
4932         {
4933                 .num_items = 5,
4934                 .items = {
4935                         { "Mic", 0x0 },
4936                         { "Line", 0x2 },
4937                         { "CD", 0x4 },
4938                         { "Headphone", 0x6 },
4939                         { "Mixer", 0x5 },
4940                 },
4941         },
4942 };
4943
4944 /* Maxdata Favorit 100XS */
4945 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4946         {
4947                 .num_items = 2,
4948                 .items = {
4949                         { "Line/Mic", 0x0 },
4950                         { "CD", 0x4 },
4951                 },
4952         },
4953         {
4954                 .num_items = 3,
4955                 .items = {
4956                         { "Line/Mic", 0x0 },
4957                         { "CD", 0x4 },
4958                         { "Mixer", 0x5 },
4959                 },
4960         },
4961 };
4962
4963 /*
4964  * This is just place-holder, so there's something for alc_build_pcms to look
4965  * at when it calculates the maximum number of channels. ALC260 has no mixer
4966  * element which allows changing the channel mode, so the verb list is
4967  * never used.
4968  */
4969 static struct hda_channel_mode alc260_modes[1] = {
4970         { 2, NULL },
4971 };
4972
4973
4974 /* Mixer combinations
4975  *
4976  * basic: base_output + input + pc_beep + capture
4977  * HP: base_output + input + capture_alt
4978  * HP_3013: hp_3013 + input + capture
4979  * fujitsu: fujitsu + capture
4980  * acer: acer + capture
4981  */
4982
4983 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4984         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4985         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4986         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4987         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4988         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4989         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4990         { } /* end */
4991 };
4992
4993 static struct snd_kcontrol_new alc260_input_mixer[] = {
4994         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4995         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4996         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4997         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4998         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4999         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5000         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5001         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5002         { } /* end */
5003 };
5004
5005 /* update HP, line and mono out pins according to the master switch */
5006 static void alc260_hp_master_update(struct hda_codec *codec,
5007                                     hda_nid_t hp, hda_nid_t line,
5008                                     hda_nid_t mono)
5009 {
5010         struct alc_spec *spec = codec->spec;
5011         unsigned int val = spec->master_sw ? PIN_HP : 0;
5012         /* change HP and line-out pins */
5013         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5014                             val);
5015         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5016                             val);
5017         /* mono (speaker) depending on the HP jack sense */
5018         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5019         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5020                             val);
5021 }
5022
5023 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5024                                    struct snd_ctl_elem_value *ucontrol)
5025 {
5026         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5027         struct alc_spec *spec = codec->spec;
5028         *ucontrol->value.integer.value = spec->master_sw;
5029         return 0;
5030 }
5031
5032 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5033                                    struct snd_ctl_elem_value *ucontrol)
5034 {
5035         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5036         struct alc_spec *spec = codec->spec;
5037         int val = !!*ucontrol->value.integer.value;
5038         hda_nid_t hp, line, mono;
5039
5040         if (val == spec->master_sw)
5041                 return 0;
5042         spec->master_sw = val;
5043         hp = (kcontrol->private_value >> 16) & 0xff;
5044         line = (kcontrol->private_value >> 8) & 0xff;
5045         mono = kcontrol->private_value & 0xff;
5046         alc260_hp_master_update(codec, hp, line, mono);
5047         return 1;
5048 }
5049
5050 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5051         {
5052                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5053                 .name = "Master Playback Switch",
5054                 .info = snd_ctl_boolean_mono_info,
5055                 .get = alc260_hp_master_sw_get,
5056                 .put = alc260_hp_master_sw_put,
5057                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5058         },
5059         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5060         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5061         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5062         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5063         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5064                               HDA_OUTPUT),
5065         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5066         { } /* end */
5067 };
5068
5069 static struct hda_verb alc260_hp_unsol_verbs[] = {
5070         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5071         {},
5072 };
5073
5074 static void alc260_hp_automute(struct hda_codec *codec)
5075 {
5076         struct alc_spec *spec = codec->spec;
5077         unsigned int present;
5078
5079         present = snd_hda_codec_read(codec, 0x10, 0,
5080                                      AC_VERB_GET_PIN_SENSE, 0);
5081         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5082         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5083 }
5084
5085 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5086 {
5087         if ((res >> 26) == ALC880_HP_EVENT)
5088                 alc260_hp_automute(codec);
5089 }
5090
5091 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5092         {
5093                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5094                 .name = "Master Playback Switch",
5095                 .info = snd_ctl_boolean_mono_info,
5096                 .get = alc260_hp_master_sw_get,
5097                 .put = alc260_hp_master_sw_put,
5098                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5099         },
5100         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5101         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5102         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5103         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5104         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5105         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5106         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5107         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5108         { } /* end */
5109 };
5110
5111 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5112         .ops = &snd_hda_bind_vol,
5113         .values = {
5114                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5115                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5116                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5117                 0
5118         },
5119 };
5120
5121 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5122         .ops = &snd_hda_bind_sw,
5123         .values = {
5124                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5125                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5126                 0
5127         },
5128 };
5129
5130 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5131         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5132         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5133         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5134         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5135         { } /* end */
5136 };
5137
5138 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5139         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5140         {},
5141 };
5142
5143 static void alc260_hp_3013_automute(struct hda_codec *codec)
5144 {
5145         struct alc_spec *spec = codec->spec;
5146         unsigned int present;
5147
5148         present = snd_hda_codec_read(codec, 0x15, 0,
5149                                      AC_VERB_GET_PIN_SENSE, 0);
5150         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5151         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5152 }
5153
5154 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5155                                        unsigned int res)
5156 {
5157         if ((res >> 26) == ALC880_HP_EVENT)
5158                 alc260_hp_3013_automute(codec);
5159 }
5160
5161 static void alc260_hp_3012_automute(struct hda_codec *codec)
5162 {
5163         unsigned int present, bits;
5164
5165         present = snd_hda_codec_read(codec, 0x10, 0,
5166                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5167
5168         bits = present ? 0 : PIN_OUT;
5169         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5170                             bits);
5171         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5172                             bits);
5173         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5174                             bits);
5175 }
5176
5177 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5178                                        unsigned int res)
5179 {
5180         if ((res >> 26) == ALC880_HP_EVENT)
5181                 alc260_hp_3012_automute(codec);
5182 }
5183
5184 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5185  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5186  */
5187 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5188         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5189         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5190         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5191         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5192         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5193         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5194         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5195         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5196         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5197         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5198         { } /* end */
5199 };
5200
5201 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5202  * versions of the ALC260 don't act on requests to enable mic bias from NID
5203  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5204  * datasheet doesn't mention this restriction.  At this stage it's not clear
5205  * whether this behaviour is intentional or is a hardware bug in chip
5206  * revisions available in early 2006.  Therefore for now allow the
5207  * "Headphone Jack Mode" control to span all choices, but if it turns out
5208  * that the lack of mic bias for this NID is intentional we could change the
5209  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5210  *
5211  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5212  * don't appear to make the mic bias available from the "line" jack, even
5213  * though the NID used for this jack (0x14) can supply it.  The theory is
5214  * that perhaps Acer have included blocking capacitors between the ALC260
5215  * and the output jack.  If this turns out to be the case for all such
5216  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5217  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5218  *
5219  * The C20x Tablet series have a mono internal speaker which is controlled
5220  * via the chip's Mono sum widget and pin complex, so include the necessary
5221  * controls for such models.  On models without a "mono speaker" the control
5222  * won't do anything.
5223  */
5224 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5225         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5226         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5227         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5228         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5229                               HDA_OUTPUT),
5230         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5231                            HDA_INPUT),
5232         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5233         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5234         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5235         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5236         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5237         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5238         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5239         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5240         { } /* end */
5241 };
5242
5243 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5244  */
5245 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5246         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5247         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5248         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5249         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5250         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5251         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5252         { } /* end */
5253 };
5254
5255 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5256  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5257  */
5258 static struct snd_kcontrol_new alc260_will_mixer[] = {
5259         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5260         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5261         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5262         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5263         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5264         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5265         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5266         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5267         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5268         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5269         { } /* end */
5270 };
5271
5272 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5273  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5274  */
5275 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5276         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5277         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5278         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5279         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5280         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5281         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5282         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5283         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5284         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5285         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5286         { } /* end */
5287 };
5288
5289 /*
5290  * initialization verbs
5291  */
5292 static struct hda_verb alc260_init_verbs[] = {
5293         /* Line In pin widget for input */
5294         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5295         /* CD pin widget for input */
5296         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5297         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5298         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5299         /* Mic2 (front panel) pin widget for input and vref at 80% */
5300         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5301         /* LINE-2 is used for line-out in rear */
5302         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5303         /* select line-out */
5304         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5305         /* LINE-OUT pin */
5306         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5307         /* enable HP */
5308         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5309         /* enable Mono */
5310         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5311         /* mute capture amp left and right */
5312         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5313         /* set connection select to line in (default select for this ADC) */
5314         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5315         /* mute capture amp left and right */
5316         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5317         /* set connection select to line in (default select for this ADC) */
5318         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5319         /* set vol=0 Line-Out mixer amp left and right */
5320         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5321         /* unmute pin widget amp left and right (no gain on this amp) */
5322         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5323         /* set vol=0 HP mixer amp left and right */
5324         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5325         /* unmute pin widget amp left and right (no gain on this amp) */
5326         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5327         /* set vol=0 Mono mixer amp left and right */
5328         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5329         /* unmute pin widget amp left and right (no gain on this amp) */
5330         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5331         /* unmute LINE-2 out pin */
5332         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5333         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5334          * Line In 2 = 0x03
5335          */
5336         /* mute analog inputs */
5337         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5338         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5339         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5340         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5341         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5342         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5343         /* mute Front out path */
5344         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5345         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5346         /* mute Headphone out path */
5347         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5348         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5349         /* mute Mono out path */
5350         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5351         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5352         { }
5353 };
5354
5355 #if 0 /* should be identical with alc260_init_verbs? */
5356 static struct hda_verb alc260_hp_init_verbs[] = {
5357         /* Headphone and output */
5358         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5359         /* mono output */
5360         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5361         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5362         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5363         /* Mic2 (front panel) pin widget for input and vref at 80% */
5364         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5365         /* Line In pin widget for input */
5366         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5367         /* Line-2 pin widget for output */
5368         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5369         /* CD pin widget for input */
5370         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5371         /* unmute amp left and right */
5372         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5373         /* set connection select to line in (default select for this ADC) */
5374         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5375         /* unmute Line-Out mixer amp left and right (volume = 0) */
5376         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5377         /* mute pin widget amp left and right (no gain on this amp) */
5378         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5379         /* unmute HP mixer amp left and right (volume = 0) */
5380         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5381         /* mute pin widget amp left and right (no gain on this amp) */
5382         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5383         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5384          * Line In 2 = 0x03
5385          */
5386         /* mute analog inputs */
5387         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5388         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5389         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5390         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5391         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5392         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5393         /* Unmute Front out path */
5394         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5395         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5396         /* Unmute Headphone out path */
5397         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5398         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5399         /* Unmute Mono out path */
5400         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5401         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5402         { }
5403 };
5404 #endif
5405
5406 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5407         /* Line out and output */
5408         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5409         /* mono output */
5410         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5411         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5412         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5413         /* Mic2 (front panel) pin widget for input and vref at 80% */
5414         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5415         /* Line In pin widget for input */
5416         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5417         /* Headphone pin widget for output */
5418         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5419         /* CD pin widget for input */
5420         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5421         /* unmute amp left and right */
5422         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5423         /* set connection select to line in (default select for this ADC) */
5424         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5425         /* unmute Line-Out mixer amp left and right (volume = 0) */
5426         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5427         /* mute pin widget amp left and right (no gain on this amp) */
5428         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5429         /* unmute HP mixer amp left and right (volume = 0) */
5430         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5431         /* mute pin widget amp left and right (no gain on this amp) */
5432         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5433         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5434          * Line In 2 = 0x03
5435          */
5436         /* mute analog inputs */
5437         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5438         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5439         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5440         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5441         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5442         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5443         /* Unmute Front out path */
5444         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5445         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5446         /* Unmute Headphone out path */
5447         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5448         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5449         /* Unmute Mono out path */
5450         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5451         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5452         { }
5453 };
5454
5455 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5456  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5457  * audio = 0x16, internal speaker = 0x10.
5458  */
5459 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5460         /* Disable all GPIOs */
5461         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5462         /* Internal speaker is connected to headphone pin */
5463         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5464         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5465         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5466         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5467         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5468         /* Ensure all other unused pins are disabled and muted. */
5469         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5470         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5471         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5472         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5473         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5474         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5475         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5476         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5477
5478         /* Disable digital (SPDIF) pins */
5479         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5480         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5481
5482         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5483          * when acting as an output.
5484          */
5485         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5486
5487         /* Start with output sum widgets muted and their output gains at min */
5488         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5489         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5490         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5491         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5492         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5494         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5495         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5496         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5497
5498         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5499         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5500         /* Unmute Line1 pin widget output buffer since it starts as an output.
5501          * If the pin mode is changed by the user the pin mode control will
5502          * take care of enabling the pin's input/output buffers as needed.
5503          * Therefore there's no need to enable the input buffer at this
5504          * stage.
5505          */
5506         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5507         /* Unmute input buffer of pin widget used for Line-in (no equiv
5508          * mixer ctrl)
5509          */
5510         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5511
5512         /* Mute capture amp left and right */
5513         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5514         /* Set ADC connection select to match default mixer setting - line
5515          * in (on mic1 pin)
5516          */
5517         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5518
5519         /* Do the same for the second ADC: mute capture input amp and
5520          * set ADC connection to line in (on mic1 pin)
5521          */
5522         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5523         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5524
5525         /* Mute all inputs to mixer widget (even unconnected ones) */
5526         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5527         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5528         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5529         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5530         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5531         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5532         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5533         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5534
5535         { }
5536 };
5537
5538 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5539  * similar laptops (adapted from Fujitsu init verbs).
5540  */
5541 static struct hda_verb alc260_acer_init_verbs[] = {
5542         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5543          * the headphone jack.  Turn this on and rely on the standard mute
5544          * methods whenever the user wants to turn these outputs off.
5545          */
5546         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5547         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5548         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5549         /* Internal speaker/Headphone jack is connected to Line-out pin */
5550         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5551         /* Internal microphone/Mic jack is connected to Mic1 pin */
5552         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5553         /* Line In jack is connected to Line1 pin */
5554         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5555         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5556         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5557         /* Ensure all other unused pins are disabled and muted. */
5558         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5559         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5560         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5561         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5562         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5563         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5564         /* Disable digital (SPDIF) pins */
5565         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5566         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5567
5568         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5569          * bus when acting as outputs.
5570          */
5571         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5572         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5573
5574         /* Start with output sum widgets muted and their output gains at min */
5575         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5576         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5577         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5578         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5579         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5580         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5581         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5582         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5583         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5584
5585         /* Unmute Line-out pin widget amp left and right
5586          * (no equiv mixer ctrl)
5587          */
5588         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5589         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5590         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5591         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5592          * inputs. If the pin mode is changed by the user the pin mode control
5593          * will take care of enabling the pin's input/output buffers as needed.
5594          * Therefore there's no need to enable the input buffer at this
5595          * stage.
5596          */
5597         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5598         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5599
5600         /* Mute capture amp left and right */
5601         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5602         /* Set ADC connection select to match default mixer setting - mic
5603          * (on mic1 pin)
5604          */
5605         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5606
5607         /* Do similar with the second ADC: mute capture input amp and
5608          * set ADC connection to mic to match ALSA's default state.
5609          */
5610         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5611         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5612
5613         /* Mute all inputs to mixer widget (even unconnected ones) */
5614         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5615         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5616         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5617         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5618         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5619         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5620         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5621         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5622
5623         { }
5624 };
5625
5626 /* Initialisation sequence for Maxdata Favorit 100XS
5627  * (adapted from Acer init verbs).
5628  */
5629 static struct hda_verb alc260_favorit100_init_verbs[] = {
5630         /* GPIO 0 enables the output jack.
5631          * Turn this on and rely on the standard mute
5632          * methods whenever the user wants to turn these outputs off.
5633          */
5634         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5635         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5636         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5637         /* Line/Mic input jack is connected to Mic1 pin */
5638         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5639         /* Ensure all other unused pins are disabled and muted. */
5640         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5641         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5642         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5643         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5644         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5645         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5646         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5647         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5648         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5649         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5650         /* Disable digital (SPDIF) pins */
5651         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5652         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5653
5654         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5655          * bus when acting as outputs.
5656          */
5657         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5658         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5659
5660         /* Start with output sum widgets muted and their output gains at min */
5661         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5662         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5663         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5664         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5665         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5666         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5667         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5668         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5669         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5670
5671         /* Unmute Line-out pin widget amp left and right
5672          * (no equiv mixer ctrl)
5673          */
5674         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5675         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5676          * inputs. If the pin mode is changed by the user the pin mode control
5677          * will take care of enabling the pin's input/output buffers as needed.
5678          * Therefore there's no need to enable the input buffer at this
5679          * stage.
5680          */
5681         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5682
5683         /* Mute capture amp left and right */
5684         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5685         /* Set ADC connection select to match default mixer setting - mic
5686          * (on mic1 pin)
5687          */
5688         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5689
5690         /* Do similar with the second ADC: mute capture input amp and
5691          * set ADC connection to mic to match ALSA's default state.
5692          */
5693         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5694         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5695
5696         /* Mute all inputs to mixer widget (even unconnected ones) */
5697         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5698         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5699         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5700         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5701         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5702         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5703         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5704         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5705
5706         { }
5707 };
5708
5709 static struct hda_verb alc260_will_verbs[] = {
5710         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5711         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5712         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5713         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5714         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5715         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5716         {}
5717 };
5718
5719 static struct hda_verb alc260_replacer_672v_verbs[] = {
5720         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5721         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5722         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5723
5724         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5725         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5726         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5727
5728         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5729         {}
5730 };
5731
5732 /* toggle speaker-output according to the hp-jack state */
5733 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5734 {
5735         unsigned int present;
5736
5737         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5738         present = snd_hda_codec_read(codec, 0x0f, 0,
5739                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5740         if (present) {
5741                 snd_hda_codec_write_cache(codec, 0x01, 0,
5742                                           AC_VERB_SET_GPIO_DATA, 1);
5743                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5744                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5745                                           PIN_HP);
5746         } else {
5747                 snd_hda_codec_write_cache(codec, 0x01, 0,
5748                                           AC_VERB_SET_GPIO_DATA, 0);
5749                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5750                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5751                                           PIN_OUT);
5752         }
5753 }
5754
5755 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5756                                        unsigned int res)
5757 {
5758         if ((res >> 26) == ALC880_HP_EVENT)
5759                 alc260_replacer_672v_automute(codec);
5760 }
5761
5762 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5763         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5764         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5765         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5766         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5767         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5768         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5769         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5770         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5771         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5772         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5773         {}
5774 };
5775
5776 /* Test configuration for debugging, modelled after the ALC880 test
5777  * configuration.
5778  */
5779 #ifdef CONFIG_SND_DEBUG
5780 static hda_nid_t alc260_test_dac_nids[1] = {
5781         0x02,
5782 };
5783 static hda_nid_t alc260_test_adc_nids[2] = {
5784         0x04, 0x05,
5785 };
5786 /* For testing the ALC260, each input MUX needs its own definition since
5787  * the signal assignments are different.  This assumes that the first ADC
5788  * is NID 0x04.
5789  */
5790 static struct hda_input_mux alc260_test_capture_sources[2] = {
5791         {
5792                 .num_items = 7,
5793                 .items = {
5794                         { "MIC1 pin", 0x0 },
5795                         { "MIC2 pin", 0x1 },
5796                         { "LINE1 pin", 0x2 },
5797                         { "LINE2 pin", 0x3 },
5798                         { "CD pin", 0x4 },
5799                         { "LINE-OUT pin", 0x5 },
5800                         { "HP-OUT pin", 0x6 },
5801                 },
5802         },
5803         {
5804                 .num_items = 8,
5805                 .items = {
5806                         { "MIC1 pin", 0x0 },
5807                         { "MIC2 pin", 0x1 },
5808                         { "LINE1 pin", 0x2 },
5809                         { "LINE2 pin", 0x3 },
5810                         { "CD pin", 0x4 },
5811                         { "Mixer", 0x5 },
5812                         { "LINE-OUT pin", 0x6 },
5813                         { "HP-OUT pin", 0x7 },
5814                 },
5815         },
5816 };
5817 static struct snd_kcontrol_new alc260_test_mixer[] = {
5818         /* Output driver widgets */
5819         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5820         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5821         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5822         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5823         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5824         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5825
5826         /* Modes for retasking pin widgets
5827          * Note: the ALC260 doesn't seem to act on requests to enable mic
5828          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5829          * mention this restriction.  At this stage it's not clear whether
5830          * this behaviour is intentional or is a hardware bug in chip
5831          * revisions available at least up until early 2006.  Therefore for
5832          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5833          * choices, but if it turns out that the lack of mic bias for these
5834          * NIDs is intentional we could change their modes from
5835          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5836          */
5837         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5838         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5839         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5840         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5841         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5842         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5843
5844         /* Loopback mixer controls */
5845         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5846         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5847         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5848         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5849         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5850         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5851         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5852         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5853         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5854         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5855         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5856         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5857         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5858         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5859
5860         /* Controls for GPIO pins, assuming they are configured as outputs */
5861         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5862         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5863         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5864         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5865
5866         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5867          * is ambigious as to which NID is which; testing on laptops which
5868          * make this output available should provide clarification.
5869          */
5870         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5871         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5872
5873         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5874          * this output to turn on an external amplifier.
5875          */
5876         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5877         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5878
5879         { } /* end */
5880 };
5881 static struct hda_verb alc260_test_init_verbs[] = {
5882         /* Enable all GPIOs as outputs with an initial value of 0 */
5883         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5884         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5885         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5886
5887         /* Enable retasking pins as output, initially without power amp */
5888         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5889         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5890         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5891         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5892         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5893         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5894
5895         /* Disable digital (SPDIF) pins initially, but users can enable
5896          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5897          * payload also sets the generation to 0, output to be in "consumer"
5898          * PCM format, copyright asserted, no pre-emphasis and no validity
5899          * control.
5900          */
5901         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5902         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5903
5904         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5905          * OUT1 sum bus when acting as an output.
5906          */
5907         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5908         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5909         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5910         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5911
5912         /* Start with output sum widgets muted and their output gains at min */
5913         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5914         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5915         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5916         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5917         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5918         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5919         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5920         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5921         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5922
5923         /* Unmute retasking pin widget output buffers since the default
5924          * state appears to be output.  As the pin mode is changed by the
5925          * user the pin mode control will take care of enabling the pin's
5926          * input/output buffers as needed.
5927          */
5928         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5929         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5930         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5931         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5932         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5933         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5934         /* Also unmute the mono-out pin widget */
5935         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5936
5937         /* Mute capture amp left and right */
5938         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5939         /* Set ADC connection select to match default mixer setting (mic1
5940          * pin)
5941          */
5942         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5943
5944         /* Do the same for the second ADC: mute capture input amp and
5945          * set ADC connection to mic1 pin
5946          */
5947         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5948         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5949
5950         /* Mute all inputs to mixer widget (even unconnected ones) */
5951         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5952         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5953         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5954         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5955         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5956         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5957         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5958         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5959
5960         { }
5961 };
5962 #endif
5963
5964 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5965 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5966
5967 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5968 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5969
5970 /*
5971  * for BIOS auto-configuration
5972  */
5973
5974 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5975                                         const char *pfx, int *vol_bits)
5976 {
5977         hda_nid_t nid_vol;
5978         unsigned long vol_val, sw_val;
5979         int err;
5980
5981         if (nid >= 0x0f && nid < 0x11) {
5982                 nid_vol = nid - 0x7;
5983                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5984                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5985         } else if (nid == 0x11) {
5986                 nid_vol = nid - 0x7;
5987                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5988                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5989         } else if (nid >= 0x12 && nid <= 0x15) {
5990                 nid_vol = 0x08;
5991                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5992                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5993         } else
5994                 return 0; /* N/A */
5995
5996         if (!(*vol_bits & (1 << nid_vol))) {
5997                 /* first control for the volume widget */
5998                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
5999                 if (err < 0)
6000                         return err;
6001                 *vol_bits |= (1 << nid_vol);
6002         }
6003         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6004         if (err < 0)
6005                 return err;
6006         return 1;
6007 }
6008
6009 /* add playback controls from the parsed DAC table */
6010 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
6011                                              const struct auto_pin_cfg *cfg)
6012 {
6013         hda_nid_t nid;
6014         int err;
6015         int vols = 0;
6016
6017         spec->multiout.num_dacs = 1;
6018         spec->multiout.dac_nids = spec->private_dac_nids;
6019         spec->multiout.dac_nids[0] = 0x02;
6020
6021         nid = cfg->line_out_pins[0];
6022         if (nid) {
6023                 const char *pfx;
6024                 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
6025                         pfx = "Master";
6026                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
6027                         pfx = "Speaker";
6028                 else
6029                         pfx = "Front";
6030                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
6031                 if (err < 0)
6032                         return err;
6033         }
6034
6035         nid = cfg->speaker_pins[0];
6036         if (nid) {
6037                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
6038                 if (err < 0)
6039                         return err;
6040         }
6041
6042         nid = cfg->hp_pins[0];
6043         if (nid) {
6044                 err = alc260_add_playback_controls(spec, nid, "Headphone",
6045                                                    &vols);
6046                 if (err < 0)
6047                         return err;
6048         }
6049         return 0;
6050 }
6051
6052 /* create playback/capture controls for input pins */
6053 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
6054                                                 const struct auto_pin_cfg *cfg)
6055 {
6056         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
6057 }
6058
6059 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
6060                                               hda_nid_t nid, int pin_type,
6061                                               int sel_idx)
6062 {
6063         alc_set_pin_output(codec, nid, pin_type);
6064         /* need the manual connection? */
6065         if (nid >= 0x12) {
6066                 int idx = nid - 0x12;
6067                 snd_hda_codec_write(codec, idx + 0x0b, 0,
6068                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
6069         }
6070 }
6071
6072 static void alc260_auto_init_multi_out(struct hda_codec *codec)
6073 {
6074         struct alc_spec *spec = codec->spec;
6075         hda_nid_t nid;
6076
6077         nid = spec->autocfg.line_out_pins[0];
6078         if (nid) {
6079                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6080                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
6081         }
6082
6083         nid = spec->autocfg.speaker_pins[0];
6084         if (nid)
6085                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
6086
6087         nid = spec->autocfg.hp_pins[0];
6088         if (nid)
6089                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
6090 }
6091
6092 #define ALC260_PIN_CD_NID               0x16
6093 static void alc260_auto_init_analog_input(struct hda_codec *codec)
6094 {
6095         struct alc_spec *spec = codec->spec;
6096         int i;
6097
6098         for (i = 0; i < AUTO_PIN_LAST; i++) {
6099                 hda_nid_t nid = spec->autocfg.input_pins[i];
6100                 if (nid >= 0x12) {
6101                         alc_set_input_pin(codec, nid, i);
6102                         if (nid != ALC260_PIN_CD_NID &&
6103                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
6104                                 snd_hda_codec_write(codec, nid, 0,
6105                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6106                                                     AMP_OUT_MUTE);
6107                 }
6108         }
6109 }
6110
6111 /*
6112  * generic initialization of ADC, input mixers and output mixers
6113  */
6114 static struct hda_verb alc260_volume_init_verbs[] = {
6115         /*
6116          * Unmute ADC0-1 and set the default input to mic-in
6117          */
6118         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6119         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6120         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6121         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6122
6123         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6124          * mixer widget
6125          * Note: PASD motherboards uses the Line In 2 as the input for
6126          * front panel mic (mic 2)
6127          */
6128         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6129         /* mute analog inputs */
6130         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6131         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6132         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6133         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6134         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6135
6136         /*
6137          * Set up output mixers (0x08 - 0x0a)
6138          */
6139         /* set vol=0 to output mixers */
6140         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6141         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6142         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6143         /* set up input amps for analog loopback */
6144         /* Amp Indices: DAC = 0, mixer = 1 */
6145         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6146         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6147         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6148         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6149         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6150         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6151
6152         { }
6153 };
6154
6155 static int alc260_parse_auto_config(struct hda_codec *codec)
6156 {
6157         struct alc_spec *spec = codec->spec;
6158         int err;
6159         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
6160
6161         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6162                                            alc260_ignore);
6163         if (err < 0)
6164                 return err;
6165         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
6166         if (err < 0)
6167                 return err;
6168         if (!spec->kctls.list)
6169                 return 0; /* can't find valid BIOS pin config */
6170         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
6171         if (err < 0)
6172                 return err;
6173
6174         spec->multiout.max_channels = 2;
6175
6176         if (spec->autocfg.dig_outs)
6177                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6178         if (spec->kctls.list)
6179                 add_mixer(spec, spec->kctls.list);
6180
6181         add_verb(spec, alc260_volume_init_verbs);
6182
6183         spec->num_mux_defs = 1;
6184         spec->input_mux = &spec->private_imux[0];
6185
6186         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6187
6188         return 1;
6189 }
6190
6191 /* additional initialization for auto-configuration model */
6192 static void alc260_auto_init(struct hda_codec *codec)
6193 {
6194         struct alc_spec *spec = codec->spec;
6195         alc260_auto_init_multi_out(codec);
6196         alc260_auto_init_analog_input(codec);
6197         if (spec->unsol_event)
6198                 alc_inithook(codec);
6199 }
6200
6201 #ifdef CONFIG_SND_HDA_POWER_SAVE
6202 static struct hda_amp_list alc260_loopbacks[] = {
6203         { 0x07, HDA_INPUT, 0 },
6204         { 0x07, HDA_INPUT, 1 },
6205         { 0x07, HDA_INPUT, 2 },
6206         { 0x07, HDA_INPUT, 3 },
6207         { 0x07, HDA_INPUT, 4 },
6208         { } /* end */
6209 };
6210 #endif
6211
6212 /*
6213  * ALC260 configurations
6214  */
6215 static const char *alc260_models[ALC260_MODEL_LAST] = {
6216         [ALC260_BASIC]          = "basic",
6217         [ALC260_HP]             = "hp",
6218         [ALC260_HP_3013]        = "hp-3013",
6219         [ALC260_HP_DC7600]      = "hp-dc7600",
6220         [ALC260_FUJITSU_S702X]  = "fujitsu",
6221         [ALC260_ACER]           = "acer",
6222         [ALC260_WILL]           = "will",
6223         [ALC260_REPLACER_672V]  = "replacer",
6224         [ALC260_FAVORIT100]     = "favorit100",
6225 #ifdef CONFIG_SND_DEBUG
6226         [ALC260_TEST]           = "test",
6227 #endif
6228         [ALC260_AUTO]           = "auto",
6229 };
6230
6231 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6232         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6233         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6234         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6235         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6236         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
6237         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6238         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6239         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6240         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6241         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6242         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6243         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6244         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6245         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6246         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6247         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6248         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6249         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6250         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6251         {}
6252 };
6253
6254 static struct alc_config_preset alc260_presets[] = {
6255         [ALC260_BASIC] = {
6256                 .mixers = { alc260_base_output_mixer,
6257                             alc260_input_mixer },
6258                 .init_verbs = { alc260_init_verbs },
6259                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6260                 .dac_nids = alc260_dac_nids,
6261                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6262                 .adc_nids = alc260_adc_nids,
6263                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6264                 .channel_mode = alc260_modes,
6265                 .input_mux = &alc260_capture_source,
6266         },
6267         [ALC260_HP] = {
6268                 .mixers = { alc260_hp_output_mixer,
6269                             alc260_input_mixer },
6270                 .init_verbs = { alc260_init_verbs,
6271                                 alc260_hp_unsol_verbs },
6272                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6273                 .dac_nids = alc260_dac_nids,
6274                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6275                 .adc_nids = alc260_adc_nids_alt,
6276                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6277                 .channel_mode = alc260_modes,
6278                 .input_mux = &alc260_capture_source,
6279                 .unsol_event = alc260_hp_unsol_event,
6280                 .init_hook = alc260_hp_automute,
6281         },
6282         [ALC260_HP_DC7600] = {
6283                 .mixers = { alc260_hp_dc7600_mixer,
6284                             alc260_input_mixer },
6285                 .init_verbs = { alc260_init_verbs,
6286                                 alc260_hp_dc7600_verbs },
6287                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6288                 .dac_nids = alc260_dac_nids,
6289                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6290                 .adc_nids = alc260_adc_nids_alt,
6291                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6292                 .channel_mode = alc260_modes,
6293                 .input_mux = &alc260_capture_source,
6294                 .unsol_event = alc260_hp_3012_unsol_event,
6295                 .init_hook = alc260_hp_3012_automute,
6296         },
6297         [ALC260_HP_3013] = {
6298                 .mixers = { alc260_hp_3013_mixer,
6299                             alc260_input_mixer },
6300                 .init_verbs = { alc260_hp_3013_init_verbs,
6301                                 alc260_hp_3013_unsol_verbs },
6302                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6303                 .dac_nids = alc260_dac_nids,
6304                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6305                 .adc_nids = alc260_adc_nids_alt,
6306                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6307                 .channel_mode = alc260_modes,
6308                 .input_mux = &alc260_capture_source,
6309                 .unsol_event = alc260_hp_3013_unsol_event,
6310                 .init_hook = alc260_hp_3013_automute,
6311         },
6312         [ALC260_FUJITSU_S702X] = {
6313                 .mixers = { alc260_fujitsu_mixer },
6314                 .init_verbs = { alc260_fujitsu_init_verbs },
6315                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6316                 .dac_nids = alc260_dac_nids,
6317                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6318                 .adc_nids = alc260_dual_adc_nids,
6319                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6320                 .channel_mode = alc260_modes,
6321                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6322                 .input_mux = alc260_fujitsu_capture_sources,
6323         },
6324         [ALC260_ACER] = {
6325                 .mixers = { alc260_acer_mixer },
6326                 .init_verbs = { alc260_acer_init_verbs },
6327                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6328                 .dac_nids = alc260_dac_nids,
6329                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6330                 .adc_nids = alc260_dual_adc_nids,
6331                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6332                 .channel_mode = alc260_modes,
6333                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6334                 .input_mux = alc260_acer_capture_sources,
6335         },
6336         [ALC260_FAVORIT100] = {
6337                 .mixers = { alc260_favorit100_mixer },
6338                 .init_verbs = { alc260_favorit100_init_verbs },
6339                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6340                 .dac_nids = alc260_dac_nids,
6341                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6342                 .adc_nids = alc260_dual_adc_nids,
6343                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6344                 .channel_mode = alc260_modes,
6345                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6346                 .input_mux = alc260_favorit100_capture_sources,
6347         },
6348         [ALC260_WILL] = {
6349                 .mixers = { alc260_will_mixer },
6350                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6351                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6352                 .dac_nids = alc260_dac_nids,
6353                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6354                 .adc_nids = alc260_adc_nids,
6355                 .dig_out_nid = ALC260_DIGOUT_NID,
6356                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6357                 .channel_mode = alc260_modes,
6358                 .input_mux = &alc260_capture_source,
6359         },
6360         [ALC260_REPLACER_672V] = {
6361                 .mixers = { alc260_replacer_672v_mixer },
6362                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6363                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6364                 .dac_nids = alc260_dac_nids,
6365                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6366                 .adc_nids = alc260_adc_nids,
6367                 .dig_out_nid = ALC260_DIGOUT_NID,
6368                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6369                 .channel_mode = alc260_modes,
6370                 .input_mux = &alc260_capture_source,
6371                 .unsol_event = alc260_replacer_672v_unsol_event,
6372                 .init_hook = alc260_replacer_672v_automute,
6373         },
6374 #ifdef CONFIG_SND_DEBUG
6375         [ALC260_TEST] = {
6376                 .mixers = { alc260_test_mixer },
6377                 .init_verbs = { alc260_test_init_verbs },
6378                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6379                 .dac_nids = alc260_test_dac_nids,
6380                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6381                 .adc_nids = alc260_test_adc_nids,
6382                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6383                 .channel_mode = alc260_modes,
6384                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6385                 .input_mux = alc260_test_capture_sources,
6386         },
6387 #endif
6388 };
6389
6390 static int patch_alc260(struct hda_codec *codec)
6391 {
6392         struct alc_spec *spec;
6393         int err, board_config;
6394
6395         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6396         if (spec == NULL)
6397                 return -ENOMEM;
6398
6399         codec->spec = spec;
6400
6401         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6402                                                   alc260_models,
6403                                                   alc260_cfg_tbl);
6404         if (board_config < 0) {
6405                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6406                            codec->chip_name);
6407                 board_config = ALC260_AUTO;
6408         }
6409
6410         if (board_config == ALC260_AUTO) {
6411                 /* automatic parse from the BIOS config */
6412                 err = alc260_parse_auto_config(codec);
6413                 if (err < 0) {
6414                         alc_free(codec);
6415                         return err;
6416                 } else if (!err) {
6417                         printk(KERN_INFO
6418                                "hda_codec: Cannot set up configuration "
6419                                "from BIOS.  Using base mode...\n");
6420                         board_config = ALC260_BASIC;
6421                 }
6422         }
6423
6424         err = snd_hda_attach_beep_device(codec, 0x1);
6425         if (err < 0) {
6426                 alc_free(codec);
6427                 return err;
6428         }
6429
6430         if (board_config != ALC260_AUTO)
6431                 setup_preset(codec, &alc260_presets[board_config]);
6432
6433         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6434         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6435
6436         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6437         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6438
6439         if (!spec->adc_nids && spec->input_mux) {
6440                 /* check whether NID 0x04 is valid */
6441                 unsigned int wcap = get_wcaps(codec, 0x04);
6442                 wcap = get_wcaps_type(wcap);
6443                 /* get type */
6444                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6445                         spec->adc_nids = alc260_adc_nids_alt;
6446                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6447                 } else {
6448                         spec->adc_nids = alc260_adc_nids;
6449                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6450                 }
6451         }
6452         set_capture_mixer(codec);
6453         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6454
6455         spec->vmaster_nid = 0x08;
6456
6457         codec->patch_ops = alc_patch_ops;
6458         if (board_config == ALC260_AUTO)
6459                 spec->init_hook = alc260_auto_init;
6460 #ifdef CONFIG_SND_HDA_POWER_SAVE
6461         if (!spec->loopback.amplist)
6462                 spec->loopback.amplist = alc260_loopbacks;
6463 #endif
6464         codec->proc_widget_hook = print_realtek_coef;
6465
6466         return 0;
6467 }
6468
6469
6470 /*
6471  * ALC882/883/885/888/889 support
6472  *
6473  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6474  * configuration.  Each pin widget can choose any input DACs and a mixer.
6475  * Each ADC is connected from a mixer of all inputs.  This makes possible
6476  * 6-channel independent captures.
6477  *
6478  * In addition, an independent DAC for the multi-playback (not used in this
6479  * driver yet).
6480  */
6481 #define ALC882_DIGOUT_NID       0x06
6482 #define ALC882_DIGIN_NID        0x0a
6483 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
6484 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
6485 #define ALC1200_DIGOUT_NID      0x10
6486
6487
6488 static struct hda_channel_mode alc882_ch_modes[1] = {
6489         { 8, NULL }
6490 };
6491
6492 /* DACs */
6493 static hda_nid_t alc882_dac_nids[4] = {
6494         /* front, rear, clfe, rear_surr */
6495         0x02, 0x03, 0x04, 0x05
6496 };
6497 #define alc883_dac_nids         alc882_dac_nids
6498
6499 /* ADCs */
6500 #define alc882_adc_nids         alc880_adc_nids
6501 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6502 #define alc883_adc_nids         alc882_adc_nids_alt
6503 static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
6504 static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
6505 #define alc889_adc_nids         alc880_adc_nids
6506
6507 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6508 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6509 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
6510 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
6511 #define alc889_capsrc_nids      alc882_capsrc_nids
6512
6513 /* input MUX */
6514 /* FIXME: should be a matrix-type input source selection */
6515
6516 static struct hda_input_mux alc882_capture_source = {
6517         .num_items = 4,
6518         .items = {
6519                 { "Mic", 0x0 },
6520                 { "Front Mic", 0x1 },
6521                 { "Line", 0x2 },
6522                 { "CD", 0x4 },
6523         },
6524 };
6525
6526 #define alc883_capture_source   alc882_capture_source
6527
6528 static struct hda_input_mux alc889_capture_source = {
6529         .num_items = 3,
6530         .items = {
6531                 { "Front Mic", 0x0 },
6532                 { "Mic", 0x3 },
6533                 { "Line", 0x2 },
6534         },
6535 };
6536
6537 static struct hda_input_mux mb5_capture_source = {
6538         .num_items = 3,
6539         .items = {
6540                 { "Mic", 0x1 },
6541                 { "Line", 0x2 },
6542                 { "CD", 0x4 },
6543         },
6544 };
6545
6546 static struct hda_input_mux alc883_3stack_6ch_intel = {
6547         .num_items = 4,
6548         .items = {
6549                 { "Mic", 0x1 },
6550                 { "Front Mic", 0x0 },
6551                 { "Line", 0x2 },
6552                 { "CD", 0x4 },
6553         },
6554 };
6555
6556 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6557         .num_items = 2,
6558         .items = {
6559                 { "Mic", 0x1 },
6560                 { "Line", 0x2 },
6561         },
6562 };
6563
6564 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6565         .num_items = 4,
6566         .items = {
6567                 { "Mic", 0x0 },
6568                 { "iMic", 0x1 },
6569                 { "Line", 0x2 },
6570                 { "CD", 0x4 },
6571         },
6572 };
6573
6574 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6575         .num_items = 2,
6576         .items = {
6577                 { "Mic", 0x0 },
6578                 { "Int Mic", 0x1 },
6579         },
6580 };
6581
6582 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6583         .num_items = 3,
6584         .items = {
6585                 { "Mic", 0x0 },
6586                 { "Front Mic", 0x1 },
6587                 { "Line", 0x4 },
6588         },
6589 };
6590
6591 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6592         .num_items = 2,
6593         .items = {
6594                 { "Mic", 0x0 },
6595                 { "Line", 0x2 },
6596         },
6597 };
6598
6599 static struct hda_input_mux alc889A_mb31_capture_source = {
6600         .num_items = 2,
6601         .items = {
6602                 { "Mic", 0x0 },
6603                 /* Front Mic (0x01) unused */
6604                 { "Line", 0x2 },
6605                 /* Line 2 (0x03) unused */
6606                 /* CD (0x04) unsused? */
6607         },
6608 };
6609
6610 /*
6611  * 2ch mode
6612  */
6613 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6614         { 2, NULL }
6615 };
6616
6617 /*
6618  * 2ch mode
6619  */
6620 static struct hda_verb alc882_3ST_ch2_init[] = {
6621         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6622         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6623         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6624         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6625         { } /* end */
6626 };
6627
6628 /*
6629  * 4ch mode
6630  */
6631 static struct hda_verb alc882_3ST_ch4_init[] = {
6632         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6633         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6634         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6635         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6636         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6637         { } /* end */
6638 };
6639
6640 /*
6641  * 6ch mode
6642  */
6643 static struct hda_verb alc882_3ST_ch6_init[] = {
6644         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6645         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6646         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6647         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6648         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6649         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6650         { } /* end */
6651 };
6652
6653 static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6654         { 2, alc882_3ST_ch2_init },
6655         { 4, alc882_3ST_ch4_init },
6656         { 6, alc882_3ST_ch6_init },
6657 };
6658
6659 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
6660
6661 /*
6662  * 2ch mode
6663  */
6664 static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
6665         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
6666         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6667         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6668         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6669         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6670         { } /* end */
6671 };
6672
6673 /*
6674  * 4ch mode
6675  */
6676 static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
6677         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6678         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6679         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6680         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6681         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6682         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6683         { } /* end */
6684 };
6685
6686 /*
6687  * 6ch mode
6688  */
6689 static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
6690         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6691         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6692         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6693         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6694         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6695         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6696         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6697         { } /* end */
6698 };
6699
6700 static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
6701         { 2, alc883_3ST_ch2_clevo_init },
6702         { 4, alc883_3ST_ch4_clevo_init },
6703         { 6, alc883_3ST_ch6_clevo_init },
6704 };
6705
6706
6707 /*
6708  * 6ch mode
6709  */
6710 static struct hda_verb alc882_sixstack_ch6_init[] = {
6711         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6712         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6713         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6714         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6715         { } /* end */
6716 };
6717
6718 /*
6719  * 8ch mode
6720  */
6721 static struct hda_verb alc882_sixstack_ch8_init[] = {
6722         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6723         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6724         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6725         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6726         { } /* end */
6727 };
6728
6729 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6730         { 6, alc882_sixstack_ch6_init },
6731         { 8, alc882_sixstack_ch8_init },
6732 };
6733
6734 /*
6735  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6736  */
6737
6738 /*
6739  * 2ch mode
6740  */
6741 static struct hda_verb alc885_mbp_ch2_init[] = {
6742         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6743         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6744         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6745         { } /* end */
6746 };
6747
6748 /*
6749  * 4ch mode
6750  */
6751 static struct hda_verb alc885_mbp_ch4_init[] = {
6752         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6753         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6754         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6755         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6756         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6757         { } /* end */
6758 };
6759
6760 static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6761         { 2, alc885_mbp_ch2_init },
6762         { 4, alc885_mbp_ch4_init },
6763 };
6764
6765 /*
6766  * 2ch
6767  * Speakers/Woofer/HP = Front
6768  * LineIn = Input
6769  */
6770 static struct hda_verb alc885_mb5_ch2_init[] = {
6771         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6772         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6773         { } /* end */
6774 };
6775
6776 /*
6777  * 6ch mode
6778  * Speakers/HP = Front
6779  * Woofer = LFE
6780  * LineIn = Surround
6781  */
6782 static struct hda_verb alc885_mb5_ch6_init[] = {
6783         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6784         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6785         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6786         { } /* end */
6787 };
6788
6789 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6790         { 2, alc885_mb5_ch2_init },
6791         { 6, alc885_mb5_ch6_init },
6792 };
6793
6794
6795 /*
6796  * 2ch mode
6797  */
6798 static struct hda_verb alc883_4ST_ch2_init[] = {
6799         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6800         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6801         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6802         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6803         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6804         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6805         { } /* end */
6806 };
6807
6808 /*
6809  * 4ch mode
6810  */
6811 static struct hda_verb alc883_4ST_ch4_init[] = {
6812         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6813         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6814         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6815         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6816         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6817         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6818         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6819         { } /* end */
6820 };
6821
6822 /*
6823  * 6ch mode
6824  */
6825 static struct hda_verb alc883_4ST_ch6_init[] = {
6826         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6827         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6828         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6829         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6830         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6831         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6832         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6833         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6834         { } /* end */
6835 };
6836
6837 /*
6838  * 8ch mode
6839  */
6840 static struct hda_verb alc883_4ST_ch8_init[] = {
6841         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6842         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6843         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6844         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6845         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6846         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6847         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6848         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6849         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6850         { } /* end */
6851 };
6852
6853 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
6854         { 2, alc883_4ST_ch2_init },
6855         { 4, alc883_4ST_ch4_init },
6856         { 6, alc883_4ST_ch6_init },
6857         { 8, alc883_4ST_ch8_init },
6858 };
6859
6860
6861 /*
6862  * 2ch mode
6863  */
6864 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6865         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6866         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6867         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6868         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6869         { } /* end */
6870 };
6871
6872 /*
6873  * 4ch mode
6874  */
6875 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6876         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6877         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6878         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6879         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6880         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6881         { } /* end */
6882 };
6883
6884 /*
6885  * 6ch mode
6886  */
6887 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6888         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6889         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6890         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6891         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6892         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6893         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6894         { } /* end */
6895 };
6896
6897 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6898         { 2, alc883_3ST_ch2_intel_init },
6899         { 4, alc883_3ST_ch4_intel_init },
6900         { 6, alc883_3ST_ch6_intel_init },
6901 };
6902
6903 /*
6904  * 2ch mode
6905  */
6906 static struct hda_verb alc889_ch2_intel_init[] = {
6907         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6908         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
6909         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
6910         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
6911         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6912         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6913         { } /* end */
6914 };
6915
6916 /*
6917  * 6ch mode
6918  */
6919 static struct hda_verb alc889_ch6_intel_init[] = {
6920         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6921         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6922         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6923         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6924         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6925         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6926         { } /* end */
6927 };
6928
6929 /*
6930  * 8ch mode
6931  */
6932 static struct hda_verb alc889_ch8_intel_init[] = {
6933         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6934         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6935         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6936         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6937         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
6938         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6939         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6940         { } /* end */
6941 };
6942
6943 static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
6944         { 2, alc889_ch2_intel_init },
6945         { 6, alc889_ch6_intel_init },
6946         { 8, alc889_ch8_intel_init },
6947 };
6948
6949 /*
6950  * 6ch mode
6951  */
6952 static struct hda_verb alc883_sixstack_ch6_init[] = {
6953         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6954         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6955         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6956         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6957         { } /* end */
6958 };
6959
6960 /*
6961  * 8ch mode
6962  */
6963 static struct hda_verb alc883_sixstack_ch8_init[] = {
6964         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6965         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6966         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6967         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6968         { } /* end */
6969 };
6970
6971 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6972         { 6, alc883_sixstack_ch6_init },
6973         { 8, alc883_sixstack_ch8_init },
6974 };
6975
6976
6977 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6978  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6979  */
6980 static struct snd_kcontrol_new alc882_base_mixer[] = {
6981         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6982         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6983         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6984         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6985         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6986         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6987         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6988         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6989         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6990         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6991         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6992         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6993         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6994         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6995         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6996         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6997         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6998         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6999         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7000         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7001         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7002         { } /* end */
7003 };
7004
7005 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7006         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7007         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
7008         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7009         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
7010         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7011         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7012         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7013         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7014         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7015         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
7016         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7017         { } /* end */
7018 };
7019
7020 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7021         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7022         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
7023         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7024         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7025         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7026         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7027         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7028         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
7029         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7030         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7031         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7032         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7033         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
7034         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
7035         { } /* end */
7036 };
7037
7038 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7039         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7040         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7041         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7042         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7043         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7044         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7045         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7046         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7047         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7048         { } /* end */
7049 };
7050
7051 static struct snd_kcontrol_new alc882_targa_mixer[] = {
7052         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7053         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7054         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7055         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7056         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7057         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7058         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7059         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7060         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7061         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7062         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7063         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7064         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7065         { } /* end */
7066 };
7067
7068 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
7069  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
7070  */
7071 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
7072         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7073         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7074         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7075         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
7076         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7077         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7078         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7079         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7080         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
7081         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
7082         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7083         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7084         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7085         { } /* end */
7086 };
7087
7088 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
7089         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7090         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7091         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7092         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7093         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7094         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7095         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7096         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7098         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7099         { } /* end */
7100 };
7101
7102 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
7103         {
7104                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7105                 .name = "Channel Mode",
7106                 .info = alc_ch_mode_info,
7107                 .get = alc_ch_mode_get,
7108                 .put = alc_ch_mode_put,
7109         },
7110         { } /* end */
7111 };
7112
7113 static struct hda_verb alc882_base_init_verbs[] = {
7114         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7115         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7116         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7117         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7118         /* Rear mixer */
7119         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7120         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7121         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7122         /* CLFE mixer */
7123         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7124         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7125         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7126         /* Side mixer */
7127         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7128         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7129         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7130
7131         /* mute analog input loopbacks */
7132         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7133         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7134         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7136         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7137
7138         /* Front Pin: output 0 (0x0c) */
7139         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7140         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7141         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7142         /* Rear Pin: output 1 (0x0d) */
7143         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7144         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7145         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7146         /* CLFE Pin: output 2 (0x0e) */
7147         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7148         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7149         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7150         /* Side Pin: output 3 (0x0f) */
7151         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7152         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7153         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7154         /* Mic (rear) pin: input vref at 80% */
7155         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7156         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7157         /* Front Mic pin: input vref at 80% */
7158         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7159         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7160         /* Line In pin: input */
7161         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7162         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7163         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7164         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7165         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7166         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7167         /* CD pin widget for input */
7168         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7169
7170         /* FIXME: use matrix-type input source selection */
7171         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7172         /* Input mixer2 */
7173         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7174         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7175         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7176         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7177         /* Input mixer3 */
7178         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7179         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7180         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7181         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7182         /* ADC2: mute amp left and right */
7183         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7184         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7185         /* ADC3: mute amp left and right */
7186         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7187         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7188
7189         { }
7190 };
7191
7192 static struct hda_verb alc882_adc1_init_verbs[] = {
7193         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7195         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7196         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7197         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7198         /* ADC1: mute amp left and right */
7199         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7200         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7201         { }
7202 };
7203
7204 static struct hda_verb alc882_eapd_verbs[] = {
7205         /* change to EAPD mode */
7206         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7207         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
7208         { }
7209 };
7210
7211 static struct hda_verb alc889_eapd_verbs[] = {
7212         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
7213         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
7214         { }
7215 };
7216
7217 static struct hda_verb alc_hp15_unsol_verbs[] = {
7218         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7219         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7220         {}
7221 };
7222
7223 static struct hda_verb alc885_init_verbs[] = {
7224         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7225         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7226         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7227         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7228         /* Rear mixer */
7229         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7230         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7231         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7232         /* CLFE mixer */
7233         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7234         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7235         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7236         /* Side mixer */
7237         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7238         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7239         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7240
7241         /* mute analog input loopbacks */
7242         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7243         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7244         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7245
7246         /* Front HP Pin: output 0 (0x0c) */
7247         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7248         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7249         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7250         /* Front Pin: output 0 (0x0c) */
7251         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7252         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7253         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7254         /* Rear Pin: output 1 (0x0d) */
7255         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7256         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7257         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
7258         /* CLFE Pin: output 2 (0x0e) */
7259         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7260         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7261         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7262         /* Side Pin: output 3 (0x0f) */
7263         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7264         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7265         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7266         /* Mic (rear) pin: input vref at 80% */
7267         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7268         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7269         /* Front Mic pin: input vref at 80% */
7270         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7271         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7272         /* Line In pin: input */
7273         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7274         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7275
7276         /* Mixer elements: 0x18, , 0x1a, 0x1b */
7277         /* Input mixer1 */
7278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7281         /* Input mixer2 */
7282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7283         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7284         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7285         /* Input mixer3 */
7286         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7288         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7289         /* ADC2: mute amp left and right */
7290         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7291         /* ADC3: mute amp left and right */
7292         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7293
7294         { }
7295 };
7296
7297 static struct hda_verb alc885_init_input_verbs[] = {
7298         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7299         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7300         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7301         { }
7302 };
7303
7304
7305 /* Unmute Selector 24h and set the default input to front mic */
7306 static struct hda_verb alc889_init_input_verbs[] = {
7307         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
7308         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7309         { }
7310 };
7311
7312
7313 #define alc883_init_verbs       alc882_base_init_verbs
7314
7315 /* Mac Pro test */
7316 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7317         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7318         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7319         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
7320         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7321         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7322         /* FIXME: this looks suspicious...
7323         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
7324         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
7325         */
7326         { } /* end */
7327 };
7328
7329 static struct hda_verb alc882_macpro_init_verbs[] = {
7330         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7331         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7332         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7333         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7334         /* Front Pin: output 0 (0x0c) */
7335         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7336         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7337         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7338         /* Front Mic pin: input vref at 80% */
7339         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7340         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7341         /* Speaker:  output */
7342         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7343         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7344         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
7345         /* Headphone output (output 0 - 0x0c) */
7346         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7347         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7348         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7349
7350         /* FIXME: use matrix-type input source selection */
7351         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7352         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7353         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7354         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7355         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7356         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7357         /* Input mixer2 */
7358         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7359         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7360         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7361         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7362         /* Input mixer3 */
7363         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7364         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7365         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7366         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7367         /* ADC1: mute amp left and right */
7368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7369         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7370         /* ADC2: mute amp left and right */
7371         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7372         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7373         /* ADC3: mute amp left and right */
7374         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7375         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7376
7377         { }
7378 };
7379
7380 /* Macbook 5,1 */
7381 static struct hda_verb alc885_mb5_init_verbs[] = {
7382         /* DACs */
7383         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7384         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7385         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7386         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7387         /* Front mixer */
7388         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7389         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7390         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7391         /* Surround mixer */
7392         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7393         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7394         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7395         /* LFE mixer */
7396         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7397         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7398         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7399         /* HP mixer */
7400         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7401         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7402         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7403         /* Front Pin (0x0c) */
7404         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7405         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7406         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7407         /* LFE Pin (0x0e) */
7408         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7409         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7410         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
7411         /* HP Pin (0x0f) */
7412         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7413         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7414         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7415         /* Front Mic pin: input vref at 80% */
7416         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7417         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7418         /* Line In pin */
7419         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7420         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7421
7422         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7423         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7424         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7425         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7426         { }
7427 };
7428
7429 /* Macbook Pro rev3 */
7430 static struct hda_verb alc885_mbp3_init_verbs[] = {
7431         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7432         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7433         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7434         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7435         /* Rear mixer */
7436         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7437         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7438         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7439         /* HP mixer */
7440         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7441         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7442         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7443         /* Front Pin: output 0 (0x0c) */
7444         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7445         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7446         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7447         /* HP Pin: output 0 (0x0e) */
7448         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7449         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7450         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
7451         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7452         /* Mic (rear) pin: input vref at 80% */
7453         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7454         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7455         /* Front Mic pin: input vref at 80% */
7456         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7457         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7458         /* Line In pin: use output 1 when in LineOut mode */
7459         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7460         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7461         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7462
7463         /* FIXME: use matrix-type input source selection */
7464         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7465         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7466         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7467         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7468         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7469         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7470         /* Input mixer2 */
7471         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7472         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7473         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7474         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7475         /* Input mixer3 */
7476         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7477         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7478         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7479         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7480         /* ADC1: mute amp left and right */
7481         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7482         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7483         /* ADC2: mute amp left and right */
7484         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7485         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7486         /* ADC3: mute amp left and right */
7487         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7488         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7489
7490         { }
7491 };
7492
7493 /* iMac 24 mixer. */
7494 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7495         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7496         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
7497         { } /* end */
7498 };
7499
7500 /* iMac 24 init verbs. */
7501 static struct hda_verb alc885_imac24_init_verbs[] = {
7502         /* Internal speakers: output 0 (0x0c) */
7503         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7504         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7505         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7506         /* Internal speakers: output 0 (0x0c) */
7507         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7508         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7509         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7510         /* Headphone: output 0 (0x0c) */
7511         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7512         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7513         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7514         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7515         /* Front Mic: input vref at 80% */
7516         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7517         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7518         { }
7519 };
7520
7521 /* Toggle speaker-output according to the hp-jack state */
7522 static void alc885_imac24_setup(struct hda_codec *codec)
7523 {
7524         struct alc_spec *spec = codec->spec;
7525
7526         spec->autocfg.hp_pins[0] = 0x14;
7527         spec->autocfg.speaker_pins[0] = 0x18;
7528         spec->autocfg.speaker_pins[1] = 0x1a;
7529 }
7530
7531 static void alc885_mbp3_setup(struct hda_codec *codec)
7532 {
7533         struct alc_spec *spec = codec->spec;
7534
7535         spec->autocfg.hp_pins[0] = 0x15;
7536         spec->autocfg.speaker_pins[0] = 0x14;
7537 }
7538
7539
7540 static struct hda_verb alc882_targa_verbs[] = {
7541         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7543
7544         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7545         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7546
7547         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7548         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7549         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7550
7551         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7552         { } /* end */
7553 };
7554
7555 /* toggle speaker-output according to the hp-jack state */
7556 static void alc882_targa_automute(struct hda_codec *codec)
7557 {
7558         struct alc_spec *spec = codec->spec;
7559         alc_automute_amp(codec);
7560         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7561                                   spec->jack_present ? 1 : 3);
7562 }
7563
7564 static void alc882_targa_setup(struct hda_codec *codec)
7565 {
7566         struct alc_spec *spec = codec->spec;
7567
7568         spec->autocfg.hp_pins[0] = 0x14;
7569         spec->autocfg.speaker_pins[0] = 0x1b;
7570 }
7571
7572 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
7573 {
7574         if ((res >> 26) == ALC880_HP_EVENT)
7575                 alc882_targa_automute(codec);
7576 }
7577
7578 static struct hda_verb alc882_asus_a7j_verbs[] = {
7579         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7580         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7581
7582         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7583         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7584         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7585
7586         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7587         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7588         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7589
7590         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7591         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7592         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7593         { } /* end */
7594 };
7595
7596 static struct hda_verb alc882_asus_a7m_verbs[] = {
7597         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7598         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7599
7600         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7601         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7602         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7603
7604         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7605         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7606         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7607
7608         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7609         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7610         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7611         { } /* end */
7612 };
7613
7614 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
7615 {
7616         unsigned int gpiostate, gpiomask, gpiodir;
7617
7618         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
7619                                        AC_VERB_GET_GPIO_DATA, 0);
7620
7621         if (!muted)
7622                 gpiostate |= (1 << pin);
7623         else
7624                 gpiostate &= ~(1 << pin);
7625
7626         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7627                                       AC_VERB_GET_GPIO_MASK, 0);
7628         gpiomask |= (1 << pin);
7629
7630         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7631                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7632         gpiodir |= (1 << pin);
7633
7634
7635         snd_hda_codec_write(codec, codec->afg, 0,
7636                             AC_VERB_SET_GPIO_MASK, gpiomask);
7637         snd_hda_codec_write(codec, codec->afg, 0,
7638                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7639
7640         msleep(1);
7641
7642         snd_hda_codec_write(codec, codec->afg, 0,
7643                             AC_VERB_SET_GPIO_DATA, gpiostate);
7644 }
7645
7646 /* set up GPIO at initialization */
7647 static void alc885_macpro_init_hook(struct hda_codec *codec)
7648 {
7649         alc882_gpio_mute(codec, 0, 0);
7650         alc882_gpio_mute(codec, 1, 0);
7651 }
7652
7653 /* set up GPIO and update auto-muting at initialization */
7654 static void alc885_imac24_init_hook(struct hda_codec *codec)
7655 {
7656         alc885_macpro_init_hook(codec);
7657         alc_automute_amp(codec);
7658 }
7659
7660 /*
7661  * generic initialization of ADC, input mixers and output mixers
7662  */
7663 static struct hda_verb alc883_auto_init_verbs[] = {
7664         /*
7665          * Unmute ADC0-2 and set the default input to mic-in
7666          */
7667         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7668         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7669         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7670         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7671
7672         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7673          * mixer widget
7674          * Note: PASD motherboards uses the Line In 2 as the input for
7675          * front panel mic (mic 2)
7676          */
7677         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7678         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7679         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7680         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7681         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7682         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7683
7684         /*
7685          * Set up output mixers (0x0c - 0x0f)
7686          */
7687         /* set vol=0 to output mixers */
7688         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7689         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7690         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7691         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7692         /* set up input amps for analog loopback */
7693         /* Amp Indices: DAC = 0, mixer = 1 */
7694         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7695         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7696         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7697         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7698         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7699         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7700         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7701         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7702         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7703         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7704
7705         /* FIXME: use matrix-type input source selection */
7706         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7707         /* Input mixer2 */
7708         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7709         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7710         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7711         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7712         /* Input mixer3 */
7713         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7714         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7715         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7716         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7717
7718         { }
7719 };
7720
7721 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7722 static struct hda_verb alc889A_mb31_ch2_init[] = {
7723         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7724         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7725         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7726         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7727         { } /* end */
7728 };
7729
7730 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7731 static struct hda_verb alc889A_mb31_ch4_init[] = {
7732         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7733         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7734         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7735         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7736         { } /* end */
7737 };
7738
7739 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7740 static struct hda_verb alc889A_mb31_ch5_init[] = {
7741         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7742         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7743         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7744         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7745         { } /* end */
7746 };
7747
7748 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7749 static struct hda_verb alc889A_mb31_ch6_init[] = {
7750         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7751         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7752         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7753         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7754         { } /* end */
7755 };
7756
7757 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7758         { 2, alc889A_mb31_ch2_init },
7759         { 4, alc889A_mb31_ch4_init },
7760         { 5, alc889A_mb31_ch5_init },
7761         { 6, alc889A_mb31_ch6_init },
7762 };
7763
7764 static struct hda_verb alc883_medion_eapd_verbs[] = {
7765         /* eanable EAPD on medion laptop */
7766         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7767         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7768         { }
7769 };
7770
7771 #define alc883_base_mixer       alc882_base_mixer
7772
7773 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7774         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7775         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7776         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7777         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7778         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7779         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7780         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7781         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7782         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7783         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7784         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7785         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7786         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7787         { } /* end */
7788 };
7789
7790 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7791         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7792         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7793         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7794         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7795         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7796         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7797         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7798         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7799         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7800         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7801         { } /* end */
7802 };
7803
7804 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7805         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7806         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7807         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7808         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7809         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7810         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7811         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7812         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7813         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7814         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7815         { } /* end */
7816 };
7817
7818 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7819         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7820         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7821         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7822         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7823         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7824         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7825         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7827         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7828         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7829         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7830         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7831         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7832         { } /* end */
7833 };
7834
7835 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7836         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7837         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7838         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7839         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7840         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7841         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7842         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7843         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7844         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7845         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7846         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7847         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7848         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7849         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7850         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7851         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7852         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7853         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7854         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7855         { } /* end */
7856 };
7857
7858 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7859         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7860         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7861         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7862         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7863         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7864                               HDA_OUTPUT),
7865         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7866         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7867         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7868         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7869         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7870         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7871         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7872         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7874         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7875         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7876         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7877         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7878         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7879         { } /* end */
7880 };
7881
7882 static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
7883         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7884         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7885         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7886         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7887         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7888                               HDA_OUTPUT),
7889         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7890         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7891         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7892         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7893         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
7894         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7895         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7896         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7897         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
7898         HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
7899         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
7900         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7901         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7902         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7903         { } /* end */
7904 };
7905
7906 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7907         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7908         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7909         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7910         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7911         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7912         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7913         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7914         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7915         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7916         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7917         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7918         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7919         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7920         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7921         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7922         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7923         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7924         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7925         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7926         { } /* end */
7927 };
7928
7929 static struct snd_kcontrol_new alc883_targa_mixer[] = {
7930         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7931         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7932         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7933         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7934         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7935         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7936         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7937         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7938         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7939         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7940         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7941         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7942         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7943         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7944         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7945         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7946         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7947         { } /* end */
7948 };
7949
7950 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
7951         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7952         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7953         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7954         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7955         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7956         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7957         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7958         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7959         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7960         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7961         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7962         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7963         { } /* end */
7964 };
7965
7966 static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
7967         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7968         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7969         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7970         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7971         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7972         { } /* end */
7973 };
7974
7975 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7976         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7977         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7978         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7979         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7980         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7981         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7982         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7983         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7984         { } /* end */
7985 };
7986
7987 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7988         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7989         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7990         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7991         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7992         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7995         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7996         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7997         { } /* end */
7998 };
7999
8000 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8001         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8002         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8003         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8004         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8005         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8006         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8007         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8008         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8009         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8010         { } /* end */
8011 };
8012
8013 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8014         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8015         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8016         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8017         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8018         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8019         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8020         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8021         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8022         { } /* end */
8023 };
8024
8025 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8026         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8027         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8028         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8029         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8030         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8031         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8032         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8033         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8034         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8035         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8036         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8037         { } /* end */
8038 };
8039
8040 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8041         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8042         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8043         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8044         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8045         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8046                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8047         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8048         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8049         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8050         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8051         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8052         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8053         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8054         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8055         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8056         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8057         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8058         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8059         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8060         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8061         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8062         { } /* end */
8063 };
8064
8065 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8066         /* Output mixers */
8067         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8068         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8069         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8070         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8071         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8072                 HDA_OUTPUT),
8073         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8074         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8075         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8076         /* Output switches */
8077         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8078         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8079         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8080         /* Boost mixers */
8081         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8082         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8083         /* Input mixers */
8084         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8085         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8086         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8087         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8088         { } /* end */
8089 };
8090
8091 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8092         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8093         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8094         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8095         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8096         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8097         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8098         { } /* end */
8099 };
8100
8101 static struct hda_bind_ctls alc883_bind_cap_vol = {
8102         .ops = &snd_hda_bind_vol,
8103         .values = {
8104                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8105                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8106                 0
8107         },
8108 };
8109
8110 static struct hda_bind_ctls alc883_bind_cap_switch = {
8111         .ops = &snd_hda_bind_sw,
8112         .values = {
8113                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8114                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8115                 0
8116         },
8117 };
8118
8119 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8120         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8121         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8123         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8124         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8125         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8126         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8127         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8128         { } /* end */
8129 };
8130
8131 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8132         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8133         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8134         {
8135                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8136                 /* .name = "Capture Source", */
8137                 .name = "Input Source",
8138                 .count = 1,
8139                 .info = alc_mux_enum_info,
8140                 .get = alc_mux_enum_get,
8141                 .put = alc_mux_enum_put,
8142         },
8143         { } /* end */
8144 };
8145
8146 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8147         {
8148                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8149                 .name = "Channel Mode",
8150                 .info = alc_ch_mode_info,
8151                 .get = alc_ch_mode_get,
8152                 .put = alc_ch_mode_put,
8153         },
8154         { } /* end */
8155 };
8156
8157 /* toggle speaker-output according to the hp-jack state */
8158 static void alc883_mitac_setup(struct hda_codec *codec)
8159 {
8160         struct alc_spec *spec = codec->spec;
8161
8162         spec->autocfg.hp_pins[0] = 0x15;
8163         spec->autocfg.speaker_pins[0] = 0x14;
8164         spec->autocfg.speaker_pins[1] = 0x17;
8165 }
8166
8167 /* auto-toggle front mic */
8168 /*
8169 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8170 {
8171         unsigned int present;
8172         unsigned char bits;
8173
8174         present = snd_hda_codec_read(codec, 0x18, 0,
8175                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8176         bits = present ? HDA_AMP_MUTE : 0;
8177         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8178 }
8179 */
8180
8181 static struct hda_verb alc883_mitac_verbs[] = {
8182         /* HP */
8183         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8184         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8185         /* Subwoofer */
8186         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8187         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8188
8189         /* enable unsolicited event */
8190         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8191         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8192
8193         { } /* end */
8194 };
8195
8196 static struct hda_verb alc883_clevo_m540r_verbs[] = {
8197         /* HP */
8198         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8199         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8200         /* Int speaker */
8201         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
8202
8203         /* enable unsolicited event */
8204         /*
8205         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8206         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8207         */
8208
8209         { } /* end */
8210 };
8211
8212 static struct hda_verb alc883_clevo_m720_verbs[] = {
8213         /* HP */
8214         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8215         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8216         /* Int speaker */
8217         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8218         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8219
8220         /* enable unsolicited event */
8221         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8222         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8223
8224         { } /* end */
8225 };
8226
8227 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8228         /* HP */
8229         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8230         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8231         /* Subwoofer */
8232         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8234
8235         /* enable unsolicited event */
8236         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8237
8238         { } /* end */
8239 };
8240
8241 static struct hda_verb alc883_targa_verbs[] = {
8242         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8244
8245         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8246         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8247
8248 /* Connect Line-Out side jack (SPDIF) to Side */
8249         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8250         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8251         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8252 /* Connect Mic jack to CLFE */
8253         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8254         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8255         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8256 /* Connect Line-in jack to Surround */
8257         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8258         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8259         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8260 /* Connect HP out jack to Front */
8261         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8262         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8263         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8264
8265         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8266
8267         { } /* end */
8268 };
8269
8270 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8271         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8272         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8273         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8274         { } /* end */
8275 };
8276
8277 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8278         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8279         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8280         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8282         { } /* end */
8283 };
8284
8285 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8286         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8287         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8288         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8289         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8290         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8291         { } /* end */
8292 };
8293
8294 static struct hda_verb alc883_haier_w66_verbs[] = {
8295         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8296         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8297
8298         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8299
8300         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8301         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8302         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8303         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8304         { } /* end */
8305 };
8306
8307 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8308         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8309         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8310         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8311         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8312         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8313         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8314         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8315         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8316         { } /* end */
8317 };
8318
8319 static struct hda_verb alc888_6st_dell_verbs[] = {
8320         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8321         { }
8322 };
8323
8324 static struct hda_verb alc883_vaiott_verbs[] = {
8325         /* HP */
8326         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8327         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8328
8329         /* enable unsolicited event */
8330         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8331
8332         { } /* end */
8333 };
8334
8335 static void alc888_3st_hp_setup(struct hda_codec *codec)
8336 {
8337         struct alc_spec *spec = codec->spec;
8338
8339         spec->autocfg.hp_pins[0] = 0x1b;
8340         spec->autocfg.speaker_pins[0] = 0x14;
8341         spec->autocfg.speaker_pins[1] = 0x16;
8342         spec->autocfg.speaker_pins[2] = 0x18;
8343 }
8344
8345 static struct hda_verb alc888_3st_hp_verbs[] = {
8346         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8347         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8348         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8349         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8350         { } /* end */
8351 };
8352
8353 /*
8354  * 2ch mode
8355  */
8356 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8357         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8358         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8359         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8360         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8361         { } /* end */
8362 };
8363
8364 /*
8365  * 4ch mode
8366  */
8367 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8368         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8369         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8370         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8371         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8372         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8373         { } /* end */
8374 };
8375
8376 /*
8377  * 6ch mode
8378  */
8379 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8380         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8381         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8382         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8383         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8384         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8385         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8386         { } /* end */
8387 };
8388
8389 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8390         { 2, alc888_3st_hp_2ch_init },
8391         { 4, alc888_3st_hp_4ch_init },
8392         { 6, alc888_3st_hp_6ch_init },
8393 };
8394
8395 /* toggle front-jack and RCA according to the hp-jack state */
8396 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8397 {
8398         unsigned int present;
8399
8400         present = snd_hda_codec_read(codec, 0x1b, 0,
8401                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8402         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8403                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8404         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8405                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8406 }
8407
8408 /* toggle RCA according to the front-jack state */
8409 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8410 {
8411         unsigned int present;
8412
8413         present = snd_hda_codec_read(codec, 0x14, 0,
8414                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8415         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8416                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8417 }
8418
8419 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8420                                              unsigned int res)
8421 {
8422         if ((res >> 26) == ALC880_HP_EVENT)
8423                 alc888_lenovo_ms7195_front_automute(codec);
8424         if ((res >> 26) == ALC880_FRONT_EVENT)
8425                 alc888_lenovo_ms7195_rca_automute(codec);
8426 }
8427
8428 static struct hda_verb alc883_medion_md2_verbs[] = {
8429         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8430         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8431
8432         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8433
8434         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8435         { } /* end */
8436 };
8437
8438 /* toggle speaker-output according to the hp-jack state */
8439 static void alc883_medion_md2_setup(struct hda_codec *codec)
8440 {
8441         struct alc_spec *spec = codec->spec;
8442
8443         spec->autocfg.hp_pins[0] = 0x14;
8444         spec->autocfg.speaker_pins[0] = 0x15;
8445 }
8446
8447 /* toggle speaker-output according to the hp-jack state */
8448 #define alc883_targa_init_hook          alc882_targa_init_hook
8449 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8450
8451 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8452 {
8453         unsigned int present;
8454
8455         present = snd_hda_codec_read(codec, 0x18, 0,
8456                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8457         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8458                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8459 }
8460
8461 static void alc883_clevo_m720_setup(struct hda_codec *codec)
8462 {
8463         struct alc_spec *spec = codec->spec;
8464
8465         spec->autocfg.hp_pins[0] = 0x15;
8466         spec->autocfg.speaker_pins[0] = 0x14;
8467 }
8468
8469 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8470 {
8471         alc_automute_amp(codec);
8472         alc883_clevo_m720_mic_automute(codec);
8473 }
8474
8475 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8476                                            unsigned int res)
8477 {
8478         switch (res >> 26) {
8479         case ALC880_MIC_EVENT:
8480                 alc883_clevo_m720_mic_automute(codec);
8481                 break;
8482         default:
8483                 alc_automute_amp_unsol_event(codec, res);
8484                 break;
8485         }
8486 }
8487
8488 /* toggle speaker-output according to the hp-jack state */
8489 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8490 {
8491         struct alc_spec *spec = codec->spec;
8492
8493         spec->autocfg.hp_pins[0] = 0x14;
8494         spec->autocfg.speaker_pins[0] = 0x15;
8495 }
8496
8497 static void alc883_haier_w66_setup(struct hda_codec *codec)
8498 {
8499         struct alc_spec *spec = codec->spec;
8500
8501         spec->autocfg.hp_pins[0] = 0x1b;
8502         spec->autocfg.speaker_pins[0] = 0x14;
8503 }
8504
8505 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8506 {
8507         unsigned int present;
8508         unsigned char bits;
8509
8510         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8511                 & AC_PINSENSE_PRESENCE;
8512         bits = present ? HDA_AMP_MUTE : 0;
8513         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8514                                  HDA_AMP_MUTE, bits);
8515 }
8516
8517 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8518 {
8519         unsigned int present;
8520         unsigned char bits;
8521
8522         present = snd_hda_codec_read(codec, 0x1b, 0,
8523                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8524         bits = present ? HDA_AMP_MUTE : 0;
8525         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8526                                  HDA_AMP_MUTE, bits);
8527         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8528                                  HDA_AMP_MUTE, bits);
8529 }
8530
8531 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8532                                            unsigned int res)
8533 {
8534         if ((res >> 26) == ALC880_HP_EVENT)
8535                 alc883_lenovo_101e_all_automute(codec);
8536         if ((res >> 26) == ALC880_FRONT_EVENT)
8537                 alc883_lenovo_101e_ispeaker_automute(codec);
8538 }
8539
8540 /* toggle speaker-output according to the hp-jack state */
8541 static void alc883_acer_aspire_setup(struct hda_codec *codec)
8542 {
8543         struct alc_spec *spec = codec->spec;
8544
8545         spec->autocfg.hp_pins[0] = 0x14;
8546         spec->autocfg.speaker_pins[0] = 0x15;
8547         spec->autocfg.speaker_pins[1] = 0x16;
8548 }
8549
8550 static struct hda_verb alc883_acer_eapd_verbs[] = {
8551         /* HP Pin: output 0 (0x0c) */
8552         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8553         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8554         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8555         /* Front Pin: output 0 (0x0c) */
8556         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8557         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8558         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8559         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8560         /* eanable EAPD on medion laptop */
8561         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8562         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8563         /* enable unsolicited event */
8564         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8565         { }
8566 };
8567
8568 static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
8569         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8570         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8571         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8572         { } /* end */
8573 };
8574
8575 static void alc888_6st_dell_setup(struct hda_codec *codec)
8576 {
8577         struct alc_spec *spec = codec->spec;
8578
8579         spec->autocfg.hp_pins[0] = 0x1b;
8580         spec->autocfg.speaker_pins[0] = 0x14;
8581         spec->autocfg.speaker_pins[1] = 0x15;
8582         spec->autocfg.speaker_pins[2] = 0x16;
8583         spec->autocfg.speaker_pins[3] = 0x17;
8584 }
8585
8586 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
8587 {
8588         struct alc_spec *spec = codec->spec;
8589
8590         spec->autocfg.hp_pins[0] = 0x1b;
8591         spec->autocfg.speaker_pins[0] = 0x14;
8592         spec->autocfg.speaker_pins[1] = 0x15;
8593         spec->autocfg.speaker_pins[2] = 0x16;
8594         spec->autocfg.speaker_pins[3] = 0x17;
8595         spec->autocfg.speaker_pins[4] = 0x1a;
8596 }
8597
8598 static void alc883_vaiott_setup(struct hda_codec *codec)
8599 {
8600         struct alc_spec *spec = codec->spec;
8601
8602         spec->autocfg.hp_pins[0] = 0x15;
8603         spec->autocfg.speaker_pins[0] = 0x14;
8604         spec->autocfg.speaker_pins[1] = 0x17;
8605 }
8606
8607 static struct hda_verb alc888_asus_m90v_verbs[] = {
8608         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8609         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8610         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8611         /* enable unsolicited event */
8612         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8613         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8614         { } /* end */
8615 };
8616
8617 static void alc883_mode2_setup(struct hda_codec *codec)
8618 {
8619         struct alc_spec *spec = codec->spec;
8620
8621         spec->autocfg.hp_pins[0] = 0x1b;
8622         spec->autocfg.speaker_pins[0] = 0x14;
8623         spec->autocfg.speaker_pins[1] = 0x15;
8624         spec->autocfg.speaker_pins[2] = 0x16;
8625         spec->ext_mic.pin = 0x18;
8626         spec->int_mic.pin = 0x19;
8627         spec->ext_mic.mux_idx = 0;
8628         spec->int_mic.mux_idx = 1;
8629         spec->auto_mic = 1;
8630 }
8631
8632 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8633         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8634         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8635         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8636         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8637         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8638         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8639         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8640         /* enable unsolicited event */
8641         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8642         { } /* end */
8643 };
8644
8645 static void alc883_eee1601_inithook(struct hda_codec *codec)
8646 {
8647         struct alc_spec *spec = codec->spec;
8648
8649         spec->autocfg.hp_pins[0] = 0x14;
8650         spec->autocfg.speaker_pins[0] = 0x1b;
8651         alc_automute_pin(codec);
8652 }
8653
8654 static struct hda_verb alc889A_mb31_verbs[] = {
8655         /* Init rear pin (used as headphone output) */
8656         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8657         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8658         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8659         /* Init line pin (used as output in 4ch and 6ch mode) */
8660         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8661         /* Init line 2 pin (used as headphone out by default) */
8662         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8663         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
8664         { } /* end */
8665 };
8666
8667 /* Mute speakers according to the headphone jack state */
8668 static void alc889A_mb31_automute(struct hda_codec *codec)
8669 {
8670         unsigned int present;
8671
8672         /* Mute only in 2ch or 4ch mode */
8673         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8674             == 0x00) {
8675                 present = snd_hda_codec_read(codec, 0x15, 0,
8676                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8677                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
8678                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8679                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8680                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8681         }
8682 }
8683
8684 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8685 {
8686         if ((res >> 26) == ALC880_HP_EVENT)
8687                 alc889A_mb31_automute(codec);
8688 }
8689
8690
8691 #ifdef CONFIG_SND_HDA_POWER_SAVE
8692 #define alc882_loopbacks        alc880_loopbacks
8693 #endif
8694
8695 /* pcm configuration: identical with ALC880 */
8696 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
8697 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
8698 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
8699 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
8700
8701 static hda_nid_t alc883_slave_dig_outs[] = {
8702         ALC1200_DIGOUT_NID, 0,
8703 };
8704
8705 static hda_nid_t alc1200_slave_dig_outs[] = {
8706         ALC883_DIGOUT_NID, 0,
8707 };
8708
8709 /*
8710  * configuration and preset
8711  */
8712 static const char *alc882_models[ALC882_MODEL_LAST] = {
8713         [ALC882_3ST_DIG]        = "3stack-dig",
8714         [ALC882_6ST_DIG]        = "6stack-dig",
8715         [ALC882_ARIMA]          = "arima",
8716         [ALC882_W2JC]           = "w2jc",
8717         [ALC882_TARGA]          = "targa",
8718         [ALC882_ASUS_A7J]       = "asus-a7j",
8719         [ALC882_ASUS_A7M]       = "asus-a7m",
8720         [ALC885_MACPRO]         = "macpro",
8721         [ALC885_MB5]            = "mb5",
8722         [ALC885_MBP3]           = "mbp3",
8723         [ALC885_IMAC24]         = "imac24",
8724         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
8725         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8726         [ALC883_3ST_6ch]        = "3stack-6ch",
8727         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
8728         [ALC883_TARGA_DIG]      = "targa-dig",
8729         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8730         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
8731         [ALC883_ACER]           = "acer",
8732         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8733         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8734         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
8735         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
8736         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
8737         [ALC883_MEDION]         = "medion",
8738         [ALC883_MEDION_MD2]     = "medion-md2",
8739         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8740         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8741         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8742         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8743         [ALC888_LENOVO_SKY] = "lenovo-sky",
8744         [ALC883_HAIER_W66]      = "haier-w66",
8745         [ALC888_3ST_HP]         = "3stack-hp",
8746         [ALC888_6ST_DELL]       = "6stack-dell",
8747         [ALC883_MITAC]          = "mitac",
8748         [ALC883_CLEVO_M540R]    = "clevo-m540r",
8749         [ALC883_CLEVO_M720]     = "clevo-m720",
8750         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8751         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8752         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8753         [ALC889A_INTEL]         = "intel-alc889a",
8754         [ALC889_INTEL]          = "intel-x58",
8755         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8756         [ALC889A_MB31]          = "mb31",
8757         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
8758         [ALC882_AUTO]           = "auto",
8759 };
8760
8761 static struct snd_pci_quirk alc882_cfg_tbl[] = {
8762         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8763
8764         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8765         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8766         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8767         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8768         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8769         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8770         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8771                 ALC888_ACER_ASPIRE_4930G),
8772         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8773                 ALC888_ACER_ASPIRE_4930G),
8774         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
8775                 ALC888_ACER_ASPIRE_8930G),
8776         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
8777                 ALC888_ACER_ASPIRE_8930G),
8778         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
8779         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
8780         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8781                 ALC888_ACER_ASPIRE_6530G),
8782         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8783                 ALC888_ACER_ASPIRE_6530G),
8784         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8785                 ALC888_ACER_ASPIRE_7730G),
8786         /* default Acer -- disabled as it causes more problems.
8787          *    model=auto should work fine now
8788          */
8789         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8790
8791         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8792
8793         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8794         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8795         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8796         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8797         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8798         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8799
8800         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
8801         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
8802         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
8803         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8804         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
8805         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
8806         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
8807         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8808         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8809         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8810         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8811
8812         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
8813         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8814         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
8815         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8816         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8817         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8818         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8819         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8820         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8821
8822         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8823         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8824         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8825         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
8826         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8827         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8828         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8829         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8830         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8831         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8832         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8833         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8834         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8835         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8836         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
8837         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8838         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8839         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8840         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
8841         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8842         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8843         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8844         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8845         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8846         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8847         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8848         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
8849         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8850         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8851
8852         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8853         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8854         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8855         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
8856         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8857         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8858         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
8859         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8860         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8861                       ALC883_FUJITSU_PI2515),
8862         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8863                 ALC888_FUJITSU_XA3530),
8864         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8865         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8866         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8867         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8868         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8869         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8870         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8871         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8872         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8873
8874         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8875         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8876         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8877         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8878         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8879         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
8880         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8881
8882         {}
8883 };
8884
8885 /* codec SSID table for Intel Mac */
8886 static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8887         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
8888         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
8889         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
8890         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
8891         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
8892         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
8893         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
8894         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8895         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8896         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
8897         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8898         /* FIXME: HP jack sense seems not working for MBP 5,1, so apparently
8899          * no perfect solution yet
8900          */
8901         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8902         {} /* terminator */
8903 };
8904
8905 static struct alc_config_preset alc882_presets[] = {
8906         [ALC882_3ST_DIG] = {
8907                 .mixers = { alc882_base_mixer },
8908                 .init_verbs = { alc882_base_init_verbs,
8909                                 alc882_adc1_init_verbs },
8910                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8911                 .dac_nids = alc882_dac_nids,
8912                 .dig_out_nid = ALC882_DIGOUT_NID,
8913                 .dig_in_nid = ALC882_DIGIN_NID,
8914                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8915                 .channel_mode = alc882_ch_modes,
8916                 .need_dac_fix = 1,
8917                 .input_mux = &alc882_capture_source,
8918         },
8919         [ALC882_6ST_DIG] = {
8920                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8921                 .init_verbs = { alc882_base_init_verbs,
8922                                 alc882_adc1_init_verbs },
8923                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8924                 .dac_nids = alc882_dac_nids,
8925                 .dig_out_nid = ALC882_DIGOUT_NID,
8926                 .dig_in_nid = ALC882_DIGIN_NID,
8927                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8928                 .channel_mode = alc882_sixstack_modes,
8929                 .input_mux = &alc882_capture_source,
8930         },
8931         [ALC882_ARIMA] = {
8932                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8933                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8934                                 alc882_eapd_verbs },
8935                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8936                 .dac_nids = alc882_dac_nids,
8937                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8938                 .channel_mode = alc882_sixstack_modes,
8939                 .input_mux = &alc882_capture_source,
8940         },
8941         [ALC882_W2JC] = {
8942                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
8943                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8944                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
8945                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8946                 .dac_nids = alc882_dac_nids,
8947                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
8948                 .channel_mode = alc880_threestack_modes,
8949                 .need_dac_fix = 1,
8950                 .input_mux = &alc882_capture_source,
8951                 .dig_out_nid = ALC882_DIGOUT_NID,
8952         },
8953         [ALC885_MBP3] = {
8954                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8955                 .init_verbs = { alc885_mbp3_init_verbs,
8956                                 alc880_gpio1_init_verbs },
8957                 .num_dacs = 2,
8958                 .dac_nids = alc882_dac_nids,
8959                 .hp_nid = 0x04,
8960                 .channel_mode = alc885_mbp_4ch_modes,
8961                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
8962                 .input_mux = &alc882_capture_source,
8963                 .dig_out_nid = ALC882_DIGOUT_NID,
8964                 .dig_in_nid = ALC882_DIGIN_NID,
8965                 .unsol_event = alc_automute_amp_unsol_event,
8966                 .setup = alc885_mbp3_setup,
8967                 .init_hook = alc_automute_amp,
8968         },
8969         [ALC885_MB5] = {
8970                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
8971                 .init_verbs = { alc885_mb5_init_verbs,
8972                                 alc880_gpio1_init_verbs },
8973                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8974                 .dac_nids = alc882_dac_nids,
8975                 .channel_mode = alc885_mb5_6ch_modes,
8976                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
8977                 .input_mux = &mb5_capture_source,
8978                 .dig_out_nid = ALC882_DIGOUT_NID,
8979                 .dig_in_nid = ALC882_DIGIN_NID,
8980         },
8981         [ALC885_MACPRO] = {
8982                 .mixers = { alc882_macpro_mixer },
8983                 .init_verbs = { alc882_macpro_init_verbs },
8984                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8985                 .dac_nids = alc882_dac_nids,
8986                 .dig_out_nid = ALC882_DIGOUT_NID,
8987                 .dig_in_nid = ALC882_DIGIN_NID,
8988                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8989                 .channel_mode = alc882_ch_modes,
8990                 .input_mux = &alc882_capture_source,
8991                 .init_hook = alc885_macpro_init_hook,
8992         },
8993         [ALC885_IMAC24] = {
8994                 .mixers = { alc885_imac24_mixer },
8995                 .init_verbs = { alc885_imac24_init_verbs },
8996                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8997                 .dac_nids = alc882_dac_nids,
8998                 .dig_out_nid = ALC882_DIGOUT_NID,
8999                 .dig_in_nid = ALC882_DIGIN_NID,
9000                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9001                 .channel_mode = alc882_ch_modes,
9002                 .input_mux = &alc882_capture_source,
9003                 .unsol_event = alc_automute_amp_unsol_event,
9004                 .setup = alc885_imac24_setup,
9005                 .init_hook = alc885_imac24_init_hook,
9006         },
9007         [ALC882_TARGA] = {
9008                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9009                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9010                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
9011                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9012                 .dac_nids = alc882_dac_nids,
9013                 .dig_out_nid = ALC882_DIGOUT_NID,
9014                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9015                 .adc_nids = alc882_adc_nids,
9016                 .capsrc_nids = alc882_capsrc_nids,
9017                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9018                 .channel_mode = alc882_3ST_6ch_modes,
9019                 .need_dac_fix = 1,
9020                 .input_mux = &alc882_capture_source,
9021                 .unsol_event = alc882_targa_unsol_event,
9022                 .setup = alc882_targa_setup,
9023                 .init_hook = alc882_targa_automute,
9024         },
9025         [ALC882_ASUS_A7J] = {
9026                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9027                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9028                                 alc882_asus_a7j_verbs},
9029                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9030                 .dac_nids = alc882_dac_nids,
9031                 .dig_out_nid = ALC882_DIGOUT_NID,
9032                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9033                 .adc_nids = alc882_adc_nids,
9034                 .capsrc_nids = alc882_capsrc_nids,
9035                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9036                 .channel_mode = alc882_3ST_6ch_modes,
9037                 .need_dac_fix = 1,
9038                 .input_mux = &alc882_capture_source,
9039         },
9040         [ALC882_ASUS_A7M] = {
9041                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9042                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9043                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
9044                                 alc882_asus_a7m_verbs },
9045                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9046                 .dac_nids = alc882_dac_nids,
9047                 .dig_out_nid = ALC882_DIGOUT_NID,
9048                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
9049                 .channel_mode = alc880_threestack_modes,
9050                 .need_dac_fix = 1,
9051                 .input_mux = &alc882_capture_source,
9052         },
9053         [ALC883_3ST_2ch_DIG] = {
9054                 .mixers = { alc883_3ST_2ch_mixer },
9055                 .init_verbs = { alc883_init_verbs },
9056                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9057                 .dac_nids = alc883_dac_nids,
9058                 .dig_out_nid = ALC883_DIGOUT_NID,
9059                 .dig_in_nid = ALC883_DIGIN_NID,
9060                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9061                 .channel_mode = alc883_3ST_2ch_modes,
9062                 .input_mux = &alc883_capture_source,
9063         },
9064         [ALC883_3ST_6ch_DIG] = {
9065                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9066                 .init_verbs = { alc883_init_verbs },
9067                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9068                 .dac_nids = alc883_dac_nids,
9069                 .dig_out_nid = ALC883_DIGOUT_NID,
9070                 .dig_in_nid = ALC883_DIGIN_NID,
9071                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9072                 .channel_mode = alc883_3ST_6ch_modes,
9073                 .need_dac_fix = 1,
9074                 .input_mux = &alc883_capture_source,
9075         },
9076         [ALC883_3ST_6ch] = {
9077                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9078                 .init_verbs = { alc883_init_verbs },
9079                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9080                 .dac_nids = alc883_dac_nids,
9081                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9082                 .channel_mode = alc883_3ST_6ch_modes,
9083                 .need_dac_fix = 1,
9084                 .input_mux = &alc883_capture_source,
9085         },
9086         [ALC883_3ST_6ch_INTEL] = {
9087                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9088                 .init_verbs = { alc883_init_verbs },
9089                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9090                 .dac_nids = alc883_dac_nids,
9091                 .dig_out_nid = ALC883_DIGOUT_NID,
9092                 .dig_in_nid = ALC883_DIGIN_NID,
9093                 .slave_dig_outs = alc883_slave_dig_outs,
9094                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9095                 .channel_mode = alc883_3ST_6ch_intel_modes,
9096                 .need_dac_fix = 1,
9097                 .input_mux = &alc883_3stack_6ch_intel,
9098         },
9099         [ALC889A_INTEL] = {
9100                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9101                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
9102                                 alc_hp15_unsol_verbs },
9103                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9104                 .dac_nids = alc883_dac_nids,
9105                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9106                 .adc_nids = alc889_adc_nids,
9107                 .dig_out_nid = ALC883_DIGOUT_NID,
9108                 .dig_in_nid = ALC883_DIGIN_NID,
9109                 .slave_dig_outs = alc883_slave_dig_outs,
9110                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9111                 .channel_mode = alc889_8ch_intel_modes,
9112                 .capsrc_nids = alc889_capsrc_nids,
9113                 .input_mux = &alc889_capture_source,
9114                 .setup = alc889_automute_setup,
9115                 .init_hook = alc_automute_amp,
9116                 .unsol_event = alc_automute_amp_unsol_event,
9117                 .need_dac_fix = 1,
9118         },
9119         [ALC889_INTEL] = {
9120                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9121                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9122                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
9123                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9124                 .dac_nids = alc883_dac_nids,
9125                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9126                 .adc_nids = alc889_adc_nids,
9127                 .dig_out_nid = ALC883_DIGOUT_NID,
9128                 .dig_in_nid = ALC883_DIGIN_NID,
9129                 .slave_dig_outs = alc883_slave_dig_outs,
9130                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9131                 .channel_mode = alc889_8ch_intel_modes,
9132                 .capsrc_nids = alc889_capsrc_nids,
9133                 .input_mux = &alc889_capture_source,
9134                 .setup = alc889_automute_setup,
9135                 .init_hook = alc889_intel_init_hook,
9136                 .unsol_event = alc_automute_amp_unsol_event,
9137                 .need_dac_fix = 1,
9138         },
9139         [ALC883_6ST_DIG] = {
9140                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9141                 .init_verbs = { alc883_init_verbs },
9142                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9143                 .dac_nids = alc883_dac_nids,
9144                 .dig_out_nid = ALC883_DIGOUT_NID,
9145                 .dig_in_nid = ALC883_DIGIN_NID,
9146                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9147                 .channel_mode = alc883_sixstack_modes,
9148                 .input_mux = &alc883_capture_source,
9149         },
9150         [ALC883_TARGA_DIG] = {
9151                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9152                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9153                                 alc883_targa_verbs},
9154                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9155                 .dac_nids = alc883_dac_nids,
9156                 .dig_out_nid = ALC883_DIGOUT_NID,
9157                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9158                 .channel_mode = alc883_3ST_6ch_modes,
9159                 .need_dac_fix = 1,
9160                 .input_mux = &alc883_capture_source,
9161                 .unsol_event = alc883_targa_unsol_event,
9162                 .setup = alc882_targa_setup,
9163                 .init_hook = alc882_targa_automute,
9164         },
9165         [ALC883_TARGA_2ch_DIG] = {
9166                 .mixers = { alc883_targa_2ch_mixer},
9167                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9168                                 alc883_targa_verbs},
9169                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9170                 .dac_nids = alc883_dac_nids,
9171                 .adc_nids = alc883_adc_nids_alt,
9172                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9173                 .dig_out_nid = ALC883_DIGOUT_NID,
9174                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9175                 .channel_mode = alc883_3ST_2ch_modes,
9176                 .input_mux = &alc883_capture_source,
9177                 .unsol_event = alc883_targa_unsol_event,
9178                 .setup = alc882_targa_setup,
9179                 .init_hook = alc882_targa_automute,
9180         },
9181         [ALC883_TARGA_8ch_DIG] = {
9182                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9183                             alc883_chmode_mixer },
9184                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9185                                 alc883_targa_verbs },
9186                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9187                 .dac_nids = alc883_dac_nids,
9188                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9189                 .adc_nids = alc883_adc_nids_rev,
9190                 .capsrc_nids = alc883_capsrc_nids_rev,
9191                 .dig_out_nid = ALC883_DIGOUT_NID,
9192                 .dig_in_nid = ALC883_DIGIN_NID,
9193                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9194                 .channel_mode = alc883_4ST_8ch_modes,
9195                 .need_dac_fix = 1,
9196                 .input_mux = &alc883_capture_source,
9197                 .unsol_event = alc883_targa_unsol_event,
9198                 .setup = alc882_targa_setup,
9199                 .init_hook = alc882_targa_automute,
9200         },
9201         [ALC883_ACER] = {
9202                 .mixers = { alc883_base_mixer },
9203                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9204                  * and the headphone jack.  Turn this on and rely on the
9205                  * standard mute methods whenever the user wants to turn
9206                  * these outputs off.
9207                  */
9208                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9209                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9210                 .dac_nids = alc883_dac_nids,
9211                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9212                 .channel_mode = alc883_3ST_2ch_modes,
9213                 .input_mux = &alc883_capture_source,
9214         },
9215         [ALC883_ACER_ASPIRE] = {
9216                 .mixers = { alc883_acer_aspire_mixer },
9217                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9218                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9219                 .dac_nids = alc883_dac_nids,
9220                 .dig_out_nid = ALC883_DIGOUT_NID,
9221                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9222                 .channel_mode = alc883_3ST_2ch_modes,
9223                 .input_mux = &alc883_capture_source,
9224                 .unsol_event = alc_automute_amp_unsol_event,
9225                 .setup = alc883_acer_aspire_setup,
9226                 .init_hook = alc_automute_amp,
9227         },
9228         [ALC888_ACER_ASPIRE_4930G] = {
9229                 .mixers = { alc888_base_mixer,
9230                                 alc883_chmode_mixer },
9231                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9232                                 alc888_acer_aspire_4930g_verbs },
9233                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9234                 .dac_nids = alc883_dac_nids,
9235                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9236                 .adc_nids = alc883_adc_nids_rev,
9237                 .capsrc_nids = alc883_capsrc_nids_rev,
9238                 .dig_out_nid = ALC883_DIGOUT_NID,
9239                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9240                 .channel_mode = alc883_3ST_6ch_modes,
9241                 .need_dac_fix = 1,
9242                 .num_mux_defs =
9243                         ARRAY_SIZE(alc888_2_capture_sources),
9244                 .input_mux = alc888_2_capture_sources,
9245                 .unsol_event = alc_automute_amp_unsol_event,
9246                 .setup = alc888_acer_aspire_4930g_setup,
9247                 .init_hook = alc_automute_amp,
9248         },
9249         [ALC888_ACER_ASPIRE_6530G] = {
9250                 .mixers = { alc888_acer_aspire_6530_mixer },
9251                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9252                                 alc888_acer_aspire_6530g_verbs },
9253                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9254                 .dac_nids = alc883_dac_nids,
9255                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9256                 .adc_nids = alc883_adc_nids_rev,
9257                 .capsrc_nids = alc883_capsrc_nids_rev,
9258                 .dig_out_nid = ALC883_DIGOUT_NID,
9259                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9260                 .channel_mode = alc883_3ST_2ch_modes,
9261                 .num_mux_defs =
9262                         ARRAY_SIZE(alc888_2_capture_sources),
9263                 .input_mux = alc888_acer_aspire_6530_sources,
9264                 .unsol_event = alc_automute_amp_unsol_event,
9265                 .setup = alc888_acer_aspire_6530g_setup,
9266                 .init_hook = alc_automute_amp,
9267         },
9268         [ALC888_ACER_ASPIRE_8930G] = {
9269                 .mixers = { alc888_base_mixer,
9270                                 alc883_chmode_mixer },
9271                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9272                                 alc889_acer_aspire_8930g_verbs },
9273                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9274                 .dac_nids = alc883_dac_nids,
9275                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9276                 .adc_nids = alc889_adc_nids,
9277                 .capsrc_nids = alc889_capsrc_nids,
9278                 .dig_out_nid = ALC883_DIGOUT_NID,
9279                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9280                 .channel_mode = alc883_3ST_6ch_modes,
9281                 .need_dac_fix = 1,
9282                 .const_channel_count = 6,
9283                 .num_mux_defs =
9284                         ARRAY_SIZE(alc889_capture_sources),
9285                 .input_mux = alc889_capture_sources,
9286                 .unsol_event = alc_automute_amp_unsol_event,
9287                 .setup = alc889_acer_aspire_8930g_setup,
9288                 .init_hook = alc_automute_amp,
9289         },
9290         [ALC888_ACER_ASPIRE_7730G] = {
9291                 .mixers = { alc883_3ST_6ch_mixer,
9292                                 alc883_chmode_mixer },
9293                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9294                                 alc888_acer_aspire_7730G_verbs },
9295                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9296                 .dac_nids = alc883_dac_nids,
9297                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9298                 .adc_nids = alc883_adc_nids_rev,
9299                 .capsrc_nids = alc883_capsrc_nids_rev,
9300                 .dig_out_nid = ALC883_DIGOUT_NID,
9301                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9302                 .channel_mode = alc883_3ST_6ch_modes,
9303                 .need_dac_fix = 1,
9304                 .const_channel_count = 6,
9305                 .input_mux = &alc883_capture_source,
9306                 .unsol_event = alc_automute_amp_unsol_event,
9307                 .setup = alc888_acer_aspire_6530g_setup,
9308                 .init_hook = alc_automute_amp,
9309         },
9310         [ALC883_MEDION] = {
9311                 .mixers = { alc883_fivestack_mixer,
9312                             alc883_chmode_mixer },
9313                 .init_verbs = { alc883_init_verbs,
9314                                 alc883_medion_eapd_verbs },
9315                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9316                 .dac_nids = alc883_dac_nids,
9317                 .adc_nids = alc883_adc_nids_alt,
9318                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9319                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9320                 .channel_mode = alc883_sixstack_modes,
9321                 .input_mux = &alc883_capture_source,
9322         },
9323         [ALC883_MEDION_MD2] = {
9324                 .mixers = { alc883_medion_md2_mixer},
9325                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9326                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9327                 .dac_nids = alc883_dac_nids,
9328                 .dig_out_nid = ALC883_DIGOUT_NID,
9329                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9330                 .channel_mode = alc883_3ST_2ch_modes,
9331                 .input_mux = &alc883_capture_source,
9332                 .unsol_event = alc_automute_amp_unsol_event,
9333                 .setup = alc883_medion_md2_setup,
9334                 .init_hook = alc_automute_amp,
9335         },
9336         [ALC883_LAPTOP_EAPD] = {
9337                 .mixers = { alc883_base_mixer },
9338                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9339                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9340                 .dac_nids = alc883_dac_nids,
9341                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9342                 .channel_mode = alc883_3ST_2ch_modes,
9343                 .input_mux = &alc883_capture_source,
9344         },
9345         [ALC883_CLEVO_M540R] = {
9346                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9347                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
9348                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9349                 .dac_nids = alc883_dac_nids,
9350                 .dig_out_nid = ALC883_DIGOUT_NID,
9351                 .dig_in_nid = ALC883_DIGIN_NID,
9352                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
9353                 .channel_mode = alc883_3ST_6ch_clevo_modes,
9354                 .need_dac_fix = 1,
9355                 .input_mux = &alc883_capture_source,
9356                 /* This machine has the hardware HP auto-muting, thus
9357                  * we need no software mute via unsol event
9358                  */
9359         },
9360         [ALC883_CLEVO_M720] = {
9361                 .mixers = { alc883_clevo_m720_mixer },
9362                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9363                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9364                 .dac_nids = alc883_dac_nids,
9365                 .dig_out_nid = ALC883_DIGOUT_NID,
9366                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9367                 .channel_mode = alc883_3ST_2ch_modes,
9368                 .input_mux = &alc883_capture_source,
9369                 .unsol_event = alc883_clevo_m720_unsol_event,
9370                 .setup = alc883_clevo_m720_setup,
9371                 .init_hook = alc883_clevo_m720_init_hook,
9372         },
9373         [ALC883_LENOVO_101E_2ch] = {
9374                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9375                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9376                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9377                 .dac_nids = alc883_dac_nids,
9378                 .adc_nids = alc883_adc_nids_alt,
9379                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9380                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9381                 .channel_mode = alc883_3ST_2ch_modes,
9382                 .input_mux = &alc883_lenovo_101e_capture_source,
9383                 .unsol_event = alc883_lenovo_101e_unsol_event,
9384                 .init_hook = alc883_lenovo_101e_all_automute,
9385         },
9386         [ALC883_LENOVO_NB0763] = {
9387                 .mixers = { alc883_lenovo_nb0763_mixer },
9388                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9389                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9390                 .dac_nids = alc883_dac_nids,
9391                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9392                 .channel_mode = alc883_3ST_2ch_modes,
9393                 .need_dac_fix = 1,
9394                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9395                 .unsol_event = alc_automute_amp_unsol_event,
9396                 .setup = alc883_medion_md2_setup,
9397                 .init_hook = alc_automute_amp,
9398         },
9399         [ALC888_LENOVO_MS7195_DIG] = {
9400                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9401                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9402                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9403                 .dac_nids = alc883_dac_nids,
9404                 .dig_out_nid = ALC883_DIGOUT_NID,
9405                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9406                 .channel_mode = alc883_3ST_6ch_modes,
9407                 .need_dac_fix = 1,
9408                 .input_mux = &alc883_capture_source,
9409                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9410                 .init_hook = alc888_lenovo_ms7195_front_automute,
9411         },
9412         [ALC883_HAIER_W66] = {
9413                 .mixers = { alc883_targa_2ch_mixer},
9414                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_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_capture_source,
9421                 .unsol_event = alc_automute_amp_unsol_event,
9422                 .setup = alc883_haier_w66_setup,
9423                 .init_hook = alc_automute_amp,
9424         },
9425         [ALC888_3ST_HP] = {
9426                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9427                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9428                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9429                 .dac_nids = alc883_dac_nids,
9430                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9431                 .channel_mode = alc888_3st_hp_modes,
9432                 .need_dac_fix = 1,
9433                 .input_mux = &alc883_capture_source,
9434                 .unsol_event = alc_automute_amp_unsol_event,
9435                 .setup = alc888_3st_hp_setup,
9436                 .init_hook = alc_automute_amp,
9437         },
9438         [ALC888_6ST_DELL] = {
9439                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9440                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9441                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9442                 .dac_nids = alc883_dac_nids,
9443                 .dig_out_nid = ALC883_DIGOUT_NID,
9444                 .dig_in_nid = ALC883_DIGIN_NID,
9445                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9446                 .channel_mode = alc883_sixstack_modes,
9447                 .input_mux = &alc883_capture_source,
9448                 .unsol_event = alc_automute_amp_unsol_event,
9449                 .setup = alc888_6st_dell_setup,
9450                 .init_hook = alc_automute_amp,
9451         },
9452         [ALC883_MITAC] = {
9453                 .mixers = { alc883_mitac_mixer },
9454                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9455                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9456                 .dac_nids = alc883_dac_nids,
9457                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9458                 .channel_mode = alc883_3ST_2ch_modes,
9459                 .input_mux = &alc883_capture_source,
9460                 .unsol_event = alc_automute_amp_unsol_event,
9461                 .setup = alc883_mitac_setup,
9462                 .init_hook = alc_automute_amp,
9463         },
9464         [ALC883_FUJITSU_PI2515] = {
9465                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9466                 .init_verbs = { alc883_init_verbs,
9467                                 alc883_2ch_fujitsu_pi2515_verbs},
9468                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9469                 .dac_nids = alc883_dac_nids,
9470                 .dig_out_nid = ALC883_DIGOUT_NID,
9471                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9472                 .channel_mode = alc883_3ST_2ch_modes,
9473                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9474                 .unsol_event = alc_automute_amp_unsol_event,
9475                 .setup = alc883_2ch_fujitsu_pi2515_setup,
9476                 .init_hook = alc_automute_amp,
9477         },
9478         [ALC888_FUJITSU_XA3530] = {
9479                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9480                 .init_verbs = { alc883_init_verbs,
9481                         alc888_fujitsu_xa3530_verbs },
9482                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9483                 .dac_nids = alc883_dac_nids,
9484                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9485                 .adc_nids = alc883_adc_nids_rev,
9486                 .capsrc_nids = alc883_capsrc_nids_rev,
9487                 .dig_out_nid = ALC883_DIGOUT_NID,
9488                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9489                 .channel_mode = alc888_4ST_8ch_intel_modes,
9490                 .num_mux_defs =
9491                         ARRAY_SIZE(alc888_2_capture_sources),
9492                 .input_mux = alc888_2_capture_sources,
9493                 .unsol_event = alc_automute_amp_unsol_event,
9494                 .setup = alc888_fujitsu_xa3530_setup,
9495                 .init_hook = alc_automute_amp,
9496         },
9497         [ALC888_LENOVO_SKY] = {
9498                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9499                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9500                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9501                 .dac_nids = alc883_dac_nids,
9502                 .dig_out_nid = ALC883_DIGOUT_NID,
9503                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9504                 .channel_mode = alc883_sixstack_modes,
9505                 .need_dac_fix = 1,
9506                 .input_mux = &alc883_lenovo_sky_capture_source,
9507                 .unsol_event = alc_automute_amp_unsol_event,
9508                 .setup = alc888_lenovo_sky_setup,
9509                 .init_hook = alc_automute_amp,
9510         },
9511         [ALC888_ASUS_M90V] = {
9512                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9513                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9514                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9515                 .dac_nids = alc883_dac_nids,
9516                 .dig_out_nid = ALC883_DIGOUT_NID,
9517                 .dig_in_nid = ALC883_DIGIN_NID,
9518                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9519                 .channel_mode = alc883_3ST_6ch_modes,
9520                 .need_dac_fix = 1,
9521                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9522                 .unsol_event = alc_sku_unsol_event,
9523                 .setup = alc883_mode2_setup,
9524                 .init_hook = alc_inithook,
9525         },
9526         [ALC888_ASUS_EEE1601] = {
9527                 .mixers = { alc883_asus_eee1601_mixer },
9528                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9529                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9530                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9531                 .dac_nids = alc883_dac_nids,
9532                 .dig_out_nid = ALC883_DIGOUT_NID,
9533                 .dig_in_nid = ALC883_DIGIN_NID,
9534                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9535                 .channel_mode = alc883_3ST_2ch_modes,
9536                 .need_dac_fix = 1,
9537                 .input_mux = &alc883_asus_eee1601_capture_source,
9538                 .unsol_event = alc_sku_unsol_event,
9539                 .init_hook = alc883_eee1601_inithook,
9540         },
9541         [ALC1200_ASUS_P5Q] = {
9542                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9543                 .init_verbs = { alc883_init_verbs },
9544                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9545                 .dac_nids = alc883_dac_nids,
9546                 .dig_out_nid = ALC1200_DIGOUT_NID,
9547                 .dig_in_nid = ALC883_DIGIN_NID,
9548                 .slave_dig_outs = alc1200_slave_dig_outs,
9549                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9550                 .channel_mode = alc883_sixstack_modes,
9551                 .input_mux = &alc883_capture_source,
9552         },
9553         [ALC889A_MB31] = {
9554                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9555                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9556                         alc880_gpio1_init_verbs },
9557                 .adc_nids = alc883_adc_nids,
9558                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9559                 .dac_nids = alc883_dac_nids,
9560                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9561                 .channel_mode = alc889A_mb31_6ch_modes,
9562                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9563                 .input_mux = &alc889A_mb31_capture_source,
9564                 .dig_out_nid = ALC883_DIGOUT_NID,
9565                 .unsol_event = alc889A_mb31_unsol_event,
9566                 .init_hook = alc889A_mb31_automute,
9567         },
9568         [ALC883_SONY_VAIO_TT] = {
9569                 .mixers = { alc883_vaiott_mixer },
9570                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9571                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9572                 .dac_nids = alc883_dac_nids,
9573                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9574                 .channel_mode = alc883_3ST_2ch_modes,
9575                 .input_mux = &alc883_capture_source,
9576                 .unsol_event = alc_automute_amp_unsol_event,
9577                 .setup = alc883_vaiott_setup,
9578                 .init_hook = alc_automute_amp,
9579         },
9580 };
9581
9582
9583 /*
9584  * Pin config fixes
9585  */
9586 enum {
9587         PINFIX_ABIT_AW9D_MAX
9588 };
9589
9590 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
9591         { 0x15, 0x01080104 }, /* side */
9592         { 0x16, 0x01011012 }, /* rear */
9593         { 0x17, 0x01016011 }, /* clfe */
9594         { }
9595 };
9596
9597 static const struct alc_pincfg *alc882_pin_fixes[] = {
9598         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
9599 };
9600
9601 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
9602         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
9603         {}
9604 };
9605
9606 /*
9607  * BIOS auto configuration
9608  */
9609 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
9610                                                 const struct auto_pin_cfg *cfg)
9611 {
9612         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
9613 }
9614
9615 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9616                                               hda_nid_t nid, int pin_type,
9617                                               int dac_idx)
9618 {
9619         /* set as output */
9620         struct alc_spec *spec = codec->spec;
9621         int idx;
9622
9623         alc_set_pin_output(codec, nid, pin_type);
9624         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9625                 idx = 4;
9626         else
9627                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9628         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9629
9630 }
9631
9632 static void alc882_auto_init_multi_out(struct hda_codec *codec)
9633 {
9634         struct alc_spec *spec = codec->spec;
9635         int i;
9636
9637         for (i = 0; i <= HDA_SIDE; i++) {
9638                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9639                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9640                 if (nid)
9641                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9642                                                           i);
9643         }
9644 }
9645
9646 static void alc882_auto_init_hp_out(struct hda_codec *codec)
9647 {
9648         struct alc_spec *spec = codec->spec;
9649         hda_nid_t pin;
9650
9651         pin = spec->autocfg.hp_pins[0];
9652         if (pin) /* connect to front */
9653                 /* use dac 0 */
9654                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9655         pin = spec->autocfg.speaker_pins[0];
9656         if (pin)
9657                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9658 }
9659
9660 static void alc882_auto_init_analog_input(struct hda_codec *codec)
9661 {
9662         struct alc_spec *spec = codec->spec;
9663         int i;
9664
9665         for (i = 0; i < AUTO_PIN_LAST; i++) {
9666                 hda_nid_t nid = spec->autocfg.input_pins[i];
9667                 if (!nid)
9668                         continue;
9669                 alc_set_input_pin(codec, nid, i);
9670                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
9671                         snd_hda_codec_write(codec, nid, 0,
9672                                             AC_VERB_SET_AMP_GAIN_MUTE,
9673                                             AMP_OUT_MUTE);
9674         }
9675 }
9676
9677 static void alc882_auto_init_input_src(struct hda_codec *codec)
9678 {
9679         struct alc_spec *spec = codec->spec;
9680         int c;
9681
9682         for (c = 0; c < spec->num_adc_nids; c++) {
9683                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
9684                 hda_nid_t nid = spec->capsrc_nids[c];
9685                 unsigned int mux_idx;
9686                 const struct hda_input_mux *imux;
9687                 int conns, mute, idx, item;
9688
9689                 conns = snd_hda_get_connections(codec, nid, conn_list,
9690                                                 ARRAY_SIZE(conn_list));
9691                 if (conns < 0)
9692                         continue;
9693                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9694                 imux = &spec->input_mux[mux_idx];
9695                 for (idx = 0; idx < conns; idx++) {
9696                         /* if the current connection is the selected one,
9697                          * unmute it as default - otherwise mute it
9698                          */
9699                         mute = AMP_IN_MUTE(idx);
9700                         for (item = 0; item < imux->num_items; item++) {
9701                                 if (imux->items[item].index == idx) {
9702                                         if (spec->cur_mux[c] == item)
9703                                                 mute = AMP_IN_UNMUTE(idx);
9704                                         break;
9705                                 }
9706                         }
9707                         /* check if we have a selector or mixer
9708                          * we could check for the widget type instead, but
9709                          * just check for Amp-In presence (in case of mixer
9710                          * without amp-in there is something wrong, this
9711                          * function shouldn't be used or capsrc nid is wrong)
9712                          */
9713                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
9714                                 snd_hda_codec_write(codec, nid, 0,
9715                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9716                                                     mute);
9717                         else if (mute != AMP_IN_MUTE(idx))
9718                                 snd_hda_codec_write(codec, nid, 0,
9719                                                     AC_VERB_SET_CONNECT_SEL,
9720                                                     idx);
9721                 }
9722         }
9723 }
9724
9725 /* add mic boosts if needed */
9726 static int alc_auto_add_mic_boost(struct hda_codec *codec)
9727 {
9728         struct alc_spec *spec = codec->spec;
9729         int err;
9730         hda_nid_t nid;
9731
9732         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
9733         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9734                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9735                                   "Mic Boost",
9736                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9737                 if (err < 0)
9738                         return err;
9739         }
9740         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
9741         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9742                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9743                                   "Front Mic Boost",
9744                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9745                 if (err < 0)
9746                         return err;
9747         }
9748         return 0;
9749 }
9750
9751 /* almost identical with ALC880 parser... */
9752 static int alc882_parse_auto_config(struct hda_codec *codec)
9753 {
9754         struct alc_spec *spec = codec->spec;
9755         static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9756         int i, err;
9757
9758         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9759                                            alc882_ignore);
9760         if (err < 0)
9761                 return err;
9762         if (!spec->autocfg.line_outs)
9763                 return 0; /* can't find valid BIOS pin config */
9764
9765         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
9766         if (err < 0)
9767                 return err;
9768         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
9769         if (err < 0)
9770                 return err;
9771         err = alc880_auto_create_extra_out(spec,
9772                                            spec->autocfg.speaker_pins[0],
9773                                            "Speaker");
9774         if (err < 0)
9775                 return err;
9776         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
9777                                            "Headphone");
9778         if (err < 0)
9779                 return err;
9780         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
9781         if (err < 0)
9782                 return err;
9783
9784         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9785
9786         /* check multiple SPDIF-out (for recent codecs) */
9787         for (i = 0; i < spec->autocfg.dig_outs; i++) {
9788                 hda_nid_t dig_nid;
9789                 err = snd_hda_get_connections(codec,
9790                                               spec->autocfg.dig_out_pins[i],
9791                                               &dig_nid, 1);
9792                 if (err < 0)
9793                         continue;
9794                 if (!i)
9795                         spec->multiout.dig_out_nid = dig_nid;
9796                 else {
9797                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9798                         spec->slave_dig_outs[i - 1] = dig_nid;
9799                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
9800                                 break;
9801                 }
9802         }
9803         if (spec->autocfg.dig_in_pin)
9804                 spec->dig_in_nid = ALC880_DIGIN_NID;
9805
9806         if (spec->kctls.list)
9807                 add_mixer(spec, spec->kctls.list);
9808
9809         add_verb(spec, alc883_auto_init_verbs);
9810         /* if ADC 0x07 is available, initialize it, too */
9811         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
9812                 add_verb(spec, alc882_adc1_init_verbs);
9813
9814         spec->num_mux_defs = 1;
9815         spec->input_mux = &spec->private_imux[0];
9816
9817         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
9818
9819         err = alc_auto_add_mic_boost(codec);
9820         if (err < 0)
9821                 return err;
9822
9823         return 1; /* config found */
9824 }
9825
9826 /* additional initialization for auto-configuration model */
9827 static void alc882_auto_init(struct hda_codec *codec)
9828 {
9829         struct alc_spec *spec = codec->spec;
9830         alc882_auto_init_multi_out(codec);
9831         alc882_auto_init_hp_out(codec);
9832         alc882_auto_init_analog_input(codec);
9833         alc882_auto_init_input_src(codec);
9834         if (spec->unsol_event)
9835                 alc_inithook(codec);
9836 }
9837
9838 static int patch_alc882(struct hda_codec *codec)
9839 {
9840         struct alc_spec *spec;
9841         int err, board_config;
9842
9843         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9844         if (spec == NULL)
9845                 return -ENOMEM;
9846
9847         codec->spec = spec;
9848
9849         switch (codec->vendor_id) {
9850         case 0x10ec0882:
9851         case 0x10ec0885:
9852                 break;
9853         default:
9854                 /* ALC883 and variants */
9855                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9856                 break;
9857         }
9858
9859         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9860                                                   alc882_models,
9861                                                   alc882_cfg_tbl);
9862
9863         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9864                 board_config = snd_hda_check_board_codec_sid_config(codec,
9865                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9866
9867         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9868                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9869                        codec->chip_name);
9870                 board_config = ALC882_AUTO;
9871         }
9872
9873         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
9874
9875         if (board_config == ALC882_AUTO) {
9876                 /* automatic parse from the BIOS config */
9877                 err = alc882_parse_auto_config(codec);
9878                 if (err < 0) {
9879                         alc_free(codec);
9880                         return err;
9881                 } else if (!err) {
9882                         printk(KERN_INFO
9883                                "hda_codec: Cannot set up configuration "
9884                                "from BIOS.  Using base mode...\n");
9885                         board_config = ALC882_3ST_DIG;
9886                 }
9887         }
9888
9889         err = snd_hda_attach_beep_device(codec, 0x1);
9890         if (err < 0) {
9891                 alc_free(codec);
9892                 return err;
9893         }
9894
9895         if (board_config != ALC882_AUTO)
9896                 setup_preset(codec, &alc882_presets[board_config]);
9897
9898         spec->stream_analog_playback = &alc882_pcm_analog_playback;
9899         spec->stream_analog_capture = &alc882_pcm_analog_capture;
9900         /* FIXME: setup DAC5 */
9901         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9902         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9903
9904         spec->stream_digital_playback = &alc882_pcm_digital_playback;
9905         spec->stream_digital_capture = &alc882_pcm_digital_capture;
9906
9907         if (codec->vendor_id == 0x10ec0888)
9908                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9909
9910         if (!spec->adc_nids && spec->input_mux) {
9911                 int i;
9912                 spec->num_adc_nids = 0;
9913                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9914                         hda_nid_t cap;
9915                         hda_nid_t nid = alc882_adc_nids[i];
9916                         unsigned int wcap = get_wcaps(codec, nid);
9917                         /* get type */
9918                         wcap = get_wcaps_type(wcap);
9919                         if (wcap != AC_WID_AUD_IN)
9920                                 continue;
9921                         spec->private_adc_nids[spec->num_adc_nids] = nid;
9922                         err = snd_hda_get_connections(codec, nid, &cap, 1);
9923                         if (err < 0)
9924                                 continue;
9925                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9926                         spec->num_adc_nids++;
9927                 }
9928                 spec->adc_nids = spec->private_adc_nids;
9929                 spec->capsrc_nids = spec->private_capsrc_nids;
9930         }
9931
9932         set_capture_mixer(codec);
9933         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9934
9935         spec->vmaster_nid = 0x0c;
9936
9937         codec->patch_ops = alc_patch_ops;
9938         if (board_config == ALC882_AUTO)
9939                 spec->init_hook = alc882_auto_init;
9940 #ifdef CONFIG_SND_HDA_POWER_SAVE
9941         if (!spec->loopback.amplist)
9942                 spec->loopback.amplist = alc882_loopbacks;
9943 #endif
9944         codec->proc_widget_hook = print_realtek_coef;
9945
9946         return 0;
9947 }
9948
9949
9950 /*
9951  * ALC262 support
9952  */
9953
9954 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9955 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9956
9957 #define alc262_dac_nids         alc260_dac_nids
9958 #define alc262_adc_nids         alc882_adc_nids
9959 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9960 #define alc262_capsrc_nids      alc882_capsrc_nids
9961 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9962
9963 #define alc262_modes            alc260_modes
9964 #define alc262_capture_source   alc882_capture_source
9965
9966 static hda_nid_t alc262_dmic_adc_nids[1] = {
9967         /* ADC0 */
9968         0x09
9969 };
9970
9971 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9972
9973 static struct snd_kcontrol_new alc262_base_mixer[] = {
9974         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9975         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9976         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9977         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9978         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9979         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9980         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9981         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9982         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9983         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9984         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9985         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9986         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9987         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9988         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9989         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9990         { } /* end */
9991 };
9992
9993 /* update HP, line and mono-out pins according to the master switch */
9994 static void alc262_hp_master_update(struct hda_codec *codec)
9995 {
9996         struct alc_spec *spec = codec->spec;
9997         int val = spec->master_sw;
9998
9999         /* HP & line-out */
10000         snd_hda_codec_write_cache(codec, 0x1b, 0,
10001                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10002                                   val ? PIN_HP : 0);
10003         snd_hda_codec_write_cache(codec, 0x15, 0,
10004                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10005                                   val ? PIN_HP : 0);
10006         /* mono (speaker) depending on the HP jack sense */
10007         val = val && !spec->jack_present;
10008         snd_hda_codec_write_cache(codec, 0x16, 0,
10009                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10010                                   val ? PIN_OUT : 0);
10011 }
10012
10013 static void alc262_hp_bpc_automute(struct hda_codec *codec)
10014 {
10015         struct alc_spec *spec = codec->spec;
10016         unsigned int presence;
10017         presence = snd_hda_codec_read(codec, 0x1b, 0,
10018                                       AC_VERB_GET_PIN_SENSE, 0);
10019         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10020         alc262_hp_master_update(codec);
10021 }
10022
10023 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10024 {
10025         if ((res >> 26) != ALC880_HP_EVENT)
10026                 return;
10027         alc262_hp_bpc_automute(codec);
10028 }
10029
10030 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10031 {
10032         struct alc_spec *spec = codec->spec;
10033         unsigned int presence;
10034         presence = snd_hda_codec_read(codec, 0x15, 0,
10035                                       AC_VERB_GET_PIN_SENSE, 0);
10036         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10037         alc262_hp_master_update(codec);
10038 }
10039
10040 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
10041                                            unsigned int res)
10042 {
10043         if ((res >> 26) != ALC880_HP_EVENT)
10044                 return;
10045         alc262_hp_wildwest_automute(codec);
10046 }
10047
10048 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
10049
10050 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
10051                                    struct snd_ctl_elem_value *ucontrol)
10052 {
10053         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10054         struct alc_spec *spec = codec->spec;
10055         int val = !!*ucontrol->value.integer.value;
10056
10057         if (val == spec->master_sw)
10058                 return 0;
10059         spec->master_sw = val;
10060         alc262_hp_master_update(codec);
10061         return 1;
10062 }
10063
10064 #define ALC262_HP_MASTER_SWITCH                                 \
10065         {                                                       \
10066                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10067                 .name = "Master Playback Switch",               \
10068                 .info = snd_ctl_boolean_mono_info,              \
10069                 .get = alc262_hp_master_sw_get,                 \
10070                 .put = alc262_hp_master_sw_put,                 \
10071         }
10072
10073 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10074         ALC262_HP_MASTER_SWITCH,
10075         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10076         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10077         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10078         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10079                               HDA_OUTPUT),
10080         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10081                             HDA_OUTPUT),
10082         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10083         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10084         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10085         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10086         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10087         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10088         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10089         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10090         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10091         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10092         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
10093         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
10094         { } /* end */
10095 };
10096
10097 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10098         ALC262_HP_MASTER_SWITCH,
10099         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10100         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10101         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10102         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10103         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10104                               HDA_OUTPUT),
10105         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10106                             HDA_OUTPUT),
10107         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10108         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10109         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10110         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10111         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10112         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10113         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10114         { } /* end */
10115 };
10116
10117 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10118         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10119         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10120         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10121         { } /* end */
10122 };
10123
10124 /* mute/unmute internal speaker according to the hp jack and mute state */
10125 static void alc262_hp_t5735_setup(struct hda_codec *codec)
10126 {
10127         struct alc_spec *spec = codec->spec;
10128
10129         spec->autocfg.hp_pins[0] = 0x15;
10130         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10131 }
10132
10133 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10134         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10135         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10136         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10137         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10138         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10139         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10140         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10141         { } /* end */
10142 };
10143
10144 static struct hda_verb alc262_hp_t5735_verbs[] = {
10145         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10146         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10147
10148         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10149         { }
10150 };
10151
10152 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10153         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10154         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10155         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10156         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10157         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10158         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10159         { } /* end */
10160 };
10161
10162 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10163         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10164         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10165         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10166         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10167         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10168         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10169         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10170         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10171         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10172         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10173         {}
10174 };
10175
10176 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10177         .num_items = 1,
10178         .items = {
10179                 { "Line", 0x1 },
10180         },
10181 };
10182
10183 /* bind hp and internal speaker mute (with plug check) as master switch */
10184 static void alc262_hippo_master_update(struct hda_codec *codec)
10185 {
10186         struct alc_spec *spec = codec->spec;
10187         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10188         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10189         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10190         unsigned int mute;
10191
10192         /* HP */
10193         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10194         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10195                                  HDA_AMP_MUTE, mute);
10196         /* mute internal speaker per jack sense */
10197         if (spec->jack_present)
10198                 mute = HDA_AMP_MUTE;
10199         if (line_nid)
10200                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10201                                          HDA_AMP_MUTE, mute);
10202         if (speaker_nid && speaker_nid != line_nid)
10203                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10204                                          HDA_AMP_MUTE, mute);
10205 }
10206
10207 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10208
10209 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10210                                       struct snd_ctl_elem_value *ucontrol)
10211 {
10212         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10213         struct alc_spec *spec = codec->spec;
10214         int val = !!*ucontrol->value.integer.value;
10215
10216         if (val == spec->master_sw)
10217                 return 0;
10218         spec->master_sw = val;
10219         alc262_hippo_master_update(codec);
10220         return 1;
10221 }
10222
10223 #define ALC262_HIPPO_MASTER_SWITCH                              \
10224         {                                                       \
10225                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10226                 .name = "Master Playback Switch",               \
10227                 .info = snd_ctl_boolean_mono_info,              \
10228                 .get = alc262_hippo_master_sw_get,              \
10229                 .put = alc262_hippo_master_sw_put,              \
10230         }
10231
10232 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10233         ALC262_HIPPO_MASTER_SWITCH,
10234         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10235         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10236         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10237         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10238         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10239         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10240         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10241         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10242         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10243         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10244         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10245         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10246         { } /* end */
10247 };
10248
10249 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10250         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10251         ALC262_HIPPO_MASTER_SWITCH,
10252         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10253         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10254         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10255         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10256         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10257         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10258         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10259         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10260         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10261         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10262         { } /* end */
10263 };
10264
10265 /* mute/unmute internal speaker according to the hp jack and mute state */
10266 static void alc262_hippo_automute(struct hda_codec *codec)
10267 {
10268         struct alc_spec *spec = codec->spec;
10269         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10270         unsigned int present;
10271
10272         /* need to execute and sync at first */
10273         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10274         present = snd_hda_codec_read(codec, hp_nid, 0,
10275                                      AC_VERB_GET_PIN_SENSE, 0);
10276         spec->jack_present = (present & 0x80000000) != 0;
10277         alc262_hippo_master_update(codec);
10278 }
10279
10280 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10281 {
10282         if ((res >> 26) != ALC880_HP_EVENT)
10283                 return;
10284         alc262_hippo_automute(codec);
10285 }
10286
10287 static void alc262_hippo_setup(struct hda_codec *codec)
10288 {
10289         struct alc_spec *spec = codec->spec;
10290
10291         spec->autocfg.hp_pins[0] = 0x15;
10292         spec->autocfg.speaker_pins[0] = 0x14;
10293 }
10294
10295 static void alc262_hippo1_setup(struct hda_codec *codec)
10296 {
10297         struct alc_spec *spec = codec->spec;
10298
10299         spec->autocfg.hp_pins[0] = 0x1b;
10300         spec->autocfg.speaker_pins[0] = 0x14;
10301 }
10302
10303
10304 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10305         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10306         ALC262_HIPPO_MASTER_SWITCH,
10307         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10308         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10309         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10310         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10311         { } /* end */
10312 };
10313
10314 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10315         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10316         ALC262_HIPPO_MASTER_SWITCH,
10317         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10318         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10319         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10320         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10321         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10322         { } /* end */
10323 };
10324
10325 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10326         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10327         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10328         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10329         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10330         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10331         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10332         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10333         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10334         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10335         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10336         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10337         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10338         { } /* end */
10339 };
10340
10341 static struct hda_verb alc262_tyan_verbs[] = {
10342         /* Headphone automute */
10343         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10344         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10345         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10346
10347         /* P11 AUX_IN, white 4-pin connector */
10348         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10349         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10350         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10351         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10352
10353         {}
10354 };
10355
10356 /* unsolicited event for HP jack sensing */
10357 static void alc262_tyan_setup(struct hda_codec *codec)
10358 {
10359         struct alc_spec *spec = codec->spec;
10360
10361         spec->autocfg.hp_pins[0] = 0x1b;
10362         spec->autocfg.speaker_pins[0] = 0x15;
10363 }
10364
10365
10366 #define alc262_capture_mixer            alc882_capture_mixer
10367 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10368
10369 /*
10370  * generic initialization of ADC, input mixers and output mixers
10371  */
10372 static struct hda_verb alc262_init_verbs[] = {
10373         /*
10374          * Unmute ADC0-2 and set the default input to mic-in
10375          */
10376         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10377         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10378         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10379         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10380         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10381         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10382
10383         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10384          * mixer widget
10385          * Note: PASD motherboards uses the Line In 2 as the input for
10386          * front panel mic (mic 2)
10387          */
10388         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10389         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10390         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10391         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10392         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10393         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10394
10395         /*
10396          * Set up output mixers (0x0c - 0x0e)
10397          */
10398         /* set vol=0 to output mixers */
10399         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10400         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10401         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10402         /* set up input amps for analog loopback */
10403         /* Amp Indices: DAC = 0, mixer = 1 */
10404         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10405         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10406         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10407         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10408         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10409         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10410
10411         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10412         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10413         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10414         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10415         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10416         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10417
10418         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10419         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10420         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10421         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10422         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10423
10424         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10425         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10426
10427         /* FIXME: use matrix-type input source selection */
10428         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10429         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10430         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10431         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10432         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10433         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10434         /* Input mixer2 */
10435         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10436         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10437         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10438         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10439         /* Input mixer3 */
10440         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10441         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10442         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10443         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10444
10445         { }
10446 };
10447
10448 static struct hda_verb alc262_eapd_verbs[] = {
10449         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10450         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10451         { }
10452 };
10453
10454 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10455         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10456         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10457         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10458
10459         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10460         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10461         {}
10462 };
10463
10464 static struct hda_verb alc262_sony_unsol_verbs[] = {
10465         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10466         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10467         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10468
10469         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10470         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10471         {}
10472 };
10473
10474 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10475         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10476         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10477         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10478         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10479         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10480         { } /* end */
10481 };
10482
10483 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10484         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10485         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10486         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10487         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10488         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10489         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10490         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10491         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10492         {}
10493 };
10494
10495 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10496 {
10497         struct alc_spec *spec = codec->spec;
10498
10499         spec->autocfg.hp_pins[0] = 0x15;
10500         spec->autocfg.speaker_pins[0] = 0x14;
10501         spec->ext_mic.pin = 0x18;
10502         spec->ext_mic.mux_idx = 0;
10503         spec->int_mic.pin = 0x12;
10504         spec->int_mic.mux_idx = 9;
10505         spec->auto_mic = 1;
10506 }
10507
10508 /*
10509  * nec model
10510  *  0x15 = headphone
10511  *  0x16 = internal speaker
10512  *  0x18 = external mic
10513  */
10514
10515 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10516         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10517         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10518
10519         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10520         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10521         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10522
10523         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10524         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10525         { } /* end */
10526 };
10527
10528 static struct hda_verb alc262_nec_verbs[] = {
10529         /* Unmute Speaker */
10530         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10531
10532         /* Headphone */
10533         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10534         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10535
10536         /* External mic to headphone */
10537         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10538         /* External mic to speaker */
10539         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10540         {}
10541 };
10542
10543 /*
10544  * fujitsu model
10545  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10546  *  0x1b = port replicator headphone out
10547  */
10548
10549 #define ALC_HP_EVENT    0x37
10550
10551 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10552         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10553         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10554         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10555         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10556         {}
10557 };
10558
10559 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10560         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10561         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10562         {}
10563 };
10564
10565 static struct hda_input_mux alc262_fujitsu_capture_source = {
10566         .num_items = 3,
10567         .items = {
10568                 { "Mic", 0x0 },
10569                 { "Int Mic", 0x1 },
10570                 { "CD", 0x4 },
10571         },
10572 };
10573
10574 static struct hda_input_mux alc262_HP_capture_source = {
10575         .num_items = 5,
10576         .items = {
10577                 { "Mic", 0x0 },
10578                 { "Front Mic", 0x1 },
10579                 { "Line", 0x2 },
10580                 { "CD", 0x4 },
10581                 { "AUX IN", 0x6 },
10582         },
10583 };
10584
10585 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10586         .num_items = 4,
10587         .items = {
10588                 { "Mic", 0x0 },
10589                 { "Front Mic", 0x2 },
10590                 { "Line", 0x1 },
10591                 { "CD", 0x4 },
10592         },
10593 };
10594
10595 /* mute/unmute internal speaker according to the hp jacks and mute state */
10596 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10597 {
10598         struct alc_spec *spec = codec->spec;
10599         unsigned int mute;
10600
10601         if (force || !spec->sense_updated) {
10602                 unsigned int present;
10603                 /* need to execute and sync at first */
10604                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10605                 /* check laptop HP jack */
10606                 present = snd_hda_codec_read(codec, 0x14, 0,
10607                                              AC_VERB_GET_PIN_SENSE, 0);
10608                 /* need to execute and sync at first */
10609                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10610                 /* check docking HP jack */
10611                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10612                                               AC_VERB_GET_PIN_SENSE, 0);
10613                 if (present & AC_PINSENSE_PRESENCE)
10614                         spec->jack_present = 1;
10615                 else
10616                         spec->jack_present = 0;
10617                 spec->sense_updated = 1;
10618         }
10619         /* unmute internal speaker only if both HPs are unplugged and
10620          * master switch is on
10621          */
10622         if (spec->jack_present)
10623                 mute = HDA_AMP_MUTE;
10624         else
10625                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10626         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10627                                  HDA_AMP_MUTE, mute);
10628 }
10629
10630 /* unsolicited event for HP jack sensing */
10631 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10632                                        unsigned int res)
10633 {
10634         if ((res >> 26) != ALC_HP_EVENT)
10635                 return;
10636         alc262_fujitsu_automute(codec, 1);
10637 }
10638
10639 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10640 {
10641         alc262_fujitsu_automute(codec, 1);
10642 }
10643
10644 /* bind volumes of both NID 0x0c and 0x0d */
10645 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10646         .ops = &snd_hda_bind_vol,
10647         .values = {
10648                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10649                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10650                 0
10651         },
10652 };
10653
10654 /* mute/unmute internal speaker according to the hp jack and mute state */
10655 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10656 {
10657         struct alc_spec *spec = codec->spec;
10658         unsigned int mute;
10659
10660         if (force || !spec->sense_updated) {
10661                 unsigned int present_int_hp;
10662                 /* need to execute and sync at first */
10663                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10664                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10665                                         AC_VERB_GET_PIN_SENSE, 0);
10666                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10667                 spec->sense_updated = 1;
10668         }
10669         if (spec->jack_present) {
10670                 /* mute internal speaker */
10671                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10672                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10673                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10674                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10675         } else {
10676                 /* unmute internal speaker if necessary */
10677                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10678                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10679                                          HDA_AMP_MUTE, mute);
10680                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10681                                          HDA_AMP_MUTE, mute);
10682         }
10683 }
10684
10685 /* unsolicited event for HP jack sensing */
10686 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10687                                        unsigned int res)
10688 {
10689         if ((res >> 26) != ALC_HP_EVENT)
10690                 return;
10691         alc262_lenovo_3000_automute(codec, 1);
10692 }
10693
10694 static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
10695                                   int dir, int idx, long *valp)
10696 {
10697         int i, change = 0;
10698
10699         for (i = 0; i < 2; i++, valp++)
10700                 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
10701                                                    HDA_AMP_MUTE,
10702                                                    *valp ? 0 : HDA_AMP_MUTE);
10703         return change;
10704 }
10705
10706 /* bind hp and internal speaker mute (with plug check) */
10707 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10708                                          struct snd_ctl_elem_value *ucontrol)
10709 {
10710         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10711         long *valp = ucontrol->value.integer.value;
10712         int change;
10713
10714         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10715         change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10716         if (change)
10717                 alc262_fujitsu_automute(codec, 0);
10718         return change;
10719 }
10720
10721 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10722         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10723         {
10724                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10725                 .name = "Master Playback Switch",
10726                 .info = snd_hda_mixer_amp_switch_info,
10727                 .get = snd_hda_mixer_amp_switch_get,
10728                 .put = alc262_fujitsu_master_sw_put,
10729                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10730         },
10731         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10732         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10733         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10734         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10735         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10736         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10737         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10738         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10739         { } /* end */
10740 };
10741
10742 /* bind hp and internal speaker mute (with plug check) */
10743 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10744                                          struct snd_ctl_elem_value *ucontrol)
10745 {
10746         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10747         long *valp = ucontrol->value.integer.value;
10748         int change;
10749
10750         change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10751         if (change)
10752                 alc262_lenovo_3000_automute(codec, 0);
10753         return change;
10754 }
10755
10756 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10757         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10758         {
10759                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10760                 .name = "Master Playback Switch",
10761                 .info = snd_hda_mixer_amp_switch_info,
10762                 .get = snd_hda_mixer_amp_switch_get,
10763                 .put = alc262_lenovo_3000_master_sw_put,
10764                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10765         },
10766         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10767         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10768         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10769         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10770         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10771         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10772         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10773         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10774         { } /* end */
10775 };
10776
10777 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10778         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10779         ALC262_HIPPO_MASTER_SWITCH,
10780         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10781         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10782         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10783         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10784         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10785         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10786         { } /* end */
10787 };
10788
10789 /* additional init verbs for Benq laptops */
10790 static struct hda_verb alc262_EAPD_verbs[] = {
10791         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10792         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10793         {}
10794 };
10795
10796 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10797         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10798         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10799
10800         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10801         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10802         {}
10803 };
10804
10805 /* Samsung Q1 Ultra Vista model setup */
10806 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10807         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10808         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10809         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10810         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10811         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10812         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10813         { } /* end */
10814 };
10815
10816 static struct hda_verb alc262_ultra_verbs[] = {
10817         /* output mixer */
10818         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10819         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10820         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10821         /* speaker */
10822         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10823         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10824         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10825         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10826         /* HP */
10827         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10828         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10829         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10830         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10831         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10832         /* internal mic */
10833         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10834         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10835         /* ADC, choose mic */
10836         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10837         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10838         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10839         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10840         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10841         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10842         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10843         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10844         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10845         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10846         {}
10847 };
10848
10849 /* mute/unmute internal speaker according to the hp jack and mute state */
10850 static void alc262_ultra_automute(struct hda_codec *codec)
10851 {
10852         struct alc_spec *spec = codec->spec;
10853         unsigned int mute;
10854
10855         mute = 0;
10856         /* auto-mute only when HP is used as HP */
10857         if (!spec->cur_mux[0]) {
10858                 unsigned int present;
10859                 /* need to execute and sync at first */
10860                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10861                 present = snd_hda_codec_read(codec, 0x15, 0,
10862                                              AC_VERB_GET_PIN_SENSE, 0);
10863                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10864                 if (spec->jack_present)
10865                         mute = HDA_AMP_MUTE;
10866         }
10867         /* mute/unmute internal speaker */
10868         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10869                                  HDA_AMP_MUTE, mute);
10870         /* mute/unmute HP */
10871         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10872                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10873 }
10874
10875 /* unsolicited event for HP jack sensing */
10876 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10877                                        unsigned int res)
10878 {
10879         if ((res >> 26) != ALC880_HP_EVENT)
10880                 return;
10881         alc262_ultra_automute(codec);
10882 }
10883
10884 static struct hda_input_mux alc262_ultra_capture_source = {
10885         .num_items = 2,
10886         .items = {
10887                 { "Mic", 0x1 },
10888                 { "Headphone", 0x7 },
10889         },
10890 };
10891
10892 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10893                                      struct snd_ctl_elem_value *ucontrol)
10894 {
10895         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10896         struct alc_spec *spec = codec->spec;
10897         int ret;
10898
10899         ret = alc_mux_enum_put(kcontrol, ucontrol);
10900         if (!ret)
10901                 return 0;
10902         /* reprogram the HP pin as mic or HP according to the input source */
10903         snd_hda_codec_write_cache(codec, 0x15, 0,
10904                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10905                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10906         alc262_ultra_automute(codec); /* mute/unmute HP */
10907         return ret;
10908 }
10909
10910 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10911         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10912         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10913         {
10914                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10915                 .name = "Capture Source",
10916                 .info = alc_mux_enum_info,
10917                 .get = alc_mux_enum_get,
10918                 .put = alc262_ultra_mux_enum_put,
10919         },
10920         { } /* end */
10921 };
10922
10923 /* We use two mixers depending on the output pin; 0x16 is a mono output
10924  * and thus it's bound with a different mixer.
10925  * This function returns which mixer amp should be used.
10926  */
10927 static int alc262_check_volbit(hda_nid_t nid)
10928 {
10929         if (!nid)
10930                 return 0;
10931         else if (nid == 0x16)
10932                 return 2;
10933         else
10934                 return 1;
10935 }
10936
10937 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10938                                   const char *pfx, int *vbits)
10939 {
10940         unsigned long val;
10941         int vbit;
10942
10943         vbit = alc262_check_volbit(nid);
10944         if (!vbit)
10945                 return 0;
10946         if (*vbits & vbit) /* a volume control for this mixer already there */
10947                 return 0;
10948         *vbits |= vbit;
10949         if (vbit == 2)
10950                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10951         else
10952                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10953         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10954 }
10955
10956 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10957                                  const char *pfx)
10958 {
10959         unsigned long val;
10960
10961         if (!nid)
10962                 return 0;
10963         if (nid == 0x16)
10964                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10965         else
10966                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10967         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10968 }
10969
10970 /* add playback controls from the parsed DAC table */
10971 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10972                                              const struct auto_pin_cfg *cfg)
10973 {
10974         const char *pfx;
10975         int vbits;
10976         int err;
10977
10978         spec->multiout.num_dacs = 1;    /* only use one dac */
10979         spec->multiout.dac_nids = spec->private_dac_nids;
10980         spec->multiout.dac_nids[0] = 2;
10981
10982         if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
10983                 pfx = "Master";
10984         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
10985                 pfx = "Speaker";
10986         else
10987                 pfx = "Front";
10988         err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
10989         if (err < 0)
10990                 return err;
10991         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
10992         if (err < 0)
10993                 return err;
10994         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
10995         if (err < 0)
10996                 return err;
10997
10998         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
10999                 alc262_check_volbit(cfg->speaker_pins[0]) |
11000                 alc262_check_volbit(cfg->hp_pins[0]);
11001         if (vbits == 1 || vbits == 2)
11002                 pfx = "Master"; /* only one mixer is used */
11003         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11004                 pfx = "Speaker";
11005         else
11006                 pfx = "Front";
11007         vbits = 0;
11008         err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
11009         if (err < 0)
11010                 return err;
11011         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
11012                                      &vbits);
11013         if (err < 0)
11014                 return err;
11015         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
11016                                      &vbits);
11017         if (err < 0)
11018                 return err;
11019         return 0;
11020 }
11021
11022 #define alc262_auto_create_input_ctls \
11023         alc880_auto_create_input_ctls
11024
11025 /*
11026  * generic initialization of ADC, input mixers and output mixers
11027  */
11028 static struct hda_verb alc262_volume_init_verbs[] = {
11029         /*
11030          * Unmute ADC0-2 and set the default input to mic-in
11031          */
11032         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11034         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11035         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11036         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11037         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11038
11039         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11040          * mixer widget
11041          * Note: PASD motherboards uses the Line In 2 as the input for
11042          * front panel mic (mic 2)
11043          */
11044         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11045         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11046         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11047         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11048         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11049         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11050
11051         /*
11052          * Set up output mixers (0x0c - 0x0f)
11053          */
11054         /* set vol=0 to output mixers */
11055         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11056         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11057         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11058
11059         /* set up input amps for analog loopback */
11060         /* Amp Indices: DAC = 0, mixer = 1 */
11061         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11062         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11063         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11064         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11065         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11066         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11067
11068         /* FIXME: use matrix-type input source selection */
11069         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11070         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11071         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11072         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11073         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11074         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11075         /* Input mixer2 */
11076         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11077         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11078         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11079         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11080         /* Input mixer3 */
11081         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11082         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11083         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11084         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11085
11086         { }
11087 };
11088
11089 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11090         /*
11091          * Unmute ADC0-2 and set the default input to mic-in
11092          */
11093         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11094         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11095         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11096         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11097         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11098         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11099
11100         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11101          * mixer widget
11102          * Note: PASD motherboards uses the Line In 2 as the input for
11103          * front panel mic (mic 2)
11104          */
11105         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11106         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11107         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11108         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11109         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11110         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11111         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11112         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11113
11114         /*
11115          * Set up output mixers (0x0c - 0x0e)
11116          */
11117         /* set vol=0 to output mixers */
11118         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11119         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11120         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11121
11122         /* set up input amps for analog loopback */
11123         /* Amp Indices: DAC = 0, mixer = 1 */
11124         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11125         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11126         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11127         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11128         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11129         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11130
11131         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11132         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11133         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11134
11135         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11136         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11137
11138         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11139         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11140
11141         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11142         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11143         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11144         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11145         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11146
11147         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11148         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11149         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11150         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11151         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11152         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11153
11154
11155         /* FIXME: use matrix-type input source selection */
11156         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11157         /* Input mixer1: only unmute Mic */
11158         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11159         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11160         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11161         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11162         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11163         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11164         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11165         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11166         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11167         /* Input mixer2 */
11168         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11169         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11170         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11171         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11172         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11173         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11174         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11175         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11176         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11177         /* Input mixer3 */
11178         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11179         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11180         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11181         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11182         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11183         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11184         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11185         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11186         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11187
11188         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11189
11190         { }
11191 };
11192
11193 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11194         /*
11195          * Unmute ADC0-2 and set the default input to mic-in
11196          */
11197         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11198         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11199         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11200         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11201         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11202         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11203
11204         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11205          * mixer widget
11206          * Note: PASD motherboards uses the Line In 2 as the input for front
11207          * panel mic (mic 2)
11208          */
11209         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11210         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11211         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11212         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11214         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11215         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11216         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11217         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11218         /*
11219          * Set up output mixers (0x0c - 0x0e)
11220          */
11221         /* set vol=0 to output mixers */
11222         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11223         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11224         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11225
11226         /* set up input amps for analog loopback */
11227         /* Amp Indices: DAC = 0, mixer = 1 */
11228         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11229         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11230         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11231         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11232         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11233         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11234
11235
11236         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11237         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11238         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11239         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11240         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11241         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11242         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11243
11244         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11245         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11246
11247         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11248         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11249
11250         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11251         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11252         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11253         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11254         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11255         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11256
11257         /* FIXME: use matrix-type input source selection */
11258         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11259         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11260         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11261         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11262         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11263         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11264         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11265         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11266         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11267         /* Input mixer2 */
11268         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11269         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11270         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11271         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11272         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11273         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11274         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11275         /* Input mixer3 */
11276         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11277         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11278         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11279         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11280         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11281         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11282         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11283
11284         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11285
11286         { }
11287 };
11288
11289 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11290
11291         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11292         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11293         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11294
11295         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11296         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11297         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11298         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11299
11300         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11301         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11302         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11303         {}
11304 };
11305
11306
11307 #ifdef CONFIG_SND_HDA_POWER_SAVE
11308 #define alc262_loopbacks        alc880_loopbacks
11309 #endif
11310
11311 /* pcm configuration: identical with ALC880 */
11312 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11313 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11314 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11315 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11316
11317 /*
11318  * BIOS auto configuration
11319  */
11320 static int alc262_parse_auto_config(struct hda_codec *codec)
11321 {
11322         struct alc_spec *spec = codec->spec;
11323         int err;
11324         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11325
11326         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11327                                            alc262_ignore);
11328         if (err < 0)
11329                 return err;
11330         if (!spec->autocfg.line_outs) {
11331                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11332                         spec->multiout.max_channels = 2;
11333                         spec->no_analog = 1;
11334                         goto dig_only;
11335                 }
11336                 return 0; /* can't find valid BIOS pin config */
11337         }
11338         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11339         if (err < 0)
11340                 return err;
11341         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11342         if (err < 0)
11343                 return err;
11344
11345         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11346
11347  dig_only:
11348         if (spec->autocfg.dig_outs) {
11349                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11350                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11351         }
11352         if (spec->autocfg.dig_in_pin)
11353                 spec->dig_in_nid = ALC262_DIGIN_NID;
11354
11355         if (spec->kctls.list)
11356                 add_mixer(spec, spec->kctls.list);
11357
11358         add_verb(spec, alc262_volume_init_verbs);
11359         spec->num_mux_defs = 1;
11360         spec->input_mux = &spec->private_imux[0];
11361
11362         err = alc_auto_add_mic_boost(codec);
11363         if (err < 0)
11364                 return err;
11365
11366         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11367
11368         return 1;
11369 }
11370
11371 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11372 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11373 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11374 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11375
11376
11377 /* init callback for auto-configuration model -- overriding the default init */
11378 static void alc262_auto_init(struct hda_codec *codec)
11379 {
11380         struct alc_spec *spec = codec->spec;
11381         alc262_auto_init_multi_out(codec);
11382         alc262_auto_init_hp_out(codec);
11383         alc262_auto_init_analog_input(codec);
11384         alc262_auto_init_input_src(codec);
11385         if (spec->unsol_event)
11386                 alc_inithook(codec);
11387 }
11388
11389 /*
11390  * configuration and preset
11391  */
11392 static const char *alc262_models[ALC262_MODEL_LAST] = {
11393         [ALC262_BASIC]          = "basic",
11394         [ALC262_HIPPO]          = "hippo",
11395         [ALC262_HIPPO_1]        = "hippo_1",
11396         [ALC262_FUJITSU]        = "fujitsu",
11397         [ALC262_HP_BPC]         = "hp-bpc",
11398         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11399         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11400         [ALC262_HP_RP5700]      = "hp-rp5700",
11401         [ALC262_BENQ_ED8]       = "benq",
11402         [ALC262_BENQ_T31]       = "benq-t31",
11403         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11404         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11405         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11406         [ALC262_ULTRA]          = "ultra",
11407         [ALC262_LENOVO_3000]    = "lenovo-3000",
11408         [ALC262_NEC]            = "nec",
11409         [ALC262_TYAN]           = "tyan",
11410         [ALC262_AUTO]           = "auto",
11411 };
11412
11413 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11414         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11415         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11416         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11417                            ALC262_HP_BPC),
11418         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11419                            ALC262_HP_BPC),
11420         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11421                            ALC262_HP_BPC),
11422         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11423         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11424         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11425         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11426         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11427         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11428         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11429         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11430         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11431         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11432         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11433         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11434                       ALC262_HP_TC_T5735),
11435         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11436         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11437         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11438         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11439         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11440         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11441         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11442                            ALC262_SONY_ASSAMD),
11443         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11444                       ALC262_TOSHIBA_RX1),
11445         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11446         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11447         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11448         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11449         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11450                            ALC262_ULTRA),
11451         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11452         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11453         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11454         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11455         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11456         {}
11457 };
11458
11459 static struct alc_config_preset alc262_presets[] = {
11460         [ALC262_BASIC] = {
11461                 .mixers = { alc262_base_mixer },
11462                 .init_verbs = { alc262_init_verbs },
11463                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11464                 .dac_nids = alc262_dac_nids,
11465                 .hp_nid = 0x03,
11466                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11467                 .channel_mode = alc262_modes,
11468                 .input_mux = &alc262_capture_source,
11469         },
11470         [ALC262_HIPPO] = {
11471                 .mixers = { alc262_hippo_mixer },
11472                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11473                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11474                 .dac_nids = alc262_dac_nids,
11475                 .hp_nid = 0x03,
11476                 .dig_out_nid = ALC262_DIGOUT_NID,
11477                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11478                 .channel_mode = alc262_modes,
11479                 .input_mux = &alc262_capture_source,
11480                 .unsol_event = alc262_hippo_unsol_event,
11481                 .setup = alc262_hippo_setup,
11482                 .init_hook = alc262_hippo_automute,
11483         },
11484         [ALC262_HIPPO_1] = {
11485                 .mixers = { alc262_hippo1_mixer },
11486                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11487                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11488                 .dac_nids = alc262_dac_nids,
11489                 .hp_nid = 0x02,
11490                 .dig_out_nid = ALC262_DIGOUT_NID,
11491                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11492                 .channel_mode = alc262_modes,
11493                 .input_mux = &alc262_capture_source,
11494                 .unsol_event = alc262_hippo_unsol_event,
11495                 .setup = alc262_hippo1_setup,
11496                 .init_hook = alc262_hippo_automute,
11497         },
11498         [ALC262_FUJITSU] = {
11499                 .mixers = { alc262_fujitsu_mixer },
11500                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11501                                 alc262_fujitsu_unsol_verbs },
11502                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11503                 .dac_nids = alc262_dac_nids,
11504                 .hp_nid = 0x03,
11505                 .dig_out_nid = ALC262_DIGOUT_NID,
11506                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11507                 .channel_mode = alc262_modes,
11508                 .input_mux = &alc262_fujitsu_capture_source,
11509                 .unsol_event = alc262_fujitsu_unsol_event,
11510                 .init_hook = alc262_fujitsu_init_hook,
11511         },
11512         [ALC262_HP_BPC] = {
11513                 .mixers = { alc262_HP_BPC_mixer },
11514                 .init_verbs = { alc262_HP_BPC_init_verbs },
11515                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11516                 .dac_nids = alc262_dac_nids,
11517                 .hp_nid = 0x03,
11518                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11519                 .channel_mode = alc262_modes,
11520                 .input_mux = &alc262_HP_capture_source,
11521                 .unsol_event = alc262_hp_bpc_unsol_event,
11522                 .init_hook = alc262_hp_bpc_automute,
11523         },
11524         [ALC262_HP_BPC_D7000_WF] = {
11525                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11526                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11527                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11528                 .dac_nids = alc262_dac_nids,
11529                 .hp_nid = 0x03,
11530                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11531                 .channel_mode = alc262_modes,
11532                 .input_mux = &alc262_HP_D7000_capture_source,
11533                 .unsol_event = alc262_hp_wildwest_unsol_event,
11534                 .init_hook = alc262_hp_wildwest_automute,
11535         },
11536         [ALC262_HP_BPC_D7000_WL] = {
11537                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11538                             alc262_HP_BPC_WildWest_option_mixer },
11539                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11540                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11541                 .dac_nids = alc262_dac_nids,
11542                 .hp_nid = 0x03,
11543                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11544                 .channel_mode = alc262_modes,
11545                 .input_mux = &alc262_HP_D7000_capture_source,
11546                 .unsol_event = alc262_hp_wildwest_unsol_event,
11547                 .init_hook = alc262_hp_wildwest_automute,
11548         },
11549         [ALC262_HP_TC_T5735] = {
11550                 .mixers = { alc262_hp_t5735_mixer },
11551                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11552                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11553                 .dac_nids = alc262_dac_nids,
11554                 .hp_nid = 0x03,
11555                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11556                 .channel_mode = alc262_modes,
11557                 .input_mux = &alc262_capture_source,
11558                 .unsol_event = alc_automute_amp_unsol_event,
11559                 .setup = alc262_hp_t5735_setup,
11560                 .init_hook = alc_automute_amp,
11561         },
11562         [ALC262_HP_RP5700] = {
11563                 .mixers = { alc262_hp_rp5700_mixer },
11564                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11565                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11566                 .dac_nids = alc262_dac_nids,
11567                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11568                 .channel_mode = alc262_modes,
11569                 .input_mux = &alc262_hp_rp5700_capture_source,
11570         },
11571         [ALC262_BENQ_ED8] = {
11572                 .mixers = { alc262_base_mixer },
11573                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11574                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11575                 .dac_nids = alc262_dac_nids,
11576                 .hp_nid = 0x03,
11577                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11578                 .channel_mode = alc262_modes,
11579                 .input_mux = &alc262_capture_source,
11580         },
11581         [ALC262_SONY_ASSAMD] = {
11582                 .mixers = { alc262_sony_mixer },
11583                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11584                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11585                 .dac_nids = alc262_dac_nids,
11586                 .hp_nid = 0x02,
11587                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11588                 .channel_mode = alc262_modes,
11589                 .input_mux = &alc262_capture_source,
11590                 .unsol_event = alc262_hippo_unsol_event,
11591                 .setup = alc262_hippo_setup,
11592                 .init_hook = alc262_hippo_automute,
11593         },
11594         [ALC262_BENQ_T31] = {
11595                 .mixers = { alc262_benq_t31_mixer },
11596                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
11597                                 alc_hp15_unsol_verbs },
11598                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11599                 .dac_nids = alc262_dac_nids,
11600                 .hp_nid = 0x03,
11601                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11602                 .channel_mode = alc262_modes,
11603                 .input_mux = &alc262_capture_source,
11604                 .unsol_event = alc262_hippo_unsol_event,
11605                 .setup = alc262_hippo_setup,
11606                 .init_hook = alc262_hippo_automute,
11607         },
11608         [ALC262_ULTRA] = {
11609                 .mixers = { alc262_ultra_mixer },
11610                 .cap_mixer = alc262_ultra_capture_mixer,
11611                 .init_verbs = { alc262_ultra_verbs },
11612                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11613                 .dac_nids = alc262_dac_nids,
11614                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11615                 .channel_mode = alc262_modes,
11616                 .input_mux = &alc262_ultra_capture_source,
11617                 .adc_nids = alc262_adc_nids, /* ADC0 */
11618                 .capsrc_nids = alc262_capsrc_nids,
11619                 .num_adc_nids = 1, /* single ADC */
11620                 .unsol_event = alc262_ultra_unsol_event,
11621                 .init_hook = alc262_ultra_automute,
11622         },
11623         [ALC262_LENOVO_3000] = {
11624                 .mixers = { alc262_lenovo_3000_mixer },
11625                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11626                                 alc262_lenovo_3000_unsol_verbs },
11627                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11628                 .dac_nids = alc262_dac_nids,
11629                 .hp_nid = 0x03,
11630                 .dig_out_nid = ALC262_DIGOUT_NID,
11631                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11632                 .channel_mode = alc262_modes,
11633                 .input_mux = &alc262_fujitsu_capture_source,
11634                 .unsol_event = alc262_lenovo_3000_unsol_event,
11635         },
11636         [ALC262_NEC] = {
11637                 .mixers = { alc262_nec_mixer },
11638                 .init_verbs = { alc262_nec_verbs },
11639                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11640                 .dac_nids = alc262_dac_nids,
11641                 .hp_nid = 0x03,
11642                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11643                 .channel_mode = alc262_modes,
11644                 .input_mux = &alc262_capture_source,
11645         },
11646         [ALC262_TOSHIBA_S06] = {
11647                 .mixers = { alc262_toshiba_s06_mixer },
11648                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11649                                                         alc262_eapd_verbs },
11650                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11651                 .capsrc_nids = alc262_dmic_capsrc_nids,
11652                 .dac_nids = alc262_dac_nids,
11653                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11654                 .num_adc_nids = 1, /* single ADC */
11655                 .dig_out_nid = ALC262_DIGOUT_NID,
11656                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11657                 .channel_mode = alc262_modes,
11658                 .unsol_event = alc_sku_unsol_event,
11659                 .setup = alc262_toshiba_s06_setup,
11660                 .init_hook = alc_inithook,
11661         },
11662         [ALC262_TOSHIBA_RX1] = {
11663                 .mixers = { alc262_toshiba_rx1_mixer },
11664                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11665                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11666                 .dac_nids = alc262_dac_nids,
11667                 .hp_nid = 0x03,
11668                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11669                 .channel_mode = alc262_modes,
11670                 .input_mux = &alc262_capture_source,
11671                 .unsol_event = alc262_hippo_unsol_event,
11672                 .setup = alc262_hippo_setup,
11673                 .init_hook = alc262_hippo_automute,
11674         },
11675         [ALC262_TYAN] = {
11676                 .mixers = { alc262_tyan_mixer },
11677                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11678                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11679                 .dac_nids = alc262_dac_nids,
11680                 .hp_nid = 0x02,
11681                 .dig_out_nid = ALC262_DIGOUT_NID,
11682                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11683                 .channel_mode = alc262_modes,
11684                 .input_mux = &alc262_capture_source,
11685                 .unsol_event = alc_automute_amp_unsol_event,
11686                 .setup = alc262_tyan_setup,
11687                 .init_hook = alc_automute_amp,
11688         },
11689 };
11690
11691 static int patch_alc262(struct hda_codec *codec)
11692 {
11693         struct alc_spec *spec;
11694         int board_config;
11695         int err;
11696
11697         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11698         if (spec == NULL)
11699                 return -ENOMEM;
11700
11701         codec->spec = spec;
11702 #if 0
11703         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11704          * under-run
11705          */
11706         {
11707         int tmp;
11708         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11709         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11710         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11711         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11712         }
11713 #endif
11714
11715         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11716
11717         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11718                                                   alc262_models,
11719                                                   alc262_cfg_tbl);
11720
11721         if (board_config < 0) {
11722                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11723                        codec->chip_name);
11724                 board_config = ALC262_AUTO;
11725         }
11726
11727         if (board_config == ALC262_AUTO) {
11728                 /* automatic parse from the BIOS config */
11729                 err = alc262_parse_auto_config(codec);
11730                 if (err < 0) {
11731                         alc_free(codec);
11732                         return err;
11733                 } else if (!err) {
11734                         printk(KERN_INFO
11735                                "hda_codec: Cannot set up configuration "
11736                                "from BIOS.  Using base mode...\n");
11737                         board_config = ALC262_BASIC;
11738                 }
11739         }
11740
11741         if (!spec->no_analog) {
11742                 err = snd_hda_attach_beep_device(codec, 0x1);
11743                 if (err < 0) {
11744                         alc_free(codec);
11745                         return err;
11746                 }
11747         }
11748
11749         if (board_config != ALC262_AUTO)
11750                 setup_preset(codec, &alc262_presets[board_config]);
11751
11752         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11753         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11754
11755         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11756         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11757
11758         if (!spec->adc_nids && spec->input_mux) {
11759                 int i;
11760                 /* check whether the digital-mic has to be supported */
11761                 for (i = 0; i < spec->input_mux->num_items; i++) {
11762                         if (spec->input_mux->items[i].index >= 9)
11763                                 break;
11764                 }
11765                 if (i < spec->input_mux->num_items) {
11766                         /* use only ADC0 */
11767                         spec->adc_nids = alc262_dmic_adc_nids;
11768                         spec->num_adc_nids = 1;
11769                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11770                 } else {
11771                         /* all analog inputs */
11772                         /* check whether NID 0x07 is valid */
11773                         unsigned int wcap = get_wcaps(codec, 0x07);
11774
11775                         /* get type */
11776                         wcap = get_wcaps_type(wcap);
11777                         if (wcap != AC_WID_AUD_IN) {
11778                                 spec->adc_nids = alc262_adc_nids_alt;
11779                                 spec->num_adc_nids =
11780                                         ARRAY_SIZE(alc262_adc_nids_alt);
11781                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11782                         } else {
11783                                 spec->adc_nids = alc262_adc_nids;
11784                                 spec->num_adc_nids =
11785                                         ARRAY_SIZE(alc262_adc_nids);
11786                                 spec->capsrc_nids = alc262_capsrc_nids;
11787                         }
11788                 }
11789         }
11790         if (!spec->cap_mixer && !spec->no_analog)
11791                 set_capture_mixer(codec);
11792         if (!spec->no_analog)
11793                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11794
11795         spec->vmaster_nid = 0x0c;
11796
11797         codec->patch_ops = alc_patch_ops;
11798         if (board_config == ALC262_AUTO)
11799                 spec->init_hook = alc262_auto_init;
11800 #ifdef CONFIG_SND_HDA_POWER_SAVE
11801         if (!spec->loopback.amplist)
11802                 spec->loopback.amplist = alc262_loopbacks;
11803 #endif
11804         codec->proc_widget_hook = print_realtek_coef;
11805
11806         return 0;
11807 }
11808
11809 /*
11810  *  ALC268 channel source setting (2 channel)
11811  */
11812 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11813 #define alc268_modes            alc260_modes
11814
11815 static hda_nid_t alc268_dac_nids[2] = {
11816         /* front, hp */
11817         0x02, 0x03
11818 };
11819
11820 static hda_nid_t alc268_adc_nids[2] = {
11821         /* ADC0-1 */
11822         0x08, 0x07
11823 };
11824
11825 static hda_nid_t alc268_adc_nids_alt[1] = {
11826         /* ADC0 */
11827         0x08
11828 };
11829
11830 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11831
11832 static struct snd_kcontrol_new alc268_base_mixer[] = {
11833         /* output mixer control */
11834         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11835         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11836         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11837         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11838         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11839         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11840         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11841         { }
11842 };
11843
11844 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11845         /* output mixer control */
11846         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11847         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11848         ALC262_HIPPO_MASTER_SWITCH,
11849         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11850         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11851         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11852         { }
11853 };
11854
11855 /* bind Beep switches of both NID 0x0f and 0x10 */
11856 static struct hda_bind_ctls alc268_bind_beep_sw = {
11857         .ops = &snd_hda_bind_sw,
11858         .values = {
11859                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11860                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11861                 0
11862         },
11863 };
11864
11865 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11866         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11867         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11868         { }
11869 };
11870
11871 static struct hda_verb alc268_eapd_verbs[] = {
11872         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11873         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11874         { }
11875 };
11876
11877 /* Toshiba specific */
11878 static struct hda_verb alc268_toshiba_verbs[] = {
11879         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11880         { } /* end */
11881 };
11882
11883 /* Acer specific */
11884 /* bind volumes of both NID 0x02 and 0x03 */
11885 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11886         .ops = &snd_hda_bind_vol,
11887         .values = {
11888                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11889                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11890                 0
11891         },
11892 };
11893
11894 /* mute/unmute internal speaker according to the hp jack and mute state */
11895 static void alc268_acer_automute(struct hda_codec *codec, int force)
11896 {
11897         struct alc_spec *spec = codec->spec;
11898         unsigned int mute;
11899
11900         if (force || !spec->sense_updated) {
11901                 unsigned int present;
11902                 present = snd_hda_codec_read(codec, 0x14, 0,
11903                                          AC_VERB_GET_PIN_SENSE, 0);
11904                 spec->jack_present = (present & 0x80000000) != 0;
11905                 spec->sense_updated = 1;
11906         }
11907         if (spec->jack_present)
11908                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11909         else /* unmute internal speaker if necessary */
11910                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11911         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11912                                  HDA_AMP_MUTE, mute);
11913 }
11914
11915
11916 /* bind hp and internal speaker mute (with plug check) */
11917 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11918                                      struct snd_ctl_elem_value *ucontrol)
11919 {
11920         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11921         long *valp = ucontrol->value.integer.value;
11922         int change;
11923
11924         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11925         if (change)
11926                 alc268_acer_automute(codec, 0);
11927         return change;
11928 }
11929
11930 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11931         /* output mixer control */
11932         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11933         {
11934                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11935                 .name = "Master Playback Switch",
11936                 .info = snd_hda_mixer_amp_switch_info,
11937                 .get = snd_hda_mixer_amp_switch_get,
11938                 .put = alc268_acer_master_sw_put,
11939                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11940         },
11941         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11942         { }
11943 };
11944
11945 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11946         /* output mixer control */
11947         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11948         {
11949                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11950                 .name = "Master Playback Switch",
11951                 .info = snd_hda_mixer_amp_switch_info,
11952                 .get = snd_hda_mixer_amp_switch_get,
11953                 .put = alc268_acer_master_sw_put,
11954                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11955         },
11956         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11957         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11958         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11959         { }
11960 };
11961
11962 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11963         /* output mixer control */
11964         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11965         {
11966                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11967                 .name = "Master Playback Switch",
11968                 .info = snd_hda_mixer_amp_switch_info,
11969                 .get = snd_hda_mixer_amp_switch_get,
11970                 .put = alc268_acer_master_sw_put,
11971                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11972         },
11973         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11974         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11975         { }
11976 };
11977
11978 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11979         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11980         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11981         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11982         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11983         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11984         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11985         { }
11986 };
11987
11988 static struct hda_verb alc268_acer_verbs[] = {
11989         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11990         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11991         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11992         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11993         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11994         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11995         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11996         { }
11997 };
11998
11999 /* unsolicited event for HP jack sensing */
12000 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
12001 #define alc268_toshiba_setup            alc262_hippo_setup
12002 #define alc268_toshiba_automute         alc262_hippo_automute
12003
12004 static void alc268_acer_unsol_event(struct hda_codec *codec,
12005                                        unsigned int res)
12006 {
12007         if ((res >> 26) != ALC880_HP_EVENT)
12008                 return;
12009         alc268_acer_automute(codec, 1);
12010 }
12011
12012 static void alc268_acer_init_hook(struct hda_codec *codec)
12013 {
12014         alc268_acer_automute(codec, 1);
12015 }
12016
12017 /* toggle speaker-output according to the hp-jack state */
12018 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12019 {
12020         unsigned int present;
12021         unsigned char bits;
12022
12023         present = snd_hda_codec_read(codec, 0x15, 0,
12024                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12025         bits = present ? AMP_IN_MUTE(0) : 0;
12026         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12027                                 AMP_IN_MUTE(0), bits);
12028         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12029                                 AMP_IN_MUTE(0), bits);
12030 }
12031
12032 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
12033                                     unsigned int res)
12034 {
12035         switch (res >> 26) {
12036         case ALC880_HP_EVENT:
12037                 alc268_aspire_one_speaker_automute(codec);
12038                 break;
12039         case ALC880_MIC_EVENT:
12040                 alc_mic_automute(codec);
12041                 break;
12042         }
12043 }
12044
12045 static void alc268_acer_lc_setup(struct hda_codec *codec)
12046 {
12047         struct alc_spec *spec = codec->spec;
12048         spec->ext_mic.pin = 0x18;
12049         spec->ext_mic.mux_idx = 0;
12050         spec->int_mic.pin = 0x12;
12051         spec->int_mic.mux_idx = 6;
12052         spec->auto_mic = 1;
12053 }
12054
12055 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
12056 {
12057         alc268_aspire_one_speaker_automute(codec);
12058         alc_mic_automute(codec);
12059 }
12060
12061 static struct snd_kcontrol_new alc268_dell_mixer[] = {
12062         /* output mixer control */
12063         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12064         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12065         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12066         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12067         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12068         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12069         { }
12070 };
12071
12072 static struct hda_verb alc268_dell_verbs[] = {
12073         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12074         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12075         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12076         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12077         { }
12078 };
12079
12080 /* mute/unmute internal speaker according to the hp jack and mute state */
12081 static void alc268_dell_setup(struct hda_codec *codec)
12082 {
12083         struct alc_spec *spec = codec->spec;
12084
12085         spec->autocfg.hp_pins[0] = 0x15;
12086         spec->autocfg.speaker_pins[0] = 0x14;
12087         spec->ext_mic.pin = 0x18;
12088         spec->ext_mic.mux_idx = 0;
12089         spec->int_mic.pin = 0x19;
12090         spec->int_mic.mux_idx = 1;
12091         spec->auto_mic = 1;
12092 }
12093
12094 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12095         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12096         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12097         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12098         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12099         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12100         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12101         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12102         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12103         { }
12104 };
12105
12106 static struct hda_verb alc267_quanta_il1_verbs[] = {
12107         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12108         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12109         { }
12110 };
12111
12112 static void alc267_quanta_il1_setup(struct hda_codec *codec)
12113 {
12114         struct alc_spec *spec = codec->spec;
12115         spec->autocfg.hp_pins[0] = 0x15;
12116         spec->autocfg.speaker_pins[0] = 0x14;
12117         spec->ext_mic.pin = 0x18;
12118         spec->ext_mic.mux_idx = 0;
12119         spec->int_mic.pin = 0x19;
12120         spec->int_mic.mux_idx = 1;
12121         spec->auto_mic = 1;
12122 }
12123
12124 /*
12125  * generic initialization of ADC, input mixers and output mixers
12126  */
12127 static struct hda_verb alc268_base_init_verbs[] = {
12128         /* Unmute DAC0-1 and set vol = 0 */
12129         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12130         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12131
12132         /*
12133          * Set up output mixers (0x0c - 0x0e)
12134          */
12135         /* set vol=0 to output mixers */
12136         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12137         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12138
12139         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12140         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12141
12142         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12143         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12144         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12145         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12146         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12147         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12148         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12149         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12150
12151         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12152         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12153         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12154         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12155         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12156
12157         /* set PCBEEP vol = 0, mute connections */
12158         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12159         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12160         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12161
12162         /* Unmute Selector 23h,24h and set the default input to mic-in */
12163
12164         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12165         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12166         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12167         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12168
12169         { }
12170 };
12171
12172 /*
12173  * generic initialization of ADC, input mixers and output mixers
12174  */
12175 static struct hda_verb alc268_volume_init_verbs[] = {
12176         /* set output DAC */
12177         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12178         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12179
12180         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12181         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12182         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12183         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12184         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12185
12186         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12187         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12188         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12189
12190         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12191         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12192
12193         /* set PCBEEP vol = 0, mute connections */
12194         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12195         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12196         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12197
12198         { }
12199 };
12200
12201 static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
12202         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12203         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12204         { } /* end */
12205 };
12206
12207 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12208         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12209         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12210         _DEFINE_CAPSRC(1),
12211         { } /* end */
12212 };
12213
12214 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12215         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12216         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12217         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12218         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12219         _DEFINE_CAPSRC(2),
12220         { } /* end */
12221 };
12222
12223 static struct hda_input_mux alc268_capture_source = {
12224         .num_items = 4,
12225         .items = {
12226                 { "Mic", 0x0 },
12227                 { "Front Mic", 0x1 },
12228                 { "Line", 0x2 },
12229                 { "CD", 0x3 },
12230         },
12231 };
12232
12233 static struct hda_input_mux alc268_acer_capture_source = {
12234         .num_items = 3,
12235         .items = {
12236                 { "Mic", 0x0 },
12237                 { "Internal Mic", 0x1 },
12238                 { "Line", 0x2 },
12239         },
12240 };
12241
12242 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12243         .num_items = 3,
12244         .items = {
12245                 { "Mic", 0x0 },
12246                 { "Internal Mic", 0x6 },
12247                 { "Line", 0x2 },
12248         },
12249 };
12250
12251 #ifdef CONFIG_SND_DEBUG
12252 static struct snd_kcontrol_new alc268_test_mixer[] = {
12253         /* Volume widgets */
12254         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12255         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12256         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12257         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12258         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12259         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12260         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12261         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12262         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12263         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12264         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12265         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12266         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12267         /* The below appears problematic on some hardwares */
12268         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12269         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12270         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12271         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12272         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12273
12274         /* Modes for retasking pin widgets */
12275         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12276         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12277         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12278         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12279
12280         /* Controls for GPIO pins, assuming they are configured as outputs */
12281         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12282         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12283         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12284         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12285
12286         /* Switches to allow the digital SPDIF output pin to be enabled.
12287          * The ALC268 does not have an SPDIF input.
12288          */
12289         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12290
12291         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12292          * this output to turn on an external amplifier.
12293          */
12294         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12295         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12296
12297         { } /* end */
12298 };
12299 #endif
12300
12301 /* create input playback/capture controls for the given pin */
12302 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12303                                     const char *ctlname, int idx)
12304 {
12305         hda_nid_t dac;
12306         int err;
12307
12308         switch (nid) {
12309         case 0x14:
12310         case 0x16:
12311                 dac = 0x02;
12312                 break;
12313         case 0x15:
12314                 dac = 0x03;
12315                 break;
12316         default:
12317                 return 0;
12318         }
12319         if (spec->multiout.dac_nids[0] != dac &&
12320             spec->multiout.dac_nids[1] != dac) {
12321                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12322                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12323                                                       HDA_OUTPUT));
12324                 if (err < 0)
12325                         return err;
12326                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12327         }
12328
12329         if (nid != 0x16)
12330                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12331                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12332         else /* mono */
12333                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12334                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12335         if (err < 0)
12336                 return err;
12337         return 0;
12338 }
12339
12340 /* add playback controls from the parsed DAC table */
12341 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12342                                              const struct auto_pin_cfg *cfg)
12343 {
12344         hda_nid_t nid;
12345         int err;
12346
12347         spec->multiout.dac_nids = spec->private_dac_nids;
12348
12349         nid = cfg->line_out_pins[0];
12350         if (nid) {
12351                 const char *name;
12352                 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12353                         name = "Speaker";
12354                 else
12355                         name = "Front";
12356                 err = alc268_new_analog_output(spec, nid, name, 0);
12357                 if (err < 0)
12358                         return err;
12359         }
12360
12361         nid = cfg->speaker_pins[0];
12362         if (nid == 0x1d) {
12363                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12364                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12365                 if (err < 0)
12366                         return err;
12367         } else {
12368                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12369                 if (err < 0)
12370                         return err;
12371         }
12372         nid = cfg->hp_pins[0];
12373         if (nid) {
12374                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
12375                 if (err < 0)
12376                         return err;
12377         }
12378
12379         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12380         if (nid == 0x16) {
12381                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12382                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12383                 if (err < 0)
12384                         return err;
12385         }
12386         return 0;
12387 }
12388
12389 /* create playback/capture controls for input pins */
12390 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12391                                                 const struct auto_pin_cfg *cfg)
12392 {
12393         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12394 }
12395
12396 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12397                                               hda_nid_t nid, int pin_type)
12398 {
12399         int idx;
12400
12401         alc_set_pin_output(codec, nid, pin_type);
12402         if (nid == 0x14 || nid == 0x16)
12403                 idx = 0;
12404         else
12405                 idx = 1;
12406         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12407 }
12408
12409 static void alc268_auto_init_multi_out(struct hda_codec *codec)
12410 {
12411         struct alc_spec *spec = codec->spec;
12412         hda_nid_t nid = spec->autocfg.line_out_pins[0];
12413         if (nid) {
12414                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12415                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12416         }
12417 }
12418
12419 static void alc268_auto_init_hp_out(struct hda_codec *codec)
12420 {
12421         struct alc_spec *spec = codec->spec;
12422         hda_nid_t pin;
12423
12424         pin = spec->autocfg.hp_pins[0];
12425         if (pin)
12426                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
12427         pin = spec->autocfg.speaker_pins[0];
12428         if (pin)
12429                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
12430 }
12431
12432 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12433 {
12434         struct alc_spec *spec = codec->spec;
12435         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12436         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12437         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12438         unsigned int    dac_vol1, dac_vol2;
12439
12440         if (line_nid == 0x1d || speaker_nid == 0x1d) {
12441                 snd_hda_codec_write(codec, speaker_nid, 0,
12442                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12443                 /* mute mixer inputs from 0x1d */
12444                 snd_hda_codec_write(codec, 0x0f, 0,
12445                                     AC_VERB_SET_AMP_GAIN_MUTE,
12446                                     AMP_IN_UNMUTE(1));
12447                 snd_hda_codec_write(codec, 0x10, 0,
12448                                     AC_VERB_SET_AMP_GAIN_MUTE,
12449                                     AMP_IN_UNMUTE(1));
12450         } else {
12451                 /* unmute mixer inputs from 0x1d */
12452                 snd_hda_codec_write(codec, 0x0f, 0,
12453                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12454                 snd_hda_codec_write(codec, 0x10, 0,
12455                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12456         }
12457
12458         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12459         if (line_nid == 0x14)
12460                 dac_vol2 = AMP_OUT_ZERO;
12461         else if (line_nid == 0x15)
12462                 dac_vol1 = AMP_OUT_ZERO;
12463         if (hp_nid == 0x14)
12464                 dac_vol2 = AMP_OUT_ZERO;
12465         else if (hp_nid == 0x15)
12466                 dac_vol1 = AMP_OUT_ZERO;
12467         if (line_nid != 0x16 || hp_nid != 0x16 ||
12468             spec->autocfg.line_out_pins[1] != 0x16 ||
12469             spec->autocfg.line_out_pins[2] != 0x16)
12470                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12471
12472         snd_hda_codec_write(codec, 0x02, 0,
12473                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12474         snd_hda_codec_write(codec, 0x03, 0,
12475                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12476 }
12477
12478 /* pcm configuration: identical with ALC880 */
12479 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12480 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12481 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12482 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12483
12484 /*
12485  * BIOS auto configuration
12486  */
12487 static int alc268_parse_auto_config(struct hda_codec *codec)
12488 {
12489         struct alc_spec *spec = codec->spec;
12490         int err;
12491         static hda_nid_t alc268_ignore[] = { 0 };
12492
12493         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12494                                            alc268_ignore);
12495         if (err < 0)
12496                 return err;
12497         if (!spec->autocfg.line_outs) {
12498                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12499                         spec->multiout.max_channels = 2;
12500                         spec->no_analog = 1;
12501                         goto dig_only;
12502                 }
12503                 return 0; /* can't find valid BIOS pin config */
12504         }
12505         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12506         if (err < 0)
12507                 return err;
12508         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12509         if (err < 0)
12510                 return err;
12511
12512         spec->multiout.max_channels = 2;
12513
12514  dig_only:
12515         /* digital only support output */
12516         if (spec->autocfg.dig_outs) {
12517                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12518                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12519         }
12520         if (spec->kctls.list)
12521                 add_mixer(spec, spec->kctls.list);
12522
12523         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12524                 add_mixer(spec, alc268_beep_mixer);
12525
12526         add_verb(spec, alc268_volume_init_verbs);
12527         spec->num_mux_defs = 2;
12528         spec->input_mux = &spec->private_imux[0];
12529
12530         err = alc_auto_add_mic_boost(codec);
12531         if (err < 0)
12532                 return err;
12533
12534         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12535
12536         return 1;
12537 }
12538
12539 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12540
12541 /* init callback for auto-configuration model -- overriding the default init */
12542 static void alc268_auto_init(struct hda_codec *codec)
12543 {
12544         struct alc_spec *spec = codec->spec;
12545         alc268_auto_init_multi_out(codec);
12546         alc268_auto_init_hp_out(codec);
12547         alc268_auto_init_mono_speaker_out(codec);
12548         alc268_auto_init_analog_input(codec);
12549         if (spec->unsol_event)
12550                 alc_inithook(codec);
12551 }
12552
12553 /*
12554  * configuration and preset
12555  */
12556 static const char *alc268_models[ALC268_MODEL_LAST] = {
12557         [ALC267_QUANTA_IL1]     = "quanta-il1",
12558         [ALC268_3ST]            = "3stack",
12559         [ALC268_TOSHIBA]        = "toshiba",
12560         [ALC268_ACER]           = "acer",
12561         [ALC268_ACER_DMIC]      = "acer-dmic",
12562         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12563         [ALC268_DELL]           = "dell",
12564         [ALC268_ZEPTO]          = "zepto",
12565 #ifdef CONFIG_SND_DEBUG
12566         [ALC268_TEST]           = "test",
12567 #endif
12568         [ALC268_AUTO]           = "auto",
12569 };
12570
12571 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12572         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12573         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12574         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12575         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12576         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12577         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12578                                                 ALC268_ACER_ASPIRE_ONE),
12579         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12580         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12581         /* almost compatible with toshiba but with optional digital outs;
12582          * auto-probing seems working fine
12583          */
12584         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12585                            ALC268_AUTO),
12586         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12587         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12588         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12589         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12590         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12591         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12592         {}
12593 };
12594
12595 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
12596 static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
12597         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
12598         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
12599         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12600                            ALC268_TOSHIBA),
12601         {}
12602 };
12603
12604 static struct alc_config_preset alc268_presets[] = {
12605         [ALC267_QUANTA_IL1] = {
12606                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12607                             alc268_capture_nosrc_mixer },
12608                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12609                                 alc267_quanta_il1_verbs },
12610                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12611                 .dac_nids = alc268_dac_nids,
12612                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12613                 .adc_nids = alc268_adc_nids_alt,
12614                 .hp_nid = 0x03,
12615                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12616                 .channel_mode = alc268_modes,
12617                 .unsol_event = alc_sku_unsol_event,
12618                 .setup = alc267_quanta_il1_setup,
12619                 .init_hook = alc_inithook,
12620         },
12621         [ALC268_3ST] = {
12622                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12623                             alc268_beep_mixer },
12624                 .init_verbs = { alc268_base_init_verbs },
12625                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12626                 .dac_nids = alc268_dac_nids,
12627                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12628                 .adc_nids = alc268_adc_nids_alt,
12629                 .capsrc_nids = alc268_capsrc_nids,
12630                 .hp_nid = 0x03,
12631                 .dig_out_nid = ALC268_DIGOUT_NID,
12632                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12633                 .channel_mode = alc268_modes,
12634                 .input_mux = &alc268_capture_source,
12635         },
12636         [ALC268_TOSHIBA] = {
12637                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12638                             alc268_beep_mixer },
12639                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12640                                 alc268_toshiba_verbs },
12641                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12642                 .dac_nids = alc268_dac_nids,
12643                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12644                 .adc_nids = alc268_adc_nids_alt,
12645                 .capsrc_nids = alc268_capsrc_nids,
12646                 .hp_nid = 0x03,
12647                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12648                 .channel_mode = alc268_modes,
12649                 .input_mux = &alc268_capture_source,
12650                 .unsol_event = alc268_toshiba_unsol_event,
12651                 .setup = alc268_toshiba_setup,
12652                 .init_hook = alc268_toshiba_automute,
12653         },
12654         [ALC268_ACER] = {
12655                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12656                             alc268_beep_mixer },
12657                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12658                                 alc268_acer_verbs },
12659                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12660                 .dac_nids = alc268_dac_nids,
12661                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12662                 .adc_nids = alc268_adc_nids_alt,
12663                 .capsrc_nids = alc268_capsrc_nids,
12664                 .hp_nid = 0x02,
12665                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12666                 .channel_mode = alc268_modes,
12667                 .input_mux = &alc268_acer_capture_source,
12668                 .unsol_event = alc268_acer_unsol_event,
12669                 .init_hook = alc268_acer_init_hook,
12670         },
12671         [ALC268_ACER_DMIC] = {
12672                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12673                             alc268_beep_mixer },
12674                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12675                                 alc268_acer_verbs },
12676                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12677                 .dac_nids = alc268_dac_nids,
12678                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12679                 .adc_nids = alc268_adc_nids_alt,
12680                 .capsrc_nids = alc268_capsrc_nids,
12681                 .hp_nid = 0x02,
12682                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12683                 .channel_mode = alc268_modes,
12684                 .input_mux = &alc268_acer_dmic_capture_source,
12685                 .unsol_event = alc268_acer_unsol_event,
12686                 .init_hook = alc268_acer_init_hook,
12687         },
12688         [ALC268_ACER_ASPIRE_ONE] = {
12689                 .mixers = { alc268_acer_aspire_one_mixer,
12690                             alc268_beep_mixer,
12691                             alc268_capture_nosrc_mixer },
12692                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12693                                 alc268_acer_aspire_one_verbs },
12694                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12695                 .dac_nids = alc268_dac_nids,
12696                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12697                 .adc_nids = alc268_adc_nids_alt,
12698                 .capsrc_nids = alc268_capsrc_nids,
12699                 .hp_nid = 0x03,
12700                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12701                 .channel_mode = alc268_modes,
12702                 .unsol_event = alc268_acer_lc_unsol_event,
12703                 .setup = alc268_acer_lc_setup,
12704                 .init_hook = alc268_acer_lc_init_hook,
12705         },
12706         [ALC268_DELL] = {
12707                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12708                             alc268_capture_nosrc_mixer },
12709                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12710                                 alc268_dell_verbs },
12711                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12712                 .dac_nids = alc268_dac_nids,
12713                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12714                 .adc_nids = alc268_adc_nids_alt,
12715                 .capsrc_nids = alc268_capsrc_nids,
12716                 .hp_nid = 0x02,
12717                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12718                 .channel_mode = alc268_modes,
12719                 .unsol_event = alc_sku_unsol_event,
12720                 .setup = alc268_dell_setup,
12721                 .init_hook = alc_inithook,
12722         },
12723         [ALC268_ZEPTO] = {
12724                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12725                             alc268_beep_mixer },
12726                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12727                                 alc268_toshiba_verbs },
12728                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12729                 .dac_nids = alc268_dac_nids,
12730                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12731                 .adc_nids = alc268_adc_nids_alt,
12732                 .capsrc_nids = alc268_capsrc_nids,
12733                 .hp_nid = 0x03,
12734                 .dig_out_nid = ALC268_DIGOUT_NID,
12735                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12736                 .channel_mode = alc268_modes,
12737                 .input_mux = &alc268_capture_source,
12738                 .setup = alc268_toshiba_setup,
12739                 .init_hook = alc268_toshiba_automute,
12740         },
12741 #ifdef CONFIG_SND_DEBUG
12742         [ALC268_TEST] = {
12743                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12744                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12745                                 alc268_volume_init_verbs },
12746                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12747                 .dac_nids = alc268_dac_nids,
12748                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12749                 .adc_nids = alc268_adc_nids_alt,
12750                 .capsrc_nids = alc268_capsrc_nids,
12751                 .hp_nid = 0x03,
12752                 .dig_out_nid = ALC268_DIGOUT_NID,
12753                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12754                 .channel_mode = alc268_modes,
12755                 .input_mux = &alc268_capture_source,
12756         },
12757 #endif
12758 };
12759
12760 static int patch_alc268(struct hda_codec *codec)
12761 {
12762         struct alc_spec *spec;
12763         int board_config;
12764         int i, has_beep, err;
12765
12766         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12767         if (spec == NULL)
12768                 return -ENOMEM;
12769
12770         codec->spec = spec;
12771
12772         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12773                                                   alc268_models,
12774                                                   alc268_cfg_tbl);
12775
12776         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12777                 board_config = snd_hda_check_board_codec_sid_config(codec,
12778                         ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12779
12780         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12781                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12782                        codec->chip_name);
12783                 board_config = ALC268_AUTO;
12784         }
12785
12786         if (board_config == ALC268_AUTO) {
12787                 /* automatic parse from the BIOS config */
12788                 err = alc268_parse_auto_config(codec);
12789                 if (err < 0) {
12790                         alc_free(codec);
12791                         return err;
12792                 } else if (!err) {
12793                         printk(KERN_INFO
12794                                "hda_codec: Cannot set up configuration "
12795                                "from BIOS.  Using base mode...\n");
12796                         board_config = ALC268_3ST;
12797                 }
12798         }
12799
12800         if (board_config != ALC268_AUTO)
12801                 setup_preset(codec, &alc268_presets[board_config]);
12802
12803         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12804         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12805         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12806
12807         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12808
12809         has_beep = 0;
12810         for (i = 0; i < spec->num_mixers; i++) {
12811                 if (spec->mixers[i] == alc268_beep_mixer) {
12812                         has_beep = 1;
12813                         break;
12814                 }
12815         }
12816
12817         if (has_beep) {
12818                 err = snd_hda_attach_beep_device(codec, 0x1);
12819                 if (err < 0) {
12820                         alc_free(codec);
12821                         return err;
12822                 }
12823                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12824                         /* override the amp caps for beep generator */
12825                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12826                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12827                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12828                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12829                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12830         }
12831
12832         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12833                 /* check whether NID 0x07 is valid */
12834                 unsigned int wcap = get_wcaps(codec, 0x07);
12835                 int i;
12836
12837                 /* get type */
12838                 wcap = get_wcaps_type(wcap);
12839                 if (spec->auto_mic ||
12840                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12841                         spec->adc_nids = alc268_adc_nids_alt;
12842                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12843                         if (spec->auto_mic || spec->input_mux->num_items == 1)
12844                                 add_mixer(spec, alc268_capture_nosrc_mixer);
12845                         else
12846                                 add_mixer(spec, alc268_capture_alt_mixer);
12847                 } else {
12848                         spec->adc_nids = alc268_adc_nids;
12849                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12850                         add_mixer(spec, alc268_capture_mixer);
12851                 }
12852                 spec->capsrc_nids = alc268_capsrc_nids;
12853                 /* set default input source */
12854                 for (i = 0; i < spec->num_adc_nids; i++)
12855                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12856                                 0, AC_VERB_SET_CONNECT_SEL,
12857                                 i < spec->num_mux_defs ?
12858                                 spec->input_mux[i].items[0].index :
12859                                 spec->input_mux->items[0].index);
12860         }
12861
12862         spec->vmaster_nid = 0x02;
12863
12864         codec->patch_ops = alc_patch_ops;
12865         if (board_config == ALC268_AUTO)
12866                 spec->init_hook = alc268_auto_init;
12867
12868         codec->proc_widget_hook = print_realtek_coef;
12869
12870         return 0;
12871 }
12872
12873 /*
12874  *  ALC269 channel source setting (2 channel)
12875  */
12876 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12877
12878 #define alc269_dac_nids         alc260_dac_nids
12879
12880 static hda_nid_t alc269_adc_nids[1] = {
12881         /* ADC1 */
12882         0x08,
12883 };
12884
12885 static hda_nid_t alc269_capsrc_nids[1] = {
12886         0x23,
12887 };
12888
12889 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12890  *       not a mux!
12891  */
12892
12893 #define alc269_modes            alc260_modes
12894 #define alc269_capture_source   alc880_lg_lw_capture_source
12895
12896 static struct snd_kcontrol_new alc269_base_mixer[] = {
12897         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12898         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12899         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12900         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12901         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12902         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12903         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12904         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12905         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12906         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12907         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12908         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12909         { } /* end */
12910 };
12911
12912 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12913         /* output mixer control */
12914         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12915         {
12916                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12917                 .name = "Master Playback Switch",
12918                 .info = snd_hda_mixer_amp_switch_info,
12919                 .get = snd_hda_mixer_amp_switch_get,
12920                 .put = alc268_acer_master_sw_put,
12921                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12922         },
12923         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12924         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12925         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12926         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12927         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12928         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12929         { }
12930 };
12931
12932 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12933         /* output mixer control */
12934         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12935         {
12936                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12937                 .name = "Master Playback Switch",
12938                 .info = snd_hda_mixer_amp_switch_info,
12939                 .get = snd_hda_mixer_amp_switch_get,
12940                 .put = alc268_acer_master_sw_put,
12941                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12942         },
12943         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12944         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12945         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12946         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12947         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12948         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12949         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12950         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12951         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12952         { }
12953 };
12954
12955 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12956         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12957         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12958         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12959         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12960         { } /* end */
12961 };
12962
12963 /* capture mixer elements */
12964 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12965         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12966         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12967         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12968         { } /* end */
12969 };
12970
12971 /* FSC amilo */
12972 #define alc269_fujitsu_mixer    alc269_eeepc_mixer
12973
12974 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12975         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12976         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12977         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12978         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12979         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12980         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12981         { }
12982 };
12983
12984 static struct hda_verb alc269_lifebook_verbs[] = {
12985         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12986         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12987         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12988         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12989         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12990         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12991         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12992         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12993         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12994         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12995         { }
12996 };
12997
12998 /* toggle speaker-output according to the hp-jack state */
12999 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13000 {
13001         unsigned int present;
13002         unsigned char bits;
13003
13004         present = snd_hda_codec_read(codec, 0x15, 0,
13005                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13006         bits = present ? AMP_IN_MUTE(0) : 0;
13007         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13008                         AMP_IN_MUTE(0), bits);
13009         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13010                         AMP_IN_MUTE(0), bits);
13011
13012         snd_hda_codec_write(codec, 0x20, 0,
13013                         AC_VERB_SET_COEF_INDEX, 0x0c);
13014         snd_hda_codec_write(codec, 0x20, 0,
13015                         AC_VERB_SET_PROC_COEF, 0x680);
13016
13017         snd_hda_codec_write(codec, 0x20, 0,
13018                         AC_VERB_SET_COEF_INDEX, 0x0c);
13019         snd_hda_codec_write(codec, 0x20, 0,
13020                         AC_VERB_SET_PROC_COEF, 0x480);
13021 }
13022
13023 /* toggle speaker-output according to the hp-jacks state */
13024 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13025 {
13026         unsigned int present;
13027         unsigned char bits;
13028
13029         /* Check laptop headphone socket */
13030         present = snd_hda_codec_read(codec, 0x15, 0,
13031                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13032
13033         /* Check port replicator headphone socket */
13034         present |= snd_hda_codec_read(codec, 0x1a, 0,
13035                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13036
13037         bits = present ? AMP_IN_MUTE(0) : 0;
13038         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13039                         AMP_IN_MUTE(0), bits);
13040         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13041                         AMP_IN_MUTE(0), bits);
13042
13043         snd_hda_codec_write(codec, 0x20, 0,
13044                         AC_VERB_SET_COEF_INDEX, 0x0c);
13045         snd_hda_codec_write(codec, 0x20, 0,
13046                         AC_VERB_SET_PROC_COEF, 0x680);
13047
13048         snd_hda_codec_write(codec, 0x20, 0,
13049                         AC_VERB_SET_COEF_INDEX, 0x0c);
13050         snd_hda_codec_write(codec, 0x20, 0,
13051                         AC_VERB_SET_PROC_COEF, 0x480);
13052 }
13053
13054 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13055 {
13056         unsigned int present_laptop;
13057         unsigned int present_dock;
13058
13059         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13060                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13061
13062         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13063                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13064
13065         /* Laptop mic port overrides dock mic port, design decision */
13066         if (present_dock)
13067                 snd_hda_codec_write(codec, 0x23, 0,
13068                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13069         if (present_laptop)
13070                 snd_hda_codec_write(codec, 0x23, 0,
13071                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13072         if (!present_dock && !present_laptop)
13073                 snd_hda_codec_write(codec, 0x23, 0,
13074                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13075 }
13076
13077 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13078                                     unsigned int res)
13079 {
13080         switch (res >> 26) {
13081         case ALC880_HP_EVENT:
13082                 alc269_quanta_fl1_speaker_automute(codec);
13083                 break;
13084         case ALC880_MIC_EVENT:
13085                 alc_mic_automute(codec);
13086                 break;
13087         }
13088 }
13089
13090 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13091                                         unsigned int res)
13092 {
13093         if ((res >> 26) == ALC880_HP_EVENT)
13094                 alc269_lifebook_speaker_automute(codec);
13095         if ((res >> 26) == ALC880_MIC_EVENT)
13096                 alc269_lifebook_mic_autoswitch(codec);
13097 }
13098
13099 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13100 {
13101         struct alc_spec *spec = codec->spec;
13102         spec->ext_mic.pin = 0x18;
13103         spec->ext_mic.mux_idx = 0;
13104         spec->int_mic.pin = 0x19;
13105         spec->int_mic.mux_idx = 1;
13106         spec->auto_mic = 1;
13107 }
13108
13109 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13110 {
13111         alc269_quanta_fl1_speaker_automute(codec);
13112         alc_mic_automute(codec);
13113 }
13114
13115 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13116 {
13117         alc269_lifebook_speaker_automute(codec);
13118         alc269_lifebook_mic_autoswitch(codec);
13119 }
13120
13121 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13122         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13123         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13124         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13125         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13126         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13127         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13128         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13129         {}
13130 };
13131
13132 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13133         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13134         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13135         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13136         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13137         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13138         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13139         {}
13140 };
13141
13142 /* toggle speaker-output according to the hp-jack state */
13143 static void alc269_speaker_automute(struct hda_codec *codec)
13144 {
13145         unsigned int present;
13146         unsigned char bits;
13147
13148         present = snd_hda_codec_read(codec, 0x15, 0,
13149                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13150         bits = present ? AMP_IN_MUTE(0) : 0;
13151         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13152                                 AMP_IN_MUTE(0), bits);
13153         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13154                                 AMP_IN_MUTE(0), bits);
13155 }
13156
13157 /* unsolicited event for HP jack sensing */
13158 static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13159                                      unsigned int res)
13160 {
13161         switch (res >> 26) {
13162         case ALC880_HP_EVENT:
13163                 alc269_speaker_automute(codec);
13164                 break;
13165         case ALC880_MIC_EVENT:
13166                 alc_mic_automute(codec);
13167                 break;
13168         }
13169 }
13170
13171 static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13172 {
13173         struct alc_spec *spec = codec->spec;
13174         spec->ext_mic.pin = 0x18;
13175         spec->ext_mic.mux_idx = 0;
13176         spec->int_mic.pin = 0x12;
13177         spec->int_mic.mux_idx = 5;
13178         spec->auto_mic = 1;
13179 }
13180
13181 static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13182 {
13183         struct alc_spec *spec = codec->spec;
13184         spec->ext_mic.pin = 0x18;
13185         spec->ext_mic.mux_idx = 0;
13186         spec->int_mic.pin = 0x19;
13187         spec->int_mic.mux_idx = 1;
13188         spec->auto_mic = 1;
13189 }
13190
13191 static void alc269_eeepc_inithook(struct hda_codec *codec)
13192 {
13193         alc269_speaker_automute(codec);
13194         alc_mic_automute(codec);
13195 }
13196
13197 /*
13198  * generic initialization of ADC, input mixers and output mixers
13199  */
13200 static struct hda_verb alc269_init_verbs[] = {
13201         /*
13202          * Unmute ADC0 and set the default input to mic-in
13203          */
13204         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13205
13206         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13207          * analog-loopback mixer widget
13208          * Note: PASD motherboards uses the Line In 2 as the input for
13209          * front panel mic (mic 2)
13210          */
13211         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13212         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13214         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13215         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13216         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13217
13218         /*
13219          * Set up output mixers (0x0c - 0x0e)
13220          */
13221         /* set vol=0 to output mixers */
13222         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13223         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13224
13225         /* set up input amps for analog loopback */
13226         /* Amp Indices: DAC = 0, mixer = 1 */
13227         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13228         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13229         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13230         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13231         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13232         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13233
13234         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13235         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13236         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13237         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13238         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13239         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13240         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13241
13242         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13243         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13244         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13245         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13246         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13247         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13248         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13249
13250         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13251         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13252
13253         /* FIXME: use matrix-type input source selection */
13254         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13255         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13256         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13257         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13258         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13259         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13260
13261         /* set EAPD */
13262         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13263         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13264         { }
13265 };
13266
13267 #define alc269_auto_create_multi_out_ctls \
13268         alc268_auto_create_multi_out_ctls
13269 #define alc269_auto_create_input_ctls \
13270         alc268_auto_create_input_ctls
13271
13272 #ifdef CONFIG_SND_HDA_POWER_SAVE
13273 #define alc269_loopbacks        alc880_loopbacks
13274 #endif
13275
13276 /* pcm configuration: identical with ALC880 */
13277 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13278 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13279 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13280 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13281
13282 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13283         .substreams = 1,
13284         .channels_min = 2,
13285         .channels_max = 8,
13286         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13287         /* NID is set in alc_build_pcms */
13288         .ops = {
13289                 .open = alc880_playback_pcm_open,
13290                 .prepare = alc880_playback_pcm_prepare,
13291                 .cleanup = alc880_playback_pcm_cleanup
13292         },
13293 };
13294
13295 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13296         .substreams = 1,
13297         .channels_min = 2,
13298         .channels_max = 2,
13299         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13300         /* NID is set in alc_build_pcms */
13301 };
13302
13303 /*
13304  * BIOS auto configuration
13305  */
13306 static int alc269_parse_auto_config(struct hda_codec *codec)
13307 {
13308         struct alc_spec *spec = codec->spec;
13309         int err;
13310         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13311
13312         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13313                                            alc269_ignore);
13314         if (err < 0)
13315                 return err;
13316
13317         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13318         if (err < 0)
13319                 return err;
13320         err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13321         if (err < 0)
13322                 return err;
13323
13324         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13325
13326         if (spec->autocfg.dig_outs)
13327                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13328
13329         if (spec->kctls.list)
13330                 add_mixer(spec, spec->kctls.list);
13331
13332         add_verb(spec, alc269_init_verbs);
13333         spec->num_mux_defs = 1;
13334         spec->input_mux = &spec->private_imux[0];
13335         /* set default input source */
13336         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13337                                   0, AC_VERB_SET_CONNECT_SEL,
13338                                   spec->input_mux->items[0].index);
13339
13340         err = alc_auto_add_mic_boost(codec);
13341         if (err < 0)
13342                 return err;
13343
13344         if (!spec->cap_mixer && !spec->no_analog)
13345                 set_capture_mixer(codec);
13346
13347         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13348
13349         return 1;
13350 }
13351
13352 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
13353 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
13354 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13355
13356
13357 /* init callback for auto-configuration model -- overriding the default init */
13358 static void alc269_auto_init(struct hda_codec *codec)
13359 {
13360         struct alc_spec *spec = codec->spec;
13361         alc269_auto_init_multi_out(codec);
13362         alc269_auto_init_hp_out(codec);
13363         alc269_auto_init_analog_input(codec);
13364         if (spec->unsol_event)
13365                 alc_inithook(codec);
13366 }
13367
13368 /*
13369  * configuration and preset
13370  */
13371 static const char *alc269_models[ALC269_MODEL_LAST] = {
13372         [ALC269_BASIC]                  = "basic",
13373         [ALC269_QUANTA_FL1]             = "quanta",
13374         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13375         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13376         [ALC269_FUJITSU]                = "fujitsu",
13377         [ALC269_LIFEBOOK]               = "lifebook",
13378         [ALC269_AUTO]                   = "auto",
13379 };
13380
13381 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13382         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13383         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13384                       ALC269_ASUS_EEEPC_P703),
13385         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13386         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13387         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13388         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13389         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13390         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13391         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13392                       ALC269_ASUS_EEEPC_P901),
13393         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13394                       ALC269_ASUS_EEEPC_P901),
13395         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13396         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13397         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13398         {}
13399 };
13400
13401 static struct alc_config_preset alc269_presets[] = {
13402         [ALC269_BASIC] = {
13403                 .mixers = { alc269_base_mixer },
13404                 .init_verbs = { alc269_init_verbs },
13405                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13406                 .dac_nids = alc269_dac_nids,
13407                 .hp_nid = 0x03,
13408                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13409                 .channel_mode = alc269_modes,
13410                 .input_mux = &alc269_capture_source,
13411         },
13412         [ALC269_QUANTA_FL1] = {
13413                 .mixers = { alc269_quanta_fl1_mixer },
13414                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13415                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13416                 .dac_nids = alc269_dac_nids,
13417                 .hp_nid = 0x03,
13418                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13419                 .channel_mode = alc269_modes,
13420                 .input_mux = &alc269_capture_source,
13421                 .unsol_event = alc269_quanta_fl1_unsol_event,
13422                 .setup = alc269_quanta_fl1_setup,
13423                 .init_hook = alc269_quanta_fl1_init_hook,
13424         },
13425         [ALC269_ASUS_EEEPC_P703] = {
13426                 .mixers = { alc269_eeepc_mixer },
13427                 .cap_mixer = alc269_epc_capture_mixer,
13428                 .init_verbs = { alc269_init_verbs,
13429                                 alc269_eeepc_amic_init_verbs },
13430                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13431                 .dac_nids = alc269_dac_nids,
13432                 .hp_nid = 0x03,
13433                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13434                 .channel_mode = alc269_modes,
13435                 .unsol_event = alc269_eeepc_unsol_event,
13436                 .setup = alc269_eeepc_amic_setup,
13437                 .init_hook = alc269_eeepc_inithook,
13438         },
13439         [ALC269_ASUS_EEEPC_P901] = {
13440                 .mixers = { alc269_eeepc_mixer },
13441                 .cap_mixer = alc269_epc_capture_mixer,
13442                 .init_verbs = { alc269_init_verbs,
13443                                 alc269_eeepc_dmic_init_verbs },
13444                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13445                 .dac_nids = alc269_dac_nids,
13446                 .hp_nid = 0x03,
13447                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13448                 .channel_mode = alc269_modes,
13449                 .unsol_event = alc269_eeepc_unsol_event,
13450                 .setup = alc269_eeepc_dmic_setup,
13451                 .init_hook = alc269_eeepc_inithook,
13452         },
13453         [ALC269_FUJITSU] = {
13454                 .mixers = { alc269_fujitsu_mixer },
13455                 .cap_mixer = alc269_epc_capture_mixer,
13456                 .init_verbs = { alc269_init_verbs,
13457                                 alc269_eeepc_dmic_init_verbs },
13458                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13459                 .dac_nids = alc269_dac_nids,
13460                 .hp_nid = 0x03,
13461                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13462                 .channel_mode = alc269_modes,
13463                 .unsol_event = alc269_eeepc_unsol_event,
13464                 .setup = alc269_eeepc_dmic_setup,
13465                 .init_hook = alc269_eeepc_inithook,
13466         },
13467         [ALC269_LIFEBOOK] = {
13468                 .mixers = { alc269_lifebook_mixer },
13469                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13470                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13471                 .dac_nids = alc269_dac_nids,
13472                 .hp_nid = 0x03,
13473                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13474                 .channel_mode = alc269_modes,
13475                 .input_mux = &alc269_capture_source,
13476                 .unsol_event = alc269_lifebook_unsol_event,
13477                 .init_hook = alc269_lifebook_init_hook,
13478         },
13479 };
13480
13481 static int patch_alc269(struct hda_codec *codec)
13482 {
13483         struct alc_spec *spec;
13484         int board_config;
13485         int err;
13486
13487         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13488         if (spec == NULL)
13489                 return -ENOMEM;
13490
13491         codec->spec = spec;
13492
13493         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13494
13495         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13496                                                   alc269_models,
13497                                                   alc269_cfg_tbl);
13498
13499         if (board_config < 0) {
13500                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13501                        codec->chip_name);
13502                 board_config = ALC269_AUTO;
13503         }
13504
13505         if (board_config == ALC269_AUTO) {
13506                 /* automatic parse from the BIOS config */
13507                 err = alc269_parse_auto_config(codec);
13508                 if (err < 0) {
13509                         alc_free(codec);
13510                         return err;
13511                 } else if (!err) {
13512                         printk(KERN_INFO
13513                                "hda_codec: Cannot set up configuration "
13514                                "from BIOS.  Using base mode...\n");
13515                         board_config = ALC269_BASIC;
13516                 }
13517         }
13518
13519         err = snd_hda_attach_beep_device(codec, 0x1);
13520         if (err < 0) {
13521                 alc_free(codec);
13522                 return err;
13523         }
13524
13525         if (board_config != ALC269_AUTO)
13526                 setup_preset(codec, &alc269_presets[board_config]);
13527
13528         if (codec->subsystem_id == 0x17aa3bf8) {
13529                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13530                  * fix the sample rate of analog I/O to 44.1kHz
13531                  */
13532                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13533                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13534         } else {
13535                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13536                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13537         }
13538         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13539         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13540
13541         spec->adc_nids = alc269_adc_nids;
13542         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13543         spec->capsrc_nids = alc269_capsrc_nids;
13544         if (!spec->cap_mixer)
13545                 set_capture_mixer(codec);
13546         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13547
13548         spec->vmaster_nid = 0x02;
13549
13550         codec->patch_ops = alc_patch_ops;
13551         if (board_config == ALC269_AUTO)
13552                 spec->init_hook = alc269_auto_init;
13553 #ifdef CONFIG_SND_HDA_POWER_SAVE
13554         if (!spec->loopback.amplist)
13555                 spec->loopback.amplist = alc269_loopbacks;
13556 #endif
13557         codec->proc_widget_hook = print_realtek_coef;
13558
13559         return 0;
13560 }
13561
13562 /*
13563  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13564  */
13565
13566 /*
13567  * set the path ways for 2 channel output
13568  * need to set the codec line out and mic 1 pin widgets to inputs
13569  */
13570 static struct hda_verb alc861_threestack_ch2_init[] = {
13571         /* set pin widget 1Ah (line in) for input */
13572         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13573         /* set pin widget 18h (mic1/2) for input, for mic also enable
13574          * the vref
13575          */
13576         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13577
13578         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13579 #if 0
13580         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13581         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13582 #endif
13583         { } /* end */
13584 };
13585 /*
13586  * 6ch mode
13587  * need to set the codec line out and mic 1 pin widgets to outputs
13588  */
13589 static struct hda_verb alc861_threestack_ch6_init[] = {
13590         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13591         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13592         /* set pin widget 18h (mic1) for output (CLFE)*/
13593         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13594
13595         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13596         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13597
13598         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13599 #if 0
13600         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13601         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13602 #endif
13603         { } /* end */
13604 };
13605
13606 static struct hda_channel_mode alc861_threestack_modes[2] = {
13607         { 2, alc861_threestack_ch2_init },
13608         { 6, alc861_threestack_ch6_init },
13609 };
13610 /* Set mic1 as input and unmute the mixer */
13611 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13612         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13613         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13614         { } /* end */
13615 };
13616 /* Set mic1 as output and mute mixer */
13617 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13618         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13619         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13620         { } /* end */
13621 };
13622
13623 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13624         { 2, alc861_uniwill_m31_ch2_init },
13625         { 4, alc861_uniwill_m31_ch4_init },
13626 };
13627
13628 /* Set mic1 and line-in as input and unmute the mixer */
13629 static struct hda_verb alc861_asus_ch2_init[] = {
13630         /* set pin widget 1Ah (line in) for input */
13631         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13632         /* set pin widget 18h (mic1/2) for input, for mic also enable
13633          * the vref
13634          */
13635         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13636
13637         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13638 #if 0
13639         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13640         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13641 #endif
13642         { } /* end */
13643 };
13644 /* Set mic1 nad line-in as output and mute mixer */
13645 static struct hda_verb alc861_asus_ch6_init[] = {
13646         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13647         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13648         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13649         /* set pin widget 18h (mic1) for output (CLFE)*/
13650         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13651         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13652         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13653         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13654
13655         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13656 #if 0
13657         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13658         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13659 #endif
13660         { } /* end */
13661 };
13662
13663 static struct hda_channel_mode alc861_asus_modes[2] = {
13664         { 2, alc861_asus_ch2_init },
13665         { 6, alc861_asus_ch6_init },
13666 };
13667
13668 /* patch-ALC861 */
13669
13670 static struct snd_kcontrol_new alc861_base_mixer[] = {
13671         /* output mixer control */
13672         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13673         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13674         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13675         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13676         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13677
13678         /*Input mixer control */
13679         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13680            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13681         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13682         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13683         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13684         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13685         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13686         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13687         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13688         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13689
13690         { } /* end */
13691 };
13692
13693 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13694         /* output mixer control */
13695         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13696         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13697         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13698         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13699         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13700
13701         /* Input mixer control */
13702         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13703            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13704         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13705         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13706         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13707         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13708         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13709         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13710         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13711         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13712
13713         {
13714                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13715                 .name = "Channel Mode",
13716                 .info = alc_ch_mode_info,
13717                 .get = alc_ch_mode_get,
13718                 .put = alc_ch_mode_put,
13719                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13720         },
13721         { } /* end */
13722 };
13723
13724 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13725         /* output mixer control */
13726         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13727         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13728         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13729
13730         { } /* end */
13731 };
13732
13733 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13734         /* output mixer control */
13735         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13736         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13737         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13738         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13739         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13740
13741         /* Input mixer control */
13742         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13743            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13744         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13745         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13746         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13747         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13748         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13749         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13750         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13751         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13752
13753         {
13754                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13755                 .name = "Channel Mode",
13756                 .info = alc_ch_mode_info,
13757                 .get = alc_ch_mode_get,
13758                 .put = alc_ch_mode_put,
13759                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13760         },
13761         { } /* end */
13762 };
13763
13764 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13765         /* output mixer control */
13766         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13767         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13768         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13769         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13770         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13771
13772         /* Input mixer control */
13773         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13774         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13775         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13776         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13777         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13778         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13779         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13780         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13781         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13782         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13783
13784         {
13785                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13786                 .name = "Channel Mode",
13787                 .info = alc_ch_mode_info,
13788                 .get = alc_ch_mode_get,
13789                 .put = alc_ch_mode_put,
13790                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13791         },
13792         { }
13793 };
13794
13795 /* additional mixer */
13796 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13797         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13798         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13799         { }
13800 };
13801
13802 /*
13803  * generic initialization of ADC, input mixers and output mixers
13804  */
13805 static struct hda_verb alc861_base_init_verbs[] = {
13806         /*
13807          * Unmute ADC0 and set the default input to mic-in
13808          */
13809         /* port-A for surround (rear panel) */
13810         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13811         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13812         /* port-B for mic-in (rear panel) with vref */
13813         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13814         /* port-C for line-in (rear panel) */
13815         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13816         /* port-D for Front */
13817         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13818         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13819         /* port-E for HP out (front panel) */
13820         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13821         /* route front PCM to HP */
13822         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13823         /* port-F for mic-in (front panel) with vref */
13824         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13825         /* port-G for CLFE (rear panel) */
13826         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13827         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13828         /* port-H for side (rear panel) */
13829         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13830         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13831         /* CD-in */
13832         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13833         /* route front mic to ADC1*/
13834         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13835         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13836
13837         /* Unmute DAC0~3 & spdif out*/
13838         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13839         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13840         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13841         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13842         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13843
13844         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13845         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13846         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13847         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13848         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13849
13850         /* Unmute Stereo Mixer 15 */
13851         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13852         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13853         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13854         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13855
13856         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13857         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13858         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13859         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13860         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13861         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13862         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13863         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13864         /* hp used DAC 3 (Front) */
13865         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13866         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13867
13868         { }
13869 };
13870
13871 static struct hda_verb alc861_threestack_init_verbs[] = {
13872         /*
13873          * Unmute ADC0 and set the default input to mic-in
13874          */
13875         /* port-A for surround (rear panel) */
13876         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13877         /* port-B for mic-in (rear panel) with vref */
13878         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13879         /* port-C for line-in (rear panel) */
13880         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13881         /* port-D for Front */
13882         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13883         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13884         /* port-E for HP out (front panel) */
13885         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13886         /* route front PCM to HP */
13887         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13888         /* port-F for mic-in (front panel) with vref */
13889         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13890         /* port-G for CLFE (rear panel) */
13891         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13892         /* port-H for side (rear panel) */
13893         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13894         /* CD-in */
13895         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13896         /* route front mic to ADC1*/
13897         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13898         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13899         /* Unmute DAC0~3 & spdif out*/
13900         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13901         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13902         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13903         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13904         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13905
13906         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13907         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13908         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13909         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13910         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13911
13912         /* Unmute Stereo Mixer 15 */
13913         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13914         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13915         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13916         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13917
13918         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13919         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13920         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13921         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13922         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13923         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13924         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13925         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13926         /* hp used DAC 3 (Front) */
13927         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13928         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13929         { }
13930 };
13931
13932 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13933         /*
13934          * Unmute ADC0 and set the default input to mic-in
13935          */
13936         /* port-A for surround (rear panel) */
13937         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13938         /* port-B for mic-in (rear panel) with vref */
13939         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13940         /* port-C for line-in (rear panel) */
13941         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13942         /* port-D for Front */
13943         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13944         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13945         /* port-E for HP out (front panel) */
13946         /* this has to be set to VREF80 */
13947         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13948         /* route front PCM to HP */
13949         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13950         /* port-F for mic-in (front panel) with vref */
13951         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13952         /* port-G for CLFE (rear panel) */
13953         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13954         /* port-H for side (rear panel) */
13955         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13956         /* CD-in */
13957         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13958         /* route front mic to ADC1*/
13959         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13960         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13961         /* Unmute DAC0~3 & spdif out*/
13962         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13963         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13964         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13965         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13966         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13967
13968         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13969         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13970         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13971         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13972         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13973
13974         /* Unmute Stereo Mixer 15 */
13975         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13977         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13978         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13979
13980         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13981         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13982         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13983         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13984         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13985         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13986         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13987         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13988         /* hp used DAC 3 (Front) */
13989         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13990         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13991         { }
13992 };
13993
13994 static struct hda_verb alc861_asus_init_verbs[] = {
13995         /*
13996          * Unmute ADC0 and set the default input to mic-in
13997          */
13998         /* port-A for surround (rear panel)
13999          * according to codec#0 this is the HP jack
14000          */
14001         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14002         /* route front PCM to HP */
14003         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14004         /* port-B for mic-in (rear panel) with vref */
14005         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14006         /* port-C for line-in (rear panel) */
14007         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14008         /* port-D for Front */
14009         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14010         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14011         /* port-E for HP out (front panel) */
14012         /* this has to be set to VREF80 */
14013         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14014         /* route front PCM to HP */
14015         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14016         /* port-F for mic-in (front panel) with vref */
14017         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14018         /* port-G for CLFE (rear panel) */
14019         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14020         /* port-H for side (rear panel) */
14021         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14022         /* CD-in */
14023         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14024         /* route front mic to ADC1*/
14025         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14026         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14027         /* Unmute DAC0~3 & spdif out*/
14028         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14029         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14030         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14031         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14033         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14034         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14035         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14036         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14037         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14038
14039         /* Unmute Stereo Mixer 15 */
14040         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14041         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14042         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14043         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14044
14045         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14046         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14047         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14048         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14049         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14050         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14051         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14052         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14053         /* hp used DAC 3 (Front) */
14054         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14055         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14056         { }
14057 };
14058
14059 /* additional init verbs for ASUS laptops */
14060 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14061         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14062         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14063         { }
14064 };
14065
14066 /*
14067  * generic initialization of ADC, input mixers and output mixers
14068  */
14069 static struct hda_verb alc861_auto_init_verbs[] = {
14070         /*
14071          * Unmute ADC0 and set the default input to mic-in
14072          */
14073         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14074         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14075
14076         /* Unmute DAC0~3 & spdif out*/
14077         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14078         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14079         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14080         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14081         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14082
14083         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14084         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14085         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14086         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14087         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14088
14089         /* Unmute Stereo Mixer 15 */
14090         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14091         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14092         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14093         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14094
14095         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14096         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14097         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14098         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14099         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14100         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14101         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14102         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14103
14104         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14105         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14106         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14107         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14108         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14109         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14110         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14111         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14112
14113         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14114
14115         { }
14116 };
14117
14118 static struct hda_verb alc861_toshiba_init_verbs[] = {
14119         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14120
14121         { }
14122 };
14123
14124 /* toggle speaker-output according to the hp-jack state */
14125 static void alc861_toshiba_automute(struct hda_codec *codec)
14126 {
14127         unsigned int present;
14128
14129         present = snd_hda_codec_read(codec, 0x0f, 0,
14130                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14131         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14132                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14133         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14134                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14135 }
14136
14137 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14138                                        unsigned int res)
14139 {
14140         if ((res >> 26) == ALC880_HP_EVENT)
14141                 alc861_toshiba_automute(codec);
14142 }
14143
14144 /* pcm configuration: identical with ALC880 */
14145 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14146 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14147 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14148 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14149
14150
14151 #define ALC861_DIGOUT_NID       0x07
14152
14153 static struct hda_channel_mode alc861_8ch_modes[1] = {
14154         { 8, NULL }
14155 };
14156
14157 static hda_nid_t alc861_dac_nids[4] = {
14158         /* front, surround, clfe, side */
14159         0x03, 0x06, 0x05, 0x04
14160 };
14161
14162 static hda_nid_t alc660_dac_nids[3] = {
14163         /* front, clfe, surround */
14164         0x03, 0x05, 0x06
14165 };
14166
14167 static hda_nid_t alc861_adc_nids[1] = {
14168         /* ADC0-2 */
14169         0x08,
14170 };
14171
14172 static struct hda_input_mux alc861_capture_source = {
14173         .num_items = 5,
14174         .items = {
14175                 { "Mic", 0x0 },
14176                 { "Front Mic", 0x3 },
14177                 { "Line", 0x1 },
14178                 { "CD", 0x4 },
14179                 { "Mixer", 0x5 },
14180         },
14181 };
14182
14183 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
14184 {
14185         struct alc_spec *spec = codec->spec;
14186         hda_nid_t mix, srcs[5];
14187         int i, j, num;
14188
14189         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
14190                 return 0;
14191         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14192         if (num < 0)
14193                 return 0;
14194         for (i = 0; i < num; i++) {
14195                 unsigned int type;
14196                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14197                 if (type != AC_WID_AUD_OUT)
14198                         continue;
14199                 for (j = 0; j < spec->multiout.num_dacs; j++)
14200                         if (spec->multiout.dac_nids[j] == srcs[i])
14201                                 break;
14202                 if (j >= spec->multiout.num_dacs)
14203                         return srcs[i];
14204         }
14205         return 0;
14206 }
14207
14208 /* fill in the dac_nids table from the parsed pin configuration */
14209 static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14210                                      const struct auto_pin_cfg *cfg)
14211 {
14212         struct alc_spec *spec = codec->spec;
14213         int i;
14214         hda_nid_t nid, dac;
14215
14216         spec->multiout.dac_nids = spec->private_dac_nids;
14217         for (i = 0; i < cfg->line_outs; i++) {
14218                 nid = cfg->line_out_pins[i];
14219                 dac = alc861_look_for_dac(codec, nid);
14220                 if (!dac)
14221                         continue;
14222                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14223         }
14224         return 0;
14225 }
14226
14227 static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14228                                 hda_nid_t nid, unsigned int chs)
14229 {
14230         return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14231                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14232 }
14233
14234 /* add playback controls from the parsed DAC table */
14235 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14236                                              const struct auto_pin_cfg *cfg)
14237 {
14238         struct alc_spec *spec = codec->spec;
14239         static const char *chname[4] = {
14240                 "Front", "Surround", NULL /*CLFE*/, "Side"
14241         };
14242         hda_nid_t nid;
14243         int i, err;
14244
14245         if (cfg->line_outs == 1) {
14246                 const char *pfx = NULL;
14247                 if (!cfg->hp_outs)
14248                         pfx = "Master";
14249                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
14250                         pfx = "Speaker";
14251                 if (pfx) {
14252                         nid = spec->multiout.dac_nids[0];
14253                         return alc861_create_out_sw(codec, pfx, nid, 3);
14254                 }
14255         }
14256
14257         for (i = 0; i < cfg->line_outs; i++) {
14258                 nid = spec->multiout.dac_nids[i];
14259                 if (!nid)
14260                         continue;
14261                 if (i == 2) {
14262                         /* Center/LFE */
14263                         err = alc861_create_out_sw(codec, "Center", nid, 1);
14264                         if (err < 0)
14265                                 return err;
14266                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
14267                         if (err < 0)
14268                                 return err;
14269                 } else {
14270                         err = alc861_create_out_sw(codec, chname[i], nid, 3);
14271                         if (err < 0)
14272                                 return err;
14273                 }
14274         }
14275         return 0;
14276 }
14277
14278 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14279 {
14280         struct alc_spec *spec = codec->spec;
14281         int err;
14282         hda_nid_t nid;
14283
14284         if (!pin)
14285                 return 0;
14286
14287         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14288                 nid = alc861_look_for_dac(codec, pin);
14289                 if (nid) {
14290                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14291                         if (err < 0)
14292                                 return err;
14293                         spec->multiout.hp_nid = nid;
14294                 }
14295         }
14296         return 0;
14297 }
14298
14299 /* create playback/capture controls for input pins */
14300 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14301                                                 const struct auto_pin_cfg *cfg)
14302 {
14303         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14304 }
14305
14306 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14307                                               hda_nid_t nid,
14308                                               int pin_type, hda_nid_t dac)
14309 {
14310         hda_nid_t mix, srcs[5];
14311         int i, num;
14312
14313         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14314                             pin_type);
14315         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14316                             AMP_OUT_UNMUTE);
14317         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
14318                 return;
14319         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14320         if (num < 0)
14321                 return;
14322         for (i = 0; i < num; i++) {
14323                 unsigned int mute;
14324                 if (srcs[i] == dac || srcs[i] == 0x15)
14325                         mute = AMP_IN_UNMUTE(i);
14326                 else
14327                         mute = AMP_IN_MUTE(i);
14328                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14329                                     mute);
14330         }
14331 }
14332
14333 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14334 {
14335         struct alc_spec *spec = codec->spec;
14336         int i;
14337
14338         for (i = 0; i < spec->autocfg.line_outs; i++) {
14339                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14340                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14341                 if (nid)
14342                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14343                                                           spec->multiout.dac_nids[i]);
14344         }
14345 }
14346
14347 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14348 {
14349         struct alc_spec *spec = codec->spec;
14350         hda_nid_t pin;
14351
14352         pin = spec->autocfg.hp_pins[0];
14353         if (pin)
14354                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
14355                                                   spec->multiout.hp_nid);
14356         pin = spec->autocfg.speaker_pins[0];
14357         if (pin)
14358                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT,
14359                                                   spec->multiout.dac_nids[0]);
14360 }
14361
14362 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14363 {
14364         struct alc_spec *spec = codec->spec;
14365         int i;
14366
14367         for (i = 0; i < AUTO_PIN_LAST; i++) {
14368                 hda_nid_t nid = spec->autocfg.input_pins[i];
14369                 if (nid >= 0x0c && nid <= 0x11)
14370                         alc_set_input_pin(codec, nid, i);
14371         }
14372 }
14373
14374 /* parse the BIOS configuration and set up the alc_spec */
14375 /* return 1 if successful, 0 if the proper config is not found,
14376  * or a negative error code
14377  */
14378 static int alc861_parse_auto_config(struct hda_codec *codec)
14379 {
14380         struct alc_spec *spec = codec->spec;
14381         int err;
14382         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14383
14384         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14385                                            alc861_ignore);
14386         if (err < 0)
14387                 return err;
14388         if (!spec->autocfg.line_outs)
14389                 return 0; /* can't find valid BIOS pin config */
14390
14391         err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14392         if (err < 0)
14393                 return err;
14394         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14395         if (err < 0)
14396                 return err;
14397         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
14398         if (err < 0)
14399                 return err;
14400         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14401         if (err < 0)
14402                 return err;
14403
14404         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14405
14406         if (spec->autocfg.dig_outs)
14407                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14408
14409         if (spec->kctls.list)
14410                 add_mixer(spec, spec->kctls.list);
14411
14412         add_verb(spec, alc861_auto_init_verbs);
14413
14414         spec->num_mux_defs = 1;
14415         spec->input_mux = &spec->private_imux[0];
14416
14417         spec->adc_nids = alc861_adc_nids;
14418         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14419         set_capture_mixer(codec);
14420
14421         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14422
14423         return 1;
14424 }
14425
14426 /* additional initialization for auto-configuration model */
14427 static void alc861_auto_init(struct hda_codec *codec)
14428 {
14429         struct alc_spec *spec = codec->spec;
14430         alc861_auto_init_multi_out(codec);
14431         alc861_auto_init_hp_out(codec);
14432         alc861_auto_init_analog_input(codec);
14433         if (spec->unsol_event)
14434                 alc_inithook(codec);
14435 }
14436
14437 #ifdef CONFIG_SND_HDA_POWER_SAVE
14438 static struct hda_amp_list alc861_loopbacks[] = {
14439         { 0x15, HDA_INPUT, 0 },
14440         { 0x15, HDA_INPUT, 1 },
14441         { 0x15, HDA_INPUT, 2 },
14442         { 0x15, HDA_INPUT, 3 },
14443         { } /* end */
14444 };
14445 #endif
14446
14447
14448 /*
14449  * configuration and preset
14450  */
14451 static const char *alc861_models[ALC861_MODEL_LAST] = {
14452         [ALC861_3ST]            = "3stack",
14453         [ALC660_3ST]            = "3stack-660",
14454         [ALC861_3ST_DIG]        = "3stack-dig",
14455         [ALC861_6ST_DIG]        = "6stack-dig",
14456         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14457         [ALC861_TOSHIBA]        = "toshiba",
14458         [ALC861_ASUS]           = "asus",
14459         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14460         [ALC861_AUTO]           = "auto",
14461 };
14462
14463 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14464         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14465         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14466         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14467         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14468         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14469         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14470         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14471         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14472          *        Any other models that need this preset?
14473          */
14474         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14475         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14476         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14477         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14478         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14479         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14480         /* FIXME: the below seems conflict */
14481         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14482         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14483         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14484         {}
14485 };
14486
14487 static struct alc_config_preset alc861_presets[] = {
14488         [ALC861_3ST] = {
14489                 .mixers = { alc861_3ST_mixer },
14490                 .init_verbs = { alc861_threestack_init_verbs },
14491                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14492                 .dac_nids = alc861_dac_nids,
14493                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14494                 .channel_mode = alc861_threestack_modes,
14495                 .need_dac_fix = 1,
14496                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14497                 .adc_nids = alc861_adc_nids,
14498                 .input_mux = &alc861_capture_source,
14499         },
14500         [ALC861_3ST_DIG] = {
14501                 .mixers = { alc861_base_mixer },
14502                 .init_verbs = { alc861_threestack_init_verbs },
14503                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14504                 .dac_nids = alc861_dac_nids,
14505                 .dig_out_nid = ALC861_DIGOUT_NID,
14506                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14507                 .channel_mode = alc861_threestack_modes,
14508                 .need_dac_fix = 1,
14509                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14510                 .adc_nids = alc861_adc_nids,
14511                 .input_mux = &alc861_capture_source,
14512         },
14513         [ALC861_6ST_DIG] = {
14514                 .mixers = { alc861_base_mixer },
14515                 .init_verbs = { alc861_base_init_verbs },
14516                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14517                 .dac_nids = alc861_dac_nids,
14518                 .dig_out_nid = ALC861_DIGOUT_NID,
14519                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14520                 .channel_mode = alc861_8ch_modes,
14521                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14522                 .adc_nids = alc861_adc_nids,
14523                 .input_mux = &alc861_capture_source,
14524         },
14525         [ALC660_3ST] = {
14526                 .mixers = { alc861_3ST_mixer },
14527                 .init_verbs = { alc861_threestack_init_verbs },
14528                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14529                 .dac_nids = alc660_dac_nids,
14530                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14531                 .channel_mode = alc861_threestack_modes,
14532                 .need_dac_fix = 1,
14533                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14534                 .adc_nids = alc861_adc_nids,
14535                 .input_mux = &alc861_capture_source,
14536         },
14537         [ALC861_UNIWILL_M31] = {
14538                 .mixers = { alc861_uniwill_m31_mixer },
14539                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14540                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14541                 .dac_nids = alc861_dac_nids,
14542                 .dig_out_nid = ALC861_DIGOUT_NID,
14543                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14544                 .channel_mode = alc861_uniwill_m31_modes,
14545                 .need_dac_fix = 1,
14546                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14547                 .adc_nids = alc861_adc_nids,
14548                 .input_mux = &alc861_capture_source,
14549         },
14550         [ALC861_TOSHIBA] = {
14551                 .mixers = { alc861_toshiba_mixer },
14552                 .init_verbs = { alc861_base_init_verbs,
14553                                 alc861_toshiba_init_verbs },
14554                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14555                 .dac_nids = alc861_dac_nids,
14556                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14557                 .channel_mode = alc883_3ST_2ch_modes,
14558                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14559                 .adc_nids = alc861_adc_nids,
14560                 .input_mux = &alc861_capture_source,
14561                 .unsol_event = alc861_toshiba_unsol_event,
14562                 .init_hook = alc861_toshiba_automute,
14563         },
14564         [ALC861_ASUS] = {
14565                 .mixers = { alc861_asus_mixer },
14566                 .init_verbs = { alc861_asus_init_verbs },
14567                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14568                 .dac_nids = alc861_dac_nids,
14569                 .dig_out_nid = ALC861_DIGOUT_NID,
14570                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14571                 .channel_mode = alc861_asus_modes,
14572                 .need_dac_fix = 1,
14573                 .hp_nid = 0x06,
14574                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14575                 .adc_nids = alc861_adc_nids,
14576                 .input_mux = &alc861_capture_source,
14577         },
14578         [ALC861_ASUS_LAPTOP] = {
14579                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14580                 .init_verbs = { alc861_asus_init_verbs,
14581                                 alc861_asus_laptop_init_verbs },
14582                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14583                 .dac_nids = alc861_dac_nids,
14584                 .dig_out_nid = ALC861_DIGOUT_NID,
14585                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14586                 .channel_mode = alc883_3ST_2ch_modes,
14587                 .need_dac_fix = 1,
14588                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14589                 .adc_nids = alc861_adc_nids,
14590                 .input_mux = &alc861_capture_source,
14591         },
14592 };
14593
14594
14595 static int patch_alc861(struct hda_codec *codec)
14596 {
14597         struct alc_spec *spec;
14598         int board_config;
14599         int err;
14600
14601         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14602         if (spec == NULL)
14603                 return -ENOMEM;
14604
14605         codec->spec = spec;
14606
14607         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14608                                                   alc861_models,
14609                                                   alc861_cfg_tbl);
14610
14611         if (board_config < 0) {
14612                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14613                        codec->chip_name);
14614                 board_config = ALC861_AUTO;
14615         }
14616
14617         if (board_config == ALC861_AUTO) {
14618                 /* automatic parse from the BIOS config */
14619                 err = alc861_parse_auto_config(codec);
14620                 if (err < 0) {
14621                         alc_free(codec);
14622                         return err;
14623                 } else if (!err) {
14624                         printk(KERN_INFO
14625                                "hda_codec: Cannot set up configuration "
14626                                "from BIOS.  Using base mode...\n");
14627                    board_config = ALC861_3ST_DIG;
14628                 }
14629         }
14630
14631         err = snd_hda_attach_beep_device(codec, 0x23);
14632         if (err < 0) {
14633                 alc_free(codec);
14634                 return err;
14635         }
14636
14637         if (board_config != ALC861_AUTO)
14638                 setup_preset(codec, &alc861_presets[board_config]);
14639
14640         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14641         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14642
14643         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14644         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14645
14646         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14647
14648         spec->vmaster_nid = 0x03;
14649
14650         codec->patch_ops = alc_patch_ops;
14651         if (board_config == ALC861_AUTO)
14652                 spec->init_hook = alc861_auto_init;
14653 #ifdef CONFIG_SND_HDA_POWER_SAVE
14654         if (!spec->loopback.amplist)
14655                 spec->loopback.amplist = alc861_loopbacks;
14656 #endif
14657         codec->proc_widget_hook = print_realtek_coef;
14658
14659         return 0;
14660 }
14661
14662 /*
14663  * ALC861-VD support
14664  *
14665  * Based on ALC882
14666  *
14667  * In addition, an independent DAC
14668  */
14669 #define ALC861VD_DIGOUT_NID     0x06
14670
14671 static hda_nid_t alc861vd_dac_nids[4] = {
14672         /* front, surr, clfe, side surr */
14673         0x02, 0x03, 0x04, 0x05
14674 };
14675
14676 /* dac_nids for ALC660vd are in a different order - according to
14677  * Realtek's driver.
14678  * This should probably result in a different mixer for 6stack models
14679  * of ALC660vd codecs, but for now there is only 3stack mixer
14680  * - and it is the same as in 861vd.
14681  * adc_nids in ALC660vd are (is) the same as in 861vd
14682  */
14683 static hda_nid_t alc660vd_dac_nids[3] = {
14684         /* front, rear, clfe, rear_surr */
14685         0x02, 0x04, 0x03
14686 };
14687
14688 static hda_nid_t alc861vd_adc_nids[1] = {
14689         /* ADC0 */
14690         0x09,
14691 };
14692
14693 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14694
14695 /* input MUX */
14696 /* FIXME: should be a matrix-type input source selection */
14697 static struct hda_input_mux alc861vd_capture_source = {
14698         .num_items = 4,
14699         .items = {
14700                 { "Mic", 0x0 },
14701                 { "Front Mic", 0x1 },
14702                 { "Line", 0x2 },
14703                 { "CD", 0x4 },
14704         },
14705 };
14706
14707 static struct hda_input_mux alc861vd_dallas_capture_source = {
14708         .num_items = 2,
14709         .items = {
14710                 { "Ext Mic", 0x0 },
14711                 { "Int Mic", 0x1 },
14712         },
14713 };
14714
14715 static struct hda_input_mux alc861vd_hp_capture_source = {
14716         .num_items = 2,
14717         .items = {
14718                 { "Front Mic", 0x0 },
14719                 { "ATAPI Mic", 0x1 },
14720         },
14721 };
14722
14723 /*
14724  * 2ch mode
14725  */
14726 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14727         { 2, NULL }
14728 };
14729
14730 /*
14731  * 6ch mode
14732  */
14733 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14734         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14735         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14736         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14737         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14738         { } /* end */
14739 };
14740
14741 /*
14742  * 8ch mode
14743  */
14744 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14745         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14746         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14747         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14748         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14749         { } /* end */
14750 };
14751
14752 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14753         { 6, alc861vd_6stack_ch6_init },
14754         { 8, alc861vd_6stack_ch8_init },
14755 };
14756
14757 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14758         {
14759                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14760                 .name = "Channel Mode",
14761                 .info = alc_ch_mode_info,
14762                 .get = alc_ch_mode_get,
14763                 .put = alc_ch_mode_put,
14764         },
14765         { } /* end */
14766 };
14767
14768 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14769  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14770  */
14771 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14772         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14773         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14774
14775         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14776         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14777
14778         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14779                                 HDA_OUTPUT),
14780         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14781                                 HDA_OUTPUT),
14782         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14783         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14784
14785         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14786         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14787
14788         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14789
14790         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14791         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14792         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14793
14794         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14795         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14796         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14797
14798         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14799         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14800
14801         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14802         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14803
14804         { } /* end */
14805 };
14806
14807 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14808         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14809         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14810
14811         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14812
14813         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14814         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14815         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14816
14817         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14818         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14819         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14820
14821         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14822         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14823
14824         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14825         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14826
14827         { } /* end */
14828 };
14829
14830 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14831         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14832         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14833         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14834
14835         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14836
14837         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14838         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14839         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14840
14841         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14842         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14843         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14844
14845         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14846         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14847
14848         { } /* end */
14849 };
14850
14851 /* Pin assignment: Speaker=0x14, HP = 0x15,
14852  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14853  */
14854 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14855         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14856         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14857         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14858         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14859         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14860         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14861         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14862         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14863         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14864         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14865         { } /* end */
14866 };
14867
14868 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14869  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14870  */
14871 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14872         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14873         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14874         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14875         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14876         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14877         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14878         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14879         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14880
14881         { } /* end */
14882 };
14883
14884 /*
14885  * generic initialization of ADC, input mixers and output mixers
14886  */
14887 static struct hda_verb alc861vd_volume_init_verbs[] = {
14888         /*
14889          * Unmute ADC0 and set the default input to mic-in
14890          */
14891         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14892         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14893
14894         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14895          * the analog-loopback mixer widget
14896          */
14897         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14898         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14899         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14900         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14901         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14902         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14903
14904         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14905         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14906         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14907         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14908         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14909
14910         /*
14911          * Set up output mixers (0x02 - 0x05)
14912          */
14913         /* set vol=0 to output mixers */
14914         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14915         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14916         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14917         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14918
14919         /* set up input amps for analog loopback */
14920         /* Amp Indices: DAC = 0, mixer = 1 */
14921         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14922         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14923         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14924         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14925         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14926         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14927         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14928         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14929
14930         { }
14931 };
14932
14933 /*
14934  * 3-stack pin configuration:
14935  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14936  */
14937 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14938         /*
14939          * Set pin mode and muting
14940          */
14941         /* set front pin widgets 0x14 for output */
14942         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14943         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14944         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14945
14946         /* Mic (rear) pin: input vref at 80% */
14947         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14948         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14949         /* Front Mic pin: input vref at 80% */
14950         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14951         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14952         /* Line In pin: input */
14953         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14954         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14955         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14956         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14957         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14958         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14959         /* CD pin widget for input */
14960         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14961
14962         { }
14963 };
14964
14965 /*
14966  * 6-stack pin configuration:
14967  */
14968 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14969         /*
14970          * Set pin mode and muting
14971          */
14972         /* set front pin widgets 0x14 for output */
14973         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14974         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14975         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14976
14977         /* Rear Pin: output 1 (0x0d) */
14978         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14979         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14980         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14981         /* CLFE Pin: output 2 (0x0e) */
14982         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14983         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14984         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14985         /* Side Pin: output 3 (0x0f) */
14986         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14987         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14988         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14989
14990         /* Mic (rear) pin: input vref at 80% */
14991         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14992         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14993         /* Front Mic pin: input vref at 80% */
14994         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14995         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14996         /* Line In pin: input */
14997         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14998         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14999         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15000         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15001         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15002         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15003         /* CD pin widget for input */
15004         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15005
15006         { }
15007 };
15008
15009 static struct hda_verb alc861vd_eapd_verbs[] = {
15010         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15011         { }
15012 };
15013
15014 static struct hda_verb alc660vd_eapd_verbs[] = {
15015         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15016         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15017         { }
15018 };
15019
15020 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15021         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15022         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15023         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15024         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15025         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15026         {}
15027 };
15028
15029 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15030 {
15031         unsigned int present;
15032         unsigned char bits;
15033
15034         present = snd_hda_codec_read(codec, 0x18, 0,
15035                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15036         bits = present ? HDA_AMP_MUTE : 0;
15037         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15038                                  HDA_AMP_MUTE, bits);
15039 }
15040
15041 static void alc861vd_lenovo_setup(struct hda_codec *codec)
15042 {
15043         struct alc_spec *spec = codec->spec;
15044         spec->autocfg.hp_pins[0] = 0x1b;
15045         spec->autocfg.speaker_pins[0] = 0x14;
15046 }
15047
15048 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15049 {
15050         alc_automute_amp(codec);
15051         alc861vd_lenovo_mic_automute(codec);
15052 }
15053
15054 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15055                                         unsigned int res)
15056 {
15057         switch (res >> 26) {
15058         case ALC880_MIC_EVENT:
15059                 alc861vd_lenovo_mic_automute(codec);
15060                 break;
15061         default:
15062                 alc_automute_amp_unsol_event(codec, res);
15063                 break;
15064         }
15065 }
15066
15067 static struct hda_verb alc861vd_dallas_verbs[] = {
15068         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15069         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15070         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15071         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15072
15073         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15075         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15076         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15077         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15078         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15079         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15080         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15081
15082         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15083         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15084         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15085         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15086         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15087         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15088         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15089         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15090
15091         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15092         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15093         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15094         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15095         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15096         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15097         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15098         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15099
15100         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15104
15105         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15106         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15107         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15108
15109         { } /* end */
15110 };
15111
15112 /* toggle speaker-output according to the hp-jack state */
15113 static void alc861vd_dallas_setup(struct hda_codec *codec)
15114 {
15115         struct alc_spec *spec = codec->spec;
15116
15117         spec->autocfg.hp_pins[0] = 0x15;
15118         spec->autocfg.speaker_pins[0] = 0x14;
15119 }
15120
15121 #ifdef CONFIG_SND_HDA_POWER_SAVE
15122 #define alc861vd_loopbacks      alc880_loopbacks
15123 #endif
15124
15125 /* pcm configuration: identical with ALC880 */
15126 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15127 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15128 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15129 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15130
15131 /*
15132  * configuration and preset
15133  */
15134 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15135         [ALC660VD_3ST]          = "3stack-660",
15136         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15137         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15138         [ALC861VD_3ST]          = "3stack",
15139         [ALC861VD_3ST_DIG]      = "3stack-digout",
15140         [ALC861VD_6ST_DIG]      = "6stack-digout",
15141         [ALC861VD_LENOVO]       = "lenovo",
15142         [ALC861VD_DALLAS]       = "dallas",
15143         [ALC861VD_HP]           = "hp",
15144         [ALC861VD_AUTO]         = "auto",
15145 };
15146
15147 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15148         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15149         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15150         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15151         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
15152         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15153         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15154         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15155         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15156         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15157         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15158         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15159         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15160         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15161         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15162         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15163         {}
15164 };
15165
15166 static struct alc_config_preset alc861vd_presets[] = {
15167         [ALC660VD_3ST] = {
15168                 .mixers = { alc861vd_3st_mixer },
15169                 .init_verbs = { alc861vd_volume_init_verbs,
15170                                  alc861vd_3stack_init_verbs },
15171                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15172                 .dac_nids = alc660vd_dac_nids,
15173                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15174                 .channel_mode = alc861vd_3stack_2ch_modes,
15175                 .input_mux = &alc861vd_capture_source,
15176         },
15177         [ALC660VD_3ST_DIG] = {
15178                 .mixers = { alc861vd_3st_mixer },
15179                 .init_verbs = { alc861vd_volume_init_verbs,
15180                                  alc861vd_3stack_init_verbs },
15181                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15182                 .dac_nids = alc660vd_dac_nids,
15183                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15184                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15185                 .channel_mode = alc861vd_3stack_2ch_modes,
15186                 .input_mux = &alc861vd_capture_source,
15187         },
15188         [ALC861VD_3ST] = {
15189                 .mixers = { alc861vd_3st_mixer },
15190                 .init_verbs = { alc861vd_volume_init_verbs,
15191                                  alc861vd_3stack_init_verbs },
15192                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15193                 .dac_nids = alc861vd_dac_nids,
15194                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15195                 .channel_mode = alc861vd_3stack_2ch_modes,
15196                 .input_mux = &alc861vd_capture_source,
15197         },
15198         [ALC861VD_3ST_DIG] = {
15199                 .mixers = { alc861vd_3st_mixer },
15200                 .init_verbs = { alc861vd_volume_init_verbs,
15201                                  alc861vd_3stack_init_verbs },
15202                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15203                 .dac_nids = alc861vd_dac_nids,
15204                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15205                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15206                 .channel_mode = alc861vd_3stack_2ch_modes,
15207                 .input_mux = &alc861vd_capture_source,
15208         },
15209         [ALC861VD_6ST_DIG] = {
15210                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15211                 .init_verbs = { alc861vd_volume_init_verbs,
15212                                 alc861vd_6stack_init_verbs },
15213                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15214                 .dac_nids = alc861vd_dac_nids,
15215                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15216                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15217                 .channel_mode = alc861vd_6stack_modes,
15218                 .input_mux = &alc861vd_capture_source,
15219         },
15220         [ALC861VD_LENOVO] = {
15221                 .mixers = { alc861vd_lenovo_mixer },
15222                 .init_verbs = { alc861vd_volume_init_verbs,
15223                                 alc861vd_3stack_init_verbs,
15224                                 alc861vd_eapd_verbs,
15225                                 alc861vd_lenovo_unsol_verbs },
15226                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15227                 .dac_nids = alc660vd_dac_nids,
15228                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15229                 .channel_mode = alc861vd_3stack_2ch_modes,
15230                 .input_mux = &alc861vd_capture_source,
15231                 .unsol_event = alc861vd_lenovo_unsol_event,
15232                 .setup = alc861vd_lenovo_setup,
15233                 .init_hook = alc861vd_lenovo_init_hook,
15234         },
15235         [ALC861VD_DALLAS] = {
15236                 .mixers = { alc861vd_dallas_mixer },
15237                 .init_verbs = { alc861vd_dallas_verbs },
15238                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15239                 .dac_nids = alc861vd_dac_nids,
15240                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15241                 .channel_mode = alc861vd_3stack_2ch_modes,
15242                 .input_mux = &alc861vd_dallas_capture_source,
15243                 .unsol_event = alc_automute_amp_unsol_event,
15244                 .setup = alc861vd_dallas_setup,
15245                 .init_hook = alc_automute_amp,
15246         },
15247         [ALC861VD_HP] = {
15248                 .mixers = { alc861vd_hp_mixer },
15249                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15250                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15251                 .dac_nids = alc861vd_dac_nids,
15252                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15253                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15254                 .channel_mode = alc861vd_3stack_2ch_modes,
15255                 .input_mux = &alc861vd_hp_capture_source,
15256                 .unsol_event = alc_automute_amp_unsol_event,
15257                 .setup = alc861vd_dallas_setup,
15258                 .init_hook = alc_automute_amp,
15259         },
15260         [ALC660VD_ASUS_V1S] = {
15261                 .mixers = { alc861vd_lenovo_mixer },
15262                 .init_verbs = { alc861vd_volume_init_verbs,
15263                                 alc861vd_3stack_init_verbs,
15264                                 alc861vd_eapd_verbs,
15265                                 alc861vd_lenovo_unsol_verbs },
15266                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15267                 .dac_nids = alc660vd_dac_nids,
15268                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15269                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15270                 .channel_mode = alc861vd_3stack_2ch_modes,
15271                 .input_mux = &alc861vd_capture_source,
15272                 .unsol_event = alc861vd_lenovo_unsol_event,
15273                 .setup = alc861vd_lenovo_setup,
15274                 .init_hook = alc861vd_lenovo_init_hook,
15275         },
15276 };
15277
15278 /*
15279  * BIOS auto configuration
15280  */
15281 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
15282                                                 const struct auto_pin_cfg *cfg)
15283 {
15284         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
15285 }
15286
15287
15288 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15289                                 hda_nid_t nid, int pin_type, int dac_idx)
15290 {
15291         alc_set_pin_output(codec, nid, pin_type);
15292 }
15293
15294 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15295 {
15296         struct alc_spec *spec = codec->spec;
15297         int i;
15298
15299         for (i = 0; i <= HDA_SIDE; i++) {
15300                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15301                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15302                 if (nid)
15303                         alc861vd_auto_set_output_and_unmute(codec, nid,
15304                                                             pin_type, i);
15305         }
15306 }
15307
15308
15309 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15310 {
15311         struct alc_spec *spec = codec->spec;
15312         hda_nid_t pin;
15313
15314         pin = spec->autocfg.hp_pins[0];
15315         if (pin) /* connect to front and use dac 0 */
15316                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15317         pin = spec->autocfg.speaker_pins[0];
15318         if (pin)
15319                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15320 }
15321
15322 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15323
15324 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15325 {
15326         struct alc_spec *spec = codec->spec;
15327         int i;
15328
15329         for (i = 0; i < AUTO_PIN_LAST; i++) {
15330                 hda_nid_t nid = spec->autocfg.input_pins[i];
15331                 if (alc_is_input_pin(codec, nid)) {
15332                         alc_set_input_pin(codec, nid, i);
15333                         if (nid != ALC861VD_PIN_CD_NID &&
15334                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15335                                 snd_hda_codec_write(codec, nid, 0,
15336                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15337                                                 AMP_OUT_MUTE);
15338                 }
15339         }
15340 }
15341
15342 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15343
15344 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15345 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15346
15347 /* add playback controls from the parsed DAC table */
15348 /* Based on ALC880 version. But ALC861VD has separate,
15349  * different NIDs for mute/unmute switch and volume control */
15350 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15351                                              const struct auto_pin_cfg *cfg)
15352 {
15353         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15354         hda_nid_t nid_v, nid_s;
15355         int i, err;
15356
15357         for (i = 0; i < cfg->line_outs; i++) {
15358                 if (!spec->multiout.dac_nids[i])
15359                         continue;
15360                 nid_v = alc861vd_idx_to_mixer_vol(
15361                                 alc880_dac_to_idx(
15362                                         spec->multiout.dac_nids[i]));
15363                 nid_s = alc861vd_idx_to_mixer_switch(
15364                                 alc880_dac_to_idx(
15365                                         spec->multiout.dac_nids[i]));
15366
15367                 if (i == 2) {
15368                         /* Center/LFE */
15369                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15370                                               "Center",
15371                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15372                                                               HDA_OUTPUT));
15373                         if (err < 0)
15374                                 return err;
15375                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15376                                               "LFE",
15377                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15378                                                               HDA_OUTPUT));
15379                         if (err < 0)
15380                                 return err;
15381                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15382                                              "Center",
15383                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15384                                                               HDA_INPUT));
15385                         if (err < 0)
15386                                 return err;
15387                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15388                                              "LFE",
15389                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15390                                                               HDA_INPUT));
15391                         if (err < 0)
15392                                 return err;
15393                 } else {
15394                         const char *pfx;
15395                         if (cfg->line_outs == 1 &&
15396                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
15397                                 if (!cfg->hp_pins)
15398                                         pfx = "Speaker";
15399                                 else
15400                                         pfx = "PCM";
15401                         } else
15402                                 pfx = chname[i];
15403                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15404                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15405                                                               HDA_OUTPUT));
15406                         if (err < 0)
15407                                 return err;
15408                         if (cfg->line_outs == 1 &&
15409                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15410                                 pfx = "Speaker";
15411                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15412                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15413                                                               HDA_INPUT));
15414                         if (err < 0)
15415                                 return err;
15416                 }
15417         }
15418         return 0;
15419 }
15420
15421 /* add playback controls for speaker and HP outputs */
15422 /* Based on ALC880 version. But ALC861VD has separate,
15423  * different NIDs for mute/unmute switch and volume control */
15424 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15425                                         hda_nid_t pin, const char *pfx)
15426 {
15427         hda_nid_t nid_v, nid_s;
15428         int err;
15429
15430         if (!pin)
15431                 return 0;
15432
15433         if (alc880_is_fixed_pin(pin)) {
15434                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15435                 /* specify the DAC as the extra output */
15436                 if (!spec->multiout.hp_nid)
15437                         spec->multiout.hp_nid = nid_v;
15438                 else
15439                         spec->multiout.extra_out_nid[0] = nid_v;
15440                 /* control HP volume/switch on the output mixer amp */
15441                 nid_v = alc861vd_idx_to_mixer_vol(
15442                                 alc880_fixed_pin_idx(pin));
15443                 nid_s = alc861vd_idx_to_mixer_switch(
15444                                 alc880_fixed_pin_idx(pin));
15445
15446                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15447                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15448                 if (err < 0)
15449                         return err;
15450                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15451                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15452                 if (err < 0)
15453                         return err;
15454         } else if (alc880_is_multi_pin(pin)) {
15455                 /* set manual connection */
15456                 /* we have only a switch on HP-out PIN */
15457                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15458                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15459                 if (err < 0)
15460                         return err;
15461         }
15462         return 0;
15463 }
15464
15465 /* parse the BIOS configuration and set up the alc_spec
15466  * return 1 if successful, 0 if the proper config is not found,
15467  * or a negative error code
15468  * Based on ALC880 version - had to change it to override
15469  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15470 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15471 {
15472         struct alc_spec *spec = codec->spec;
15473         int err;
15474         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15475
15476         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15477                                            alc861vd_ignore);
15478         if (err < 0)
15479                 return err;
15480         if (!spec->autocfg.line_outs)
15481                 return 0; /* can't find valid BIOS pin config */
15482
15483         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15484         if (err < 0)
15485                 return err;
15486         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15487         if (err < 0)
15488                 return err;
15489         err = alc861vd_auto_create_extra_out(spec,
15490                                              spec->autocfg.speaker_pins[0],
15491                                              "Speaker");
15492         if (err < 0)
15493                 return err;
15494         err = alc861vd_auto_create_extra_out(spec,
15495                                              spec->autocfg.hp_pins[0],
15496                                              "Headphone");
15497         if (err < 0)
15498                 return err;
15499         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15500         if (err < 0)
15501                 return err;
15502
15503         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15504
15505         if (spec->autocfg.dig_outs)
15506                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15507
15508         if (spec->kctls.list)
15509                 add_mixer(spec, spec->kctls.list);
15510
15511         add_verb(spec, alc861vd_volume_init_verbs);
15512
15513         spec->num_mux_defs = 1;
15514         spec->input_mux = &spec->private_imux[0];
15515
15516         err = alc_auto_add_mic_boost(codec);
15517         if (err < 0)
15518                 return err;
15519
15520         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15521
15522         return 1;
15523 }
15524
15525 /* additional initialization for auto-configuration model */
15526 static void alc861vd_auto_init(struct hda_codec *codec)
15527 {
15528         struct alc_spec *spec = codec->spec;
15529         alc861vd_auto_init_multi_out(codec);
15530         alc861vd_auto_init_hp_out(codec);
15531         alc861vd_auto_init_analog_input(codec);
15532         alc861vd_auto_init_input_src(codec);
15533         if (spec->unsol_event)
15534                 alc_inithook(codec);
15535 }
15536
15537 static int patch_alc861vd(struct hda_codec *codec)
15538 {
15539         struct alc_spec *spec;
15540         int err, board_config;
15541
15542         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15543         if (spec == NULL)
15544                 return -ENOMEM;
15545
15546         codec->spec = spec;
15547
15548         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15549                                                   alc861vd_models,
15550                                                   alc861vd_cfg_tbl);
15551
15552         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15553                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15554                        codec->chip_name);
15555                 board_config = ALC861VD_AUTO;
15556         }
15557
15558         if (board_config == ALC861VD_AUTO) {
15559                 /* automatic parse from the BIOS config */
15560                 err = alc861vd_parse_auto_config(codec);
15561                 if (err < 0) {
15562                         alc_free(codec);
15563                         return err;
15564                 } else if (!err) {
15565                         printk(KERN_INFO
15566                                "hda_codec: Cannot set up configuration "
15567                                "from BIOS.  Using base mode...\n");
15568                         board_config = ALC861VD_3ST;
15569                 }
15570         }
15571
15572         err = snd_hda_attach_beep_device(codec, 0x23);
15573         if (err < 0) {
15574                 alc_free(codec);
15575                 return err;
15576         }
15577
15578         if (board_config != ALC861VD_AUTO)
15579                 setup_preset(codec, &alc861vd_presets[board_config]);
15580
15581         if (codec->vendor_id == 0x10ec0660) {
15582                 /* always turn on EAPD */
15583                 add_verb(spec, alc660vd_eapd_verbs);
15584         }
15585
15586         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15587         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15588
15589         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15590         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15591
15592         if (!spec->adc_nids) {
15593                 spec->adc_nids = alc861vd_adc_nids;
15594                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15595         }
15596         if (!spec->capsrc_nids)
15597                 spec->capsrc_nids = alc861vd_capsrc_nids;
15598
15599         set_capture_mixer(codec);
15600         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15601
15602         spec->vmaster_nid = 0x02;
15603
15604         codec->patch_ops = alc_patch_ops;
15605
15606         if (board_config == ALC861VD_AUTO)
15607                 spec->init_hook = alc861vd_auto_init;
15608 #ifdef CONFIG_SND_HDA_POWER_SAVE
15609         if (!spec->loopback.amplist)
15610                 spec->loopback.amplist = alc861vd_loopbacks;
15611 #endif
15612         codec->proc_widget_hook = print_realtek_coef;
15613
15614         return 0;
15615 }
15616
15617 /*
15618  * ALC662 support
15619  *
15620  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15621  * configuration.  Each pin widget can choose any input DACs and a mixer.
15622  * Each ADC is connected from a mixer of all inputs.  This makes possible
15623  * 6-channel independent captures.
15624  *
15625  * In addition, an independent DAC for the multi-playback (not used in this
15626  * driver yet).
15627  */
15628 #define ALC662_DIGOUT_NID       0x06
15629 #define ALC662_DIGIN_NID        0x0a
15630
15631 static hda_nid_t alc662_dac_nids[4] = {
15632         /* front, rear, clfe, rear_surr */
15633         0x02, 0x03, 0x04
15634 };
15635
15636 static hda_nid_t alc272_dac_nids[2] = {
15637         0x02, 0x03
15638 };
15639
15640 static hda_nid_t alc662_adc_nids[2] = {
15641         /* ADC1-2 */
15642         0x09, 0x08
15643 };
15644
15645 static hda_nid_t alc272_adc_nids[1] = {
15646         /* ADC1-2 */
15647         0x08,
15648 };
15649
15650 static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15651 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15652
15653
15654 /* input MUX */
15655 /* FIXME: should be a matrix-type input source selection */
15656 static struct hda_input_mux alc662_capture_source = {
15657         .num_items = 4,
15658         .items = {
15659                 { "Mic", 0x0 },
15660                 { "Front Mic", 0x1 },
15661                 { "Line", 0x2 },
15662                 { "CD", 0x4 },
15663         },
15664 };
15665
15666 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15667         .num_items = 2,
15668         .items = {
15669                 { "Mic", 0x1 },
15670                 { "Line", 0x2 },
15671         },
15672 };
15673
15674 static struct hda_input_mux alc663_capture_source = {
15675         .num_items = 3,
15676         .items = {
15677                 { "Mic", 0x0 },
15678                 { "Front Mic", 0x1 },
15679                 { "Line", 0x2 },
15680         },
15681 };
15682
15683 #if 0 /* set to 1 for testing other input sources below */
15684 static struct hda_input_mux alc272_nc10_capture_source = {
15685         .num_items = 16,
15686         .items = {
15687                 { "Autoselect Mic", 0x0 },
15688                 { "Internal Mic", 0x1 },
15689                 { "In-0x02", 0x2 },
15690                 { "In-0x03", 0x3 },
15691                 { "In-0x04", 0x4 },
15692                 { "In-0x05", 0x5 },
15693                 { "In-0x06", 0x6 },
15694                 { "In-0x07", 0x7 },
15695                 { "In-0x08", 0x8 },
15696                 { "In-0x09", 0x9 },
15697                 { "In-0x0a", 0x0a },
15698                 { "In-0x0b", 0x0b },
15699                 { "In-0x0c", 0x0c },
15700                 { "In-0x0d", 0x0d },
15701                 { "In-0x0e", 0x0e },
15702                 { "In-0x0f", 0x0f },
15703         },
15704 };
15705 #endif
15706
15707 /*
15708  * 2ch mode
15709  */
15710 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15711         { 2, NULL }
15712 };
15713
15714 /*
15715  * 2ch mode
15716  */
15717 static struct hda_verb alc662_3ST_ch2_init[] = {
15718         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15719         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15720         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15721         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15722         { } /* end */
15723 };
15724
15725 /*
15726  * 6ch mode
15727  */
15728 static struct hda_verb alc662_3ST_ch6_init[] = {
15729         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15730         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15731         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15732         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15733         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15734         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15735         { } /* end */
15736 };
15737
15738 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15739         { 2, alc662_3ST_ch2_init },
15740         { 6, alc662_3ST_ch6_init },
15741 };
15742
15743 /*
15744  * 2ch mode
15745  */
15746 static struct hda_verb alc662_sixstack_ch6_init[] = {
15747         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15748         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15749         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15750         { } /* end */
15751 };
15752
15753 /*
15754  * 6ch mode
15755  */
15756 static struct hda_verb alc662_sixstack_ch8_init[] = {
15757         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15758         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15759         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15760         { } /* end */
15761 };
15762
15763 static struct hda_channel_mode alc662_5stack_modes[2] = {
15764         { 2, alc662_sixstack_ch6_init },
15765         { 6, alc662_sixstack_ch8_init },
15766 };
15767
15768 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15769  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15770  */
15771
15772 static struct snd_kcontrol_new alc662_base_mixer[] = {
15773         /* output mixer control */
15774         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15775         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15776         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15777         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15778         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15779         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15780         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15781         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15782         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15783
15784         /*Input mixer control */
15785         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15786         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15787         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15788         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15789         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15790         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15791         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15792         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15793         { } /* end */
15794 };
15795
15796 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15797         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15798         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15799         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15800         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15801         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15802         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15803         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15805         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15806         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15807         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15808         { } /* end */
15809 };
15810
15811 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15812         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15813         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15814         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15815         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15816         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15817         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15818         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15819         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15820         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15821         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15822         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15823         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15824         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15825         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15826         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15827         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15828         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15829         { } /* end */
15830 };
15831
15832 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15833         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15834         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15835         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15836         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15837         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15838         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15839         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15840         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15841         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15842         { } /* end */
15843 };
15844
15845 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15846         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15847         ALC262_HIPPO_MASTER_SWITCH,
15848
15849         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15850         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15851         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15852
15853         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15854         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15855         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15856         { } /* end */
15857 };
15858
15859 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15860         ALC262_HIPPO_MASTER_SWITCH,
15861         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15862         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15863         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15864         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15865         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15866         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15867         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15868         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15869         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15870         { } /* end */
15871 };
15872
15873 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15874         .ops = &snd_hda_bind_vol,
15875         .values = {
15876                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15877                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15878                 0
15879         },
15880 };
15881
15882 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15883         .ops = &snd_hda_bind_sw,
15884         .values = {
15885                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15886                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15887                 0
15888         },
15889 };
15890
15891 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15892         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15893         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15894         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15895         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15896         { } /* end */
15897 };
15898
15899 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15900         .ops = &snd_hda_bind_sw,
15901         .values = {
15902                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15903                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15904                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15905                 0
15906         },
15907 };
15908
15909 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15910         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15911         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15912         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15913         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15914         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15915         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15916
15917         { } /* end */
15918 };
15919
15920 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15921         .ops = &snd_hda_bind_sw,
15922         .values = {
15923                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15924                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15925                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15926                 0
15927         },
15928 };
15929
15930 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15931         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15932         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15933         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15934         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15935         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15936         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15937         { } /* end */
15938 };
15939
15940 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15941         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15942         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15943         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15944         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15945         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15946         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15947         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15948         { } /* end */
15949 };
15950
15951 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15952         .ops = &snd_hda_bind_vol,
15953         .values = {
15954                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15955                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15956                 0
15957         },
15958 };
15959
15960 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15961         .ops = &snd_hda_bind_sw,
15962         .values = {
15963                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15964                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15965                 0
15966         },
15967 };
15968
15969 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15970         HDA_BIND_VOL("Master Playback Volume",
15971                                 &alc663_asus_two_bind_master_vol),
15972         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15973         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15974         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15975         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15976         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15977         { } /* end */
15978 };
15979
15980 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15981         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15982         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15983         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15984         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15985         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15986         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15987         { } /* end */
15988 };
15989
15990 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15991         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15992         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15993         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15994         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15995         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15996
15997         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15998         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15999         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16000         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16001         { } /* end */
16002 };
16003
16004 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16005         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16006         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16007         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16008
16009         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16010         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16011         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16012         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16013         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16014         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16015         { } /* end */
16016 };
16017
16018 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16019         {
16020                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16021                 .name = "Channel Mode",
16022                 .info = alc_ch_mode_info,
16023                 .get = alc_ch_mode_get,
16024                 .put = alc_ch_mode_put,
16025         },
16026         { } /* end */
16027 };
16028
16029 static struct hda_verb alc662_init_verbs[] = {
16030         /* ADC: mute amp left and right */
16031         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16032         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16033         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16034
16035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16036         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16038         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16040
16041         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16042         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16043         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16044         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16045         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16046         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16047
16048         /* Front Pin: output 0 (0x0c) */
16049         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16050         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16051
16052         /* Rear Pin: output 1 (0x0d) */
16053         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16054         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16055
16056         /* CLFE Pin: output 2 (0x0e) */
16057         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16058         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16059
16060         /* Mic (rear) pin: input vref at 80% */
16061         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16062         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16063         /* Front Mic pin: input vref at 80% */
16064         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16065         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16066         /* Line In pin: input */
16067         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16068         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16069         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16070         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16071         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16072         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16073         /* CD pin widget for input */
16074         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16075
16076         /* FIXME: use matrix-type input source selection */
16077         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16078         /* Input mixer */
16079         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16080         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16081
16082         /* always trun on EAPD */
16083         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16084         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16085
16086         { }
16087 };
16088
16089 static struct hda_verb alc662_sue_init_verbs[] = {
16090         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16091         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16092         {}
16093 };
16094
16095 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16096         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16097         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16098         {}
16099 };
16100
16101 /* Set Unsolicited Event*/
16102 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16103         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16104         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16105         {}
16106 };
16107
16108 /*
16109  * generic initialization of ADC, input mixers and output mixers
16110  */
16111 static struct hda_verb alc662_auto_init_verbs[] = {
16112         /*
16113          * Unmute ADC and set the default input to mic-in
16114          */
16115         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16116         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16117
16118         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16119          * mixer widget
16120          * Note: PASD motherboards uses the Line In 2 as the input for front
16121          * panel mic (mic 2)
16122          */
16123         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16124         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16125         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16126         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16129
16130         /*
16131          * Set up output mixers (0x0c - 0x0f)
16132          */
16133         /* set vol=0 to output mixers */
16134         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16135         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16136         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16137
16138         /* set up input amps for analog loopback */
16139         /* Amp Indices: DAC = 0, mixer = 1 */
16140         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16141         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16142         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16143         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16144         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16145         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16146
16147
16148         /* FIXME: use matrix-type input source selection */
16149         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16150         /* Input mixer */
16151         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16152         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16153         { }
16154 };
16155
16156 /* additional verbs for ALC663 */
16157 static struct hda_verb alc663_auto_init_verbs[] = {
16158         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16159         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16160         { }
16161 };
16162
16163 static struct hda_verb alc663_m51va_init_verbs[] = {
16164         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16165         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16166         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16167         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16168         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16169         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16170         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16171         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16172         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16173         {}
16174 };
16175
16176 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16177         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16178         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16179         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16180         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16181         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16182         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16183         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16184         {}
16185 };
16186
16187 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16188         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16189         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16190         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16191         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16192         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16193         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16194         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16195         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16196         {}
16197 };
16198
16199 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16200         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16201         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16202         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16205         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16206         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16207         {}
16208 };
16209
16210 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16211         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16212         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16213         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16214         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16215         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16216         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16217         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16218         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16219         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16220         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16221         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16222         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16223         {}
16224 };
16225
16226 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16227         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16228         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16229         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16230         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16231         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16232         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16233         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16234         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16235         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16236         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16237         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16238         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16239         {}
16240 };
16241
16242 static struct hda_verb alc663_g71v_init_verbs[] = {
16243         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16244         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16245         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16246
16247         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16248         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16249         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16250
16251         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16252         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16253         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16254         {}
16255 };
16256
16257 static struct hda_verb alc663_g50v_init_verbs[] = {
16258         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16259         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16260         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16261
16262         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16263         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16264         {}
16265 };
16266
16267 static struct hda_verb alc662_ecs_init_verbs[] = {
16268         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16269         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16270         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16271         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16272         {}
16273 };
16274
16275 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16276         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16277         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16278         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16279         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16280         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16281         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16282         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16283         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16284         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16285         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16286         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16287         {}
16288 };
16289
16290 static struct hda_verb alc272_dell_init_verbs[] = {
16291         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16292         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16293         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16294         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16295         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16296         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16297         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16298         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16300         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16301         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16302         {}
16303 };
16304
16305 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16306         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16307         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16308         { } /* end */
16309 };
16310
16311 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16312         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16313         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16314         { } /* end */
16315 };
16316
16317 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16318 {
16319         unsigned int present;
16320         unsigned char bits;
16321
16322         present = snd_hda_codec_read(codec, 0x14, 0,
16323                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16324         bits = present ? HDA_AMP_MUTE : 0;
16325         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16326                                  HDA_AMP_MUTE, bits);
16327 }
16328
16329 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16330 {
16331         unsigned int present;
16332         unsigned char bits;
16333
16334         present = snd_hda_codec_read(codec, 0x1b, 0,
16335                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16336         bits = present ? HDA_AMP_MUTE : 0;
16337         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16338                                  HDA_AMP_MUTE, bits);
16339         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16340                                  HDA_AMP_MUTE, bits);
16341 }
16342
16343 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16344                                            unsigned int res)
16345 {
16346         if ((res >> 26) == ALC880_HP_EVENT)
16347                 alc662_lenovo_101e_all_automute(codec);
16348         if ((res >> 26) == ALC880_FRONT_EVENT)
16349                 alc662_lenovo_101e_ispeaker_automute(codec);
16350 }
16351
16352 /* unsolicited event for HP jack sensing */
16353 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16354                                      unsigned int res)
16355 {
16356         if ((res >> 26) == ALC880_MIC_EVENT)
16357                 alc_mic_automute(codec);
16358         else
16359                 alc262_hippo_unsol_event(codec, res);
16360 }
16361
16362 static void alc662_eeepc_setup(struct hda_codec *codec)
16363 {
16364         struct alc_spec *spec = codec->spec;
16365
16366         alc262_hippo1_setup(codec);
16367         spec->ext_mic.pin = 0x18;
16368         spec->ext_mic.mux_idx = 0;
16369         spec->int_mic.pin = 0x19;
16370         spec->int_mic.mux_idx = 1;
16371         spec->auto_mic = 1;
16372 }
16373
16374 static void alc662_eeepc_inithook(struct hda_codec *codec)
16375 {
16376         alc262_hippo_automute(codec);
16377         alc_mic_automute(codec);
16378 }
16379
16380 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16381 {
16382         struct alc_spec *spec = codec->spec;
16383
16384         spec->autocfg.hp_pins[0] = 0x14;
16385         spec->autocfg.speaker_pins[0] = 0x1b;
16386 }
16387
16388 #define alc662_eeepc_ep20_inithook      alc262_hippo_master_update
16389
16390 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16391 {
16392         unsigned int present;
16393         unsigned char bits;
16394
16395         present = snd_hda_codec_read(codec, 0x21, 0,
16396                         AC_VERB_GET_PIN_SENSE, 0)
16397                         & AC_PINSENSE_PRESENCE;
16398         bits = present ? HDA_AMP_MUTE : 0;
16399         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16400                                 AMP_IN_MUTE(0), bits);
16401         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16402                                 AMP_IN_MUTE(0), bits);
16403 }
16404
16405 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16406 {
16407         unsigned int present;
16408         unsigned char bits;
16409
16410         present = snd_hda_codec_read(codec, 0x21, 0,
16411                         AC_VERB_GET_PIN_SENSE, 0)
16412                         & AC_PINSENSE_PRESENCE;
16413         bits = present ? HDA_AMP_MUTE : 0;
16414         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16415                                 AMP_IN_MUTE(0), bits);
16416         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16417                                 AMP_IN_MUTE(0), bits);
16418         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16419                                 AMP_IN_MUTE(0), bits);
16420         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16421                                 AMP_IN_MUTE(0), bits);
16422 }
16423
16424 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16425 {
16426         unsigned int present;
16427         unsigned char bits;
16428
16429         present = snd_hda_codec_read(codec, 0x15, 0,
16430                         AC_VERB_GET_PIN_SENSE, 0)
16431                         & AC_PINSENSE_PRESENCE;
16432         bits = present ? HDA_AMP_MUTE : 0;
16433         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16434                                 AMP_IN_MUTE(0), bits);
16435         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16436                                 AMP_IN_MUTE(0), bits);
16437         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16438                                 AMP_IN_MUTE(0), bits);
16439         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16440                                 AMP_IN_MUTE(0), bits);
16441 }
16442
16443 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16444 {
16445         unsigned int present;
16446         unsigned char bits;
16447
16448         present = snd_hda_codec_read(codec, 0x1b, 0,
16449                         AC_VERB_GET_PIN_SENSE, 0)
16450                         & AC_PINSENSE_PRESENCE;
16451         bits = present ? 0 : PIN_OUT;
16452         snd_hda_codec_write(codec, 0x14, 0,
16453                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16454 }
16455
16456 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16457 {
16458         unsigned int present1, present2;
16459
16460         present1 = snd_hda_codec_read(codec, 0x21, 0,
16461                         AC_VERB_GET_PIN_SENSE, 0)
16462                         & AC_PINSENSE_PRESENCE;
16463         present2 = snd_hda_codec_read(codec, 0x15, 0,
16464                         AC_VERB_GET_PIN_SENSE, 0)
16465                         & AC_PINSENSE_PRESENCE;
16466
16467         if (present1 || present2) {
16468                 snd_hda_codec_write_cache(codec, 0x14, 0,
16469                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16470         } else {
16471                 snd_hda_codec_write_cache(codec, 0x14, 0,
16472                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16473         }
16474 }
16475
16476 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16477 {
16478         unsigned int present1, present2;
16479
16480         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16481                                 AC_VERB_GET_PIN_SENSE, 0)
16482                                 & AC_PINSENSE_PRESENCE;
16483         present2 = snd_hda_codec_read(codec, 0x15, 0,
16484                                 AC_VERB_GET_PIN_SENSE, 0)
16485                                 & AC_PINSENSE_PRESENCE;
16486
16487         if (present1 || present2) {
16488                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16489                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16490                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16491                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16492         } else {
16493                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16494                                 AMP_IN_MUTE(0), 0);
16495                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16496                                 AMP_IN_MUTE(0), 0);
16497         }
16498 }
16499
16500 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16501                                            unsigned int res)
16502 {
16503         switch (res >> 26) {
16504         case ALC880_HP_EVENT:
16505                 alc663_m51va_speaker_automute(codec);
16506                 break;
16507         case ALC880_MIC_EVENT:
16508                 alc_mic_automute(codec);
16509                 break;
16510         }
16511 }
16512
16513 static void alc663_m51va_setup(struct hda_codec *codec)
16514 {
16515         struct alc_spec *spec = codec->spec;
16516         spec->ext_mic.pin = 0x18;
16517         spec->ext_mic.mux_idx = 0;
16518         spec->int_mic.pin = 0x12;
16519         spec->int_mic.mux_idx = 1;
16520         spec->auto_mic = 1;
16521 }
16522
16523 static void alc663_m51va_inithook(struct hda_codec *codec)
16524 {
16525         alc663_m51va_speaker_automute(codec);
16526         alc_mic_automute(codec);
16527 }
16528
16529 /* ***************** Mode1 ******************************/
16530 #define alc663_mode1_unsol_event        alc663_m51va_unsol_event
16531 #define alc663_mode1_setup              alc663_m51va_setup
16532 #define alc663_mode1_inithook           alc663_m51va_inithook
16533
16534 /* ***************** Mode2 ******************************/
16535 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16536                                            unsigned int res)
16537 {
16538         switch (res >> 26) {
16539         case ALC880_HP_EVENT:
16540                 alc662_f5z_speaker_automute(codec);
16541                 break;
16542         case ALC880_MIC_EVENT:
16543                 alc_mic_automute(codec);
16544                 break;
16545         }
16546 }
16547
16548 #define alc662_mode2_setup      alc663_m51va_setup
16549
16550 static void alc662_mode2_inithook(struct hda_codec *codec)
16551 {
16552         alc662_f5z_speaker_automute(codec);
16553         alc_mic_automute(codec);
16554 }
16555 /* ***************** Mode3 ******************************/
16556 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16557                                            unsigned int res)
16558 {
16559         switch (res >> 26) {
16560         case ALC880_HP_EVENT:
16561                 alc663_two_hp_m1_speaker_automute(codec);
16562                 break;
16563         case ALC880_MIC_EVENT:
16564                 alc_mic_automute(codec);
16565                 break;
16566         }
16567 }
16568
16569 #define alc663_mode3_setup      alc663_m51va_setup
16570
16571 static void alc663_mode3_inithook(struct hda_codec *codec)
16572 {
16573         alc663_two_hp_m1_speaker_automute(codec);
16574         alc_mic_automute(codec);
16575 }
16576 /* ***************** Mode4 ******************************/
16577 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16578                                            unsigned int res)
16579 {
16580         switch (res >> 26) {
16581         case ALC880_HP_EVENT:
16582                 alc663_21jd_two_speaker_automute(codec);
16583                 break;
16584         case ALC880_MIC_EVENT:
16585                 alc_mic_automute(codec);
16586                 break;
16587         }
16588 }
16589
16590 #define alc663_mode4_setup      alc663_m51va_setup
16591
16592 static void alc663_mode4_inithook(struct hda_codec *codec)
16593 {
16594         alc663_21jd_two_speaker_automute(codec);
16595         alc_mic_automute(codec);
16596 }
16597 /* ***************** Mode5 ******************************/
16598 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16599                                            unsigned int res)
16600 {
16601         switch (res >> 26) {
16602         case ALC880_HP_EVENT:
16603                 alc663_15jd_two_speaker_automute(codec);
16604                 break;
16605         case ALC880_MIC_EVENT:
16606                 alc_mic_automute(codec);
16607                 break;
16608         }
16609 }
16610
16611 #define alc663_mode5_setup      alc663_m51va_setup
16612
16613 static void alc663_mode5_inithook(struct hda_codec *codec)
16614 {
16615         alc663_15jd_two_speaker_automute(codec);
16616         alc_mic_automute(codec);
16617 }
16618 /* ***************** Mode6 ******************************/
16619 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16620                                            unsigned int res)
16621 {
16622         switch (res >> 26) {
16623         case ALC880_HP_EVENT:
16624                 alc663_two_hp_m2_speaker_automute(codec);
16625                 break;
16626         case ALC880_MIC_EVENT:
16627                 alc_mic_automute(codec);
16628                 break;
16629         }
16630 }
16631
16632 #define alc663_mode6_setup      alc663_m51va_setup
16633
16634 static void alc663_mode6_inithook(struct hda_codec *codec)
16635 {
16636         alc663_two_hp_m2_speaker_automute(codec);
16637         alc_mic_automute(codec);
16638 }
16639
16640 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16641 {
16642         unsigned int present;
16643         unsigned char bits;
16644
16645         present = snd_hda_codec_read(codec, 0x21, 0,
16646                                      AC_VERB_GET_PIN_SENSE, 0)
16647                 & AC_PINSENSE_PRESENCE;
16648         bits = present ? HDA_AMP_MUTE : 0;
16649         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16650                                  HDA_AMP_MUTE, bits);
16651         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16652                                  HDA_AMP_MUTE, bits);
16653 }
16654
16655 static void alc663_g71v_front_automute(struct hda_codec *codec)
16656 {
16657         unsigned int present;
16658         unsigned char bits;
16659
16660         present = snd_hda_codec_read(codec, 0x15, 0,
16661                                      AC_VERB_GET_PIN_SENSE, 0)
16662                 & AC_PINSENSE_PRESENCE;
16663         bits = present ? HDA_AMP_MUTE : 0;
16664         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16665                                  HDA_AMP_MUTE, bits);
16666 }
16667
16668 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16669                                            unsigned int res)
16670 {
16671         switch (res >> 26) {
16672         case ALC880_HP_EVENT:
16673                 alc663_g71v_hp_automute(codec);
16674                 break;
16675         case ALC880_FRONT_EVENT:
16676                 alc663_g71v_front_automute(codec);
16677                 break;
16678         case ALC880_MIC_EVENT:
16679                 alc_mic_automute(codec);
16680                 break;
16681         }
16682 }
16683
16684 #define alc663_g71v_setup       alc663_m51va_setup
16685
16686 static void alc663_g71v_inithook(struct hda_codec *codec)
16687 {
16688         alc663_g71v_front_automute(codec);
16689         alc663_g71v_hp_automute(codec);
16690         alc_mic_automute(codec);
16691 }
16692
16693 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16694                                            unsigned int res)
16695 {
16696         switch (res >> 26) {
16697         case ALC880_HP_EVENT:
16698                 alc663_m51va_speaker_automute(codec);
16699                 break;
16700         case ALC880_MIC_EVENT:
16701                 alc_mic_automute(codec);
16702                 break;
16703         }
16704 }
16705
16706 #define alc663_g50v_setup       alc663_m51va_setup
16707
16708 static void alc663_g50v_inithook(struct hda_codec *codec)
16709 {
16710         alc663_m51va_speaker_automute(codec);
16711         alc_mic_automute(codec);
16712 }
16713
16714 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16715         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16716         ALC262_HIPPO_MASTER_SWITCH,
16717
16718         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16719         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16720         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16721
16722         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16723         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16724         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16725         { } /* end */
16726 };
16727
16728 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16729         /* Master Playback automatically created from Speaker and Headphone */
16730         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16731         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16732         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16733         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16734
16735         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16736         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16737         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16738
16739         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16740         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16741         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16742         { } /* end */
16743 };
16744
16745 #ifdef CONFIG_SND_HDA_POWER_SAVE
16746 #define alc662_loopbacks        alc880_loopbacks
16747 #endif
16748
16749
16750 /* pcm configuration: identical with ALC880 */
16751 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16752 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16753 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16754 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16755
16756 /*
16757  * configuration and preset
16758  */
16759 static const char *alc662_models[ALC662_MODEL_LAST] = {
16760         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16761         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16762         [ALC662_3ST_6ch]        = "3stack-6ch",
16763         [ALC662_5ST_DIG]        = "6stack-dig",
16764         [ALC662_LENOVO_101E]    = "lenovo-101e",
16765         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16766         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16767         [ALC662_ECS] = "ecs",
16768         [ALC663_ASUS_M51VA] = "m51va",
16769         [ALC663_ASUS_G71V] = "g71v",
16770         [ALC663_ASUS_H13] = "h13",
16771         [ALC663_ASUS_G50V] = "g50v",
16772         [ALC663_ASUS_MODE1] = "asus-mode1",
16773         [ALC662_ASUS_MODE2] = "asus-mode2",
16774         [ALC663_ASUS_MODE3] = "asus-mode3",
16775         [ALC663_ASUS_MODE4] = "asus-mode4",
16776         [ALC663_ASUS_MODE5] = "asus-mode5",
16777         [ALC663_ASUS_MODE6] = "asus-mode6",
16778         [ALC272_DELL]           = "dell",
16779         [ALC272_DELL_ZM1]       = "dell-zm1",
16780         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16781         [ALC662_AUTO]           = "auto",
16782 };
16783
16784 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16785         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16786         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16787         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16788         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16789         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16790         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16791         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16792         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16793         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16794         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16795         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16796         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16797         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16798         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16799         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16800         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16801         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16802         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16803         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16804         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16805         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16806         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16807         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16808         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16809         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16810         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16811         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16812         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16813         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16814         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16815         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16816         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16817         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16818         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16819         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16820         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16821         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16822         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16823         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16824         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16825         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16826         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16827         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16828         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16829         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16830         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16831         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16832         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16833         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16834         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16835         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16836         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16837                       ALC662_3ST_6ch_DIG),
16838         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4),
16839         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16840         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16841                       ALC662_3ST_6ch_DIG),
16842         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16843         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16844         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16845         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16846                                         ALC662_3ST_6ch_DIG),
16847         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16848                            ALC663_ASUS_H13),
16849         {}
16850 };
16851
16852 static struct alc_config_preset alc662_presets[] = {
16853         [ALC662_3ST_2ch_DIG] = {
16854                 .mixers = { alc662_3ST_2ch_mixer },
16855                 .init_verbs = { alc662_init_verbs },
16856                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16857                 .dac_nids = alc662_dac_nids,
16858                 .dig_out_nid = ALC662_DIGOUT_NID,
16859                 .dig_in_nid = ALC662_DIGIN_NID,
16860                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16861                 .channel_mode = alc662_3ST_2ch_modes,
16862                 .input_mux = &alc662_capture_source,
16863         },
16864         [ALC662_3ST_6ch_DIG] = {
16865                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16866                 .init_verbs = { alc662_init_verbs },
16867                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16868                 .dac_nids = alc662_dac_nids,
16869                 .dig_out_nid = ALC662_DIGOUT_NID,
16870                 .dig_in_nid = ALC662_DIGIN_NID,
16871                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16872                 .channel_mode = alc662_3ST_6ch_modes,
16873                 .need_dac_fix = 1,
16874                 .input_mux = &alc662_capture_source,
16875         },
16876         [ALC662_3ST_6ch] = {
16877                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16878                 .init_verbs = { alc662_init_verbs },
16879                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16880                 .dac_nids = alc662_dac_nids,
16881                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16882                 .channel_mode = alc662_3ST_6ch_modes,
16883                 .need_dac_fix = 1,
16884                 .input_mux = &alc662_capture_source,
16885         },
16886         [ALC662_5ST_DIG] = {
16887                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16888                 .init_verbs = { alc662_init_verbs },
16889                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16890                 .dac_nids = alc662_dac_nids,
16891                 .dig_out_nid = ALC662_DIGOUT_NID,
16892                 .dig_in_nid = ALC662_DIGIN_NID,
16893                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16894                 .channel_mode = alc662_5stack_modes,
16895                 .input_mux = &alc662_capture_source,
16896         },
16897         [ALC662_LENOVO_101E] = {
16898                 .mixers = { alc662_lenovo_101e_mixer },
16899                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16900                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16901                 .dac_nids = alc662_dac_nids,
16902                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16903                 .channel_mode = alc662_3ST_2ch_modes,
16904                 .input_mux = &alc662_lenovo_101e_capture_source,
16905                 .unsol_event = alc662_lenovo_101e_unsol_event,
16906                 .init_hook = alc662_lenovo_101e_all_automute,
16907         },
16908         [ALC662_ASUS_EEEPC_P701] = {
16909                 .mixers = { alc662_eeepc_p701_mixer },
16910                 .init_verbs = { alc662_init_verbs,
16911                                 alc662_eeepc_sue_init_verbs },
16912                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16913                 .dac_nids = alc662_dac_nids,
16914                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16915                 .channel_mode = alc662_3ST_2ch_modes,
16916                 .unsol_event = alc662_eeepc_unsol_event,
16917                 .setup = alc662_eeepc_setup,
16918                 .init_hook = alc662_eeepc_inithook,
16919         },
16920         [ALC662_ASUS_EEEPC_EP20] = {
16921                 .mixers = { alc662_eeepc_ep20_mixer,
16922                             alc662_chmode_mixer },
16923                 .init_verbs = { alc662_init_verbs,
16924                                 alc662_eeepc_ep20_sue_init_verbs },
16925                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16926                 .dac_nids = alc662_dac_nids,
16927                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16928                 .channel_mode = alc662_3ST_6ch_modes,
16929                 .input_mux = &alc662_lenovo_101e_capture_source,
16930                 .unsol_event = alc662_eeepc_unsol_event,
16931                 .setup = alc662_eeepc_ep20_setup,
16932                 .init_hook = alc662_eeepc_ep20_inithook,
16933         },
16934         [ALC662_ECS] = {
16935                 .mixers = { alc662_ecs_mixer },
16936                 .init_verbs = { alc662_init_verbs,
16937                                 alc662_ecs_init_verbs },
16938                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16939                 .dac_nids = alc662_dac_nids,
16940                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16941                 .channel_mode = alc662_3ST_2ch_modes,
16942                 .unsol_event = alc662_eeepc_unsol_event,
16943                 .setup = alc662_eeepc_setup,
16944                 .init_hook = alc662_eeepc_inithook,
16945         },
16946         [ALC663_ASUS_M51VA] = {
16947                 .mixers = { alc663_m51va_mixer },
16948                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16949                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16950                 .dac_nids = alc662_dac_nids,
16951                 .dig_out_nid = ALC662_DIGOUT_NID,
16952                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16953                 .channel_mode = alc662_3ST_2ch_modes,
16954                 .unsol_event = alc663_m51va_unsol_event,
16955                 .setup = alc663_m51va_setup,
16956                 .init_hook = alc663_m51va_inithook,
16957         },
16958         [ALC663_ASUS_G71V] = {
16959                 .mixers = { alc663_g71v_mixer },
16960                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16961                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16962                 .dac_nids = alc662_dac_nids,
16963                 .dig_out_nid = ALC662_DIGOUT_NID,
16964                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16965                 .channel_mode = alc662_3ST_2ch_modes,
16966                 .unsol_event = alc663_g71v_unsol_event,
16967                 .setup = alc663_g71v_setup,
16968                 .init_hook = alc663_g71v_inithook,
16969         },
16970         [ALC663_ASUS_H13] = {
16971                 .mixers = { alc663_m51va_mixer },
16972                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16973                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16974                 .dac_nids = alc662_dac_nids,
16975                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16976                 .channel_mode = alc662_3ST_2ch_modes,
16977                 .unsol_event = alc663_m51va_unsol_event,
16978                 .init_hook = alc663_m51va_inithook,
16979         },
16980         [ALC663_ASUS_G50V] = {
16981                 .mixers = { alc663_g50v_mixer },
16982                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16983                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16984                 .dac_nids = alc662_dac_nids,
16985                 .dig_out_nid = ALC662_DIGOUT_NID,
16986                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16987                 .channel_mode = alc662_3ST_6ch_modes,
16988                 .input_mux = &alc663_capture_source,
16989                 .unsol_event = alc663_g50v_unsol_event,
16990                 .setup = alc663_g50v_setup,
16991                 .init_hook = alc663_g50v_inithook,
16992         },
16993         [ALC663_ASUS_MODE1] = {
16994                 .mixers = { alc663_m51va_mixer },
16995                 .cap_mixer = alc662_auto_capture_mixer,
16996                 .init_verbs = { alc662_init_verbs,
16997                                 alc663_21jd_amic_init_verbs },
16998                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16999                 .hp_nid = 0x03,
17000                 .dac_nids = alc662_dac_nids,
17001                 .dig_out_nid = ALC662_DIGOUT_NID,
17002                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17003                 .channel_mode = alc662_3ST_2ch_modes,
17004                 .unsol_event = alc663_mode1_unsol_event,
17005                 .setup = alc663_mode1_setup,
17006                 .init_hook = alc663_mode1_inithook,
17007         },
17008         [ALC662_ASUS_MODE2] = {
17009                 .mixers = { alc662_1bjd_mixer },
17010                 .cap_mixer = alc662_auto_capture_mixer,
17011                 .init_verbs = { alc662_init_verbs,
17012                                 alc662_1bjd_amic_init_verbs },
17013                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17014                 .dac_nids = alc662_dac_nids,
17015                 .dig_out_nid = ALC662_DIGOUT_NID,
17016                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17017                 .channel_mode = alc662_3ST_2ch_modes,
17018                 .unsol_event = alc662_mode2_unsol_event,
17019                 .setup = alc662_mode2_setup,
17020                 .init_hook = alc662_mode2_inithook,
17021         },
17022         [ALC663_ASUS_MODE3] = {
17023                 .mixers = { alc663_two_hp_m1_mixer },
17024                 .cap_mixer = alc662_auto_capture_mixer,
17025                 .init_verbs = { alc662_init_verbs,
17026                                 alc663_two_hp_amic_m1_init_verbs },
17027                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17028                 .hp_nid = 0x03,
17029                 .dac_nids = alc662_dac_nids,
17030                 .dig_out_nid = ALC662_DIGOUT_NID,
17031                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17032                 .channel_mode = alc662_3ST_2ch_modes,
17033                 .unsol_event = alc663_mode3_unsol_event,
17034                 .setup = alc663_mode3_setup,
17035                 .init_hook = alc663_mode3_inithook,
17036         },
17037         [ALC663_ASUS_MODE4] = {
17038                 .mixers = { alc663_asus_21jd_clfe_mixer },
17039                 .cap_mixer = alc662_auto_capture_mixer,
17040                 .init_verbs = { alc662_init_verbs,
17041                                 alc663_21jd_amic_init_verbs},
17042                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17043                 .hp_nid = 0x03,
17044                 .dac_nids = alc662_dac_nids,
17045                 .dig_out_nid = ALC662_DIGOUT_NID,
17046                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17047                 .channel_mode = alc662_3ST_2ch_modes,
17048                 .unsol_event = alc663_mode4_unsol_event,
17049                 .setup = alc663_mode4_setup,
17050                 .init_hook = alc663_mode4_inithook,
17051         },
17052         [ALC663_ASUS_MODE5] = {
17053                 .mixers = { alc663_asus_15jd_clfe_mixer },
17054                 .cap_mixer = alc662_auto_capture_mixer,
17055                 .init_verbs = { alc662_init_verbs,
17056                                 alc663_15jd_amic_init_verbs },
17057                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17058                 .hp_nid = 0x03,
17059                 .dac_nids = alc662_dac_nids,
17060                 .dig_out_nid = ALC662_DIGOUT_NID,
17061                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17062                 .channel_mode = alc662_3ST_2ch_modes,
17063                 .unsol_event = alc663_mode5_unsol_event,
17064                 .setup = alc663_mode5_setup,
17065                 .init_hook = alc663_mode5_inithook,
17066         },
17067         [ALC663_ASUS_MODE6] = {
17068                 .mixers = { alc663_two_hp_m2_mixer },
17069                 .cap_mixer = alc662_auto_capture_mixer,
17070                 .init_verbs = { alc662_init_verbs,
17071                                 alc663_two_hp_amic_m2_init_verbs },
17072                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17073                 .hp_nid = 0x03,
17074                 .dac_nids = alc662_dac_nids,
17075                 .dig_out_nid = ALC662_DIGOUT_NID,
17076                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17077                 .channel_mode = alc662_3ST_2ch_modes,
17078                 .unsol_event = alc663_mode6_unsol_event,
17079                 .setup = alc663_mode6_setup,
17080                 .init_hook = alc663_mode6_inithook,
17081         },
17082         [ALC272_DELL] = {
17083                 .mixers = { alc663_m51va_mixer },
17084                 .cap_mixer = alc272_auto_capture_mixer,
17085                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17086                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17087                 .dac_nids = alc662_dac_nids,
17088                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17089                 .adc_nids = alc272_adc_nids,
17090                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17091                 .capsrc_nids = alc272_capsrc_nids,
17092                 .channel_mode = alc662_3ST_2ch_modes,
17093                 .unsol_event = alc663_m51va_unsol_event,
17094                 .setup = alc663_m51va_setup,
17095                 .init_hook = alc663_m51va_inithook,
17096         },
17097         [ALC272_DELL_ZM1] = {
17098                 .mixers = { alc663_m51va_mixer },
17099                 .cap_mixer = alc662_auto_capture_mixer,
17100                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17101                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17102                 .dac_nids = alc662_dac_nids,
17103                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17104                 .adc_nids = alc662_adc_nids,
17105                 .num_adc_nids = 1,
17106                 .capsrc_nids = alc662_capsrc_nids,
17107                 .channel_mode = alc662_3ST_2ch_modes,
17108                 .unsol_event = alc663_m51va_unsol_event,
17109                 .setup = alc663_m51va_setup,
17110                 .init_hook = alc663_m51va_inithook,
17111         },
17112         [ALC272_SAMSUNG_NC10] = {
17113                 .mixers = { alc272_nc10_mixer },
17114                 .init_verbs = { alc662_init_verbs,
17115                                 alc663_21jd_amic_init_verbs },
17116                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17117                 .dac_nids = alc272_dac_nids,
17118                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17119                 .channel_mode = alc662_3ST_2ch_modes,
17120                 /*.input_mux = &alc272_nc10_capture_source,*/
17121                 .unsol_event = alc663_mode4_unsol_event,
17122                 .setup = alc663_mode4_setup,
17123                 .init_hook = alc663_mode4_inithook,
17124         },
17125 };
17126
17127
17128 /*
17129  * BIOS auto configuration
17130  */
17131
17132 /* convert from MIX nid to DAC */
17133 static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
17134 {
17135         if (nid == 0x0f)
17136                 return 0x02;
17137         else if (nid >= 0x0c && nid <= 0x0e)
17138                 return nid - 0x0c + 0x02;
17139         else
17140                 return 0;
17141 }
17142
17143 /* get MIX nid connected to the given pin targeted to DAC */
17144 static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
17145                                    hda_nid_t dac)
17146 {
17147         hda_nid_t mix[4];
17148         int i, num;
17149
17150         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
17151         for (i = 0; i < num; i++) {
17152                 if (alc662_mix_to_dac(mix[i]) == dac)
17153                         return mix[i];
17154         }
17155         return 0;
17156 }
17157
17158 /* look for an empty DAC slot */
17159 static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
17160 {
17161         struct alc_spec *spec = codec->spec;
17162         hda_nid_t srcs[5];
17163         int i, j, num;
17164
17165         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
17166         if (num < 0)
17167                 return 0;
17168         for (i = 0; i < num; i++) {
17169                 hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
17170                 if (!nid)
17171                         continue;
17172                 for (j = 0; j < spec->multiout.num_dacs; j++)
17173                         if (spec->multiout.dac_nids[j] == nid)
17174                                 break;
17175                 if (j >= spec->multiout.num_dacs)
17176                         return nid;
17177         }
17178         return 0;
17179 }
17180
17181 /* fill in the dac_nids table from the parsed pin configuration */
17182 static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17183                                      const struct auto_pin_cfg *cfg)
17184 {
17185         struct alc_spec *spec = codec->spec;
17186         int i;
17187         hda_nid_t dac;
17188
17189         spec->multiout.dac_nids = spec->private_dac_nids;
17190         for (i = 0; i < cfg->line_outs; i++) {
17191                 dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
17192                 if (!dac)
17193                         continue;
17194                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
17195         }
17196         return 0;
17197 }
17198
17199 static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17200                               hda_nid_t nid, unsigned int chs)
17201 {
17202         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17203                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17204 }
17205
17206 static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17207                              hda_nid_t nid, unsigned int chs)
17208 {
17209         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17210                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17211 }
17212
17213 #define alc662_add_stereo_vol(spec, pfx, nid) \
17214         alc662_add_vol_ctl(spec, pfx, nid, 3)
17215 #define alc662_add_stereo_sw(spec, pfx, nid) \
17216         alc662_add_sw_ctl(spec, pfx, nid, 3)
17217
17218 /* add playback controls from the parsed DAC table */
17219 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
17220                                              const struct auto_pin_cfg *cfg)
17221 {
17222         struct alc_spec *spec = codec->spec;
17223         static const char *chname[4] = {
17224                 "Front", "Surround", NULL /*CLFE*/, "Side"
17225         };
17226         hda_nid_t nid, mix;
17227         int i, err;
17228
17229         for (i = 0; i < cfg->line_outs; i++) {
17230                 nid = spec->multiout.dac_nids[i];
17231                 if (!nid)
17232                         continue;
17233                 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
17234                 if (!mix)
17235                         continue;
17236                 if (i == 2) {
17237                         /* Center/LFE */
17238                         err = alc662_add_vol_ctl(spec, "Center", nid, 1);
17239                         if (err < 0)
17240                                 return err;
17241                         err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
17242                         if (err < 0)
17243                                 return err;
17244                         err = alc662_add_sw_ctl(spec, "Center", mix, 1);
17245                         if (err < 0)
17246                                 return err;
17247                         err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
17248                         if (err < 0)
17249                                 return err;
17250                 } else {
17251                         const char *pfx;
17252                         if (cfg->line_outs == 1 &&
17253                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17254                                 if (cfg->hp_outs)
17255                                         pfx = "Speaker";
17256                                 else
17257                                         pfx = "PCM";
17258                         } else
17259                                 pfx = chname[i];
17260                         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17261                         if (err < 0)
17262                                 return err;
17263                         if (cfg->line_outs == 1 &&
17264                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17265                                 pfx = "Speaker";
17266                         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17267                         if (err < 0)
17268                                 return err;
17269                 }
17270         }
17271         return 0;
17272 }
17273
17274 /* add playback controls for speaker and HP outputs */
17275 /* return DAC nid if any new DAC is assigned */
17276 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17277                                         const char *pfx)
17278 {
17279         struct alc_spec *spec = codec->spec;
17280         hda_nid_t nid, mix;
17281         int err;
17282
17283         if (!pin)
17284                 return 0;
17285         nid = alc662_look_for_dac(codec, pin);
17286         if (!nid) {
17287                 /* the corresponding DAC is already occupied */
17288                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17289                         return 0; /* no way */
17290                 /* create a switch only */
17291                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17292                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17293         }
17294
17295         mix = alc662_dac_to_mix(codec, pin, nid);
17296         if (!mix)
17297                 return 0;
17298         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17299         if (err < 0)
17300                 return err;
17301         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17302         if (err < 0)
17303                 return err;
17304         return nid;
17305 }
17306
17307 /* create playback/capture controls for input pins */
17308 #define alc662_auto_create_input_ctls \
17309         alc880_auto_create_input_ctls
17310
17311 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17312                                               hda_nid_t nid, int pin_type,
17313                                               hda_nid_t dac)
17314 {
17315         int i, num;
17316         hda_nid_t srcs[4];
17317
17318         alc_set_pin_output(codec, nid, pin_type);
17319         /* need the manual connection? */
17320         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
17321         if (num <= 1)
17322                 return;
17323         for (i = 0; i < num; i++) {
17324                 if (alc662_mix_to_dac(srcs[i]) != dac)
17325                         continue;
17326                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
17327                 return;
17328         }
17329 }
17330
17331 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17332 {
17333         struct alc_spec *spec = codec->spec;
17334         int pin_type = get_pin_type(spec->autocfg.line_out_type);
17335         int i;
17336
17337         for (i = 0; i <= HDA_SIDE; i++) {
17338                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17339                 if (nid)
17340                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17341                                         spec->multiout.dac_nids[i]);
17342         }
17343 }
17344
17345 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17346 {
17347         struct alc_spec *spec = codec->spec;
17348         hda_nid_t pin;
17349
17350         pin = spec->autocfg.hp_pins[0];
17351         if (pin)
17352                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
17353                                                   spec->multiout.hp_nid);
17354         pin = spec->autocfg.speaker_pins[0];
17355         if (pin)
17356                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
17357                                         spec->multiout.extra_out_nid[0]);
17358 }
17359
17360 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17361
17362 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17363 {
17364         struct alc_spec *spec = codec->spec;
17365         int i;
17366
17367         for (i = 0; i < AUTO_PIN_LAST; i++) {
17368                 hda_nid_t nid = spec->autocfg.input_pins[i];
17369                 if (alc_is_input_pin(codec, nid)) {
17370                         alc_set_input_pin(codec, nid, i);
17371                         if (nid != ALC662_PIN_CD_NID &&
17372                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17373                                 snd_hda_codec_write(codec, nid, 0,
17374                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17375                                                     AMP_OUT_MUTE);
17376                 }
17377         }
17378 }
17379
17380 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17381
17382 static int alc662_parse_auto_config(struct hda_codec *codec)
17383 {
17384         struct alc_spec *spec = codec->spec;
17385         int err;
17386         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17387
17388         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17389                                            alc662_ignore);
17390         if (err < 0)
17391                 return err;
17392         if (!spec->autocfg.line_outs)
17393                 return 0; /* can't find valid BIOS pin config */
17394
17395         err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
17396         if (err < 0)
17397                 return err;
17398         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
17399         if (err < 0)
17400                 return err;
17401         err = alc662_auto_create_extra_out(codec,
17402                                            spec->autocfg.speaker_pins[0],
17403                                            "Speaker");
17404         if (err < 0)
17405                 return err;
17406         if (err)
17407                 spec->multiout.extra_out_nid[0] = err;
17408         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
17409                                            "Headphone");
17410         if (err < 0)
17411                 return err;
17412         if (err)
17413                 spec->multiout.hp_nid = err;
17414         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17415         if (err < 0)
17416                 return err;
17417
17418         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17419
17420         if (spec->autocfg.dig_outs)
17421                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17422
17423         if (spec->kctls.list)
17424                 add_mixer(spec, spec->kctls.list);
17425
17426         spec->num_mux_defs = 1;
17427         spec->input_mux = &spec->private_imux[0];
17428
17429         add_verb(spec, alc662_auto_init_verbs);
17430         if (codec->vendor_id == 0x10ec0663)
17431                 add_verb(spec, alc663_auto_init_verbs);
17432
17433         err = alc_auto_add_mic_boost(codec);
17434         if (err < 0)
17435                 return err;
17436
17437         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17438
17439         return 1;
17440 }
17441
17442 /* additional initialization for auto-configuration model */
17443 static void alc662_auto_init(struct hda_codec *codec)
17444 {
17445         struct alc_spec *spec = codec->spec;
17446         alc662_auto_init_multi_out(codec);
17447         alc662_auto_init_hp_out(codec);
17448         alc662_auto_init_analog_input(codec);
17449         alc662_auto_init_input_src(codec);
17450         if (spec->unsol_event)
17451                 alc_inithook(codec);
17452 }
17453
17454 static int patch_alc662(struct hda_codec *codec)
17455 {
17456         struct alc_spec *spec;
17457         int err, board_config;
17458
17459         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17460         if (!spec)
17461                 return -ENOMEM;
17462
17463         codec->spec = spec;
17464
17465         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17466
17467         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17468                                                   alc662_models,
17469                                                   alc662_cfg_tbl);
17470         if (board_config < 0) {
17471                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17472                        codec->chip_name);
17473                 board_config = ALC662_AUTO;
17474         }
17475
17476         if (board_config == ALC662_AUTO) {
17477                 /* automatic parse from the BIOS config */
17478                 err = alc662_parse_auto_config(codec);
17479                 if (err < 0) {
17480                         alc_free(codec);
17481                         return err;
17482                 } else if (!err) {
17483                         printk(KERN_INFO
17484                                "hda_codec: Cannot set up configuration "
17485                                "from BIOS.  Using base mode...\n");
17486                         board_config = ALC662_3ST_2ch_DIG;
17487                 }
17488         }
17489
17490         err = snd_hda_attach_beep_device(codec, 0x1);
17491         if (err < 0) {
17492                 alc_free(codec);
17493                 return err;
17494         }
17495
17496         if (board_config != ALC662_AUTO)
17497                 setup_preset(codec, &alc662_presets[board_config]);
17498
17499         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17500         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17501
17502         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17503         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17504
17505         if (!spec->adc_nids) {
17506                 spec->adc_nids = alc662_adc_nids;
17507                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17508         }
17509         if (!spec->capsrc_nids)
17510                 spec->capsrc_nids = alc662_capsrc_nids;
17511
17512         if (!spec->cap_mixer)
17513                 set_capture_mixer(codec);
17514         if (codec->vendor_id == 0x10ec0662)
17515                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17516         else
17517                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17518
17519         spec->vmaster_nid = 0x02;
17520
17521         codec->patch_ops = alc_patch_ops;
17522         if (board_config == ALC662_AUTO)
17523                 spec->init_hook = alc662_auto_init;
17524 #ifdef CONFIG_SND_HDA_POWER_SAVE
17525         if (!spec->loopback.amplist)
17526                 spec->loopback.amplist = alc662_loopbacks;
17527 #endif
17528         codec->proc_widget_hook = print_realtek_coef;
17529
17530         return 0;
17531 }
17532
17533 /*
17534  * patch entries
17535  */
17536 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17537         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17538         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17539         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17540         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17541         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17542         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17543         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17544           .patch = patch_alc861 },
17545         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17546         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17547         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17548         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17549           .patch = patch_alc882 },
17550         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17551           .patch = patch_alc662 },
17552         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17553         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17554         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17555         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17556         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17557           .patch = patch_alc882 },
17558         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17559           .patch = patch_alc882 },
17560         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17561         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17562         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17563           .patch = patch_alc882 },
17564         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17565         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17566         {} /* terminator */
17567 };
17568
17569 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17570
17571 MODULE_LICENSE("GPL");
17572 MODULE_DESCRIPTION("Realtek HD-audio codec");
17573
17574 static struct hda_codec_preset_list realtek_list = {
17575         .preset = snd_hda_preset_realtek,
17576         .owner = THIS_MODULE,
17577 };
17578
17579 static int __init patch_realtek_init(void)
17580 {
17581         return snd_hda_add_codec_preset(&realtek_list);
17582 }
17583
17584 static void __exit patch_realtek_exit(void)
17585 {
17586         snd_hda_delete_codec_preset(&realtek_list);
17587 }
17588
17589 module_init(patch_realtek_init)
17590 module_exit(patch_realtek_exit)